From fa2516a72d085e7e99119ed9cf1e05b498dfc197 Mon Sep 17 00:00:00 2001 From: Bernhard Turmann Date: Thu, 4 Aug 2022 19:45:22 +0200 Subject: [PATCH] Replace discouraged function listVolumes According to the libvirt storage API reference, the function - listVolumes (virStoragePoolListVolumes) should not be used anymore: "The use of this function is discouraged. Instead, use virStoragePoolListAllVolumes()." Source: https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolListVolumes Compatibility / Risk: The function "virStoragePoolListAllVolumes()" appeared in version 0.10.2 which was released in 2012. It seems rather unlikely that somebody is still using an older unsupported libvirt version, so the risk should be rather low. Source: https://libvirt.org/hvsupport.html#virStorageDriver --- .../fragments/135_virt_pool_replace_function_listVolumes.yml | 2 ++ plugins/modules/virt_pool.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/135_virt_pool_replace_function_listVolumes.yml diff --git a/changelogs/fragments/135_virt_pool_replace_function_listVolumes.yml b/changelogs/fragments/135_virt_pool_replace_function_listVolumes.yml new file mode 100644 index 0000000..f79e66e --- /dev/null +++ b/changelogs/fragments/135_virt_pool_replace_function_listVolumes.yml @@ -0,0 +1,2 @@ +bugfixes: + - virt_pool - replace discouraged function ``listAllVolumes`` with ``listAllVolumes`` to fix potential race conditions (https://github.com/ansible-collections/community.libvirt/pull/135). diff --git a/plugins/modules/virt_pool.py b/plugins/modules/virt_pool.py index aee89a3..98c73cf 100644 --- a/plugins/modules/virt_pool.py +++ b/plugins/modules/virt_pool.py @@ -287,7 +287,7 @@ def get_volume_count(self, entryid): return self.find_entry(entryid).numOfVolumes() def get_volume_names(self, entryid): - return self.find_entry(entryid).listVolumes() + return self.find_entry(entryid).listAllVolumes() def get_devices(self, entryid): xml = etree.fromstring(self.find_entry(entryid).XMLDesc(0)) @@ -497,7 +497,7 @@ def facts(self, facts_mode='facts'): results[entry]["volume_count"] = self.conn.get_volume_count(entry) results[entry]["volumes"] = list() for volume in self.conn.get_volume_names(entry): - results[entry]["volumes"].append(volume) + results[entry]["volumes"].append(volume.name()) else: results[entry]["volume_count"] = -1