Merge "Fix inventory without existing stack"
This commit is contained in:
commit
f3b1e39f94
|
@ -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]
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue