Only work with ipv4 subnet metadata if one exists
This code currently throws an exception and fails the build if an instance boots on a network without a v4 subnet. Protect against this by checking it has a ipv4 subnet. Change-Id: I7c5de308b557293f5ac6b919d5566ace809ce200 Closes-bug: #1476402
This commit is contained in:
parent
7d39811f74
commit
6cce41eaa3
|
@ -1140,3 +1140,53 @@ class TestNetworkMetadata(test.NoDBTestCase):
|
|||
|
||||
network_json = netutils.get_network_metadata(self.netinfo)
|
||||
self.assertEqual(expected_json, network_json)
|
||||
|
||||
def test_get_network_metadata_no_ipv4(self):
|
||||
expected_json = {
|
||||
"services": [
|
||||
{
|
||||
"type": "dns",
|
||||
"address": "1:2:3:4::"
|
||||
},
|
||||
{
|
||||
"type": "dns",
|
||||
"address": "2:3:4:5::"
|
||||
}
|
||||
],
|
||||
"networks": [
|
||||
{
|
||||
"network_id": 1,
|
||||
"type": "ipv6",
|
||||
"netmask": "ffff:ffff:ffff::",
|
||||
"link": "interface0",
|
||||
"routes": [
|
||||
{
|
||||
"netmask": "::",
|
||||
"network": "::",
|
||||
"gateway": "fd00::1"
|
||||
},
|
||||
{
|
||||
"netmask": "ffff:ffff:ffff::",
|
||||
"network": "::",
|
||||
"gateway": "fd00::1:1"
|
||||
}
|
||||
],
|
||||
"ip_address": "fd00::2",
|
||||
"id": "network0"
|
||||
}
|
||||
],
|
||||
"links": [
|
||||
{
|
||||
"ethernet_mac_address": "aa:aa:aa:aa:aa:aa",
|
||||
"mtu": 1500,
|
||||
"type": "phy",
|
||||
"id": "interface0",
|
||||
"vif_id": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# drop the ipv4 subnet
|
||||
self.netinfo[0]['network']['subnets'].pop(0)
|
||||
network_json = netutils.get_network_metadata(self.netinfo)
|
||||
self.assertEqual(expected_json, network_json)
|
||||
|
|
|
@ -226,7 +226,7 @@ def get_network_metadata(network_info, use_ipv6=None):
|
|||
links.append(link)
|
||||
|
||||
# Add IPv4 and IPv6 networks if they exist
|
||||
if subnet_v4.get('ips'):
|
||||
if subnet_v4 and subnet_v4.get('ips'):
|
||||
net_num += 1
|
||||
nets.append(_get_nets(vif, subnet_v4, 4, net_num, link['id']))
|
||||
services += [dns for dns in _get_dns_services(subnet_v4)
|
||||
|
|
Loading…
Reference in New Issue