~smoser/cloud-init/lp-1077700

« back to all changes in this revision

Viewing changes to cloudinit/distros/debian.py

  • Committer: Scott Moser
  • Author(s): Joshua Harlow
  • Date: 2012-11-07 15:42:54 UTC
  • mfrom: (696.1.2 pylint-join-cleanup)
  • Revision ID: smoser@ubuntu.com-20121107154254-lhs4c0cu79unybbs
test and path cleanups.

1. Remove the usage of the path.join function now that all code should
   be going through the util file methods (and they can be mocked out as
   needed).
2. Adjust all occurences of the above join function to either not use it
   or replace it with the standard os.path.join (which can also be mocked
   out as needed)
3. Fix pylint from complaining about the tests folder 'helpers.py' not
   being found.
4. Add a pylintrc file that is used instead of the options hidden in the
   'run_pylint' tool.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
    def apply_locale(self, locale, out_fn=None):
45
45
        if not out_fn:
46
 
            out_fn = self._paths.join(False, '/etc/default/locale')
 
46
            out_fn = '/etc/default/locale'
47
47
        util.subp(['locale-gen', locale], capture=False)
48
48
        util.subp(['update-locale', locale], capture=False)
49
49
        lines = ["# Created by cloud-init", 'LANG="%s"' % (locale), ""]
54
54
        self.package_command('install', pkglist)
55
55
 
56
56
    def _write_network(self, settings):
57
 
        net_fn = self._paths.join(False, "/etc/network/interfaces")
58
 
        util.write_file(net_fn, settings)
 
57
        util.write_file("/etc/network/interfaces", settings)
59
58
        return ['all']
60
59
 
61
60
    def _bring_up_interfaces(self, device_names):
69
68
            return distros.Distro._bring_up_interfaces(self, device_names)
70
69
 
71
70
    def set_hostname(self, hostname):
72
 
        out_fn = self._paths.join(False, "/etc/hostname")
73
 
        self._write_hostname(hostname, out_fn)
74
 
        if out_fn == '/etc/hostname':
75
 
            # Only do this if we are running in non-adjusted root mode
76
 
            LOG.debug("Setting hostname to %s", hostname)
77
 
            util.subp(['hostname', hostname])
 
71
        self._write_hostname(hostname, "/etc/hostname")
 
72
        LOG.debug("Setting hostname to %s", hostname)
 
73
        util.subp(['hostname', hostname])
78
74
 
79
75
    def _write_hostname(self, hostname, out_fn):
80
76
        # "" gives trailing newline.
82
78
 
83
79
    def update_hostname(self, hostname, prev_fn):
84
80
        hostname_prev = self._read_hostname(prev_fn)
85
 
        read_fn = self._paths.join(True, "/etc/hostname")
86
 
        hostname_in_etc = self._read_hostname(read_fn)
 
81
        hostname_in_etc = self._read_hostname("/etc/hostname")
87
82
        update_files = []
88
83
        if not hostname_prev or hostname_prev != hostname:
89
84
            update_files.append(prev_fn)
90
85
        if (not hostname_in_etc or
91
86
            (hostname_in_etc == hostname_prev and
92
87
             hostname_in_etc != hostname)):
93
 
            write_fn = self._paths.join(False, "/etc/hostname")
94
 
            update_files.append(write_fn)
 
88
            update_files.append("/etc/hostname")
95
89
        for fn in update_files:
96
90
            try:
97
91
                self._write_hostname(hostname, fn)
103
97
            LOG.debug(("%s differs from /etc/hostname."
104
98
                        " Assuming user maintained hostname."), prev_fn)
105
99
        if "/etc/hostname" in update_files:
106
 
            # Only do this if we are running in non-adjusted root mode
107
100
            LOG.debug("Setting hostname to %s", hostname)
108
101
            util.subp(['hostname', hostname])
109
102
 
130
123
                                " no file found at %s") % (tz, tz_file))
131
124
        # "" provides trailing newline during join
132
125
        tz_lines = ["# Created by cloud-init", str(tz), ""]
133
 
        tz_fn = self._paths.join(False, "/etc/timezone")
134
 
        util.write_file(tz_fn, "\n".join(tz_lines))
135
 
        util.copy(tz_file, self._paths.join(False, "/etc/localtime"))
 
126
        util.write_file("/etc/timezone", "\n".join(tz_lines))
 
127
        util.copy(tz_file, "/etc/localtime")
136
128
 
137
129
    def package_command(self, command, args=None):
138
130
        e = os.environ.copy()