Without vnc autoport, the vnc port in xml will be specified.
If another vm starts with the same port, the starting will fail.

Signed-off-by: Tang Chen <tanc...@cn.fujitsu.com>
---
 client/virt/base.cfg.sample |    3 +++
 client/virt/libvirt_vm.py   |   24 ++++++++++++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/client/virt/base.cfg.sample b/client/virt/base.cfg.sample
index 03cff78..b017e1b 100644
--- a/client/virt/base.cfg.sample
+++ b/client/virt/base.cfg.sample
@@ -122,6 +122,9 @@ vcpu_thread_pattern = "thread_id=(\d+)"
 # Guest Display type (vnc, sdl, spice, or nographic)
 display = vnc
 
+# VNC autoport selection.
+vnc_autoport = yes
+
 # Guest VGA type (cirrus,  std, vmware, qxl, xenfb, none)
 vga = std
 
diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index d97ac0c..ff7a602 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -485,8 +485,8 @@ class VM(virt_vm.BaseVM):
             self.process = None
             self.serial_console = None
             self.redirs = {}
-            self.vnc_port = 5900
-            self.vnclisten = "0.0.0.0"
+            self.vnc_port = None
+            self.vnc_autoport = True
             self.pci_assignable = None
             self.netdev_id = []
             self.device_id = []
@@ -737,8 +737,11 @@ class VM(virt_vm.BaseVM):
         def add_floppy(help, filename):
             return " --disk path=%s,device=floppy,ro" % filename
 
-        def add_vnc(help, vnc_port):
-            return " --vnc --vncport=%d" % (vnc_port)
+        def add_vnc(help, vnc_port=None):
+            if vnc_port:
+                return " --vnc --vncport=%d" % (vnc_port)
+            else:
+                return " --vnc"
 
         def add_vnclisten(help, vnclisten):
             if has_option(help, "vnclisten"):
@@ -934,7 +937,11 @@ class VM(virt_vm.BaseVM):
             virt_install_cmd += add_location(help, location)
 
         if params.get("display") == "vnc":
-            if params.get("vnc_port"):
+            if params.get("vnc_autoport") == "yes":
+                vm.vnc_autoport = True
+            else:
+                vm.vnc_autoport = False
+            if not vm.vnc_autoport and params.get("vnc_port"):
                 vm.vnc_port = int(params.get("vnc_port"))
             virt_install_cmd += add_vnc(help, vm.vnc_port)
             if params.get("vnclisten"):
@@ -1188,7 +1195,12 @@ class VM(virt_vm.BaseVM):
 
             # Find available VNC port, if needed
             if params.get("display") == "vnc":
-                self.vnc_port = virt_utils.find_free_port(5900, 6100)
+                if params.get("vnc_autoport") == "yes":
+                    self.vnc_port = None
+                    self.vnc_autoport = True
+                else:
+                    self.vnc_port = virt_utils.find_free_port(5900, 6100)
+                    self.vnc_autoport = False
 
             # Find available spice port, if needed
             if params.get("spice"):
-- 
1.7.3.1

-- 
Best Regards,
Tang chen
_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to