Only add gateway IP if defined during network extract

If the gateway IP was not a subnet (IPv4 or IPv6), the network extract
command was generating a network_data.yaml file that had an entry for
gateway_ip set to null. Example:

- dns_domain: storagemgmt.tripleodomain.
  mtu: 1400
  name: StorageMgmt
  name_lower: storage_mgmt
  subnets:
    storage_mgmt_subnet:
      allocation_pools:
      - end: 172.16.3.250
        start: 172.16.3.4
      gateway_ip: null
      ip_subnet: 172.16.3.0/24
      physical_network: storage_mgmt
      routes: []
      vlan: 40
  vip: true

During "openstack overcloud network provision", the yaml was then
failing validation since null is not a valid string value for gateway_ip
as defined in the schema.

This patch updates the tripleo_overcloud_network_extract module to only
add the gateway_ip[v6] key to the subnet info if it's actually defined
on the subnet object.

Change-Id: I9701064c33c2e319617d90da99db00d10ad68a0f
Signed-off-by: James Slagle <jslagle@redhat.com>
This commit is contained in:
James Slagle 2020-12-03 21:05:49 -05:00
parent 2834bcdfd6
commit 9f99a1a2e8
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({
'ip_subnet': subnet.cidr,
'allocation_pools': subnet.allocation_pools,
'gateway_ip': subnet.gateway_ip,
'routes': subnet.host_routes,
})
if subnet.gateway_ip:
subnet_dict.update({
'gateway_ip': subnet.gateway_ip,
})
if subnet.ip_version == 6:
subnet_dict.update({
'ipv6_subnet': subnet.cidr,
'ipv6_allocation_pools': subnet.allocation_pools,
'gateway_ipv6': subnet.gateway_ip,
'routes_ipv6': subnet.host_routes,
'ipv6_address_mode': subnet.ipv6_address_mode,
'ipv6_ra_mode': subnet.ipv6_ra_mode,
})
if subnet.gateway_ip:
subnet_dict.update({
'gateway_ipv6': subnet.gateway_ip,
})
pop_defaults(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(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)
def test_get_subnet_info_ipv6(self, conn_mock):
fake_subnet = stubs.FakeNeutronSubnet(
@ -151,6 +183,42 @@ class TestTripleoOvercloudNetworkExtract(tests_base.TestCase):
self.assertEqual(name, 'public_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_network_info', auto_spec=True)
@mock.patch.object(openstack.connection, 'Connection', autospec=True)