Merge "Fix Rackspace nova server addresses attribute"

This commit is contained in:
Jenkins 2015-08-24 08:25:28 +00:00 committed by Gerrit Code Review
commit 42861939bc
2 changed files with 116 additions and 0 deletions

View File

@ -179,6 +179,27 @@ class CloudServer(server.Server):
return True
# Since rackspace compute service does not support 'os-interface' endpoint,
# accessing addresses attribute of OS::Nova::Server results in NotFound
# error. Here overrdiing '_add_port_for_address' method and using different
# endpoint named 'os-virtual-interfacesv2' to get the same information.
def _add_port_for_address(self, server):
def get_port(net_name, address):
for iface in ifaces:
for ip_addr in iface.ip_addresses:
if ip_addr['network_label'] == net_name and ip_addr[
'address'] == address:
return iface.id
nets = copy.deepcopy(server.addresses)
nova_ext = self.client().os_virtual_interfacesv2_python_novaclient_ext
ifaces = nova_ext.list(server.id)
for net_name, addresses in nets.items():
for address in addresses:
address['port'] = get_port(net_name, address['addr'])
return self._extend_networks(nets)
def resource_mapping():
return {'OS::Nova::Server': CloudServer}

View File

@ -315,6 +315,101 @@ class CloudServersTest(common.HeatTestCase):
self.m.VerifyAll()
def test_add_port_for_addresses(self):
return_server = self.fc.servers.list()[1]
stack_name = 'test_stack'
(tmpl, stack) = self._setup_test_stack(stack_name)
resource_defns = tmpl.resource_definitions(stack)
server = cloud_server.CloudServer('WebServer',
resource_defns['WebServer'], stack)
class Interface(object):
def __init__(self, id, addresses):
self.identifier = id
self.addresses = addresses
@property
def id(self):
return self.identifier
@property
def ip_addresses(self):
return self.addresses
interfaces = [
{
"id": "port-uuid-1",
"ip_addresses": [
{
"address": "4.5.6.7",
"network_id": "00xx000-0xx0-0xx0-0xx0-00xxx000",
"network_label": "public"
},
{
"address": "2001:4802:7805:104:be76:4eff:fe20:2063",
"network_id": "00xx000-0xx0-0xx0-0xx0-00xxx000",
"network_label": "public"
}
],
"mac_address": "fa:16:3e:8c:22:aa"
},
{
"id": "port-uuid-2",
"ip_addresses": [
{
"address": "5.6.9.8",
"network_id": "11xx1-1xx1-xx11-1xx1-11xxxx11",
"network_label": "public"
}
],
"mac_address": "fa:16:3e:8c:44:cc"
},
{
"id": "port-uuid-3",
"ip_addresses": [
{
"address": "10.13.12.13",
"network_id": "1xx1-1xx1-xx11-1xx1-11xxxx11",
"network_label": "private"
}
],
"mac_address": "fa:16:3e:8c:44:dd"
}
]
ifaces = [Interface(i['id'], i['ip_addresses']) for i in interfaces]
expected = {
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa':
[{'OS-EXT-IPS-MAC:mac_addr': 'fa:16:3e:8c:22:aa',
'addr': '4.5.6.7',
'port': 'port-uuid-1',
'version': 4},
{'OS-EXT-IPS-MAC:mac_addr': 'fa:16:3e:8c:33:bb',
'addr': '5.6.9.8',
'port': 'port-uuid-2',
'version': 4}],
'private': [{'OS-EXT-IPS-MAC:mac_addr': 'fa:16:3e:8c:44:cc',
'addr': '10.13.12.13',
'port': 'port-uuid-3',
'version': 4}],
'public': [{'OS-EXT-IPS-MAC:mac_addr': 'fa:16:3e:8c:22:aa',
'addr': '4.5.6.7',
'port': 'port-uuid-1',
'version': 4},
{'OS-EXT-IPS-MAC:mac_addr': 'fa:16:3e:8c:33:bb',
'addr': '5.6.9.8',
'port': 'port-uuid-2',
'version': 4}]}
server.client = mock.Mock()
mock_client = mock.Mock()
server.client.return_value = mock_client
mock_ext = mock_client.os_virtual_interfacesv2_python_novaclient_ext
mock_ext.list.return_value = ifaces
resp = server._add_port_for_address(return_server)
self.assertEqual(expected, resp)
def test_managed_cloud_build_error(self):
return_server = self.fc.servers.list()[1]
return_server.metadata = {'rax_service_level_automation':