Fix libvirt plugin to handle FQDN of compute node

The change adds simple logic to check the actual name of the compute
node. The list of nova services is filtered with FQDN hostname and if
not successful with unqualified name.

Change-Id: I9ba044f26b53a52afbac0fcd99552a4135cd4725
Story: 2001679
Task: 6785
(cherry picked from commit f3e7ff1450)
This commit is contained in:
Witold Bedyk 2018-03-19 16:08:55 +01:00
parent 0f8ae565bd
commit 0dc7b055a8

View File

@ -82,6 +82,7 @@ class LibvirtCheck(AgentCheck):
self._collect_intervals = {}
self._host_aggregate = None
self._nova_host = None
self._set_collection_intervals('disk', 'disk_collection_period')
self._set_collection_intervals('vnic', 'vnic_collection_period')
@ -136,6 +137,29 @@ class LibvirtCheck(AgentCheck):
[rule['remote_ip_prefix']]))):
return True
def _get_nova_host(self, nova_client):
if not self._nova_host:
# Find `nova-compute` on current node
services = nova_client.services.list(host=self.hostname,
binary='nova-compute')
if not services:
# Catch the case when `nova-compute` is registered with
# unqualified hostname
services = nova_client.services.list(
host=self.hostname.split('.')[0], binary='nova-compute')
if services:
self._nova_host = services[0].host
self.log.info("Found 'nova-compute' registered with host: {}"
.format(self._nova_host))
if self._nova_host:
return self._nova_host
else:
self.log.warn("No 'nova-compute' service found on host: {}"
.format(self.hostname))
# Return hostname as fallback value
return self.hostname
def _update_instance_cache(self):
"""Collect instance_id, project_id, and AZ for all instance UUIDs
"""
@ -155,7 +179,8 @@ class LibvirtCheck(AgentCheck):
client_version=ma_version.version_string)
self._get_this_host_aggregate(nova_client)
instances = nova_client.servers.list(
search_opts={'all_tenants': 1, 'host': self.hostname.split('.')[0]})
search_opts={'all_tenants': 1,
'host': self._get_nova_host(nova_client)})
# Lay the groundwork for fetching VM IPs and network namespaces
if self.init_config.get('ping_check'):
nu = neutron_client.Client(