exception when running 'watcher service list'

We have two controllers as HA in our OpenStack environment.
There are watcher-applier and watcher-decision-engine in each
controller. So there are two same name in the services table.
In this case, the objects.Service.get_by_name(context, name)
will trigger exception of MultipleResultsFound.
We should use objects.Service.get(context, id) replace of
objects.Service.get_by_name(context, name).

Change-Id: Ic3ce784590d6c2a648cb3b28299744deed281332
Closes-Bug: #1674196
This commit is contained in:
licanwei
2017-03-20 12:17:34 +08:00
parent 51bf7fedb6
commit 38a3cbc84a
2 changed files with 11 additions and 6 deletions

View File

@@ -78,13 +78,18 @@ class TestListService(api_base.FunctionalTest):
def test_many(self):
service_list = []
for idx in range(1, 6):
for idx in range(1, 4):
service = obj_utils.create_test_service(
self.context, id=idx, host='CONTROLLER',
self.context, id=idx, host='CONTROLLER1',
name='SERVICE_{0}'.format(idx))
service_list.append(service.id)
for idx in range(1, 4):
service = obj_utils.create_test_service(
self.context, id=3+idx, host='CONTROLLER2',
name='SERVICE_{0}'.format(idx))
service_list.append(service.id)
response = self.get_json('/services')
self.assertEqual(5, len(response['services']))
self.assertEqual(6, len(response['services']))
for service in response['services']:
self.assertTrue(
all(val is not None for key, val in service.items()