summaryrefslogtreecommitdiff
path: root/tests/unittests/test_distros
diff options
context:
space:
mode:
authorsshedi <53473811+sshedi@users.noreply.github.com>2021-08-09 22:19:13 +0530
committerGitHub <noreply@github.com>2021-08-09 11:49:13 -0500
commit049d62b658b06e729291def6b7b6f9520827d0ba (patch)
tree7c7166cc75742c66c58087609acb4d7ea9ab61f3 /tests/unittests/test_distros
parent00dbaf1e9ab0e59d81662f0f3561897bef499a3f (diff)
downloadvyos-cloud-init-049d62b658b06e729291def6b7b6f9520827d0ba.tar.gz
vyos-cloud-init-049d62b658b06e729291def6b7b6f9520827d0ba.zip
photon: refactor hostname handling and add networkd activator (#958)
Diffstat (limited to 'tests/unittests/test_distros')
-rw-r--r--tests/unittests/test_distros/test_photon.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/tests/unittests/test_distros/test_photon.py b/tests/unittests/test_distros/test_photon.py
index 775f37ac..1c3145ca 100644
--- a/tests/unittests/test_distros/test_photon.py
+++ b/tests/unittests/test_distros/test_photon.py
@@ -25,11 +25,28 @@ class TestPhoton(CiTestCase):
def test_get_distro(self):
self.assertEqual(self.distro.osfamily, 'photon')
- def test_write_hostname(self):
+ @mock.patch("cloudinit.distros.photon.subp.subp")
+ def test_write_hostname(self, m_subp):
hostname = 'myhostname'
- hostfile = self.tmp_path('hostfile')
+ hostfile = self.tmp_path('previous-hostname')
self.distro._write_hostname(hostname, hostfile)
- self.assertEqual(hostname + '\n', util.load_file(hostfile))
+ self.assertEqual(hostname, util.load_file(hostfile))
+
+ ret = self.distro._read_hostname(hostfile)
+ self.assertEqual(ret, hostname)
+
+ m_subp.return_value = (None, None)
+ hostfile += 'hostfile'
+ self.distro._write_hostname(hostname, hostfile)
+
+ m_subp.return_value = (hostname, None)
+ ret = self.distro._read_hostname(hostfile)
+ self.assertEqual(ret, hostname)
+
+ self.logs.truncate(0)
+ m_subp.return_value = (None, 'bla')
+ self.distro._write_hostname(hostname, None)
+ self.assertIn('Error while setting hostname', self.logs.getvalue())
@mock.patch('cloudinit.net.generate_fallback_config')
def test_fallback_netcfg(self, m_fallback_cfg):