Skip to content

Commit

Permalink
Fix bug in Endpoints Management Dashboard
Browse files Browse the repository at this point in the history
Handle correctly multi-region scenarios in which a region name may contain
capital letters
  • Loading branch information
federicofdez committed Dec 7, 2016
1 parent f182c0e commit 18d7381
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, *args, **kwargs):

for region in self.request.session['endpoints_allowed_regions']:
for interface in ['public', 'internal', 'admin']:
field_ID = '_'.join([self.service.name, region.lower(), interface])
field_ID = '_'.join([self.service.name, region, interface])
fields[field_ID] = forms.CharField(label=interface.capitalize(),
required=True,
widget=forms.TextInput(
Expand All @@ -56,7 +56,7 @@ def __init__(self, *args, **kwargs):
if self.endpoints_list:
self.service_enabled = True
for endpoint in self.endpoints_list:
field_ID = '_'.join([self.service.name, endpoint.region.lower(), endpoint.interface])
field_ID = '_'.join([self.service.name, endpoint.region, endpoint.interface])
initial[field_ID] = endpoint.url
else:
self.service_enabled = False
Expand All @@ -74,11 +74,15 @@ def handle(self, request, data):
for field_ID, new_url in data.iteritems():
service_name, region, interface = field_ID.split('_')

endpoint = next((e for e in self.endpoints_list if e.region_id == region.capitalize() and e.interface == interface), None)
# check if the endpoint already exists
endpoint = next((e for e in self.endpoints_list if e.region_id == region and e.interface == interface), None)
if not endpoint:
is_new_service = True
keystone.endpoint_create(request, service=self.service.id, url=new_url, interface=interface, region=region.capitalize())
# check if service was previously enabled for some other region of the user
is_new_service = True if next((e for e in self.endpoints_list if self.request.session['endpoints_user_region'] in e.region_id and e.interface == interface), None) else False
# create new endpoint
keystone.endpoint_create(request, service=self.service.id, url=new_url, interface=interface, region=region)
elif new_url != '' and new_url != endpoint.url:
# update endpoint
keystone.endpoint_update(request, endpoint_id=endpoint.id, endpoint_new_url=new_url)

self._create_endpoint_group_for_region(request)
Expand Down Expand Up @@ -124,7 +128,7 @@ def filter_region(form, region_id):

for field in form.fields:
service_name, region, interface = field.split('_')
if region == region_id.lower():
if region == region_id:
filtered_fields[field] = form.fields[field]

filtered_form = UpdateEndpointsForm(request=form.request,
Expand Down
10 changes: 6 additions & 4 deletions openstack_dashboard/dashboards/endpoints_management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ def _is_service_account_shared(request, service_account_name):
# let's check first if the service_account could be potentially shared
# i.e. there is another service of the same type
services_IDs = [s.id for s in fiware_api.keystone.service_list(request) if service in s.name]
if len(services_IDs) < 1:
if len(services_IDs) < 2:
return False

# let's check now if more than one of those services is enabled
endpoints = [e for e in fiware_api.keystone.endpoint_list(request) if e.region_id == region.capitalize() and \
e.service_id in services_IDs]
if len(endpoints) > 3:
endpoints = []
for region in request.session['endpoints_allowed_regions']:
endpoints.append([e for e in fiware_api.keystone.endpoint_list(request) if e.region_id == region and \
e.service_id in services_IDs])
if len(endpoints) > request.session['endpoints_allowed_regions']*3:
return True

return False

0 comments on commit 18d7381

Please sign in to comment.