[virt-tools-list] [virt-manager PATCH] cloner: don't fail to clone VM if nvram file doesn't exist
Pavel Hrdina
phrdina at redhat.com
Thu Mar 28 15:40:52 UTC 2019
If a VM is defined and never started the nvram file might not exist and
in that case it's created by libvirt automatically on the first start.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1679018
Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
Pushed
tests/clone-xml/nvram-missing-in.xml | 23 +++++++++++++++++++++++
tests/clone-xml/nvram-missing-out.xml | 23 +++++++++++++++++++++++
tests/clonetest.py | 3 +++
virtinst/cloner.py | 18 +++++++++---------
4 files changed, 58 insertions(+), 9 deletions(-)
create mode 100644 tests/clone-xml/nvram-missing-in.xml
create mode 100644 tests/clone-xml/nvram-missing-out.xml
diff --git a/tests/clone-xml/nvram-missing-in.xml b/tests/clone-xml/nvram-missing-in.xml
new file mode 100644
index 00000000..fcbce533
--- /dev/null
+++ b/tests/clone-xml/nvram-missing-in.xml
@@ -0,0 +1,23 @@
+<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'/>
+ <loader readonly='yes' type='pflash'>/usr/share/ovmf/ovmf-efi.fd</loader>
+ <nvram>/nvram/clone-orig-missing_VARS.fd</nvram>
+ </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>
+ </devices>
+</domain>
diff --git a/tests/clone-xml/nvram-missing-out.xml b/tests/clone-xml/nvram-missing-out.xml
new file mode 100644
index 00000000..c59eaea8
--- /dev/null
+++ b/tests/clone-xml/nvram-missing-out.xml
@@ -0,0 +1,23 @@
+<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"/>
+ <loader readonly="yes" type="pflash">/usr/share/ovmf/ovmf-efi.fd</loader>
+ <nvram>/nvram/clone-new_VARS.fd</nvram>
+ </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>
+ </devices>
+</domain>
diff --git a/tests/clonetest.py b/tests/clonetest.py
index 702cbd26..167b822c 100644
--- a/tests/clonetest.py
+++ b/tests/clonetest.py
@@ -162,6 +162,9 @@ class TestClone(unittest.TestCase):
def testCloneNvramNewpool(self):
self._clone("nvram-newpool")
+ def testCloneNvramMissing(self):
+ self._clone("nvram-missing")
+
def testCloneGraphicsPassword(self):
self._clone("graphics-password")
diff --git a/virtinst/cloner.py b/virtinst/cloner.py
index b29027e3..65315b8e 100644
--- a/virtinst/cloner.py
+++ b/virtinst/cloner.py
@@ -346,16 +346,15 @@ class Cloner(object):
self.clone_nvram = os.path.join(nvram_dir,
"%s_VARS.fd" % self._clone_name)
+ old_nvram = DeviceDisk(self.conn)
+ old_nvram.path = self._guest.os.nvram
+
nvram = DeviceDisk(self.conn)
nvram.path = self.clone_nvram
+
if (not self.preserve_dest_disks and
- nvram.wants_storage_creation()):
-
- old_nvram = DeviceDisk(self.conn)
- old_nvram.path = self._guest.os.nvram
- if not old_nvram.get_vol_object():
- raise RuntimeError(_("Path does not exist: %s") %
- old_nvram.path)
+ nvram.wants_storage_creation() and
+ old_nvram.get_vol_object()):
nvram_install = DeviceDisk.build_vol_install(
self.conn, os.path.basename(nvram.path),
@@ -365,8 +364,9 @@ class Cloner(object):
nvram_install.reflink = self.reflink
nvram.set_vol_install(nvram_install)
- nvram.validate()
- self._nvram_disk = nvram
+ nvram.validate()
+ self._nvram_disk = nvram
+
self._guest.os.nvram = nvram.path
--
2.20.1
More information about the virt-tools-list
mailing list