diff mbox

[Autotest,3/5] virt: Adds functionality for vms.

Message ID 1348219888-23436-4-git-send-email-jzupka@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jiri Zupka Sept. 21, 2012, 9:31 a.m. UTC
Allow creating of machine with tap devices which are not
connected to bridge.
Add function for fill virtnet object with address.

Signed-off-by: Ji?í Župka <jzupka@redhat.com>
---
 client/tests/virt/virttest/kvm_vm.py     |    9 +++++----
 client/tests/virt/virttest/utils_misc.py |    3 ++-
 client/tests/virt/virttest/virt_vm.py    |   20 ++++++++++++++++++++
 3 files changed, 27 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/client/tests/virt/virttest/kvm_vm.py b/client/tests/virt/virttest/kvm_vm.py
index 247f0eb..d3b4ede 100644
--- a/client/tests/virt/virttest/kvm_vm.py
+++ b/client/tests/virt/virttest/kvm_vm.py
@@ -949,7 +949,7 @@  class VM(virt_vm.BaseVM):
         qemu_cmd += add_name(hlp, name)
         # no automagic devices please
         defaults = params.get("defaults", "no")
-        if has_option(hlp,"nodefaults") and defaults != "yes":
+        if has_option(hlp, "nodefaults") and defaults != "yes":
             qemu_cmd += " -nodefaults"
         # Add monitors
         for monitor_name in params.objects("monitors"):
@@ -1065,7 +1065,7 @@  class VM(virt_vm.BaseVM):
 
         for nic in vm.virtnet:
             # setup nic parameters as needed
-            nic = vm.add_nic(**dict(nic)) # add_netdev if netdev_id not set
+            nic = vm.add_nic(**dict(nic))   # add_netdev if netdev_id not set
             # gather set values or None if unset
             vlan = int(nic.get('vlan'))
             netdev_id = nic.get('netdev_id')
@@ -2064,7 +2064,7 @@  class VM(virt_vm.BaseVM):
         nic.set_if_none('nettype', 'bridge')
         if nic.nettype == 'bridge': # implies tap
             # destination is required, hard-code reasonable default if unset
-            nic.set_if_none('netdst', 'virbr0')
+            # nic.set_if_none('netdst', 'virbr0')
             # tapfd allocated/set in activate because requires system resources
             nic.set_if_none('tapfd_id', utils_misc.generate_random_id())
         elif nic.nettype == 'user':
@@ -2142,7 +2142,8 @@  class VM(virt_vm.BaseVM):
             error.context("Raising bridge for " + msg_sfx + attach_cmd,
                           logging.debug)
             # assume this will puke if netdst unset
-            utils_misc.add_to_bridge(nic.ifname, nic.netdst)
+            if not nic.netdst is None:
+                utils_misc.add_to_bridge(nic.ifname, nic.netdst)
         elif nic.nettype == 'user':
             attach_cmd += " user,name=%s" % nic.ifname
         else: # unsupported nettype
diff --git a/client/tests/virt/virttest/utils_misc.py b/client/tests/virt/virttest/utils_misc.py
index e416551..b4799e7 100644
--- a/client/tests/virt/virttest/utils_misc.py
+++ b/client/tests/virt/virttest/utils_misc.py
@@ -719,7 +719,8 @@  class VirtIface(PropCan):
     Networking information for single guest interface and host connection.
     """
 
-    __slots__ = ['nic_name', 'mac', 'nic_model', 'ip', 'nettype', 'netdst']
+    __slots__ = ['nic_name', 'g_nic_name', 'mac', 'nic_model', 'ip',
+                 'nettype', 'netdst']
     # Make sure first byte generated is always zero and it follows
     # the class definition.  This helps provide more predictable
     # addressing while avoiding clashes between multiple NICs.
diff --git a/client/tests/virt/virttest/virt_vm.py b/client/tests/virt/virttest/virt_vm.py
index 79dd08b..ff6a0f7 100644
--- a/client/tests/virt/virttest/virt_vm.py
+++ b/client/tests/virt/virttest/virt_vm.py
@@ -518,6 +518,7 @@  class BaseVM(object):
             # Make sure the IP address is assigned to one or more macs
             # for this guest
             macs = self.virtnet.mac_list()
+
             if not utils_misc.verify_ip_address_ownership(arp_ip, macs):
                 raise VMAddressVerificationError(nic.mac, arp_ip)
             logging.debug('Found/Verified IP %s for VM %s NIC %s' % (
@@ -525,6 +526,25 @@  class BaseVM(object):
             return arp_ip
 
 
+    def fill_addrs(self, addrs):
+        """
+        Fill VM's nic address to the virtnet structure based on VM's address
+        structure addrs.
+
+        @param addrs: Dict of interfaces and address
+                        {"if_name":{"mac":['addrs',],
+                                    "ipv4":['addrs',],
+                                    "ipv6":['addrs',]},
+                          ...}
+        """
+        for virtnet in self.virtnet:
+            for iface_name, iface in addrs.iteritems():
+                if virtnet.mac in iface["mac"]:
+                    virtnet.ip = {"ipv4": iface["ipv4"],
+                                  "ipv6": iface["ipv6"]}
+                    virtnet.g_nic_name = iface_name
+
+
     def get_port(self, port, nic_index=0):
         """
         Return the port in host space corresponding to port in guest space.