Gracefully handle missing metadata in libvirt xml
Missing metadata in the libvirt domain xml for a nova instance would
cause ceilometer-compute to abort, leading to missing metrics for the
current and any subequent libvirt guests.
This commit puts a try/except AttributeError block around all the code
that is fetching attributes on the result of metadata_xml.find(...).
also pull in I41aa76cf9def3e8c4bceef0280d15c1fd7c48e3d
Change-Id: I8adc609cc21c86de2daba326d24b73a80d6eb61f
Closes-Bug: #1749960
(cherry picked from commit d2af7e9ece
)
This commit is contained in:
parent
75181bc803
commit
afaa7f7c8c
|
@ -166,42 +166,55 @@ class InstanceDiscovery(plugin_base.DiscoveryBase):
|
||||||
# flavor. this is why nova doesn't put the id in the libvirt
|
# flavor. this is why nova doesn't put the id in the libvirt
|
||||||
# metadata
|
# metadata
|
||||||
|
|
||||||
# This implements
|
try:
|
||||||
flavor_xml = metadata_xml.find("./flavor")
|
flavor_xml = metadata_xml.find(
|
||||||
flavor = {
|
"./flavor")
|
||||||
"id": self.get_flavor_id(flavor_xml.attrib["name"]),
|
user_id = metadata_xml.find(
|
||||||
"name": flavor_xml.attrib["name"],
|
"./owner/user").attrib["uuid"]
|
||||||
"vcpus": self._safe_find_int(flavor_xml, "vcpus"),
|
project_id = metadata_xml.find(
|
||||||
"ram": self._safe_find_int(flavor_xml, "memory"),
|
"./owner/project").attrib["uuid"]
|
||||||
"disk": self._safe_find_int(flavor_xml, "disk"),
|
instance_name = metadata_xml.find(
|
||||||
"ephemeral": self._safe_find_int(flavor_xml, "ephemeral"),
|
"./name").text
|
||||||
"swap": self._safe_find_int(flavor_xml, "swap"),
|
instance_arch = os_type_xml.attrib["arch"]
|
||||||
}
|
|
||||||
|
flavor = {
|
||||||
|
"id": self.get_flavor_id(flavor_xml.attrib["name"]),
|
||||||
|
"name": flavor_xml.attrib["name"],
|
||||||
|
"vcpus": self._safe_find_int(flavor_xml, "vcpus"),
|
||||||
|
"ram": self._safe_find_int(flavor_xml, "memory"),
|
||||||
|
"disk": self._safe_find_int(flavor_xml, "disk"),
|
||||||
|
"ephemeral": self._safe_find_int(flavor_xml, "ephemeral"),
|
||||||
|
"swap": self._safe_find_int(flavor_xml, "swap"),
|
||||||
|
}
|
||||||
|
|
||||||
|
# The image description is partial, but Gnocchi only care about
|
||||||
|
# the id, so we are fine
|
||||||
|
image_xml = metadata_xml.find("./root[@type='image']")
|
||||||
|
image = ({'id': image_xml.attrib['uuid']}
|
||||||
|
if image_xml is not None else None)
|
||||||
|
except AttributeError:
|
||||||
|
LOG.error(
|
||||||
|
"Fail to get domain uuid %s metadata: "
|
||||||
|
"metadata was missing expected attributes",
|
||||||
|
domain.UUIDString())
|
||||||
|
continue
|
||||||
|
|
||||||
dom_state = domain.state()[0]
|
dom_state = domain.state()[0]
|
||||||
vm_state = libvirt_utils.LIBVIRT_POWER_STATE.get(dom_state)
|
vm_state = libvirt_utils.LIBVIRT_POWER_STATE.get(dom_state)
|
||||||
status = libvirt_utils.LIBVIRT_STATUS.get(dom_state)
|
status = libvirt_utils.LIBVIRT_STATUS.get(dom_state)
|
||||||
|
|
||||||
user_id = metadata_xml.find("./owner/user").attrib["uuid"]
|
|
||||||
project_id = metadata_xml.find("./owner/project").attrib["uuid"]
|
|
||||||
|
|
||||||
# From:
|
# From:
|
||||||
# https://github.com/openstack/nova/blob/852f40fd0c6e9d8878212ff3120556668023f1c4/nova/api/openstack/compute/views/servers.py#L214-L220
|
# https://github.com/openstack/nova/blob/852f40fd0c6e9d8878212ff3120556668023f1c4/nova/api/openstack/compute/views/servers.py#L214-L220
|
||||||
host_id = hashlib.sha224(
|
host_id = hashlib.sha224(
|
||||||
(project_id + self.conf.host).encode('utf-8')).hexdigest()
|
(project_id + self.conf.host).encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
# The image description is partial, but Gnocchi only care about the
|
|
||||||
# id, so we are fine
|
|
||||||
image_xml = metadata_xml.find("./root[@type='image']")
|
|
||||||
image = ({'id': image_xml.attrib['uuid']}
|
|
||||||
if image_xml is not None else None)
|
|
||||||
|
|
||||||
instance_data = {
|
instance_data = {
|
||||||
"id": domain.UUIDString(),
|
"id": domain.UUIDString(),
|
||||||
"name": metadata_xml.find("./name").text,
|
"name": instance_name,
|
||||||
"flavor": flavor,
|
"flavor": flavor,
|
||||||
"image": image,
|
"image": image,
|
||||||
"os_type": os_type_xml.text,
|
"os_type": os_type_xml.text,
|
||||||
"architecture": os_type_xml.attrib["arch"],
|
"architecture": instance_arch,
|
||||||
|
|
||||||
"OS-EXT-SRV-ATTR:instance_name": domain.name(),
|
"OS-EXT-SRV-ATTR:instance_name": domain.name(),
|
||||||
"OS-EXT-SRV-ATTR:host": self.conf.host,
|
"OS-EXT-SRV-ATTR:host": self.conf.host,
|
||||||
|
|
Loading…
Reference in New Issue