Subject: virtinst: Remove only auto-generated channel source path
From: Pavel Hrdina phrdina@redhat.com Thu Jun 28 16:18:43 2018 +0200
Date: Thu Jun 28 16:45:14 2018 +0200:
Git: 931936a328d22413bb663e0e21d2f7bb111dbd7c

In attempt to fix https://bugzilla.redhat.com/show_bug.cgi?id=1270696
this code was introduced but it removes the path for all channel
devices.  We need to limit it only to the devices that have
auto-generated source path.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1591670

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>

Index: virt-manager-1.5.1/tests/clone-xml/channel-source-in.xml
===================================================================
--- /dev/null
+++ virt-manager-1.5.1/tests/clone-xml/channel-source-in.xml
@@ -0,0 +1,35 @@
+<domain type='kvm'>
+  <name>clone-orig</name>
+  <uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid>
+  <memory>262144</memory>
+  <currentMemory>262144</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='cdrom'/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-kvm</emulator>
+    <channel type='unix'>
+      <source mode='bind' path='/tmp/guestfwd'/>
+      <target type='guestfwd' address='10.0.0.1' port='1234'/>
+    </channel>
+    <channel type='unix'>
+      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-2-generic/org.qemu.guest_agent.0'/>
+      <target type='virtio' name='org.qemu.guest_agent.0'/>
+    </channel>
+    <channel type='unix'>
+      <target type='virtio' name='org.qemu.guest_agent.0'/>
+    </channel>
+    <channel type='unix'>
+      <target type='virtio'/>
+    </channel>
+  </devices>
+</domain>
Index: virt-manager-1.5.1/tests/clone-xml/channel-source-out.xml
===================================================================
--- /dev/null
+++ virt-manager-1.5.1/tests/clone-xml/channel-source-out.xml
@@ -0,0 +1,35 @@
+<domain type="kvm">
+  <name>clone-new</name>
+  <uuid>12345678-1234-1234-1234-123456789012</uuid>
+  <memory>262144</memory>
+  <currentMemory>262144</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch="i686" machine="pc">hvm</type>
+    <boot dev="cdrom"/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <clock offset="utc"/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-kvm</emulator>
+    <channel type="unix">
+      <source mode="bind" path="/tmp/guestfwd"/>
+      <target type="guestfwd" address="10.0.0.1" port="1234"/>
+    </channel>
+    <channel type="unix">
+      <source mode="bind"/>
+      <target type="virtio" name="org.qemu.guest_agent.0"/>
+    </channel>
+    <channel type="unix">
+      <target type="virtio" name="org.qemu.guest_agent.0"/>
+    </channel>
+    <channel type="unix">
+      <target type="virtio"/>
+    </channel>
+  </devices>
+</domain>
Index: virt-manager-1.5.1/tests/clonetest.py
===================================================================
--- virt-manager-1.5.1.orig/tests/clonetest.py
+++ virt-manager-1.5.1/tests/clonetest.py
@@ -191,3 +191,7 @@ class TestClone(unittest.TestCase):
     def testCloneGraphicsPassword(self):
         base = "graphics-password"
         self._clone_helper(base)
+
+    def testCloneChannelSource(self):
+        base = "channel-source"
+        self._clone_helper(base)
Index: virt-manager-1.5.1/virtinst/cloner.py
===================================================================
--- virt-manager-1.5.1.orig/virtinst/cloner.py
+++ virt-manager-1.5.1/virtinst/cloner.py
@@ -441,7 +441,9 @@ class Cloner(object):
         # For guest agent channel, remove a path to generate a new one with
         # new guest name
         for channel in self._guest.get_devices("channel"):
-            if channel.type == VirtualChannelDevice.TYPE_UNIX:
+            if (channel.type == VirtualChannelDevice.TYPE_UNIX and
+                channel.target_name and channel.source_path and
+                channel.target_name in channel.source_path):
                 channel.source_path = None
 
         if self._guest.os.nvram:
