diff options
author | Zuul <zuul@review.opendev.org> | 2022-02-09 11:25:42 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-02-09 11:25:42 +0000 |
commit | c56edab96536b641ffcf81f51e3b90647afb76a6 (patch) | |
tree | 106c7f0614b57079e79b699ca1a463f835750db2 | |
parent | 199801fbc578429fc88f3b3d0f796432c152d438 (diff) | |
parent | 1b29c70caac1e2dd4deae28e079352453daa6515 (diff) | |
download | ceilometer-c56edab96536b641ffcf81f51e3b90647afb76a6.tar.gz |
Merge "Support two nova metadata versions in instance XML" into stable/wallaby
-rw-r--r-- | ceilometer/compute/discovery.py | 13 | ||||
-rw-r--r-- | ceilometer/compute/virt/libvirt/utils.py | 34 |
2 files changed, 36 insertions, 11 deletions
diff --git a/ceilometer/compute/discovery.py b/ceilometer/compute/discovery.py index f3133059..01ef1078 100644 --- a/ceilometer/compute/discovery.py +++ b/ceilometer/compute/discovery.py @@ -137,17 +137,8 @@ class InstanceDiscovery(plugin_base.DiscoveryBase): def discover_libvirt_polling(self, manager, param=None): instances = [] for domain in self.connection.listAllDomains(): - try: - xml_string = domain.metadata( - libvirt.VIR_DOMAIN_METADATA_ELEMENT, - "http://openstack.org/xmlns/libvirt/nova/1.0") - except libvirt.libvirtError as e: - if libvirt_utils.is_disconnection_exception(e): - # Re-raise the exception so it's handled and retries - raise - LOG.error( - "Fail to get domain uuid %s metadata, libvirtError: %s", - domain.UUIDString(), e) + xml_string = libvirt_utils.instance_metadata(domain) + if xml_string is None: continue full_xml = etree.fromstring(domain.XMLDesc()) diff --git a/ceilometer/compute/virt/libvirt/utils.py b/ceilometer/compute/virt/libvirt/utils.py index 79684ea3..41a4f977 100644 --- a/ceilometer/compute/virt/libvirt/utils.py +++ b/ceilometer/compute/virt/libvirt/utils.py @@ -78,6 +78,12 @@ LIBVIRT_STATUS = { VIR_DOMAIN_PMSUSPENDED: 'suspended', } +# NOTE(pas-ha) in the order from newest to oldest +NOVA_METADATA_VERSIONS = ( + "http://openstack.org/xmlns/libvirt/nova/1.1", + "http://openstack.org/xmlns/libvirt/nova/1.0", +) + def new_libvirt_connection(conf): if not libvirt: @@ -124,3 +130,31 @@ def raise_nodata_if_unsupported(method): "error": e} raise virt_inspector.NoDataException(msg) return inner + + +@retry_on_disconnect +def instance_metadata(domain): + xml_string = None + last_error = None + for meta_version in NOVA_METADATA_VERSIONS: + try: + xml_string = domain.metadata( + libvirt.VIR_DOMAIN_METADATA_ELEMENT, meta_version) + break + except libvirt.libvirtError as exc: + if exc.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN_METADATA: + LOG.warning("Failed to find metadata %s in domain %s", + meta_version, domain.UUIDString()) + last_error = exc + continue + elif is_disconnection_exception(exc): + # Re-raise the exception so it's handled and retries + raise + last_error = exc + + if xml_string is None: + LOG.error( + "Fail to get domain uuid %s metadata, libvirtError: %s", + domain.UUIDString(), last_error + ) + return xml_string |