Merge "Only add gateway IP if defined during network extract"

This commit is contained in:
Zuul 2020-12-18 13:29:17 +00:00 committed by Gerrit Code Review
commit bfbe5497c1
2 changed files with 78 additions and 2 deletions

View File

@ -256,20 +256,28 @@ def get_subnet_info(conn, subnet_id):
subnet_dict.update({ subnet_dict.update({
'ip_subnet': subnet.cidr, 'ip_subnet': subnet.cidr,
'allocation_pools': subnet.allocation_pools, 'allocation_pools': subnet.allocation_pools,
'gateway_ip': subnet.gateway_ip,
'routes': subnet.host_routes, 'routes': subnet.host_routes,
}) })
if subnet.gateway_ip:
subnet_dict.update({
'gateway_ip': subnet.gateway_ip,
})
if subnet.ip_version == 6: if subnet.ip_version == 6:
subnet_dict.update({ subnet_dict.update({
'ipv6_subnet': subnet.cidr, 'ipv6_subnet': subnet.cidr,
'ipv6_allocation_pools': subnet.allocation_pools, 'ipv6_allocation_pools': subnet.allocation_pools,
'gateway_ipv6': subnet.gateway_ip,
'routes_ipv6': subnet.host_routes, 'routes_ipv6': subnet.host_routes,
'ipv6_address_mode': subnet.ipv6_address_mode, 'ipv6_address_mode': subnet.ipv6_address_mode,
'ipv6_ra_mode': subnet.ipv6_ra_mode, 'ipv6_ra_mode': subnet.ipv6_ra_mode,
}) })
if subnet.gateway_ip:
subnet_dict.update({
'gateway_ipv6': subnet.gateway_ip,
})
pop_defaults(subnet_dict) pop_defaults(subnet_dict)
return subnet_name, subnet_dict return subnet_name, subnet_dict

View File

@ -114,6 +114,38 @@ class TestTripleoOvercloudNetworkExtract(tests_base.TestCase):
self.assertEqual(name, 'public_subnet') self.assertEqual(name, 'public_subnet')
self.assertEqual(expected, subnet) self.assertEqual(expected, subnet)
@mock.patch.object(openstack.connection, 'Connection', autospec=True)
def test_get_subnet_info_ipv4_no_gateway_ip(self, conn_mock):
fake_subnet = stubs.FakeNeutronSubnet(
name='public_subnet',
is_dhcp_enabled=False,
tags=['tripleo_vlan_id=100'],
ip_version=4,
cidr='10.0.0.0/24',
allocation_pools=[{'start': '10.0.0.10', 'end': '10.0.0.150'}],
gateway_ip=None,
host_routes=[{'destination': '172.17.1.0/24',
'nexthop': '10.0.0.1'}],
)
fake_segment = stubs.FakeNeutronSegment(
name='public_subnet',
network_type='flat',
physical_network='public_subnet'
)
conn_mock.network.get_subnet.return_value = fake_subnet
conn_mock.network.get_segment.return_value = fake_segment
expected = {
'vlan': 100,
'ip_subnet': '10.0.0.0/24',
'allocation_pools': [{'start': '10.0.0.10', 'end': '10.0.0.150'}],
'routes': [{'destination': '172.17.1.0/24',
'nexthop': '10.0.0.1'}],
'physical_network': 'public_subnet',
}
name, subnet = plugin.get_subnet_info(conn_mock, mock.Mock())
self.assertEqual(name, 'public_subnet')
self.assertEqual(expected, subnet)
@mock.patch.object(openstack.connection, 'Connection', autospec=True) @mock.patch.object(openstack.connection, 'Connection', autospec=True)
def test_get_subnet_info_ipv6(self, conn_mock): def test_get_subnet_info_ipv6(self, conn_mock):
fake_subnet = stubs.FakeNeutronSubnet( fake_subnet = stubs.FakeNeutronSubnet(
@ -151,6 +183,42 @@ class TestTripleoOvercloudNetworkExtract(tests_base.TestCase):
self.assertEqual(name, 'public_subnet') self.assertEqual(name, 'public_subnet')
self.assertEqual(expected, subnet) self.assertEqual(expected, subnet)
@mock.patch.object(openstack.connection, 'Connection', autospec=True)
def test_get_subnet_info_ipv6_no_gateway_ip(self, conn_mock):
fake_subnet = stubs.FakeNeutronSubnet(
name='public_subnet',
is_dhcp_enabled=False,
tags=['tripleo_vlan_id=200'],
ip_version=6,
cidr='2001:db8:a::/64',
allocation_pools=[{'start': '2001:db8:a::0010',
'end': '2001:db8:a::fff9'}],
gateway_ip=None,
host_routes=[{'destination': '2001:db8:b::/64',
'nexthop': '2001:db8:a::1'}],
ipv6_address_mode=None,
ipv6_ra_mode=None,
)
fake_segment = stubs.FakeNeutronSegment(
name='public_subnet',
network_type='flat',
physical_network='public_subnet'
)
conn_mock.network.get_subnet.return_value = fake_subnet
conn_mock.network.get_segment.return_value = fake_segment
expected = {
'vlan': 200,
'ipv6_subnet': '2001:db8:a::/64',
'ipv6_allocation_pools': [{'start': '2001:db8:a::0010',
'end': '2001:db8:a::fff9'}],
'routes_ipv6': [{'destination': '2001:db8:b::/64',
'nexthop': '2001:db8:a::1'}],
'physical_network': 'public_subnet',
}
name, subnet = plugin.get_subnet_info(conn_mock, mock.Mock())
self.assertEqual(name, 'public_subnet')
self.assertEqual(expected, subnet)
@mock.patch.object(plugin, 'get_subnet_info', auto_spec=True) @mock.patch.object(plugin, 'get_subnet_info', auto_spec=True)
@mock.patch.object(plugin, 'get_network_info', auto_spec=True) @mock.patch.object(plugin, 'get_network_info', auto_spec=True)
@mock.patch.object(openstack.connection, 'Connection', autospec=True) @mock.patch.object(openstack.connection, 'Connection', autospec=True)