Fix the optimization of single instance describing

Change-Id: I66bfe3b601d1cd3bb5be2cb9e615f66726e4a053
This commit is contained in:
Feodor Tersin 2015-07-02 16:20:08 +03:00
parent cb92810330
commit 0813aa6bdd
2 changed files with 10 additions and 6 deletions

View File

@ -341,7 +341,7 @@ class InstanceDescriber(common.TaggableItemsDescriber):
self.os_volumes = _get_os_volumes(self.context)
self.os_flavors = _get_os_flavors(self.context)
nova = clients.nova(ec2_context.get_os_admin_context())
if self.ids == 1 and len(self.items) == 1:
if len(self.ids) == 1 and len(self.items) == 1:
try:
return [nova.servers.get(self.items[0]['os_id'])]
except nova_exception.NotFound:

View File

@ -732,6 +732,7 @@ class InstanceTestCase(base.ApiTestCase):
'project_id': fakes.ID_OS_PROJECT})
self.cinder.volumes.list.assert_called_once_with(search_opts=None)
self.nova_admin.reset_mock()
self.db_api.get_items_by_ids = tools.CopyingMock(
return_value=[fakes.DB_INSTANCE_1])
resp = self.execute('DescribeInstances',
@ -743,6 +744,9 @@ class InstanceTestCase(base.ApiTestCase):
mock.ANY, set([fakes.ID_EC2_INSTANCE_1]))
(self.network_interface_api.describe_network_interfaces.
assert_called_with(mock.ANY))
self.assertFalse(self.nova_admin.servers.list.called)
self.nova_admin.servers.get.assert_called_once_with(
fakes.ID_OS_INSTANCE_1)
self.check_filtering(
'DescribeInstances', 'reservationSet',
@ -860,11 +864,11 @@ class InstanceTestCase(base.ApiTestCase):
fakes.OSInstance_full({
'id': os_id,
'flavor': {'id': 'fakeFlavorId'},
'addresses': {subnet_name:
[{'addr': addr,
'version': 4,
'OS-EXT-IPS:type': 'fixed'}]
for subnet_name, addr in ips},
'addresses': {
subnet_name: [{'addr': addr,
'version': 4,
'OS-EXT-IPS:type': 'fixed'}]
for subnet_name, addr in ips},
'root_device_name': '/dev/vda',
'hostname': '%s-%s' % (fakes.ID_EC2_RESERVATION_1, l_i)})
for l_i, (os_id, ips) in enumerate(zip(