Raise correct exception when a service doesn't exist

There are heat, cinder, neutron, glance, nova and keystone actions
in Mistral. We can call any of them in workflows, but in case of
absence of one of the called services, we will get "list index out
of range" error. This patch fixes the issue.

Closes-Bug: #1422725

Change-Id: I05acb5a27eb82c08b712f9687fc8230b2275ed44
This commit is contained in:
Yaroslav Lobankov 2015-09-18 20:05:20 +03:00
parent f8bda321b8
commit ba5b18c5f5
1 changed files with 7 additions and 3 deletions

View File

@ -67,16 +67,20 @@ def get_endpoint_for_project(service_name=None, service_type=None):
service_list = keystone_client.services.list()
if service_name:
service_id = [s.id for s in service_list if s.name == service_name][0]
service_ids = [s.id for s in service_list if s.name == service_name]
elif service_type:
service_id = [s.id for s in service_list if s.type == service_type][0]
service_ids = [s.id for s in service_list if s.type == service_type]
else:
raise Exception(
"Either 'service_name' or 'service_type' must be provided."
)
if not service_ids:
raise Exception("Either service '%s' or service type "
"'%s' doesn't exist!" % (service_name, service_type))
endpoints = keystone_client.endpoints.list(
service=service_id,
service=service_ids[0],
interface='public'
)