diff mbox

[1/2] KVM test: Use -drive to add nic device when possible

Message ID 20100925092207.27856.32816.stgit@dhcp-91-158.nay.redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jason Wang Sept. 25, 2010, 9:22 a.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 135d08e..644903b 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -234,13 +234,26 @@  class VM:
             if boot: cmd += ",boot=on"
             return cmd
 
-        def add_nic(help, vlan, model=None, mac=None, netdev_id=None):
-            if has_option(help, "netdev"):
-                cmd = " -net nic,netdev=%s" % netdev_id
+        def add_nic(help, vlan, model=None, mac=None, netdev_id=None,
+                    nic_extra_params=None):
+            if has_option(help, "device"):
+                if model == "virtio": model="virtio-net-pci"
+                if not model: model= "rtl8139"
+                cmd = " -device %s" % model
+                if mac: cmd += ",mac=%s" % mac
+                if has_option(help, "netdev"):
+                    cmd += ",netdev=%s" % netdev_id
+                else:
+                    cmd += "vlan=%d,"  % vlan
+                if nic_extra_params:
+                    cmd += ",%s" % nic_extra_params
             else:
-                cmd = " -net nic,vlan=%d" % vlan
-            if model: cmd += ",model=%s" % model
-            if mac: cmd += ",macaddr='%s'" % mac
+                if has_option(help, "netdev"):
+                    cmd = " -net nic,netdev=%s" % netdev_id
+                else:
+                    cmd = " -net nic,vlan=%d" % vlan
+                if model: cmd += ",model=%s" % model
+                if mac: cmd += ",macaddr='%s'" % mac
             return cmd
 
         def add_net(help, vlan, mode, ifname=None, script=None,
@@ -388,7 +401,8 @@  class VM:
             if "address_index" in nic_params:
                 mac = kvm_utils.get_mac_ip_pair_from_dict(nic_params)[0]
             qemu_cmd += add_nic(help, vlan, nic_params.get("nic_model"), mac,
-                                self.netdev_id[vlan])
+                                self.netdev_id[vlan],
+                                nic_params.get("nic_extra_params"))
             # Handle the '-net tap' or '-net user' part
             script = nic_params.get("nic_script")
             downscript = nic_params.get("nic_downscript")
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index c8fbf50..89e6f45 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -618,6 +618,8 @@  variants:
         nic_model = e1000
     - virtio_net:
         nic_model = virtio
+        # you can add advanced attributes here
+        # nic_extra_params =
 
 
 # Guests