diff options
| author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-11-13 08:54:35 -0500 |
|---|---|---|
| committer | Scott Moser <smoser@ubuntu.com> | 2012-11-13 08:54:35 -0500 |
| commit | c26b0674aa2ef31c7c3f7a0392044382cf6a452f (patch) | |
| tree | b049de27577d6fe2400ef52649e6066c700f8c1c /tests/unittests/test_distros/test_hostname.py | |
| parent | 8d5e1e108b0cdd3af872383da7654bec91355b5f (diff) | |
| parent | cd8fbfffdf7ba9ba79d39ee7b4a223d1bd7863b4 (diff) | |
| download | vyos-cloud-init-c26b0674aa2ef31c7c3f7a0392044382cf6a452f.tar.gz vyos-cloud-init-c26b0674aa2ef31c7c3f7a0392044382cf6a452f.zip | |
Use a set of helper/parsing classes to perform system configuration
Previously file modification of system configuration was done
in a functional and hard to test manner. Now instead this patch
allows for a manner that provides a nice object oriented
interface to those objects as well as makes it possible to test
those parsing entities without having to invoke distro class code.
- Created parsers for:
- /etc/sysconfig
- /etc/hostname
- resolv.conf
- /etc/hosts
Moved duplicated functionality into the root level distro class including:
- apply_hostname
- set_hostname
- *various shared configuration file names/paths*
Diffstat (limited to 'tests/unittests/test_distros/test_hostname.py')
| -rw-r--r-- | tests/unittests/test_distros/test_hostname.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unittests/test_distros/test_hostname.py b/tests/unittests/test_distros/test_hostname.py new file mode 100644 index 00000000..8e644f4d --- /dev/null +++ b/tests/unittests/test_distros/test_hostname.py @@ -0,0 +1,38 @@ +from mocker import MockerTestCase + +from cloudinit.distros.parsers import hostname + + +BASE_HOSTNAME = ''' +# My super-duper-hostname + +blahblah + +''' +BASE_HOSTNAME = BASE_HOSTNAME.strip() + + +class TestHostnameHelper(MockerTestCase): + def test_parse_same(self): + hn = hostname.HostnameConf(BASE_HOSTNAME) + self.assertEquals(str(hn).strip(), BASE_HOSTNAME) + self.assertEquals(hn.hostname, 'blahblah') + + def test_no_adjust_hostname(self): + hn = hostname.HostnameConf(BASE_HOSTNAME) + prev_name = hn.hostname + hn.set_hostname("") + self.assertEquals(hn.hostname, prev_name) + + def test_adjust_hostname(self): + hn = hostname.HostnameConf(BASE_HOSTNAME) + prev_name = hn.hostname + self.assertEquals(prev_name, 'blahblah') + hn.set_hostname("bbbbd") + self.assertEquals(hn.hostname, 'bbbbd') + expected_out = ''' +# My super-duper-hostname + +bbbbd +''' + self.assertEquals(str(hn).strip(), expected_out.strip()) |
