Handle Name and MAC field when parse config with IPV6

It seems the Name and MAC field was not set for
v6 scenario, and them to the fields.

Co-Authored-By: chenhanxiao <chen_han_xiao@126.com>

Change-Id: I88cd310eff74ff22c2fa8c6698afb25302bb07c4
Closes-bug: #1819170
This commit is contained in:
Kevin_Zheng 2019-03-08 22:56:48 +08:00
parent 1fae06860c
commit 4c80dd5d60
6 changed files with 66 additions and 18 deletions

View File

@ -146,13 +146,15 @@ class NetworkConfigPlugin(plugin_base.BasePlugin):
name = osutils.get_network_adapter_name_by_mac_address(mac)
LOG.info("Configuring network adapter: %s", name)
reboot = osutils.set_static_network_config(
name,
nic.address,
nic.netmask,
nic.gateway,
nic.dnsnameservers
)
# In v6 only case, nic.address and nic.netmask could be unset
if nic.address and nic.netmask:
reboot = osutils.set_static_network_config(
name,
nic.address,
nic.netmask,
nic.gateway,
nic.dnsnameservers
)
reboot_required = reboot or reboot_required
# Set v6 info too if available.
if nic.address6 and nic.netmask6:

View File

@ -26,12 +26,22 @@ DNSNS0 = "208.67.220.220 208.67.222.222"
NAME1 = "eth1"
ADDRESS1 = "10.1.0.2"
ADDRESS61 = "::ffff:a00:1"
ADDRESS61 = None
NETMASK1 = "255.255.255.0"
NETMASK61 = None
BROADCAST1 = "10.1.0.255"
GATEWAY1 = "10.1.0.1"
GATEWAY61 = "2001::ffff:a00:1b"
GATEWAY61 = None
NAME2 = "eth2"
MAC2 = None
ADDRESS2 = "::ffff:a00:1"
ADDRESS62 = None
NETMASK2 = None
NETMASK62 = None
BROADCAST2 = None
GATEWAY2 = "2001::ffff:a00:1b"
GATEWAY62 = None
def get_fake_metadata_json(version):
@ -158,9 +168,9 @@ iface {name1} inet static
broadcast {broadcast1}
gateway {gateway1}
iface eth2 inet6 static
address {address61}
netmask {netmask61}
gateway {gateway61}
address {address2}
netmask {netmask2}
gateway {gateway2}
""").format(name0=NAME0, # eth0 (IPv4/6)
mac0=MAC0,
address0=ADDRESS0,
@ -179,7 +189,17 @@ iface eth2 inet6 static
gateway1=GATEWAY1,
address61=ADDRESS61,
netmask61=NETMASK61,
gateway61=GATEWAY61
gateway61=GATEWAY61,
# eth2 (IPv6)
name2=NAME1,
mac2=MAC2,
address2=ADDRESS2,
broadcast2=BROADCAST2,
netmask2=NETMASK2,
gateway2=GATEWAY2,
address62=ADDRESS62,
netmask62=NETMASK62,
gateway62=GATEWAY62
)
}
}

View File

@ -245,7 +245,19 @@ class TestBaseOpenStackService(unittest.TestCase):
fake_json_response.GATEWAY61,
None
)
self.assertEqual([nic0, nic1], ret)
nic2 = network_model.NetworkDetails(
fake_json_response.NAME2,
None,
fake_json_response.ADDRESS2,
fake_json_response.ADDRESS62,
fake_json_response.NETMASK2,
fake_json_response.NETMASK62,
fake_json_response.BROADCAST2,
fake_json_response.GATEWAY2,
fake_json_response.GATEWAY62,
None
)
self.assertEqual([nic0, nic1, nic2], ret)
def test_get_network_details_no_config(self):
self._partial_test_get_network_details(

View File

@ -92,7 +92,8 @@ class TestNetworkConfigPlugin(unittest.TestCase):
nic.gateway6,
[]
)
calls.append(call)
if nic.address and nic.netmask:
calls.append(call)
if nic.address6 and nic.netmask6:
calls.append(call6)
self.assertEqual(

View File

@ -63,7 +63,19 @@ class TestInterfacesParser(unittest.TestCase):
fake_json_response.GATEWAY61,
None
)
self.assertEqual([nic0, nic1], nics)
nic2 = network_model.NetworkDetails(
fake_json_response.NAME2,
None,
fake_json_response.ADDRESS2,
fake_json_response.ADDRESS62,
fake_json_response.NETMASK2,
fake_json_response.NETMASK62,
fake_json_response.BROADCAST2,
fake_json_response.GATEWAY2,
fake_json_response.GATEWAY62,
None
)
self.assertEqual([nic0, nic1, nic2], nics)
def test_nothing_to_parse(self):
invalid = [None, "", 324242, ("dasd", "dsa")]

View File

@ -60,7 +60,9 @@ IFACE_TEMPLATE = dict.fromkeys(FIELDS.keys())
V6_PROXY = {
ADDRESS: ADDRESS6,
NETMASK: NETMASK6,
GATEWAY: GATEWAY6
GATEWAY: GATEWAY6,
NAME: NAME,
MAC: MAC,
}
DETAIL_PREPROCESS = {
MAC: lambda value: value.upper(),
@ -79,7 +81,6 @@ def _get_iface_blocks(data):
if "iface" in line:
if "inet6" in line:
crt_lines = lines6
continue
if lines:
yield lines, lines6
lines[:] = []