node_check fails to evaluate down hypervisors

Change-Id: Id5c4406cb953c999fcc9cd96e8083a1c418b239b
This commit is contained in:
Sawan Choudhary 2020-06-07 23:46:21 -07:00 committed by Sawan Choudhary
parent ace2c424f1
commit e63302c863
1 changed files with 22 additions and 26 deletions

View File

@ -373,48 +373,44 @@ class operator_scenario(base.Scenario):
@base.scenario(admin_only=False, operator=True)
def node_check(self):
failed_hosts = None
failed_hosts = []
self.load()
nodes_from_ansible_config = [node.name.lower()
for node in
nodes_from_ansible_config = [node.name for node in
self.os_node_info_obj.get_host_list()
if "compute" in node.role.split()]
nova_hypervisor_list = self._get_nova_hypervior_list()
if nova_hypervisor_list[0] != 200:
return (404, ("Cannot get hypervisor list from "
"Nova reason-%sa") % nova_hypervisor_list[1])
nodes_from_nova = [node.lower() for node in nova_hypervisor_list[2]]
extra_nodes_nova = set(
nodes_from_nova) - set(nodes_from_ansible_config)
extra_nodes_ansible = set(
nodes_from_ansible_config) - set(nodes_from_nova)
if extra_nodes_nova:
return (404, ("Hypervisors in nova hypervisor list are more"
" than configured.nova hypervisor list = %s") %
nodes_from_nova)
if extra_nodes_ansible:
return (404, ("Hypervisors in nova hypervisor list are less"
" than configured.nova hypervisor list = %s") %
nodes_from_nova)
nodes_from_nova = [node for node in nova_hypervisor_list[2]]
anscmd = ("ansible -o all -i '%s' -m ping -u root" %
','.join(nova_hypervisor_list[2]))
','.join(nodes_from_ansible_config))
res = execute(anscmd)
res['output'] = res['output'].split('\n')
output = filter(lambda x: not re.match(r'^\s*$', x), res['output'])
for line in output:
if "SUCCESS" not in line:
failed_hosts = failed_hosts + line.split('|')[0]
failed_hosts.append(line.split('|')[0].strip())
if not res['status']:
return (200, "All nodes are up.nova hypervisor list = %s" %
nodes_from_nova)
# Check if ansible ping cmd failed with reason other than unreachable
# nodes
if res['status'] and not failed_hosts:
return (404, "Unable to perform ping test on nodes, ansible cmd: "
"'%s' failed" % anscmd)
# Check if nova also recognizes that passed nodes were up
nova_failed_hosts = [node for node in nodes_from_ansible_config if
node not in nodes_from_nova]
failed_hosts = list(set(nova_failed_hosts + failed_hosts))
if not failed_hosts:
return (200, "All nodes are up. nova hypervisor list = %s" %
', '.join(nodes_from_nova))
else:
msg = "Some nodes are not up"
if failed_hosts:
msg = ("The following nodes are not up: %s."
"nova hypervisor list = %s" %
(str(failed_hosts[0]), nodes_from_nova))
msg = ("The following nodes are down: %s. nova hypervisor list = "
"%s" % (', '.join(failed_hosts),
', '.join(nodes_from_nova)))
return (404, msg)
@base.scenario(admin_only=False, operator=True)