Fix KeyError in deployment history page

use package name as the service name when service have no name.

Change-Id: Ib7585b2c8742dde7c1c0a350db48dee96d1ad0a8
Closes-bug: #1703180
This commit is contained in:
zhurong 2017-07-09 17:45:06 +08:00
parent 0f21fc1fba
commit b9ea284b96
2 changed files with 5 additions and 3 deletions

View File

@ -728,7 +728,7 @@ def get_deployment_history_services(deployment):
service_type = service['?']['type']
if service_type.find('/') != -1:
service_type = service_type[:service_type.find('/')]
services[service['name']] = service_type
services[service.get('name', service['?']['name'])] = service_type
context = {
"services": services,
}

View File

@ -863,8 +863,10 @@ class TestDeploymentHistoryTable(testtools.TestCase):
mock.sentinel.rendered_template
test_description = {'services': [
{'name': 'foo_service', '?': {'type': 'foo/bar'}},
{'name': 'bar_service', '?': {'type': 'baz/qux'}}
{'name': 'foo_service', '?': {'type': 'foo/bar',
'name': 'foo_service'}},
{'name': 'bar_service', '?': {'type': 'baz/qux',
'name': 'bar_service'}}
]}
mock_deployment = mock.Mock(description=test_description)