diff options
author | sshedi <53473811+sshedi@users.noreply.github.com> | 2021-07-23 21:10:41 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-23 10:40:41 -0500 |
commit | 6e7066ea2b06940c4931f0258c7982b09966582f (patch) | |
tree | 6b960749538b4544b88a83c33253c5703efc430f /tests | |
parent | 4257e30ac4b8730af35c078f2df0a2234dd19ffa (diff) | |
download | vyos-cloud-init-6e7066ea2b06940c4931f0258c7982b09966582f.tar.gz vyos-cloud-init-6e7066ea2b06940c4931f0258c7982b09966582f.zip |
Add ability to manage fallback network config on PhotonOS (#941)
Currently cloud-init generates fallback network config on various
scenarios.
For example:
1. When no DS found
2. There is no 'network' info given in DS metadata.
3. If a DS gives a network config once and upon reboot if DS doesn't
give any network info, previously set network data will be
overridden.
A newly introduced key in cloud.cfg.tmpl can be used to control this
behavior on PhotonOS.
Also, if OS comes with a set of default network files(configs), like in
PhotonOS, cloud-init should not overwrite them by default.
This change also includes some nitpicking changes of reorganizing few
config variables.
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_distros/test_photon.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/unittests/test_distros/test_photon.py b/tests/unittests/test_distros/test_photon.py new file mode 100644 index 00000000..775f37ac --- /dev/null +++ b/tests/unittests/test_distros/test_photon.py @@ -0,0 +1,51 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +from . import _get_distro +from cloudinit import util +from cloudinit.tests.helpers import mock +from cloudinit.tests.helpers import CiTestCase + +SYSTEM_INFO = { + 'paths': { + 'cloud_dir': '/var/lib/cloud/', + 'templates_dir': '/etc/cloud/templates/', + }, + 'network': {'renderers': 'networkd'}, +} + + +class TestPhoton(CiTestCase): + with_logs = True + distro = _get_distro('photon', SYSTEM_INFO) + expected_log_line = 'Rely on PhotonOS default network config' + + def test_network_renderer(self): + self.assertEqual(self.distro._cfg['network']['renderers'], 'networkd') + + def test_get_distro(self): + self.assertEqual(self.distro.osfamily, 'photon') + + def test_write_hostname(self): + hostname = 'myhostname' + hostfile = self.tmp_path('hostfile') + self.distro._write_hostname(hostname, hostfile) + self.assertEqual(hostname + '\n', util.load_file(hostfile)) + + @mock.patch('cloudinit.net.generate_fallback_config') + def test_fallback_netcfg(self, m_fallback_cfg): + + key = 'disable_fallback_netcfg' + # Don't use fallback if no setting given + self.logs.truncate(0) + assert(self.distro.generate_fallback_config() is None) + self.assertIn(self.expected_log_line, self.logs.getvalue()) + + self.logs.truncate(0) + self.distro._cfg[key] = True + assert(self.distro.generate_fallback_config() is None) + self.assertIn(self.expected_log_line, self.logs.getvalue()) + + self.logs.truncate(0) + self.distro._cfg[key] = False + assert(self.distro.generate_fallback_config() is not None) + self.assertNotIn(self.expected_log_line, self.logs.getvalue()) |