Joshua Harlow 114525e386 System config niceness!
1. Move out the old helpers that provided oop access/reading/writing
   to various standard conf files and place those in parsers instead.
2. Unify the 'update_hostname' which varied very little	between	distros
   and make it generic so that subclasses can only provide a couple of 
   functions to	obtain the hostname updating functionality
3. Implement that new set of functions in rhel/debian    
4. Use the new parsers chop_comment function for similar use 
   cases as well as add a new utils make header	function that
   can be used for configuration files that are	newly generated
   to use (less	duplication here of this same thing being done
   in multiple places.
5. Add in a distro '_apply_hostname' which calls out to	the 'hostname'
   program to set the system hostname (more duplication	elimination).
6. Make the 'constant' filenames being written to for configuration
   by the various distros be instance members instead of string
   constants 'sprinkled' throughout the code
2012-10-10 16:21:22 -07:00

42 lines
1.3 KiB
Python

from mocker import MockerTestCase
from cloudinit.distros.parsers import hosts
BASE_ETC = '''
# Example
127.0.0.1 localhost
192.168.1.10 foo.mydomain.org foo
192.168.1.10 bar.mydomain.org bar
146.82.138.7 master.debian.org master
209.237.226.90 www.opensource.org
'''
BASE_ETC = BASE_ETC.strip()
class TestHostsHelper(MockerTestCase):
def test_parse(self):
eh = hosts.HostsConf(BASE_ETC)
self.assertEquals(eh.get_entry('127.0.0.1'), [['localhost']])
self.assertEquals(eh.get_entry('192.168.1.10'),
[['foo.mydomain.org', 'foo'],
['bar.mydomain.org', 'bar']])
eh = str(eh)
self.assertTrue(eh.startswith('# Example'))
def test_add(self):
eh = hosts.HostsConf(BASE_ETC)
eh.add_entry('127.0.0.0', 'blah')
self.assertEquals(eh.get_entry('127.0.0.0'), [['blah']])
eh.add_entry('127.0.0.3', 'blah', 'blah2', 'blah3')
self.assertEquals(eh.get_entry('127.0.0.3'),
[['blah', 'blah2', 'blah3']])
def test_del(self):
eh = hosts.HostsConf(BASE_ETC)
eh.add_entry('127.0.0.0', 'blah')
self.assertEquals(eh.get_entry('127.0.0.0'), [['blah']])
eh.del_entries('127.0.0.0')
self.assertEquals(eh.get_entry('127.0.0.0'), [])