Subject: domain: rename: handle firmware ending with .qcow2
From: Cole Robinson crobinso@redhat.com Sat Mar 2 09:25:44 2024 -0500
Date: Sat Mar 2 13:22:37 2024 -0500:
Git: 82f1c4495e96a0afb52471f776fba1c249d75e1c

Newer libvirt + edk2 will default to nvram in qcow2 format, but
our domain rename code had some .fd assumptions baked in.

Adjust uitests to handle it too

Signed-off-by: Cole Robinson <crobinso@redhat.com>

diff --git a/tests/uitests/test_livetests.py b/tests/uitests/test_livetests.py
index 64ff7ad9..a3c8c536 100644
--- a/tests/uitests/test_livetests.py
+++ b/tests/uitests/test_livetests.py
@@ -6,6 +6,7 @@ import os
 import libvirt
 import pytest
 
+import virtinst
 from virtinst import log
 
 import tests
@@ -515,17 +516,20 @@ def testFirmwareRename(app, dom):
     # First we refresh the 'nvram' pool, so we can reliably
     # check if nvram files are created/deleted as expected
     conn = cli.getConnection(app.conn.getURI())
+    guest = virtinst.Guest(conn, dom.XMLDesc(0))
     origname = dom.name()
-    nvramdir = conn.get_libvirt_data_root_dir() + "/qemu/nvram"
+    origpath = guest.os.nvram
+    if not origpath:
+        pytest.skip("libvirt is too old to put nvram path in inactive XML")
+    nvramdir = os.path.dirname(origpath)
 
     fakedisk = DeviceDisk(conn)
     fakedisk.set_source_path(nvramdir + "/FAKE-UITEST-FILE")
     nvram_pool = fakedisk.get_parent_pool()
     nvram_pool.refresh()
 
-    origpath = "%s/%s_VARS.fd" % (nvramdir, origname)
     newname = "uitests-firmware-efi-renamed"
-    newpath = "%s/%s_VARS.fd" % (nvramdir, newname)
+    newpath = origpath.replace(origname + "_VARS", newname + "_VARS")
     assert DeviceDisk.path_definitely_exists(app.conn, origpath)
     assert not DeviceDisk.path_definitely_exists(app.conn, newpath)
 
diff --git a/virtManager/object/domain.py b/virtManager/object/domain.py
index e7dc5035..1989a148 100644
--- a/virtManager/object/domain.py
+++ b/virtManager/object/domain.py
@@ -542,9 +542,9 @@ class vmmDomain(vmmLibvirtObject):
             return None, None
 
         old_nvram_path = self.get_xmlobj().os.nvram
-        if not old_nvram_path:
+        if not old_nvram_path:  # pragma: no cover
             # Probably using firmware=efi which doesn't put nvram
-            # path in the XML. Build the implied path
+            # path in the XML on older libvirt. Build the implied path
             old_nvram_path = os.path.join(
                 self.conn.get_backend().get_libvirt_data_root_dir(),
                 self.conn.get_backend().get_uri_driver(),
@@ -564,10 +564,11 @@ class vmmDomain(vmmLibvirtObject):
         from virtinst import Cloner
         old_nvram = DeviceDisk(self.conn.get_backend())
         old_nvram.set_source_path(old_nvram_path)
+        ext = os.path.splitext(old_nvram_path)[1]
 
         nvram_dir = os.path.dirname(old_nvram.get_source_path())
         new_nvram_path = os.path.join(nvram_dir,
-                "%s_VARS.fd" % os.path.basename(new_name))
+                "%s_VARS%s" % (os.path.basename(new_name), ext or ".fd"))
 
         new_nvram = Cloner.build_clone_disk(
                 old_nvram, new_nvram_path, True, False)