Joshua Harlow 290d4c38e9 More adjustments/cleanups for the system configuration
helper objects.

1. Add in a parser for the /etc/hostname file that can be shared
2. Adjust the sysconfig configobj parser to not always quote
   fields that it does not need to quote + add in tests around
   this to ensure that we don't go nuts with quoting again.
2012-10-11 12:49:45 -07:00

39 lines
995 B
Python

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())