Blame SOURCES/virt-manager-cloner-don-t-fail-to-clone-VM-if-nvram-file-doesn-t-exist.patch

3d61c0
From 6d6b0823f64d94726d03880400247ded280c7116 Mon Sep 17 00:00:00 2001
3d61c0
Message-Id: <6d6b0823f64d94726d03880400247ded280c7116@dist-git>
3d61c0
From: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Date: Thu, 28 Mar 2019 14:27:04 +0100
3d61c0
Subject: [PATCH] cloner: don't fail to clone VM if nvram file doesn't exist
3d61c0
3d61c0
If a VM is defined and never started the nvram file might not exist and
3d61c0
in that case it's created by libvirt automatically on the first start.
3d61c0
3d61c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1679018
3d61c0
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
(cherry picked from commit 986097d5f8e7a62d2aa6edd4596302d4e0af4175)
3d61c0
3d61c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1679021
3d61c0
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Reviewed-by: Cole Robinson <crobinso@redhat.com>
3d61c0
---
3d61c0
 tests/clone-xml/nvram-missing-in.xml  | 23 +++++++++++++++++++++++
3d61c0
 tests/clone-xml/nvram-missing-out.xml | 23 +++++++++++++++++++++++
3d61c0
 tests/clonetest.py                    |  3 +++
3d61c0
 virtinst/cloner.py                    | 18 +++++++++---------
3d61c0
 4 files changed, 58 insertions(+), 9 deletions(-)
3d61c0
 create mode 100644 tests/clone-xml/nvram-missing-in.xml
3d61c0
 create mode 100644 tests/clone-xml/nvram-missing-out.xml
3d61c0
3d61c0
diff --git a/tests/clone-xml/nvram-missing-in.xml b/tests/clone-xml/nvram-missing-in.xml
3d61c0
new file mode 100644
3d61c0
index 00000000..fcbce533
3d61c0
--- /dev/null
3d61c0
+++ b/tests/clone-xml/nvram-missing-in.xml
3d61c0
@@ -0,0 +1,23 @@
3d61c0
+<domain type='kvm'>
3d61c0
+  <name>clone-orig</name>
3d61c0
+  <uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid>
3d61c0
+  <memory>262144</memory>
3d61c0
+  <currentMemory>262144</currentMemory>
3d61c0
+  <vcpu>1</vcpu>
3d61c0
+  <os>
3d61c0
+    <type arch='i686' machine='pc'>hvm</type>
3d61c0
+    <boot dev='cdrom'/>
3d61c0
+    <loader readonly='yes' type='pflash'>/usr/share/ovmf/ovmf-efi.fd</loader>
3d61c0
+    <nvram>/nvram/clone-orig-missing_VARS.fd</nvram>
3d61c0
+  </os>
3d61c0
+  <features>
3d61c0
+    <acpi/>
3d61c0
+  </features>
3d61c0
+  <clock offset='utc'/>
3d61c0
+  <on_poweroff>destroy</on_poweroff>
3d61c0
+  <on_reboot>restart</on_reboot>
3d61c0
+  <on_crash>destroy</on_crash>
3d61c0
+  <devices>
3d61c0
+    <emulator>/usr/bin/qemu-kvm</emulator>
3d61c0
+  </devices>
3d61c0
+</domain>
3d61c0
diff --git a/tests/clone-xml/nvram-missing-out.xml b/tests/clone-xml/nvram-missing-out.xml
3d61c0
new file mode 100644
3d61c0
index 00000000..c59eaea8
3d61c0
--- /dev/null
3d61c0
+++ b/tests/clone-xml/nvram-missing-out.xml
3d61c0
@@ -0,0 +1,23 @@
3d61c0
+<domain type="kvm">
3d61c0
+  <name>clone-new</name>
3d61c0
+  <uuid>12345678-1234-1234-1234-123456789012</uuid>
3d61c0
+  <memory>262144</memory>
3d61c0
+  <currentMemory>262144</currentMemory>
3d61c0
+  <vcpu>1</vcpu>
3d61c0
+  <os>
3d61c0
+    <type arch="i686" machine="pc">hvm</type>
3d61c0
+    <boot dev="cdrom"/>
3d61c0
+    <loader readonly="yes" type="pflash">/usr/share/ovmf/ovmf-efi.fd</loader>
3d61c0
+    <nvram>/nvram/clone-new_VARS.fd</nvram>
3d61c0
+  </os>
3d61c0
+  <features>
3d61c0
+    <acpi/>
3d61c0
+  </features>
3d61c0
+  <clock offset="utc"/>
3d61c0
+  <on_poweroff>destroy</on_poweroff>
3d61c0
+  <on_reboot>restart</on_reboot>
3d61c0
+  <on_crash>destroy</on_crash>
3d61c0
+  <devices>
3d61c0
+    <emulator>/usr/bin/qemu-kvm</emulator>
3d61c0
+  </devices>
3d61c0
+</domain>
3d61c0
diff --git a/tests/clonetest.py b/tests/clonetest.py
3d61c0
index 5fd51e73..c09133ca 100644
3d61c0
--- a/tests/clonetest.py
3d61c0
+++ b/tests/clonetest.py
3d61c0
@@ -188,6 +188,9 @@ class TestClone(unittest.TestCase):
3d61c0
         base = "nvram-newpool"
3d61c0
         self._clone_helper(base)
3d61c0
 
3d61c0
+    def testCloneNvramMissing(self):
3d61c0
+        self._clone_helper("nvram-missing")
3d61c0
+
3d61c0
     def testCloneGraphicsPassword(self):
3d61c0
         base = "graphics-password"
3d61c0
         self._clone_helper(base)
3d61c0
diff --git a/virtinst/cloner.py b/virtinst/cloner.py
3d61c0
index 632c3cbf..d54c3f85 100644
3d61c0
--- a/virtinst/cloner.py
3d61c0
+++ b/virtinst/cloner.py
3d61c0
@@ -362,16 +362,15 @@ class Cloner(object):
3d61c0
             self.clone_nvram = os.path.join(nvram_dir,
3d61c0
                                             "%s_VARS.fd" % self._clone_name)
3d61c0
 
3d61c0
+        old_nvram = VirtualDisk(self.conn)
3d61c0
+        old_nvram.path = self._guest.os.nvram
3d61c0
+
3d61c0
         nvram = VirtualDisk(self.conn)
3d61c0
         nvram.path = self.clone_nvram
3d61c0
+
3d61c0
         if (not self.preserve_dest_disks and
3d61c0
-            nvram.wants_storage_creation()):
3d61c0
-
3d61c0
-            old_nvram = VirtualDisk(self.conn)
3d61c0
-            old_nvram.path = self._guest.os.nvram
3d61c0
-            if not old_nvram.get_vol_object():
3d61c0
-                raise RuntimeError(_("Path does not exist: %s") %
3d61c0
-                                     old_nvram.path)
3d61c0
+            nvram.wants_storage_creation() and
3d61c0
+            old_nvram.get_vol_object()):
3d61c0
 
3d61c0
             nvram_install = VirtualDisk.build_vol_install(
3d61c0
                     self.conn, os.path.basename(nvram.path),
3d61c0
@@ -381,8 +380,9 @@ class Cloner(object):
3d61c0
             nvram_install.reflink = self.reflink
3d61c0
             nvram.set_vol_install(nvram_install)
3d61c0
 
3d61c0
-        nvram.validate()
3d61c0
-        self._nvram_disk = nvram
3d61c0
+            nvram.validate()
3d61c0
+            self._nvram_disk = nvram
3d61c0
+
3d61c0
         self._guest.os.nvram = nvram.path
3d61c0
 
3d61c0
 
3d61c0
-- 
3d61c0
2.20.1
3d61c0