Blame SOURCES/virt-manager-graphics-move-all-listen-code-into-one-place.patch

3d61c0
From a9b4c4ca3c11da0ee5a8f5da70ec59f375b7bec6 Mon Sep 17 00:00:00 2001
3d61c0
Message-Id: <a9b4c4ca3c11da0ee5a8f5da70ec59f375b7bec6@dist-git>
3d61c0
From: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Date: Fri, 22 Feb 2019 16:32:39 +0100
3d61c0
Subject: [PATCH] graphics: move all listen code into one place
3d61c0
3d61c0
Instead of duplicating the code into CLI and GUI move it into graphics
3d61c0
device file which is used from both places.  This also fixes a bug in
3d61c0
virt-xml where changing listen to address was not working.
3d61c0
3d61c0
This also changes behavior to always configure one listen type when
3d61c0
using CLI listen option or GUI.  If user wants to modify only specific
3d61c0
listen type they can use listens[] options from CLI.
3d61c0
3d61c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1565968
3d61c0
3d61c0
Reviewed-by: Cole Robinson <crobinso@redhat.com>
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
(cherry picked from commit a0b42327c6bb587c20628f8bc946c6041f61818a)
3d61c0
Reviewed-by: Cole Robinson <crobinso@redhat.com>
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
---
3d61c0
 tests/xmlparse-xml/change-graphics-out.xml |  1 -
3d61c0
 virtManager/addhardware.py                 |  2 +-
3d61c0
 virtManager/domain.py                      | 13 +++++------
3d61c0
 virtinst/cli.py                            | 12 +----------
3d61c0
 virtinst/devicegraphics.py                 | 25 +++++++++++-----------
3d61c0
 5 files changed, 20 insertions(+), 33 deletions(-)
3d61c0
3d61c0
diff --git a/tests/xmlparse-xml/change-graphics-out.xml b/tests/xmlparse-xml/change-graphics-out.xml
3d61c0
index e56cd98c..6cdeb698 100644
3d61c0
--- a/tests/xmlparse-xml/change-graphics-out.xml
3d61c0
+++ b/tests/xmlparse-xml/change-graphics-out.xml
3d61c0
@@ -32,7 +32,6 @@
3d61c0
       <listen type="network" network="mynewnet"/>
3d61c0
     </graphics>
3d61c0
     <graphics type="spice" passwd="newpass" port="6000" tlsPort="6001" listen="1.2.3.4" passwdValidTo="2011-01-07T19:08:00" connected="disconnect" defaultMode="secure">
3d61c0
-      <listen type="address" address="1.2.3.4"/>
3d61c0
       <channel name="inputs" mode="secure"/>
3d61c0
       <channel name="main" mode="any"/>
3d61c0
       <channel name="record" mode="insecure"/>
3d61c0
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
3d61c0
index 863cb3cd..b8543b75 100644
3d61c0
--- a/virtManager/addhardware.py
3d61c0
+++ b/virtManager/addhardware.py
3d61c0
@@ -1568,7 +1568,7 @@ class vmmAddHardware(vmmGObjectUI):
3d61c0
             self._dev.rendernode = rendernode
3d61c0
 
3d61c0
             if not listen or listen == "none":
3d61c0
-                self._dev.set_listen_none()
3d61c0
+                self._dev.listen = "none"
3d61c0
             elif listen == "address":
3d61c0
                 self._dev.listen = addr
3d61c0
                 self._dev.port = port
3d61c0
diff --git a/virtManager/domain.py b/virtManager/domain.py
3d61c0
index 50ccbdb1..3ec99a49 100644
3d61c0
--- a/virtManager/domain.py
3d61c0
+++ b/virtManager/domain.py
3d61c0
@@ -895,8 +895,11 @@ class vmmDomain(vmmLibvirtObject):
3d61c0
         if not editdev:
3d61c0
             return
3d61c0
 
3d61c0
-        if addr != _SENTINEL:
3d61c0
-            editdev.listen = addr
3d61c0
+        if addr != _SENTINEL or listen != _SENTINEL:
3d61c0
+            if listen == "none":
3d61c0
+                editdev.listen = listen
3d61c0
+            else:
3d61c0
+                editdev.listen = addr
3d61c0
         if port != _SENTINEL:
3d61c0
             editdev.port = port
3d61c0
         if tlsport != _SENTINEL:
3d61c0
@@ -911,12 +914,6 @@ class vmmDomain(vmmLibvirtObject):
3d61c0
             editdev.gl = gl
3d61c0
         if rendernode != _SENTINEL:
3d61c0
             editdev.rendernode = rendernode
3d61c0
-        if listen != _SENTINEL:
3d61c0
-            listentype = editdev.get_first_listen_type()
3d61c0
-            if listen == 'none':
3d61c0
-                editdev.set_listen_none()
3d61c0
-            elif listentype and listentype == 'none':
3d61c0
-                editdev.remove_all_listens()
3d61c0
 
3d61c0
         if do_hotplug:
3d61c0
             self.hotplug(device=editdev)
3d61c0
diff --git a/virtinst/cli.py b/virtinst/cli.py
3d61c0
index 7e8ab536..2a736aa9 100644
3d61c0
--- a/virtinst/cli.py
3d61c0
+++ b/virtinst/cli.py
3d61c0
@@ -2296,16 +2296,6 @@ class ParserGraphics(VirtCLIParser):
3d61c0
             return
3d61c0
         inst.type = val
3d61c0
 
3d61c0
-    def set_listen_cb(self, inst, val, virtarg):
3d61c0
-        if val == "none":
3d61c0
-            inst.set_listen_none()
3d61c0
-        elif val == "socket":
3d61c0
-            inst.remove_all_listens()
3d61c0
-            obj = inst.add_listen()
3d61c0
-            obj.type = "socket"
3d61c0
-        else:
3d61c0
-            inst.listen = val
3d61c0
-
3d61c0
     def listens_find_inst_cb(self, *args, **kwargs):
3d61c0
         cliarg = "listens"  # listens[0-9]*
3d61c0
         objpropname = "listens"  # graphics.listens
3d61c0
@@ -2340,7 +2330,7 @@ _add_device_address_args(ParserGraphics)
3d61c0
 ParserGraphics.add_arg(None, "type", cb=ParserGraphics.set_type_cb)
3d61c0
 ParserGraphics.add_arg("port", "port")
3d61c0
 ParserGraphics.add_arg("tlsPort", "tlsport")
3d61c0
-ParserGraphics.add_arg("listen", "listen", cb=ParserGraphics.set_listen_cb)
3d61c0
+ParserGraphics.add_arg("listen", "listen")
3d61c0
 ParserGraphics.add_arg("type", "listens[0-9]*.type",
3d61c0
                        find_inst_cb=ParserGraphics.listens_find_inst_cb)
3d61c0
 ParserGraphics.add_arg("address", "listens[0-9]*.address",
3d61c0
diff --git a/virtinst/devicegraphics.py b/virtinst/devicegraphics.py
3d61c0
index ffba36d9..d0ef6826 100644
3d61c0
--- a/virtinst/devicegraphics.py
3d61c0
+++ b/virtinst/devicegraphics.py
3d61c0
@@ -198,15 +198,16 @@ class VirtualGraphics(VirtualDevice):
3d61c0
 
3d61c0
 
3d61c0
     def _set_listen(self, val):
3d61c0
-        # Update the corresponding <listen> block
3d61c0
-        find_listen = [l for l in self.listens if
3d61c0
-                       (l.type == "address" and l.address == self.listen)]
3d61c0
-        if find_listen:
3d61c0
-            if val is None:
3d61c0
-                self.remove_child(find_listen[0])
3d61c0
-            else:
3d61c0
-                find_listen[0].address = val
3d61c0
-        return val
3d61c0
+        if val == "none":
3d61c0
+            self._set_listen_none()
3d61c0
+        elif val == "socket":
3d61c0
+            self._remove_all_listens()
3d61c0
+            obj = self.add_listen()
3d61c0
+            obj.type = "socket"
3d61c0
+        else:
3d61c0
+            self._remove_all_listens()
3d61c0
+            return val
3d61c0
+        return None
3d61c0
     listen = XMLProperty("./@listen", set_converter=_set_listen)
3d61c0
 
3d61c0
     type = XMLProperty("./@type",
3d61c0
@@ -219,7 +220,7 @@ class VirtualGraphics(VirtualDevice):
3d61c0
     defaultMode = XMLProperty("./@defaultMode")
3d61c0
 
3d61c0
     listens = XMLChildProperty(_GraphicsListen)
3d61c0
-    def remove_all_listens(self):
3d61c0
+    def _remove_all_listens(self):
3d61c0
         for listen in self.listens:
3d61c0
             self.remove_child(listen)
3d61c0
 
3d61c0
@@ -233,8 +234,8 @@ class VirtualGraphics(VirtualDevice):
3d61c0
             return self.listens[0].type
3d61c0
         return None
3d61c0
 
3d61c0
-    def set_listen_none(self):
3d61c0
-        self.remove_all_listens()
3d61c0
+    def _set_listen_none(self):
3d61c0
+        self._remove_all_listens()
3d61c0
         self.listen = None
3d61c0
         self.port = None
3d61c0
         self.tlsPort = None
3d61c0
-- 
3d61c0
2.20.1
3d61c0