Subject: virt-xml: Handle VM names that look like id/uuid (bz 1679025) From: Cole Robinson crobinso@redhat.com Thu Mar 21 13:34:52 2019 -0400 Date: Thu Mar 21 13:45:58 2019 -0400: Git: 7afbb90b4ddfa449e4efc2d57e726d477f96637b Previously we assume they are id/uuid, so if it's actually the VM name then the command fails. Now we always check for a name first, https://bugzilla.redhat.com/show_bug.cgi?id=1679025 Index: virt-manager-2.1.0/tests/clitest.py =================================================================== --- virt-manager-2.1.0.orig/tests/clitest.py +++ virt-manager-2.1.0/tests/clitest.py @@ -908,8 +908,8 @@ c.add_compare("--build-xml --cpu pentium c.add_compare("--build-xml --tpm /dev/tpm", "build-tpm") c.add_compare("--build-xml --blkiotune weight=100,device_path=/dev/sdf,device_weight=200", "build-blkiotune") c.add_compare("--build-xml --idmap uid_start=0,uid_target=1000,uid_count=10,gid_start=0,gid_target=1000,gid_count=10", "build-idmap") -c.add_compare("test --edit --boot network,cdrom", "edit-bootorder") -c.add_compare("--confirm test --edit --cpu host-passthrough", "prompt-response") +c.add_compare("4a64cc71-19c4-2fd0-2323-3050941ea3c3 --edit --boot network,cdrom", "edit-bootorder") # basic bootorder test, also using UUID lookup +c.add_compare("--confirm 1 --edit --cpu host-passthrough", "prompt-response") # prompt response, also using domid lookup c.add_compare("--edit --print-diff --qemu-commandline clearxml=yes", "edit-clearxml-qemu-commandline", input_file=(XMLDIR + "/virtxml-qemu-commandline-clear.xml")) c.add_compare("--connect %(URI-KVM)s test-hyperv-uefi --edit --boot uefi", "hyperv-uefi-collision") Index: virt-manager-2.1.0/virt-xml =================================================================== --- virt-manager-2.1.0.orig/virt-xml +++ virt-manager-2.1.0/virt-xml @@ -73,12 +73,18 @@ def get_domain_and_guest(conn, domstr): isuuid = bool(re.match(uuidre, domstr)) try: - if isint: - domain = conn.lookupByID(int(domstr)) - elif isuuid: - domain = conn.lookupByUUIDString(domstr) - else: + domain = None + try: domain = conn.lookupByName(domstr) + except Exception: + # Incase the VM has a UUID or ID for a name + logging.debug("Error looking up domain by name", exc_info=True) + if isint: + domain = conn.lookupByID(int(domstr)) + elif isuuid: + domain = conn.lookupByUUIDString(domstr) + else: + raise except libvirt.libvirtError as e: fail(_("Could not find domain '%s': %s") % (domstr, e))