diff --git a/shade/inventory.py b/shade/inventory.py index 3fcb0f031..101682a18 100644 --- a/shade/inventory.py +++ b/shade/inventory.py @@ -18,7 +18,6 @@ import os_client_config import shade from shade import _utils -from shade import meta class OpenStackInventory(object): @@ -65,13 +64,8 @@ class OpenStackInventory(object): for cloud in self.clouds: try: # Cycle on servers - for server in cloud.list_servers(): - - if expand: - server_vars = cloud.get_openstack_vars(server) - else: - server_vars = meta.add_server_interfaces(cloud, server) - hostvars.append(server_vars) + for server in cloud.list_servers(detailed=expand): + hostvars.append(server) except shade.OpenStackCloudException: # Don't fail on one particular cloud as others may work if fail_on_cloud_config: diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index d0a1521e6..6f7611185 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -1256,7 +1256,10 @@ class OpenStackCloud(object): for server in servers ] else: - return servers + return [ + meta.add_server_interfaces(self, server) + for server in servers + ] @_utils.cache_on_arguments(should_cache_fn=_no_pending_images) def list_images(self, filter_deleted=True): diff --git a/shade/tests/fakes.py b/shade/tests/fakes.py index 1f50c3584..19ff69f40 100644 --- a/shade/tests/fakes.py +++ b/shade/tests/fakes.py @@ -90,7 +90,10 @@ class FakeServer(object): self.id = id self.name = name self.status = status - self.addresses = addresses + if not addresses: + self.addresses = {} + else: + self.addresses = addresses if not flavor: flavor = {} self.flavor = flavor diff --git a/shade/tests/unit/test_inventory.py b/shade/tests/unit/test_inventory.py index 205d6721a..02e0228ca 100644 --- a/shade/tests/unit/test_inventory.py +++ b/shade/tests/unit/test_inventory.py @@ -92,14 +92,13 @@ class TestInventory(base.TestCase): ret = inv.list_hosts() - inv.clouds[0].list_servers.assert_called_once_with() - inv.clouds[0].get_openstack_vars.assert_called_once_with(server) + inv.clouds[0].list_servers.assert_called_once_with(detailed=True) + self.assertFalse(inv.clouds[0].get_openstack_vars.called) self.assertEqual([server], ret) @mock.patch("os_client_config.config.OpenStackConfig") - @mock.patch("shade.meta.add_server_interfaces") @mock.patch("shade.OpenStackCloud") - def test_list_hosts_no_detail(self, mock_cloud, mock_add, mock_config): + def test_list_hosts_no_detail(self, mock_cloud, mock_config): mock_config.return_value.get_all_clouds.return_value = [{}] inv = inventory.OpenStackInventory() @@ -114,9 +113,8 @@ class TestInventory(base.TestCase): inv.list_hosts(expand=False) - inv.clouds[0].list_servers.assert_called_once_with() + inv.clouds[0].list_servers.assert_called_once_with(detailed=False) self.assertFalse(inv.clouds[0].get_openstack_vars.called) - mock_add.assert_called_once_with(inv.clouds[0], server) @mock.patch("os_client_config.config.OpenStackConfig") @mock.patch("shade.OpenStackCloud") diff --git a/shade/tests/unit/test_shade.py b/shade/tests/unit/test_shade.py index 2a915a59b..137798df3 100644 --- a/shade/tests/unit/test_shade.py +++ b/shade/tests/unit/test_shade.py @@ -574,6 +574,9 @@ class TestShade(base.TestCase): munch.Munch({'name': 'testserver', 'id': '1', 'flavor': {}, + 'addresses': {}, + 'accessIPv4': '', + 'accessIPv6': '', 'image': ''}) ]