From 794ca7f3e3c38ead9dab55482adf913cca08089c Mon Sep 17 00:00:00 2001 From: maelk Date: Tue, 20 Aug 2019 14:05:11 +0300 Subject: [PATCH] Store virtual media device changes persistently Prior to this patch, ejecting virtual media was not communicated to libvirt effectively leaving virtual media inserted. Also, changing virtual media properties has not been stored persistently in the emulator. Co-Authored-By: Ilya Etingof Change-Id: Ib5505c9a5dbd55bba81bcd6bd5ba315e944e8896 --- sushy_tools/emulator/resources/systems/libvirtdriver.py | 5 +++-- sushy_tools/emulator/resources/vmedia/staticdriver.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sushy_tools/emulator/resources/systems/libvirtdriver.py b/sushy_tools/emulator/resources/systems/libvirtdriver.py index 07b4fd4b..b33ac9d1 100644 --- a/sushy_tools/emulator/resources/systems/libvirtdriver.py +++ b/sushy_tools/emulator/resources/systems/libvirtdriver.py @@ -777,8 +777,6 @@ class LibvirtDriver(AbstractSystemsDriver): if write_protected: ET.SubElement(disk_element, 'readonly') - conn.defineXML(ET.tostring(domain_tree).decode('utf-8')) - def _remove_boot_images(self, domain, domain_tree, device): identity = domain.UUIDString() @@ -841,6 +839,9 @@ class LibvirtDriver(AbstractSystemsDriver): raise error.FishyError(msg) + with libvirt_open(self._uri) as conn: + conn.defineXML(ET.tostring(domain_tree).decode('utf-8')) + def _find_device_by_path(self, vol_path): """Get device attributes using path diff --git a/sushy_tools/emulator/resources/vmedia/staticdriver.py b/sushy_tools/emulator/resources/vmedia/staticdriver.py index 74531f83..f5f5096b 100644 --- a/sushy_tools/emulator/resources/vmedia/staticdriver.py +++ b/sushy_tools/emulator/resources/vmedia/staticdriver.py @@ -200,6 +200,8 @@ class StaticDriver(DriverBase): device_info['WriteProtected'] = write_protected device_info['_local_file_path'] = local_file_path + self._devices.update({(identity, device): device_info}) + return local_file_path def eject_image(self, identity, device): @@ -216,6 +218,8 @@ class StaticDriver(DriverBase): device_info['Inserted'] = False device_info['WriteProtected'] = False + self._devices.update({(identity, device): device_info}) + local_file = device_info.pop('_local_file', None) if local_file: os.unlink(local_file)