diff options
author | Shreenidhi Shedi <53473811+sshedi@users.noreply.github.com> | 2021-08-31 00:51:10 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 14:21:10 -0500 |
commit | 7fc3f08ebc20eb496b3d318bb718ece569b10dba (patch) | |
tree | 9399b1b552aafa5f16096bd54e1566c1576bdc40 | |
parent | de8931edc4093013fd685938e1c4e5a3d53f653c (diff) | |
download | vyos-cloud-init-7fc3f08ebc20eb496b3d318bb718ece569b10dba.tar.gz vyos-cloud-init-7fc3f08ebc20eb496b3d318bb718ece569b10dba.zip |
Add support to accept-ra in networkd renderer (#999)
Also fix search path in networkd
-rw-r--r-- | cloudinit/net/networkd.py | 6 | ||||
-rw-r--r-- | tests/unittests/test_net.py | 74 | ||||
-rw-r--r-- | tests/unittests/test_net_activators.py | 4 |
3 files changed, 81 insertions, 3 deletions
diff --git a/cloudinit/net/networkd.py b/cloudinit/net/networkd.py index a311572f..ee6fd2ad 100644 --- a/cloudinit/net/networkd.py +++ b/cloudinit/net/networkd.py @@ -160,6 +160,10 @@ class Renderer(renderer.Renderer): cfg.update_section(sec, 'DHCP', dhcp) + if (dhcp in ['ipv6', 'yes'] and + isinstance(iface.get('accept-ra', ''), bool)): + cfg.update_section(sec, 'IPv6AcceptRA', iface['accept-ra']) + # This is to accommodate extra keys present in VMware config def dhcp_domain(self, d, cfg): for item in ['dhcp4domain', 'dhcp6domain']: @@ -247,7 +251,7 @@ class Renderer(renderer.Renderer): def available(target=None): expected = ['ip', 'systemctl'] - search = ['/usr/bin', '/bin'] + search = ['/usr/sbin', '/bin'] for p in expected: if not subp.which(p, search=search, target=target): return False diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index fc77b11e..094450b4 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -1205,6 +1205,13 @@ NETWORK_CONFIGS = { USERCTL=no """), }, + 'expected_networkd': textwrap.dedent("""\ + [Match] + Name=iface0 + [Network] + DHCP=ipv6 + IPv6AcceptRA=True + """).rstrip(' '), }, 'dhcpv6_reject_ra': { 'expected_eni': textwrap.dedent("""\ @@ -1260,6 +1267,13 @@ NETWORK_CONFIGS = { USERCTL=no """), }, + 'expected_networkd': textwrap.dedent("""\ + [Match] + Name=iface0 + [Network] + DHCP=ipv6 + IPv6AcceptRA=False + """).rstrip(' '), }, 'ipv6_slaac': { 'expected_eni': textwrap.dedent("""\ @@ -5203,6 +5217,66 @@ class TestNetworkdRoundTrip(CiTestCase): self.compare_dicts(actual, expected) + @mock.patch("cloudinit.net.util.chownbyname", return_value=True) + def test_dhcpv6_accept_ra_config_v1(self, m_chown): + nwk_fn = '/etc/systemd/network/10-cloud-init-iface0.network' + entry = NETWORK_CONFIGS['dhcpv6_accept_ra'] + files = self._render_and_read(network_config=yaml.load( + entry['yaml_v1'])) + + actual = files[nwk_fn].splitlines() + actual = self.create_conf_dict(actual) + + expected = entry['expected_networkd'].splitlines() + expected = self.create_conf_dict(expected) + + self.compare_dicts(actual, expected) + + @mock.patch("cloudinit.net.util.chownbyname", return_value=True) + def test_dhcpv6_accept_ra_config_v2(self, m_chown): + nwk_fn = '/etc/systemd/network/10-cloud-init-iface0.network' + entry = NETWORK_CONFIGS['dhcpv6_accept_ra'] + files = self._render_and_read(network_config=yaml.load( + entry['yaml_v2'])) + + actual = files[nwk_fn].splitlines() + actual = self.create_conf_dict(actual) + + expected = entry['expected_networkd'].splitlines() + expected = self.create_conf_dict(expected) + + self.compare_dicts(actual, expected) + + @mock.patch("cloudinit.net.util.chownbyname", return_value=True) + def test_dhcpv6_reject_ra_config_v1(self, m_chown): + nwk_fn = '/etc/systemd/network/10-cloud-init-iface0.network' + entry = NETWORK_CONFIGS['dhcpv6_reject_ra'] + files = self._render_and_read(network_config=yaml.load( + entry['yaml_v1'])) + + actual = files[nwk_fn].splitlines() + actual = self.create_conf_dict(actual) + + expected = entry['expected_networkd'].splitlines() + expected = self.create_conf_dict(expected) + + self.compare_dicts(actual, expected) + + @mock.patch("cloudinit.net.util.chownbyname", return_value=True) + def test_dhcpv6_reject_ra_config_v2(self, m_chown): + nwk_fn = '/etc/systemd/network/10-cloud-init-iface0.network' + entry = NETWORK_CONFIGS['dhcpv6_reject_ra'] + files = self._render_and_read(network_config=yaml.load( + entry['yaml_v2'])) + + actual = files[nwk_fn].splitlines() + actual = self.create_conf_dict(actual) + + expected = entry['expected_networkd'].splitlines() + expected = self.create_conf_dict(expected) + + self.compare_dicts(actual, expected) + class TestRenderersSelect: diff --git a/tests/unittests/test_net_activators.py b/tests/unittests/test_net_activators.py index 38f2edf2..f63a8b74 100644 --- a/tests/unittests/test_net_activators.py +++ b/tests/unittests/test_net_activators.py @@ -118,8 +118,8 @@ NETWORK_MANAGER_AVAILABLE_CALLS = [ ] NETWORKD_AVAILABLE_CALLS = [ - (('ip',), {'search': ['/usr/bin', '/bin'], 'target': None}), - (('systemctl',), {'search': ['/usr/bin', '/bin'], 'target': None}), + (('ip',), {'search': ['/usr/sbin', '/bin'], 'target': None}), + (('systemctl',), {'search': ['/usr/sbin', '/bin'], 'target': None}), ] |