Always do network interface introspection
We split the function that figures out what your IP is from the more API heavy functions so that we could always apply it - and then we forgot to always apply it. Change-Id: Ic670a05ed5165be144912642f5ecae4ca0bc94c2
This commit is contained in:
parent
75c62a9fa6
commit
35e6af8890
@ -18,7 +18,6 @@ import os_client_config
|
|||||||
|
|
||||||
import shade
|
import shade
|
||||||
from shade import _utils
|
from shade import _utils
|
||||||
from shade import meta
|
|
||||||
|
|
||||||
|
|
||||||
class OpenStackInventory(object):
|
class OpenStackInventory(object):
|
||||||
@ -65,13 +64,8 @@ class OpenStackInventory(object):
|
|||||||
for cloud in self.clouds:
|
for cloud in self.clouds:
|
||||||
try:
|
try:
|
||||||
# Cycle on servers
|
# Cycle on servers
|
||||||
for server in cloud.list_servers():
|
for server in cloud.list_servers(detailed=expand):
|
||||||
|
hostvars.append(server)
|
||||||
if expand:
|
|
||||||
server_vars = cloud.get_openstack_vars(server)
|
|
||||||
else:
|
|
||||||
server_vars = meta.add_server_interfaces(cloud, server)
|
|
||||||
hostvars.append(server_vars)
|
|
||||||
except shade.OpenStackCloudException:
|
except shade.OpenStackCloudException:
|
||||||
# Don't fail on one particular cloud as others may work
|
# Don't fail on one particular cloud as others may work
|
||||||
if fail_on_cloud_config:
|
if fail_on_cloud_config:
|
||||||
|
@ -1256,7 +1256,10 @@ class OpenStackCloud(object):
|
|||||||
for server in servers
|
for server in servers
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
return servers
|
return [
|
||||||
|
meta.add_server_interfaces(self, server)
|
||||||
|
for server in servers
|
||||||
|
]
|
||||||
|
|
||||||
@_utils.cache_on_arguments(should_cache_fn=_no_pending_images)
|
@_utils.cache_on_arguments(should_cache_fn=_no_pending_images)
|
||||||
def list_images(self, filter_deleted=True):
|
def list_images(self, filter_deleted=True):
|
||||||
|
@ -90,7 +90,10 @@ class FakeServer(object):
|
|||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.status = status
|
self.status = status
|
||||||
self.addresses = addresses
|
if not addresses:
|
||||||
|
self.addresses = {}
|
||||||
|
else:
|
||||||
|
self.addresses = addresses
|
||||||
if not flavor:
|
if not flavor:
|
||||||
flavor = {}
|
flavor = {}
|
||||||
self.flavor = flavor
|
self.flavor = flavor
|
||||||
|
@ -92,14 +92,13 @@ class TestInventory(base.TestCase):
|
|||||||
|
|
||||||
ret = inv.list_hosts()
|
ret = inv.list_hosts()
|
||||||
|
|
||||||
inv.clouds[0].list_servers.assert_called_once_with()
|
inv.clouds[0].list_servers.assert_called_once_with(detailed=True)
|
||||||
inv.clouds[0].get_openstack_vars.assert_called_once_with(server)
|
self.assertFalse(inv.clouds[0].get_openstack_vars.called)
|
||||||
self.assertEqual([server], ret)
|
self.assertEqual([server], ret)
|
||||||
|
|
||||||
@mock.patch("os_client_config.config.OpenStackConfig")
|
@mock.patch("os_client_config.config.OpenStackConfig")
|
||||||
@mock.patch("shade.meta.add_server_interfaces")
|
|
||||||
@mock.patch("shade.OpenStackCloud")
|
@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 = [{}]
|
mock_config.return_value.get_all_clouds.return_value = [{}]
|
||||||
|
|
||||||
inv = inventory.OpenStackInventory()
|
inv = inventory.OpenStackInventory()
|
||||||
@ -114,9 +113,8 @@ class TestInventory(base.TestCase):
|
|||||||
|
|
||||||
inv.list_hosts(expand=False)
|
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)
|
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("os_client_config.config.OpenStackConfig")
|
||||||
@mock.patch("shade.OpenStackCloud")
|
@mock.patch("shade.OpenStackCloud")
|
||||||
|
@ -574,6 +574,9 @@ class TestShade(base.TestCase):
|
|||||||
munch.Munch({'name': 'testserver',
|
munch.Munch({'name': 'testserver',
|
||||||
'id': '1',
|
'id': '1',
|
||||||
'flavor': {},
|
'flavor': {},
|
||||||
|
'addresses': {},
|
||||||
|
'accessIPv4': '',
|
||||||
|
'accessIPv6': '',
|
||||||
'image': ''})
|
'image': ''})
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user