~harlowja/cloud-init/group-dict-fix

« back to all changes in this revision

Viewing changes to tests/unittests/test_handler/test_handler_set_hostname.py

  • Committer: Joshua Harlow
  • Date: 2012-11-09 22:37:21 UTC
  • mfrom: (702.2.2 cloud-init)
  • Revision ID: harlowja@yahoo-inc.com-20121109223721-tq10b450d0n0l79v
Fix the fqdn/hostname case for rhel and ubuntu
where rhel uses the fqdn for its config while
ubuntu uses the short hostname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from cloudinit.config import cc_set_hostname
 
2
 
 
3
from cloudinit import cloud
 
4
from cloudinit import distros
 
5
from cloudinit import helpers
 
6
from cloudinit import util
 
7
 
 
8
from tests.unittests import helpers as t_help
 
9
 
 
10
import logging
 
11
 
 
12
from StringIO import StringIO
 
13
 
 
14
from configobj import ConfigObj
 
15
 
 
16
LOG = logging.getLogger(__name__)
 
17
 
 
18
 
 
19
class TestHostname(t_help.FilesystemMockingTestCase):
 
20
    def setUp(self):
 
21
        super(TestHostname, self).setUp()
 
22
        self.tmp = self.makeDir(prefix="unittest_")
 
23
 
 
24
    def _fetch_distro(self, kind):
 
25
        cls = distros.fetch(kind)
 
26
        paths = helpers.Paths({})
 
27
        return cls(kind, {}, paths)
 
28
 
 
29
    def test_write_hostname_rhel(self):
 
30
        cfg = {
 
31
            'hostname': 'blah.blah.blah.yahoo.com',
 
32
        }
 
33
        distro = self._fetch_distro('rhel')
 
34
        paths = helpers.Paths({})
 
35
        ds = None
 
36
        cc = cloud.Cloud(ds, paths, {}, distro, None)
 
37
        self.patchUtils(self.tmp)
 
38
        self.patchOS(self.tmp)
 
39
        cc_set_hostname.handle('cc_set_hostname',
 
40
                               cfg, cc, LOG, [])
 
41
        contents = util.load_file("/etc/sysconfig/network")
 
42
        n_cfg = ConfigObj(StringIO(contents))
 
43
        self.assertEquals({'HOSTNAME': 'blah.blah.blah.yahoo.com'},
 
44
                          dict(n_cfg))
 
45
 
 
46
    def test_write_hostname_debian(self):
 
47
        cfg = {
 
48
            'hostname': 'blah.blah.blah.yahoo.com',
 
49
        }
 
50
        distro = self._fetch_distro('debian')
 
51
        paths = helpers.Paths({})
 
52
        ds = None
 
53
        cc = cloud.Cloud(ds, paths, {}, distro, None)
 
54
        self.patchUtils(self.tmp)
 
55
        cc_set_hostname.handle('cc_set_hostname',
 
56
                               cfg, cc, LOG, [])
 
57
        contents = util.load_file("/etc/hostname")
 
58
        self.assertEquals('blah', contents.strip())