Fix placement endpoint check when endpoints are not set

When endpoint are not set in the heat resource, None is returned, not an empty
dict. The check then raises a 'NoneType' is not iterable exception.

Fix the logic to handle None and update the unit test.

Closes-bug: #1913416
Resolves: rhbz#1911653

Change-Id: Iba06dc0f8afe9bc6a8820742c656dca5bf75df15
(cherry picked from commit 86d0e65a29)
This commit is contained in:
Jose Luis Franco Arza 2021-01-27 14:56:21 +01:00 committed by Jesse Pretorius
parent a42a18b271
commit b8e671fe09
2 changed files with 5 additions and 4 deletions

View File

@ -294,16 +294,17 @@ class GeneratePasswordsAction(base.TripleOAction):
except heat_exc.HTTPNotFound:
stack_env = None
placement_extracted = False
try:
# We can't rely on the existence of PlacementPassword to
# determine if placement extraction has occured as it was added
# in stein while the service extraction was delayed to train.
# Inspect the endpoint map instead.
endpoint_res = heat.resources.get(self.container, 'EndpointMap')
endpoints = endpoint_res.attributes.get('endpoint_map', {})
placement_extracted = 'PlacementPublic' in endpoints
endpoints = endpoint_res.attributes.get('endpoint_map', None)
placement_extracted = endpoints and 'PlacementPublic' in endpoints
except heat_exc.HTTPNotFound:
placement_extracted = False
pass
passwords = password_utils.generate_passwords(
mistralclient=mistral,

View File

@ -764,7 +764,7 @@ class GeneratePasswordsActionTest(base.TestCase):
}
mock_resource = mock.MagicMock()
mock_resource.attributes = {
'endpoint_map': {},
'endpoint_map': None,
'value': None
}
mock_orchestration.resources.get.return_value = mock_resource