diff --git a/tripleo_validations/inventory.py b/tripleo_validations/inventory.py index af54e9c50..d3a36e304 100644 --- a/tripleo_validations/inventory.py +++ b/tripleo_validations/inventory.py @@ -15,6 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. +from heatclient.exc import HTTPNotFound + HOST_NETWORK = 'ctlplane' @@ -30,9 +32,12 @@ class StackOutputs(object): self.plan = plan self.outputs = {} self.hclient = hclient - self.output_list = [ - output['output_key'] for output in - self.hclient.stacks.output_list(plan)['outputs']] + try: + self.output_list = [ + output['output_key'] for output in + self.hclient.stacks.output_list(plan)['outputs']] + except HTTPNotFound: + self.output_list = [] def __getitem__(self, key): if key not in self.output_list: @@ -80,7 +85,7 @@ class TripleoInventory(object): try: environment = self.hclient.stacks.environment(self.configs.plan) return environment - except Exception: + except HTTPNotFound: return {} def list(self): @@ -106,13 +111,13 @@ class TripleoInventory(object): admin_password = self.get_overcloud_environment().get( 'parameter_defaults', {}).get('AdminPassword') if admin_password: - ret['undercloud']['vars']['overcloud_admin_password'] = \ + ret['undercloud']['vars']['overcloud_admin_password'] =\ admin_password endpoint_map = self.stack_outputs.get('EndpointMap') if endpoint_map: horizon_endpoint = endpoint_map.get('HorizonPublic', {}).get('uri') if horizon_endpoint: - ret['undercloud']['vars']['overcloud_horizon_url'] = \ + ret['undercloud']['vars']['overcloud_horizon_url'] =\ horizon_endpoint role_net_ip_map = self.stack_outputs.get('RoleNetIpMap', {}) @@ -142,7 +147,7 @@ class TripleoInventory(object): # Associate services with roles roles_by_service = self.get_roles_by_service( - self.stack_outputs.get('EnabledServices')) + self.stack_outputs.get('EnabledServices', {})) for service, roles in roles_by_service.items(): service_children = [role.lower() for role in roles if ret.get(role.lower()) is not None] diff --git a/tripleo_validations/tests/test_inventory.py b/tripleo_validations/tests/test_inventory.py index 8763eb788..c3b90902c 100644 --- a/tripleo_validations/tests/test_inventory.py +++ b/tripleo_validations/tests/test_inventory.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from heatclient.exc import HTTPNotFound from mock import MagicMock from tripleo_validations.inventory import StackOutputs @@ -119,6 +120,11 @@ class TestInventory(base.TestCase): } self.assertDictEqual(services, expected) + def test_outputs_are_empty_if_stack_doesnt_exist(self): + self.hclient.stacks.output_list.side_effect = HTTPNotFound('not found') + stack_outputs = StackOutputs('no-plan', self.hclient) + self.assertEqual(list(stack_outputs), []) + def test_outputs_valid_key_calls_api(self): expected = 'xyz://keystone' self.hclient.stacks.output_show.return_value = dict(output=dict(