Catch exception if servers are in error state with no bm_node attached

There have been reports (rhbz#1851507) where generating the fencing
parameters fails because of one or more servers in error state, like
when a scale out operation doesn't go as planned.

This commit wraps get_by_instance_uuid in a try/except block to prevent
this from happening, skipping the node in error state and allowing
users to still get a valid fencing config for the remaining servers.

Note: manually cherry picked skipping the unit tests (conflict vs the
mistral_to_ansible patchset).

Change-Id: I397f8d641504ac2ceed36fa975cf97fac5bbb81a
(cherry picked from commit 7d2c25319b)
This commit is contained in:
Zuul 2020-07-07 10:21:19 +00:00 committed by Luca Miccini
parent 0651b0d931
commit 8806829a62
1 changed files with 11 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import re
from oslo_utils import netutils
import six
from ironicclient import exceptions as ironicexceptions
from oslo_concurrency import processutils
from tripleo_common import exception
from tripleo_common.utils import glance
@ -708,10 +709,16 @@ def generate_hostmap(baremetal_client, compute_client):
"""Create a map between Compute nodes and Baremetal nodes"""
hostmap = {}
for node in compute_client.servers.list():
bm_node = baremetal_client.node.get_by_instance_uuid(node.id)
for port in baremetal_client.port.list(node=bm_node.uuid):
hostmap[port.address] = {"compute_name": node.name,
"baremetal_name": bm_node.name}
try:
bm_node = baremetal_client.node.get_by_instance_uuid(node.id)
for port in baremetal_client.port.list(node=bm_node.uuid):
hostmap[port.address] = {"compute_name": node.name,
"baremetal_name": bm_node.name}
except ironicexceptions.NotFound:
LOG.warning('Baremetal node for server %s not found - skipping it',
node.id)
pass
if hostmap == {}:
return None
else: