Fix private_v4 selection related to floating ip matching

The change to look for floating ips first when looking for the public
address exposed a latent bug in the private ip finding
code. When we get the mac address of the floating ip, we then look for
the corresponding fixed ip to return for private_v4. However, we weren't
specifying fixed before, so we were just getting the first one that
matched. That *happened* to be the fixed ip by accident.

Add in ext_tag='fixed' so that we look for the matching MAC from a fixed
interface.

We have to also add a second pass through the loop without the fixed
tag, as old nova network dicts do not have the fixed/floating tag like
that.

Includes a test which shows the breakage.

Story: 2001619
Change-Id: I60562a99f78c0c363f49106c285935448f804084
This commit is contained in:
Monty Taylor 2018-02-28 20:55:38 +00:00
parent 9282eb2fdd
commit 41538c865d
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 200 additions and 0 deletions

View File

@ -126,6 +126,16 @@ def get_server_private_ip(server, cloud=None):
# and possibly pre-configured network name
if cloud:
int_nets = cloud.get_internal_ipv4_networks()
for int_net in int_nets:
int_ip = get_server_ip(
server, key_name=int_net['name'],
ext_tag='fixed',
cloud_public=not cloud.private,
mac_addr=fip_mac)
if int_ip is not None:
return int_ip
# Try a second time without the fixed tag. This is for old nova-network
# results that do not have the fixed/floating tag.
for int_net in int_nets:
int_ip = get_server_ip(
server, key_name=int_net['name'],

View File

@ -151,6 +151,196 @@ class TestShade(base.RequestsMockTestCase):
self.assert_calls()
def test_list_server_private_ip(self):
self.has_neutron = True
fake_server = {
"OS-EXT-STS:task_state": None,
"addresses": {
"private": [
{
"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:b4:a3:07",
"version": 4,
"addr": "10.4.0.13",
"OS-EXT-IPS:type": "fixed"
}, {
"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:b4:a3:07",
"version": 4,
"addr": "89.40.216.229",
"OS-EXT-IPS:type": "floating"
}]},
"links": [
{
"href": "http://example.com/images/95e4c4",
"rel": "self"
}, {
"href": "http://example.com/images/95e4c4",
"rel": "bookmark"
}
],
"image": {
"id": "95e4c449-8abf-486e-97d9-dc3f82417d2d",
"links": [
{
"href": "http://example.com/images/95e4c4",
"rel": "bookmark"
}
]
},
"OS-EXT-STS:vm_state": "active",
"OS-SRV-USG:launched_at": "2018-03-01T02:44:50.000000",
"flavor": {
"id": "3bd99062-2fe8-4eac-93f0-9200cc0f97ae",
"links": [
{
"href": "http://example.com/flavors/95e4c4",
"rel": "bookmark"
}
]
},
"id": "97fe35e9-756a-41a2-960a-1d057d2c9ee4",
"security_groups": [{"name": "default"}],
"user_id": "c17534835f8f42bf98fc367e0bf35e09",
"OS-DCF:diskConfig": "MANUAL",
"accessIPv4": "",
"accessIPv6": "",
"progress": 0,
"OS-EXT-STS:power_state": 1,
"OS-EXT-AZ:availability_zone": "nova",
"metadata": {},
"status": "ACTIVE",
"updated": "2018-03-01T02:44:51Z",
"hostId": "",
"OS-SRV-USG:terminated_at": None,
"key_name": None,
"name": "mttest",
"created": "2018-03-01T02:44:46Z",
"tenant_id": "65222a4d09ea4c68934fa1028c77f394",
"os-extended-volumes:volumes_attached": [],
"config_drive": ""
}
fake_networks = {"networks": [
{
"status": "ACTIVE",
"router:external": True,
"availability_zone_hints": [],
"availability_zones": ["nova"],
"description": None,
"subnets": [
"df3e17fa-a4b2-47ae-9015-bc93eb076ba2",
"6b0c3dc9-b0b8-4d87-976a-7f2ebf13e7ec",
"fc541f48-fc7f-48c0-a063-18de6ee7bdd7"
],
"shared": False,
"tenant_id": "a564613210ee43708b8a7fc6274ebd63",
"tags": [],
"ipv6_address_scope": "9f03124f-89af-483a-b6fd-10f08079db4d",
"mtu": 1550,
"is_default": False,
"admin_state_up": True,
"revision_number": 0,
"ipv4_address_scope": None,
"port_security_enabled": True,
"project_id": "a564613210ee43708b8a7fc6274ebd63",
"id": "0232c17f-2096-49bc-b205-d3dcd9a30ebf",
"name": "ext-net"
}, {
"status": "ACTIVE",
"router:external": False,
"availability_zone_hints": [],
"availability_zones": ["nova"],
"description": "",
"subnets": ["f0ad1df5-53ee-473f-b86b-3604ea5591e9"],
"shared": False,
"tenant_id": "65222a4d09ea4c68934fa1028c77f394",
"created_at": "2016-10-22T13:46:26Z",
"tags": [],
"ipv6_address_scope": None,
"updated_at": "2016-10-22T13:46:26Z",
"admin_state_up": True,
"mtu": 1500,
"revision_number": 0,
"ipv4_address_scope": None,
"port_security_enabled": True,
"project_id": "65222a4d09ea4c68934fa1028c77f394",
"id": "2c9adcb5-c123-4c5a-a2ba-1ad4c4e1481f",
"name": "private"
}]}
fake_subnets = {
"subnets": [
{
"service_types": [],
"description": "",
"enable_dhcp": True,
"tags": [],
"network_id": "827c6bb6-492f-4168-9577-f3a131eb29e8",
"tenant_id": "65222a4d09ea4c68934fa1028c77f394",
"created_at": "2017-06-12T13:23:57Z",
"dns_nameservers": [],
"updated_at": "2017-06-12T13:23:57Z",
"gateway_ip": "10.24.4.1",
"ipv6_ra_mode": None,
"allocation_pools": [
{
"start": "10.24.4.2",
"end": "10.24.4.254"
}],
"host_routes": [],
"revision_number": 0,
"ip_version": 4,
"ipv6_address_mode": None,
"cidr": "10.24.4.0/24",
"project_id": "65222a4d09ea4c68934fa1028c77f394",
"id": "3f0642d9-4644-4dff-af25-bcf64f739698",
"subnetpool_id": None,
"name": "foo_subnet"
}, {
"service_types": [],
"description": "",
"enable_dhcp": True,
"tags": [],
"network_id": "2c9adcb5-c123-4c5a-a2ba-1ad4c4e1481f",
"tenant_id": "65222a4d09ea4c68934fa1028c77f394",
"created_at": "2016-10-22T13:46:26Z",
"dns_nameservers": ["89.36.90.101", "89.36.90.102"],
"updated_at": "2016-10-22T13:46:26Z",
"gateway_ip": "10.4.0.1",
"ipv6_ra_mode": None,
"allocation_pools": [
{
"start": "10.4.0.2",
"end": "10.4.0.200"
}],
"host_routes": [],
"revision_number": 0,
"ip_version": 4,
"ipv6_address_mode": None,
"cidr": "10.4.0.0/24",
"project_id": "65222a4d09ea4c68934fa1028c77f394",
"id": "f0ad1df5-53ee-473f-b86b-3604ea5591e9",
"subnetpool_id": None,
"name": "private-subnet-ipv4"
}]}
self.register_uris([
dict(method='GET',
uri=self.get_mock_url(
'compute', 'public', append=['servers', 'detail']),
json={'servers': [fake_server]}),
dict(method='GET',
uri=self.get_mock_url(
'network', 'public', append=['v2.0', 'networks.json']),
json=fake_networks),
dict(method='GET',
uri=self.get_mock_url(
'network', 'public', append=['v2.0', 'subnets.json']),
json=fake_subnets)
])
r = self.cloud.get_server('97fe35e9-756a-41a2-960a-1d057d2c9ee4')
self.assertEqual('10.4.0.13', r['private_v4'])
self.assert_calls()
def test_list_servers_all_projects(self):
'''This test verifies that when list_servers is called with
`all_projects=True` that it passes `all_tenants=True` to nova.'''