diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-11-09 14:37:21 -0800 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-11-09 14:37:21 -0800 |
commit | a0f5926d6a238a71f96c6d5ddd617b5a3f78af46 (patch) | |
tree | a26a5996b7e1deb404097c60216c979858b12969 /tests/unittests | |
parent | 2199cf29b48f3f9789ce108951121ac6e55c5d4c (diff) | |
parent | bd01f3466e10ca515a8e8aec42d00201f40cbd53 (diff) | |
download | vyos-cloud-init-a0f5926d6a238a71f96c6d5ddd617b5a3f78af46.tar.gz vyos-cloud-init-a0f5926d6a238a71f96c6d5ddd617b5a3f78af46.zip |
Fix the fqdn/hostname case for rhel and ubuntu
where rhel uses the fqdn for its config while
ubuntu uses the short hostname.
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_handler/test_handler_set_hostname.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/unittests/test_handler/test_handler_set_hostname.py b/tests/unittests/test_handler/test_handler_set_hostname.py new file mode 100644 index 00000000..a1aba62f --- /dev/null +++ b/tests/unittests/test_handler/test_handler_set_hostname.py @@ -0,0 +1,58 @@ +from cloudinit.config import cc_set_hostname + +from cloudinit import cloud +from cloudinit import distros +from cloudinit import helpers +from cloudinit import util + +from tests.unittests import helpers as t_help + +import logging + +from StringIO import StringIO + +from configobj import ConfigObj + +LOG = logging.getLogger(__name__) + + +class TestHostname(t_help.FilesystemMockingTestCase): + def setUp(self): + super(TestHostname, self).setUp() + self.tmp = self.makeDir(prefix="unittest_") + + def _fetch_distro(self, kind): + cls = distros.fetch(kind) + paths = helpers.Paths({}) + return cls(kind, {}, paths) + + def test_write_hostname_rhel(self): + cfg = { + 'hostname': 'blah.blah.blah.yahoo.com', + } + distro = self._fetch_distro('rhel') + paths = helpers.Paths({}) + ds = None + cc = cloud.Cloud(ds, paths, {}, distro, None) + self.patchUtils(self.tmp) + self.patchOS(self.tmp) + cc_set_hostname.handle('cc_set_hostname', + cfg, cc, LOG, []) + contents = util.load_file("/etc/sysconfig/network") + n_cfg = ConfigObj(StringIO(contents)) + self.assertEquals({'HOSTNAME': 'blah.blah.blah.yahoo.com'}, + dict(n_cfg)) + + def test_write_hostname_debian(self): + cfg = { + 'hostname': 'blah.blah.blah.yahoo.com', + } + distro = self._fetch_distro('debian') + paths = helpers.Paths({}) + ds = None + cc = cloud.Cloud(ds, paths, {}, distro, None) + self.patchUtils(self.tmp) + cc_set_hostname.handle('cc_set_hostname', + cfg, cc, LOG, []) + contents = util.load_file("/etc/hostname") + self.assertEquals('blah', contents.strip()) |