[KVM-AUTOTEST PATCH] KVM test: when available, use new syntax instead of -tftp, -bootp and -redir

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In new qemu versions the tftp, bootp and redir options may be given as part of
the -net user option.  If the output of 'qemu -help' indicates that this syntax
is acceptable, use it instead of the old one.

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm_vm.py             |   53 +++++++++++++++++++++++++++-----
 client/tests/kvm/tests_base.cfg.sample |   12 +++++--
 2 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 1102f88..603576f 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -241,7 +241,8 @@ class VM:
             return cmd
 
         def add_net(help, vlan, mode, ifname=None, script=None,
-                    downscript=None, netdev_id=None):
+                    downscript=None, tftp=None, bootfile=None, hostfwd=[],
+                    netdev_id=None):
             if has_option(help, "netdev"):
                 cmd = " -netdev %s,id=%s" % (mode, netdev_id)
             else:
@@ -250,16 +251,39 @@ class VM:
                 if ifname: cmd += ",ifname='%s'" % ifname
                 if script: cmd += ",script='%s'" % script
                 cmd += ",downscript='%s'" % (downscript or "no")
+            elif mode == "user":
+                if tftp and "[,tftp=" in help:
+                    cmd += ",tftp='%s'" % tftp
+                if bootfile and "[,bootfile=" in help:
+                    cmd += ",bootfile='%s'" % bootfile
+                if "[,hostfwd=" in help:
+                    for host_port, guest_port in hostfwd:
+                        cmd += ",hostfwd=tcp::%s-:%s" % (host_port, guest_port)
             return cmd
 
         def add_floppy(help, filename):
             return " -fda '%s'" % filename
 
         def add_tftp(help, filename):
-            return " -tftp '%s'" % filename
+            # If the new syntax is supported, don't add -tftp
+            if "[,tftp=" in help:
+                return ""
+            else:
+                return " -tftp '%s'" % filename
+
+        def add_bootp(help, filename):
+            # If the new syntax is supported, don't add -bootp
+            if "[,bootfile=" in help:
+                return ""
+            else:
+                return " -bootp '%s'" % filename
 
         def add_tcp_redir(help, host_port, guest_port):
-            return " -redir tcp:%s::%s" % (host_port, guest_port)
+            # If the new syntax is supported, don't add -redir
+            if "[,hostfwd=" in help:
+                return ""
+            else:
+                return " -redir tcp:%s::%s" % (host_port, guest_port)
 
         def add_vnc(help, vnc_port):
             return " -vnc :%d" % (vnc_port - 5900)
@@ -345,6 +369,13 @@ class VM:
                                   image_params.get("image_snapshot") == "yes",
                                   image_params.get("image_boot") == "yes")
 
+        redirs = []
+        for redir_name in kvm_utils.get_sub_dict_names(params, "redirs"):
+            redir_params = kvm_utils.get_sub_dict(params, redir_name)
+            guest_port = int(redir_params.get("guest_port"))
+            host_port = self.redirs.get(guest_port)
+            redirs += [(host_port, guest_port)]
+
         vlan = 0
         for nic_name in kvm_utils.get_sub_dict_names(params, "nics"):
             nic_params = kvm_utils.get_sub_dict(params, nic_name)
@@ -357,13 +388,18 @@ class VM:
             # Handle the '-net tap' or '-net user' part
             script = nic_params.get("nic_script")
             downscript = nic_params.get("nic_downscript")
+            tftp = nic_params.get("tftp")
             if script:
                 script = kvm_utils.get_path(root_dir, script)
             if downscript:
                 downscript = kvm_utils.get_path(root_dir, downscript)
+            if tftp:
+                tftp = kvm_utils.get_path(root_dir, tftp)
             qemu_cmd += add_net(help, vlan, nic_params.get("nic_mode", "user"),
                                 nic_params.get("nic_ifname"),
-                                script, downscript, self.netdev_id[vlan])
+                                script, downscript, tftp,
+                                nic_params.get("bootp"), redirs,
+                                self.netdev_id[vlan])
             # Proceed to next NIC
             vlan += 1
 
@@ -400,6 +436,10 @@ class VM:
             tftp = kvm_utils.get_path(root_dir, tftp)
             qemu_cmd += add_tftp(help, tftp)
 
+        bootp = params.get("bootp")
+        if bootp:
+            qemu_cmd += add_bootp(help, bootp)
+
         kernel = params.get("kernel")
         if kernel:
             kernel = kvm_utils.get_path(root_dir, kernel)
@@ -414,10 +454,7 @@ class VM:
             initrd = kvm_utils.get_path(root_dir, initrd)
             qemu_cmd += add_initrd(help, initrd)
 
-        for redir_name in kvm_utils.get_sub_dict_names(params, "redirs"):
-            redir_params = kvm_utils.get_sub_dict(params, redir_name)
-            guest_port = int(redir_params.get("guest_port"))
-            host_port = self.redirs.get(guest_port)
+        for host_port, guest_port in redirs:
             qemu_cmd += add_tcp_redir(help, host_port, guest_port)
 
         if params.get("display") == "vnc":
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index 62936d4..c2def29 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -526,7 +526,8 @@ variants:
                     pxe_image = "vmlinuz"
                     pxe_initrd = "initrd.img"
                     tftp = "images/tftpboot"
-                    extra_params += " -bootp /pxelinux.0 -boot cn"
+                    bootp = "/pxelinux.0"
+                    extra_params += " -boot cn"
                     kernel_args = "ks=floppy nicdelay=60 console=ttyS0,115200 console=tty0"
 
                 variants:
@@ -687,7 +688,8 @@ variants:
                     pxe_image = "linux"
                     pxe_initrd = "initrd"
                     tftp = "images/tftpboot"
-                    extra_params += " -bootp /pxelinux.0 -boot cn"
+                    bootp = "/pxelinux.0"
+                    extra_params += " -boot cn"
                     kernel_args = "autoyast=floppy console=ttyS0,115200 console=tty0"
                     post_install_delay = 10
 
@@ -769,7 +771,8 @@ variants:
                 unattended_install.cdrom:
                     pxe_image = "linux"
                     pxe_initrd = "initrd"
-                    extra_params += " -bootp /pxelinux.0 -boot cn"
+                    bootp = "/pxelinux.0"
+                    extra_params += " -boot cn"
                     kernel_args = "autoyast=floppy console=ttyS0,115200 console=tty0"
                     post_install_delay = 10
 
@@ -861,7 +864,8 @@ variants:
                     pxe_image = "vmlinuz"
                     pxe_initrd = "initrd.img"
                     tftp = "images/tftpboot"
-                    extra_params += " -bootp /pxelinux.0 -boot cn"
+                    bootp = "/pxelinux.0"
+                    extra_params += " -boot cn"
                     kernel_args = "ks=floppy nicdelay=60 console=ttyS0,115200 console=tty0"
 
                 variants:
-- 
1.5.4.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux