Skip to content

Commit

Permalink
Update network metadata type field for IPv6
Browse files Browse the repository at this point in the history
Currently it is not possible to decide from looking at the network
metadata whether an IPv6 subnet is using slaac, dhcpv6-stateless or
dhcpv6-stateful.

So we add ipv6_address_mode information into the subnet metadata when
it is available and use that to construct the subnet type.

As a result, the type for a subnet with mode SLAAC will be "ipv6_slaac"
instead of "ipv6_dhcp" and similarly for the other available modes.

Change-Id: I751200a354ec9be2bfd5f94d3e4bbf53dab2c8bb
Partial-Bug: 1676363
  • Loading branch information
Jens Rosenboom committed Apr 12, 2017
1 parent 32c20db commit ccebded
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions nova/network/neutronv2/api.py
Expand Up @@ -2259,6 +2259,8 @@ def _get_subnets_from_port(self, context, port, client=None):
address=subnet['gateway_ip'],
type='gateway'),
}
if subnet.get('ipv6_address_mode'):
subnet_dict['ipv6_address_mode'] = subnet['ipv6_address_mode']

# attempt to populate DHCP server field
search_opts = {'network_id': subnet['network_id'],
Expand Down
40 changes: 40 additions & 0 deletions nova/tests/unit/network/test_network_info.py
Expand Up @@ -963,6 +963,46 @@ def test_get_network_metadata_json_dhcp(self):
},
net_metadata['networks'][1])

def _test_get_network_metadata_json_ipv6_addr_mode(self, mode):
ipv6_subnet = fake_network_cache_model.new_subnet(
subnet_dict=dict(dhcp_server='1234:567::',
ipv6_address_mode=mode), version=6)

self.netinfo[0]['network']['subnets'][1] = ipv6_subnet
net_metadata = netutils.get_network_metadata(self.netinfo)

self.assertEqual(
{
'id': 'network1',
'link': 'interface0',
'ip_address': 'fd00::2',
'netmask': 'ffff:ffff:ffff::',
'routes': [
{
'network': '::',
'netmask': '::',
'gateway': 'fd00::1'
},
{
'network': '::',
'netmask': 'ffff:ffff:ffff::',
'gateway': 'fd00::1:1'
}
],
'type': 'ipv6_%s' % mode,
'network_id': 1
},
net_metadata['networks'][1])

def test_get_network_metadata_json_ipv6_addr_mode_slaac(self):
self._test_get_network_metadata_json_ipv6_addr_mode('slaac')

def test_get_network_metadata_json_ipv6_addr_mode_stateful(self):
self._test_get_network_metadata_json_ipv6_addr_mode('dhcpv6-stateful')

def test_get_network_metadata_json_ipv6_addr_mode_stateless(self):
self._test_get_network_metadata_json_ipv6_addr_mode('dhcpv6-stateless')

def test__get_nets(self):
expected_net = {
'id': 'network0',
Expand Down
7 changes: 5 additions & 2 deletions nova/virt/netutils.py
Expand Up @@ -261,7 +261,10 @@ def _get_nets(vif, subnet, version, net_num, link_id):
:param link_id: Arbitrary identifier for the link the networks are
attached to
"""
if subnet.get_meta('dhcp_server') is not None:
net_type = ''
if subnet.get_meta('ipv6_address_mode') is not None:
net_type = '_%s' % subnet.get_meta('ipv6_address_mode')
elif subnet.get_meta('dhcp_server') is not None:
net_info = {
'id': 'network%d' % net_num,
'type': 'ipv%d_dhcp' % version,
Expand All @@ -279,7 +282,7 @@ def _get_nets(vif, subnet, version, net_num, link_id):

net_info = {
'id': 'network%d' % net_num,
'type': 'ipv%d' % version,
'type': 'ipv%d%s' % (version, net_type),
'link': link_id,
'ip_address': address,
'netmask': netmask,
Expand Down
14 changes: 14 additions & 0 deletions releasenotes/notes/added-network-metadata-7784295884f65c09.yaml
@@ -0,0 +1,14 @@
---
features:
- |
The network.json metadata format has been amended for IPv6 networks
under Neutron control. The type that is shown has been changed
from being always set to ``ipv6_dhcp`` to correctly reflecting the
``ipv6_address_mode`` option in Neutron, so the type now will be
``ipv6_slaac``, ``ipv6_dhcpv6-stateless`` or ``ipv6_dhcpv6-stateful``.
upgrade:
- |
The information in the network.json metadata has been amended,
for IPv6 networks under Neutron control, the ``type`` field has been
changed from being always set to ``ipv6_dhcp`` to correctly reflecting
the ``ipv6_address_mode`` option in Neutron.

0 comments on commit ccebded

Please sign in to comment.