summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordermotbradley <dermot_bradley@yahoo.com>2020-11-09 17:24:55 +0000
committerGitHub <noreply@github.com>2020-11-09 12:24:55 -0500
commit57349eb7df1c422d9e9558e54b201c85778997ae (patch)
treec6371d6ebc7b4f31a9898d2e4abaa64cb3cacd4b /tests
parent0dc2d0304a7fa33af18475b99e808fbcdcad44f2 (diff)
downloadvyos-cloud-init-57349eb7df1c422d9e9558e54b201c85778997ae.tar.gz
vyos-cloud-init-57349eb7df1c422d9e9558e54b201c85778997ae.zip
Make wakeonlan Network Config v2 setting actually work (#626)
Add code so that specifying "wakeonlan: true" actually results in relevant configuration entry appearing in /etc/network/interfaces, Netplan, and sysconfig for RHEL and OpenSuse. Add testcases for the above.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_net.py143
1 files changed, 143 insertions, 0 deletions
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 5af82e20..70453683 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -1378,6 +1378,89 @@ NETWORK_CONFIGS = {
"""),
},
},
+ 'wakeonlan_disabled': {
+ 'expected_eni': textwrap.dedent("""\
+ auto lo
+ iface lo inet loopback
+
+ auto iface0
+ iface iface0 inet dhcp
+ """).rstrip(' '),
+ 'expected_netplan': textwrap.dedent("""
+ network:
+ ethernets:
+ iface0:
+ dhcp4: true
+ wakeonlan: false
+ version: 2
+ """),
+ 'expected_sysconfig_opensuse': {
+ 'ifcfg-iface0': textwrap.dedent("""\
+ BOOTPROTO=dhcp4
+ STARTMODE=auto
+ """),
+ },
+ 'expected_sysconfig_rhel': {
+ 'ifcfg-iface0': textwrap.dedent("""\
+ BOOTPROTO=dhcp
+ DEVICE=iface0
+ NM_CONTROLLED=no
+ ONBOOT=yes
+ TYPE=Ethernet
+ USERCTL=no
+ """),
+ },
+ 'yaml_v2': textwrap.dedent("""\
+ version: 2
+ ethernets:
+ iface0:
+ dhcp4: true
+ wakeonlan: false
+ """).rstrip(' '),
+ },
+ 'wakeonlan_enabled': {
+ 'expected_eni': textwrap.dedent("""\
+ auto lo
+ iface lo inet loopback
+
+ auto iface0
+ iface iface0 inet dhcp
+ ethernet-wol g
+ """).rstrip(' '),
+ 'expected_netplan': textwrap.dedent("""
+ network:
+ ethernets:
+ iface0:
+ dhcp4: true
+ wakeonlan: true
+ version: 2
+ """),
+ 'expected_sysconfig_opensuse': {
+ 'ifcfg-iface0': textwrap.dedent("""\
+ BOOTPROTO=dhcp4
+ ETHTOOL_OPTS="wol g"
+ STARTMODE=auto
+ """),
+ },
+ 'expected_sysconfig_rhel': {
+ 'ifcfg-iface0': textwrap.dedent("""\
+ BOOTPROTO=dhcp
+ DEVICE=iface0
+ ETHTOOL_OPTS="wol g"
+ NM_CONTROLLED=no
+ ONBOOT=yes
+ TYPE=Ethernet
+ USERCTL=no
+ """),
+ },
+ 'yaml_v2': textwrap.dedent("""\
+ version: 2
+ ethernets:
+ iface0:
+ dhcp4: true
+ wakeonlan: true
+ """).rstrip(' '),
+ },
'all': {
'expected_eni': ("""\
auto lo
@@ -3293,6 +3376,20 @@ USERCTL=no
self._compare_files_to_expected(entry[self.expected_name], found)
self._assert_headers(found)
+ def test_wakeonlan_disabled_config_v2(self):
+ entry = NETWORK_CONFIGS['wakeonlan_disabled']
+ found = self._render_and_read(network_config=yaml.load(
+ entry['yaml_v2']))
+ self._compare_files_to_expected(entry[self.expected_name], found)
+ self._assert_headers(found)
+
+ def test_wakeonlan_enabled_config_v2(self):
+ entry = NETWORK_CONFIGS['wakeonlan_enabled']
+ found = self._render_and_read(network_config=yaml.load(
+ entry['yaml_v2']))
+ self._compare_files_to_expected(entry[self.expected_name], found)
+ self._assert_headers(found)
+
def test_check_ifcfg_rh(self):
"""ifcfg-rh plugin is added NetworkManager.conf if conf present."""
render_dir = self.tmp_dir()
@@ -3829,6 +3926,20 @@ STARTMODE=auto
self._compare_files_to_expected(entry[self.expected_name], found)
self._assert_headers(found)
+ def test_wakeonlan_disabled_config_v2(self):
+ entry = NETWORK_CONFIGS['wakeonlan_disabled']
+ found = self._render_and_read(network_config=yaml.load(
+ entry['yaml_v2']))
+ self._compare_files_to_expected(entry[self.expected_name], found)
+ self._assert_headers(found)
+
+ def test_wakeonlan_enabled_config_v2(self):
+ entry = NETWORK_CONFIGS['wakeonlan_enabled']
+ found = self._render_and_read(network_config=yaml.load(
+ entry['yaml_v2']))
+ self._compare_files_to_expected(entry[self.expected_name], found)
+ self._assert_headers(found)
+
def test_render_v4_and_v6(self):
entry = NETWORK_CONFIGS['v4_and_v6']
found = self._render_and_read(network_config=yaml.load(entry['yaml']))
@@ -4478,6 +4589,22 @@ class TestNetplanRoundTrip(CiTestCase):
entry['expected_netplan'].splitlines(),
files['/etc/netplan/50-cloud-init.yaml'].splitlines())
+ def testsimple_wakeonlan_disabled_config_v2(self):
+ entry = NETWORK_CONFIGS['wakeonlan_disabled']
+ files = self._render_and_read(network_config=yaml.load(
+ entry['yaml_v2']))
+ self.assertEqual(
+ entry['expected_netplan'].splitlines(),
+ files['/etc/netplan/50-cloud-init.yaml'].splitlines())
+
+ def testsimple_wakeonlan_enabled_config_v2(self):
+ entry = NETWORK_CONFIGS['wakeonlan_enabled']
+ files = self._render_and_read(network_config=yaml.load(
+ entry['yaml_v2']))
+ self.assertEqual(
+ entry['expected_netplan'].splitlines(),
+ files['/etc/netplan/50-cloud-init.yaml'].splitlines())
+
def testsimple_render_all(self):
entry = NETWORK_CONFIGS['all']
files = self._render_and_read(network_config=yaml.load(entry['yaml']))
@@ -4645,6 +4772,22 @@ class TestEniRoundTrip(CiTestCase):
entry['expected_eni'].splitlines(),
files['/etc/network/interfaces'].splitlines())
+ def testsimple_wakeonlan_disabled_config_v2(self):
+ entry = NETWORK_CONFIGS['wakeonlan_disabled']
+ files = self._render_and_read(network_config=yaml.load(
+ entry['yaml_v2']))
+ self.assertEqual(
+ entry['expected_eni'].splitlines(),
+ files['/etc/network/interfaces'].splitlines())
+
+ def testsimple_wakeonlan_enabled_config_v2(self):
+ entry = NETWORK_CONFIGS['wakeonlan_enabled']
+ files = self._render_and_read(network_config=yaml.load(
+ entry['yaml_v2']))
+ self.assertEqual(
+ entry['expected_eni'].splitlines(),
+ files['/etc/network/interfaces'].splitlines())
+
def testsimple_render_manual(self):
"""Test rendering of 'manual' for 'type' and 'control'.