Merge lp:~harlowja/cloud-init/pylint-join-cleanup into lp:~cloud-init-dev/cloud-init/trunk
- pylint-join-cleanup
- Merge into trunk
Proposed by
Joshua Harlow
Status: | Merged |
---|---|
Merged at revision: | 700 |
Proposed branch: | lp:~harlowja/cloud-init/pylint-join-cleanup |
Merge into: | lp:~cloud-init-dev/cloud-init/trunk |
Diff against target: |
1143 lines (+180/-261) 28 files modified
Makefile (+4/-4) cloudinit/config/cc_apt_pipelining.py (+5/-7) cloudinit/config/cc_apt_update_upgrade.py (+7/-10) cloudinit/config/cc_ca_certs.py (+13/-15) cloudinit/config/cc_chef.py (+14/-16) cloudinit/config/cc_landscape.py (+4/-10) cloudinit/config/cc_mcollective.py (+9/-13) cloudinit/config/cc_mounts.py (+4/-5) cloudinit/config/cc_phone_home.py (+2/-2) cloudinit/config/cc_puppet.py (+33/-37) cloudinit/config/cc_resizefs.py (+2/-3) cloudinit/config/cc_rsyslog.py (+1/-2) cloudinit/config/cc_runcmd.py (+1/-1) cloudinit/config/cc_salt_minion.py (+2/-4) cloudinit/config/cc_set_passwords.py (+2/-4) cloudinit/config/cc_ssh.py (+7/-9) cloudinit/config/cc_ssh_authkey_fingerprints.py (+3/-4) cloudinit/config/cc_update_etc_hosts.py (+1/-2) cloudinit/distros/__init__.py (+3/-5) cloudinit/distros/debian.py (+9/-17) cloudinit/helpers.py (+1/-28) cloudinit/sources/__init__.py (+0/-2) cloudinit/ssh_util.py (+15/-19) pylintrc (+19/-0) tests/unittests/test_filters/test_launch_index.py (+2/-10) tests/unittests/test_handler/test_handler_ca_certs.py (+9/-9) tests/unittests/test_runs/test_simple_run.py (+2/-10) tools/run-pylint (+6/-13) |
To merge this branch: | bzr merge lp:~harlowja/cloud-init/pylint-join-cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
cloud-init Commiters | Pending | ||
Review via email: mp+131765@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Makefile' |
2 | --- Makefile 2012-08-09 17:42:55 +0000 |
3 | +++ Makefile 2012-10-28 02:29:21 +0000 |
4 | @@ -1,20 +1,20 @@ |
5 | CWD=$(shell pwd) |
6 | -PY_FILES=$(shell find cloudinit bin tests tools -name "*.py") |
7 | +PY_FILES=$(shell find cloudinit bin tests tools -type f -name "*.py") |
8 | PY_FILES+="bin/cloud-init" |
9 | |
10 | all: test |
11 | |
12 | pep8: |
13 | - $(CWD)/tools/run-pep8 $(PY_FILES) |
14 | + @$(CWD)/tools/run-pep8 $(PY_FILES) |
15 | |
16 | pylint: |
17 | - $(CWD)/tools/run-pylint $(PY_FILES) |
18 | + @$(CWD)/tools/run-pylint $(PY_FILES) |
19 | |
20 | pyflakes: |
21 | pyflakes $(PY_FILES) |
22 | |
23 | test: |
24 | - nosetests $(noseopts) tests/unittests/ |
25 | + @nosetests $(noseopts) tests/ |
26 | |
27 | 2to3: |
28 | 2to3 $(PY_FILES) |
29 | |
30 | === modified file 'cloudinit/config/cc_apt_pipelining.py' |
31 | --- cloudinit/config/cc_apt_pipelining.py 2012-08-22 18:12:32 +0000 |
32 | +++ cloudinit/config/cc_apt_pipelining.py 2012-10-28 02:29:21 +0000 |
33 | @@ -34,26 +34,24 @@ |
34 | # on TCP connections - otherwise data corruption will occur. |
35 | |
36 | |
37 | -def handle(_name, cfg, cloud, log, _args): |
38 | +def handle(_name, cfg, _cloud, log, _args): |
39 | |
40 | apt_pipe_value = util.get_cfg_option_str(cfg, "apt_pipelining", False) |
41 | apt_pipe_value_s = str(apt_pipe_value).lower().strip() |
42 | |
43 | if apt_pipe_value_s == "false": |
44 | - write_apt_snippet(cloud, "0", log, DEFAULT_FILE) |
45 | + write_apt_snippet("0", log, DEFAULT_FILE) |
46 | elif apt_pipe_value_s in ("none", "unchanged", "os"): |
47 | return |
48 | elif apt_pipe_value_s in [str(b) for b in xrange(0, 6)]: |
49 | - write_apt_snippet(cloud, apt_pipe_value_s, log, DEFAULT_FILE) |
50 | + write_apt_snippet(apt_pipe_value_s, log, DEFAULT_FILE) |
51 | else: |
52 | log.warn("Invalid option for apt_pipeling: %s", apt_pipe_value) |
53 | |
54 | |
55 | -def write_apt_snippet(cloud, setting, log, f_name): |
56 | +def write_apt_snippet(setting, log, f_name): |
57 | """Writes f_name with apt pipeline depth 'setting'.""" |
58 | |
59 | file_contents = APT_PIPE_TPL % (setting) |
60 | - |
61 | - util.write_file(cloud.paths.join(False, f_name), file_contents) |
62 | - |
63 | + util.write_file(f_name, file_contents) |
64 | log.debug("Wrote %s with apt pipeline depth setting %s", f_name, setting) |
65 | |
66 | === modified file 'cloudinit/config/cc_apt_update_upgrade.py' |
67 | --- cloudinit/config/cc_apt_update_upgrade.py 2012-08-22 21:02:54 +0000 |
68 | +++ cloudinit/config/cc_apt_update_upgrade.py 2012-10-28 02:29:21 +0000 |
69 | @@ -78,8 +78,7 @@ |
70 | try: |
71 | # See man 'apt.conf' |
72 | contents = PROXY_TPL % (proxy) |
73 | - util.write_file(cloud.paths.join(False, proxy_filename), |
74 | - contents) |
75 | + util.write_file(proxy_filename, contents) |
76 | except Exception as e: |
77 | util.logexc(log, "Failed to write proxy to %s", proxy_filename) |
78 | elif os.path.isfile(proxy_filename): |
79 | @@ -90,7 +89,7 @@ |
80 | params = mirrors |
81 | params['RELEASE'] = release |
82 | params['MIRROR'] = mirror |
83 | - errors = add_sources(cloud, cfg['apt_sources'], params) |
84 | + errors = add_sources(cfg['apt_sources'], params) |
85 | for e in errors: |
86 | log.warn("Source Error: %s", ':'.join(e)) |
87 | |
88 | @@ -196,11 +195,10 @@ |
89 | params = {'codename': codename} |
90 | for k in mirrors: |
91 | params[k] = mirrors[k] |
92 | - out_fn = cloud.paths.join(False, '/etc/apt/sources.list') |
93 | - templater.render_to_file(template_fn, out_fn, params) |
94 | - |
95 | - |
96 | -def add_sources(cloud, srclist, template_params=None): |
97 | + templater.render_to_file(template_fn, '/etc/apt/sources.list', params) |
98 | + |
99 | + |
100 | +def add_sources(srclist, template_params=None): |
101 | """ |
102 | add entries in /etc/apt/sources.list.d for each abbreviated |
103 | sources.list entry in 'srclist'. When rendering template, also |
104 | @@ -250,8 +248,7 @@ |
105 | |
106 | try: |
107 | contents = "%s\n" % (source) |
108 | - util.write_file(cloud.paths.join(False, ent['filename']), |
109 | - contents, omode="ab") |
110 | + util.write_file(ent['filename'], contents, omode="ab") |
111 | except: |
112 | errorlist.append([source, |
113 | "failed write to file %s" % ent['filename']]) |
114 | |
115 | === modified file 'cloudinit/config/cc_ca_certs.py' |
116 | --- cloudinit/config/cc_ca_certs.py 2012-06-23 03:59:23 +0000 |
117 | +++ cloudinit/config/cc_ca_certs.py 2012-10-28 02:29:21 +0000 |
118 | @@ -22,6 +22,7 @@ |
119 | CA_CERT_FILENAME = "cloud-init-ca-certs.crt" |
120 | CA_CERT_CONFIG = "/etc/ca-certificates.conf" |
121 | CA_CERT_SYSTEM_PATH = "/etc/ssl/certs/" |
122 | +CA_CERT_FULL_PATH = os.path.join(CA_CERT_PATH, CA_CERT_FILENAME) |
123 | |
124 | distros = ['ubuntu', 'debian'] |
125 | |
126 | @@ -33,7 +34,7 @@ |
127 | util.subp(["update-ca-certificates"], capture=False) |
128 | |
129 | |
130 | -def add_ca_certs(paths, certs): |
131 | +def add_ca_certs(certs): |
132 | """ |
133 | Adds certificates to the system. To actually apply the new certificates |
134 | you must also call L{update_ca_certs}. |
135 | @@ -43,27 +44,24 @@ |
136 | if certs: |
137 | # First ensure they are strings... |
138 | cert_file_contents = "\n".join([str(c) for c in certs]) |
139 | - cert_file_fullpath = os.path.join(CA_CERT_PATH, CA_CERT_FILENAME) |
140 | - cert_file_fullpath = paths.join(False, cert_file_fullpath) |
141 | - util.write_file(cert_file_fullpath, cert_file_contents, mode=0644) |
142 | + util.write_file(CA_CERT_FULL_PATH, cert_file_contents, mode=0644) |
143 | # Append cert filename to CA_CERT_CONFIG file. |
144 | - util.write_file(paths.join(False, CA_CERT_CONFIG), |
145 | - "\n%s" % CA_CERT_FILENAME, omode="ab") |
146 | - |
147 | - |
148 | -def remove_default_ca_certs(paths): |
149 | + util.write_file(CA_CERT_CONFIG, "\n%s" % CA_CERT_FILENAME, omode="ab") |
150 | + |
151 | + |
152 | +def remove_default_ca_certs(): |
153 | """ |
154 | Removes all default trusted CA certificates from the system. To actually |
155 | apply the change you must also call L{update_ca_certs}. |
156 | """ |
157 | - util.delete_dir_contents(paths.join(False, CA_CERT_PATH)) |
158 | - util.delete_dir_contents(paths.join(False, CA_CERT_SYSTEM_PATH)) |
159 | - util.write_file(paths.join(False, CA_CERT_CONFIG), "", mode=0644) |
160 | + util.delete_dir_contents(CA_CERT_PATH) |
161 | + util.delete_dir_contents(CA_CERT_SYSTEM_PATH) |
162 | + util.write_file(CA_CERT_CONFIG, "", mode=0644) |
163 | debconf_sel = "ca-certificates ca-certificates/trust_new_crts select no" |
164 | util.subp(('debconf-set-selections', '-'), debconf_sel) |
165 | |
166 | |
167 | -def handle(name, cfg, cloud, log, _args): |
168 | +def handle(name, cfg, _cloud, log, _args): |
169 | """ |
170 | Call to handle ca-cert sections in cloud-config file. |
171 | |
172 | @@ -85,14 +83,14 @@ |
173 | # default trusted CA certs first. |
174 | if ca_cert_cfg.get("remove-defaults", False): |
175 | log.debug("Removing default certificates") |
176 | - remove_default_ca_certs(cloud.paths) |
177 | + remove_default_ca_certs() |
178 | |
179 | # If we are given any new trusted CA certs to add, add them. |
180 | if "trusted" in ca_cert_cfg: |
181 | trusted_certs = util.get_cfg_option_list(ca_cert_cfg, "trusted") |
182 | if trusted_certs: |
183 | log.debug("Adding %d certificates" % len(trusted_certs)) |
184 | - add_ca_certs(cloud.paths, trusted_certs) |
185 | + add_ca_certs(trusted_certs) |
186 | |
187 | # Update the system with the new cert configuration. |
188 | log.debug("Updating certificates") |
189 | |
190 | === modified file 'cloudinit/config/cc_chef.py' |
191 | --- cloudinit/config/cc_chef.py 2012-06-23 06:26:50 +0000 |
192 | +++ cloudinit/config/cc_chef.py 2012-10-28 02:29:21 +0000 |
193 | @@ -26,6 +26,15 @@ |
194 | |
195 | RUBY_VERSION_DEFAULT = "1.8" |
196 | |
197 | +CHEF_DIRS = [ |
198 | + '/etc/chef', |
199 | + '/var/log/chef', |
200 | + '/var/lib/chef', |
201 | + '/var/cache/chef', |
202 | + '/var/backups/chef', |
203 | + '/var/run/chef', |
204 | +] |
205 | + |
206 | |
207 | def handle(name, cfg, cloud, log, _args): |
208 | |
209 | @@ -37,24 +46,15 @@ |
210 | chef_cfg = cfg['chef'] |
211 | |
212 | # Ensure the chef directories we use exist |
213 | - c_dirs = [ |
214 | - '/etc/chef', |
215 | - '/var/log/chef', |
216 | - '/var/lib/chef', |
217 | - '/var/cache/chef', |
218 | - '/var/backups/chef', |
219 | - '/var/run/chef', |
220 | - ] |
221 | - for d in c_dirs: |
222 | - util.ensure_dir(cloud.paths.join(False, d)) |
223 | + for d in CHEF_DIRS: |
224 | + util.ensure_dir(d) |
225 | |
226 | # Set the validation key based on the presence of either 'validation_key' |
227 | # or 'validation_cert'. In the case where both exist, 'validation_key' |
228 | # takes precedence |
229 | for key in ('validation_key', 'validation_cert'): |
230 | if key in chef_cfg and chef_cfg[key]: |
231 | - v_fn = cloud.paths.join(False, '/etc/chef/validation.pem') |
232 | - util.write_file(v_fn, chef_cfg[key]) |
233 | + util.write_file('/etc/chef/validation.pem', chef_cfg[key]) |
234 | break |
235 | |
236 | # Create the chef config from template |
237 | @@ -68,8 +68,7 @@ |
238 | '_default'), |
239 | 'validation_name': chef_cfg['validation_name'] |
240 | } |
241 | - out_fn = cloud.paths.join(False, '/etc/chef/client.rb') |
242 | - templater.render_to_file(template_fn, out_fn, params) |
243 | + templater.render_to_file(template_fn, '/etc/chef/client.rb', params) |
244 | else: |
245 | log.warn("No template found, not rendering to /etc/chef/client.rb") |
246 | |
247 | @@ -81,8 +80,7 @@ |
248 | initial_attributes = chef_cfg['initial_attributes'] |
249 | for k in list(initial_attributes.keys()): |
250 | initial_json[k] = initial_attributes[k] |
251 | - firstboot_fn = cloud.paths.join(False, '/etc/chef/firstboot.json') |
252 | - util.write_file(firstboot_fn, json.dumps(initial_json)) |
253 | + util.write_file('/etc/chef/firstboot.json', json.dumps(initial_json)) |
254 | |
255 | # If chef is not installed, we install chef based on 'install_type' |
256 | if not os.path.isfile('/usr/bin/chef-client'): |
257 | |
258 | === modified file 'cloudinit/config/cc_landscape.py' |
259 | --- cloudinit/config/cc_landscape.py 2012-10-23 10:57:26 +0000 |
260 | +++ cloudinit/config/cc_landscape.py 2012-10-28 02:29:21 +0000 |
261 | @@ -66,22 +66,16 @@ |
262 | |
263 | merge_data = [ |
264 | LSC_BUILTIN_CFG, |
265 | - cloud.paths.join(True, LSC_CLIENT_CFG_FILE), |
266 | + LSC_CLIENT_CFG_FILE, |
267 | ls_cloudcfg, |
268 | ] |
269 | merged = merge_together(merge_data) |
270 | - |
271 | - lsc_client_fn = cloud.paths.join(False, LSC_CLIENT_CFG_FILE) |
272 | - lsc_dir = cloud.paths.join(False, os.path.dirname(lsc_client_fn)) |
273 | - if not os.path.isdir(lsc_dir): |
274 | - util.ensure_dir(lsc_dir) |
275 | - |
276 | contents = StringIO() |
277 | merged.write(contents) |
278 | - contents.flush() |
279 | |
280 | - util.write_file(lsc_client_fn, contents.getvalue()) |
281 | - log.debug("Wrote landscape config file to %s", lsc_client_fn) |
282 | + util.ensure_dir(os.path.dirname(LSC_CLIENT_CFG_FILE)) |
283 | + util.write_file(LSC_CLIENT_CFG_FILE, contents.getvalue()) |
284 | + log.debug("Wrote landscape config file to %s", LSC_CLIENT_CFG_FILE) |
285 | |
286 | util.write_file(LS_DEFAULT_FILE, "RUN=1\n") |
287 | util.subp(["service", "landscape-client", "restart"]) |
288 | |
289 | === modified file 'cloudinit/config/cc_mcollective.py' |
290 | --- cloudinit/config/cc_mcollective.py 2012-06-22 15:48:18 +0000 |
291 | +++ cloudinit/config/cc_mcollective.py 2012-10-28 02:29:21 +0000 |
292 | @@ -29,6 +29,7 @@ |
293 | |
294 | PUBCERT_FILE = "/etc/mcollective/ssl/server-public.pem" |
295 | PRICERT_FILE = "/etc/mcollective/ssl/server-private.pem" |
296 | +SERVER_CFG = '/etc/mcollective/server.cfg' |
297 | |
298 | |
299 | def handle(name, cfg, cloud, log, _args): |
300 | @@ -48,26 +49,23 @@ |
301 | if 'conf' in mcollective_cfg: |
302 | # Read server.cfg values from the |
303 | # original file in order to be able to mix the rest up |
304 | - server_cfg_fn = cloud.paths.join(True, '/etc/mcollective/server.cfg') |
305 | - mcollective_config = ConfigObj(server_cfg_fn) |
306 | + mcollective_config = ConfigObj(SERVER_CFG) |
307 | # See: http://tiny.cc/jh9agw |
308 | for (cfg_name, cfg) in mcollective_cfg['conf'].iteritems(): |
309 | if cfg_name == 'public-cert': |
310 | - pubcert_fn = cloud.paths.join(True, PUBCERT_FILE) |
311 | - util.write_file(pubcert_fn, cfg, mode=0644) |
312 | - mcollective_config['plugin.ssl_server_public'] = pubcert_fn |
313 | + util.write_file(PUBCERT_FILE, cfg, mode=0644) |
314 | + mcollective_config['plugin.ssl_server_public'] = PUBCERT_FILE |
315 | mcollective_config['securityprovider'] = 'ssl' |
316 | elif cfg_name == 'private-cert': |
317 | - pricert_fn = cloud.paths.join(True, PRICERT_FILE) |
318 | - util.write_file(pricert_fn, cfg, mode=0600) |
319 | - mcollective_config['plugin.ssl_server_private'] = pricert_fn |
320 | + util.write_file(PRICERT_FILE, cfg, mode=0600) |
321 | + mcollective_config['plugin.ssl_server_private'] = PRICERT_FILE |
322 | mcollective_config['securityprovider'] = 'ssl' |
323 | else: |
324 | if isinstance(cfg, (basestring, str)): |
325 | # Just set it in the 'main' section |
326 | mcollective_config[cfg_name] = cfg |
327 | elif isinstance(cfg, (dict)): |
328 | - # Iterate throug the config items, create a section |
329 | + # Iterate through the config items, create a section |
330 | # if it is needed and then add/or create items as needed |
331 | if cfg_name not in mcollective_config.sections: |
332 | mcollective_config[cfg_name] = {} |
333 | @@ -78,14 +76,12 @@ |
334 | mcollective_config[cfg_name] = str(cfg) |
335 | # We got all our config as wanted we'll rename |
336 | # the previous server.cfg and create our new one |
337 | - old_fn = cloud.paths.join(False, '/etc/mcollective/server.cfg.old') |
338 | - util.rename(server_cfg_fn, old_fn) |
339 | + util.rename(SERVER_CFG, "%s.old" % (SERVER_CFG)) |
340 | # Now we got the whole file, write to disk... |
341 | contents = StringIO() |
342 | mcollective_config.write(contents) |
343 | contents = contents.getvalue() |
344 | - server_cfg_rw = cloud.paths.join(False, '/etc/mcollective/server.cfg') |
345 | - util.write_file(server_cfg_rw, contents, mode=0644) |
346 | + util.write_file(SERVER_CFG, contents, mode=0644) |
347 | |
348 | # Start mcollective |
349 | util.subp(['service', 'mcollective', 'start'], capture=False) |
350 | |
351 | === modified file 'cloudinit/config/cc_mounts.py' |
352 | --- cloudinit/config/cc_mounts.py 2012-09-06 18:52:53 +0000 |
353 | +++ cloudinit/config/cc_mounts.py 2012-10-28 02:29:21 +0000 |
354 | @@ -28,6 +28,7 @@ |
355 | SHORTNAME_FILTER = r"^[x]{0,1}[shv]d[a-z][0-9]*$" |
356 | SHORTNAME = re.compile(SHORTNAME_FILTER) |
357 | WS = re.compile("[%s]+" % (whitespace)) |
358 | +FSTAB_PATH = "/etc/fstab" |
359 | |
360 | |
361 | def is_mdname(name): |
362 | @@ -167,8 +168,7 @@ |
363 | cc_lines.append('\t'.join(line)) |
364 | |
365 | fstab_lines = [] |
366 | - fstab = util.load_file(cloud.paths.join(True, "/etc/fstab")) |
367 | - for line in fstab.splitlines(): |
368 | + for line in util.load_file(FSTAB_PATH).splitlines(): |
369 | try: |
370 | toks = WS.split(line) |
371 | if toks[3].find(comment) != -1: |
372 | @@ -179,7 +179,7 @@ |
373 | |
374 | fstab_lines.extend(cc_lines) |
375 | contents = "%s\n" % ('\n'.join(fstab_lines)) |
376 | - util.write_file(cloud.paths.join(False, "/etc/fstab"), contents) |
377 | + util.write_file(FSTAB_PATH, contents) |
378 | |
379 | if needswap: |
380 | try: |
381 | @@ -188,9 +188,8 @@ |
382 | util.logexc(log, "Activating swap via 'swapon -a' failed") |
383 | |
384 | for d in dirs: |
385 | - real_dir = cloud.paths.join(False, d) |
386 | try: |
387 | - util.ensure_dir(real_dir) |
388 | + util.ensure_dir(d) |
389 | except: |
390 | util.logexc(log, "Failed to make '%s' config-mount", d) |
391 | |
392 | |
393 | === modified file 'cloudinit/config/cc_phone_home.py' |
394 | --- cloudinit/config/cc_phone_home.py 2012-06-23 05:04:37 +0000 |
395 | +++ cloudinit/config/cc_phone_home.py 2012-10-28 02:29:21 +0000 |
396 | @@ -84,10 +84,10 @@ |
397 | |
398 | for (n, path) in pubkeys.iteritems(): |
399 | try: |
400 | - all_keys[n] = util.load_file(cloud.paths.join(True, path)) |
401 | + all_keys[n] = util.load_file(path) |
402 | except: |
403 | util.logexc(log, ("%s: failed to open, can not" |
404 | - " phone home that data"), path) |
405 | + " phone home that data!"), path) |
406 | |
407 | submit_keys = {} |
408 | for k in post_list: |
409 | |
410 | === modified file 'cloudinit/config/cc_puppet.py' |
411 | --- cloudinit/config/cc_puppet.py 2012-08-22 18:12:32 +0000 |
412 | +++ cloudinit/config/cc_puppet.py 2012-10-28 02:29:21 +0000 |
413 | @@ -21,12 +21,32 @@ |
414 | from StringIO import StringIO |
415 | |
416 | import os |
417 | -import pwd |
418 | import socket |
419 | |
420 | from cloudinit import helpers |
421 | from cloudinit import util |
422 | |
423 | +PUPPET_CONF_PATH = '/etc/puppet/puppet.conf' |
424 | +PUPPET_SSL_CERT_DIR = '/var/lib/puppet/ssl/certs/' |
425 | +PUPPET_SSL_DIR = '/var/lib/puppet/ssl' |
426 | +PUPPET_SSL_CERT_PATH = '/var/lib/puppet/ssl/certs/ca.pem' |
427 | + |
428 | + |
429 | +def _autostart_puppet(log): |
430 | + # Set puppet to automatically start |
431 | + if os.path.exists('/etc/default/puppet'): |
432 | + util.subp(['sed', '-i', |
433 | + '-e', 's/^START=.*/START=yes/', |
434 | + '/etc/default/puppet'], capture=False) |
435 | + elif os.path.exists('/bin/systemctl'): |
436 | + util.subp(['/bin/systemctl', 'enable', 'puppet.service'], |
437 | + capture=False) |
438 | + elif os.path.exists('/sbin/chkconfig'): |
439 | + util.subp(['/sbin/chkconfig', 'puppet', 'on'], capture=False) |
440 | + else: |
441 | + log.warn(("Sorry we do not know how to enable" |
442 | + " puppet services on this system")) |
443 | + |
444 | |
445 | def handle(name, cfg, cloud, log, _args): |
446 | # If there isn't a puppet key in the configuration don't do anything |
447 | @@ -43,8 +63,7 @@ |
448 | # ... and then update the puppet configuration |
449 | if 'conf' in puppet_cfg: |
450 | # Add all sections from the conf object to puppet.conf |
451 | - puppet_conf_fn = cloud.paths.join(True, '/etc/puppet/puppet.conf') |
452 | - contents = util.load_file(puppet_conf_fn) |
453 | + contents = util.load_file(PUPPET_CONF_PATH) |
454 | # Create object for reading puppet.conf values |
455 | puppet_config = helpers.DefaultingConfigParser() |
456 | # Read puppet.conf values from original file in order to be able to |
457 | @@ -53,28 +72,19 @@ |
458 | cleaned_lines = [i.lstrip() for i in contents.splitlines()] |
459 | cleaned_contents = '\n'.join(cleaned_lines) |
460 | puppet_config.readfp(StringIO(cleaned_contents), |
461 | - filename=puppet_conf_fn) |
462 | + filename=PUPPET_CONF_PATH) |
463 | for (cfg_name, cfg) in puppet_cfg['conf'].iteritems(): |
464 | # Cert configuration is a special case |
465 | # Dump the puppet master ca certificate in the correct place |
466 | if cfg_name == 'ca_cert': |
467 | # Puppet ssl sub-directory isn't created yet |
468 | # Create it with the proper permissions and ownership |
469 | - pp_ssl_dir = cloud.paths.join(False, '/var/lib/puppet/ssl') |
470 | - util.ensure_dir(pp_ssl_dir, 0771) |
471 | - util.chownbyid(pp_ssl_dir, |
472 | - pwd.getpwnam('puppet').pw_uid, 0) |
473 | - pp_ssl_certs = cloud.paths.join(False, |
474 | - '/var/lib/puppet/ssl/certs/') |
475 | - util.ensure_dir(pp_ssl_certs) |
476 | - util.chownbyid(pp_ssl_certs, |
477 | - pwd.getpwnam('puppet').pw_uid, 0) |
478 | - pp_ssl_ca_certs = cloud.paths.join(False, |
479 | - ('/var/lib/puppet/' |
480 | - 'ssl/certs/ca.pem')) |
481 | - util.write_file(pp_ssl_ca_certs, cfg) |
482 | - util.chownbyid(pp_ssl_ca_certs, |
483 | - pwd.getpwnam('puppet').pw_uid, 0) |
484 | + util.ensure_dir(PUPPET_SSL_DIR, 0771) |
485 | + util.chownbyname(PUPPET_SSL_DIR, 'puppet', 'root') |
486 | + util.ensure_dir(PUPPET_SSL_CERT_DIR) |
487 | + util.chownbyname(PUPPET_SSL_CERT_DIR, 'puppet', 'root') |
488 | + util.write_file(PUPPET_SSL_CERT_PATH, str(cfg)) |
489 | + util.chownbyname(PUPPET_SSL_CERT_PATH, 'puppet', 'root') |
490 | else: |
491 | # Iterate throug the config items, we'll use ConfigParser.set |
492 | # to overwrite or create new items as needed |
493 | @@ -90,25 +100,11 @@ |
494 | puppet_config.set(cfg_name, o, v) |
495 | # We got all our config as wanted we'll rename |
496 | # the previous puppet.conf and create our new one |
497 | - conf_old_fn = cloud.paths.join(False, |
498 | - '/etc/puppet/puppet.conf.old') |
499 | - util.rename(puppet_conf_fn, conf_old_fn) |
500 | - puppet_conf_rw = cloud.paths.join(False, '/etc/puppet/puppet.conf') |
501 | - util.write_file(puppet_conf_rw, puppet_config.stringify()) |
502 | + util.rename(PUPPET_CONF_PATH, "%s.old" % (PUPPET_CONF_PATH)) |
503 | + util.write_file(PUPPET_CONF_PATH, puppet_config.stringify()) |
504 | |
505 | - # Set puppet to automatically start |
506 | - if os.path.exists('/etc/default/puppet'): |
507 | - util.subp(['sed', '-i', |
508 | - '-e', 's/^START=.*/START=yes/', |
509 | - '/etc/default/puppet'], capture=False) |
510 | - elif os.path.exists('/bin/systemctl'): |
511 | - util.subp(['/bin/systemctl', 'enable', 'puppet.service'], |
512 | - capture=False) |
513 | - elif os.path.exists('/sbin/chkconfig'): |
514 | - util.subp(['/sbin/chkconfig', 'puppet', 'on'], capture=False) |
515 | - else: |
516 | - log.warn(("Sorry we do not know how to enable" |
517 | - " puppet services on this system")) |
518 | + # Set it up so it autostarts |
519 | + _autostart_puppet(log) |
520 | |
521 | # Start puppetd |
522 | util.subp(['service', 'puppet', 'start'], capture=False) |
523 | |
524 | === modified file 'cloudinit/config/cc_resizefs.py' |
525 | --- cloudinit/config/cc_resizefs.py 2012-08-22 18:12:32 +0000 |
526 | +++ cloudinit/config/cc_resizefs.py 2012-10-28 02:29:21 +0000 |
527 | @@ -62,7 +62,7 @@ |
528 | raise |
529 | |
530 | |
531 | -def handle(name, cfg, cloud, log, args): |
532 | +def handle(name, cfg, _cloud, log, args): |
533 | if len(args) != 0: |
534 | resize_root = args[0] |
535 | else: |
536 | @@ -74,11 +74,10 @@ |
537 | |
538 | # TODO(harlowja) is the directory ok to be used?? |
539 | resize_root_d = util.get_cfg_option_str(cfg, "resize_rootfs_tmp", "/run") |
540 | - resize_root_d = cloud.paths.join(False, resize_root_d) |
541 | util.ensure_dir(resize_root_d) |
542 | |
543 | # TODO(harlowja): allow what is to be resized to be configurable?? |
544 | - resize_what = cloud.paths.join(False, "/") |
545 | + resize_what = "/" |
546 | with util.ExtendedTemporaryFile(prefix="cloudinit.resizefs.", |
547 | dir=resize_root_d, delete=True) as tfh: |
548 | devpth = tfh.name |
549 | |
550 | === modified file 'cloudinit/config/cc_rsyslog.py' |
551 | --- cloudinit/config/cc_rsyslog.py 2012-06-21 16:12:16 +0000 |
552 | +++ cloudinit/config/cc_rsyslog.py 2012-10-28 02:29:21 +0000 |
553 | @@ -71,8 +71,7 @@ |
554 | |
555 | try: |
556 | contents = "%s\n" % (content) |
557 | - util.write_file(cloud.paths.join(False, filename), |
558 | - contents, omode=omode) |
559 | + util.write_file(filename, contents, omode=omode) |
560 | except Exception: |
561 | util.logexc(log, "Failed to write to %s", filename) |
562 | |
563 | |
564 | === modified file 'cloudinit/config/cc_runcmd.py' |
565 | --- cloudinit/config/cc_runcmd.py 2012-06-21 16:12:16 +0000 |
566 | +++ cloudinit/config/cc_runcmd.py 2012-10-28 02:29:21 +0000 |
567 | @@ -33,6 +33,6 @@ |
568 | cmd = cfg["runcmd"] |
569 | try: |
570 | content = util.shellify(cmd) |
571 | - util.write_file(cloud.paths.join(False, out_fn), content, 0700) |
572 | + util.write_file(out_fn, content, 0700) |
573 | except: |
574 | util.logexc(log, "Failed to shellify %s into file %s", cmd, out_fn) |
575 | |
576 | === modified file 'cloudinit/config/cc_salt_minion.py' |
577 | --- cloudinit/config/cc_salt_minion.py 2012-09-28 13:03:54 +0000 |
578 | +++ cloudinit/config/cc_salt_minion.py 2012-10-28 02:29:21 +0000 |
579 | @@ -34,8 +34,7 @@ |
580 | cloud.distro.install_packages(["salt-minion"]) |
581 | |
582 | # Ensure we can configure files at the right dir |
583 | - config_dir = cloud.paths.join(False, salt_cfg.get("config_dir", |
584 | - '/etc/salt')) |
585 | + config_dir = salt_cfg.get("config_dir", '/etc/salt') |
586 | util.ensure_dir(config_dir) |
587 | |
588 | # ... and then update the salt configuration |
589 | @@ -47,8 +46,7 @@ |
590 | |
591 | # ... copy the key pair if specified |
592 | if 'public_key' in salt_cfg and 'private_key' in salt_cfg: |
593 | - pki_dir = cloud.paths.join(False, salt_cfg.get('pki_dir', |
594 | - '/etc/salt/pki')) |
595 | + pki_dir = salt_cfg.get('pki_dir', '/etc/salt/pki') |
596 | with util.umask(077): |
597 | util.ensure_dir(pki_dir) |
598 | pub_name = os.path.join(pki_dir, 'minion.pub') |
599 | |
600 | === modified file 'cloudinit/config/cc_set_passwords.py' |
601 | --- cloudinit/config/cc_set_passwords.py 2012-09-28 21:06:22 +0000 |
602 | +++ cloudinit/config/cc_set_passwords.py 2012-10-28 02:29:21 +0000 |
603 | @@ -114,8 +114,7 @@ |
604 | replaced_auth = False |
605 | |
606 | # See: man sshd_config |
607 | - conf_fn = cloud.paths.join(True, ssh_util.DEF_SSHD_CFG) |
608 | - old_lines = ssh_util.parse_ssh_config(conf_fn) |
609 | + old_lines = ssh_util.parse_ssh_config(ssh_util.DEF_SSHD_CFG) |
610 | new_lines = [] |
611 | i = 0 |
612 | for (i, line) in enumerate(old_lines): |
613 | @@ -134,8 +133,7 @@ |
614 | pw_auth)) |
615 | |
616 | lines = [str(e) for e in new_lines] |
617 | - ssh_rw_fn = cloud.paths.join(False, ssh_util.DEF_SSHD_CFG) |
618 | - util.write_file(ssh_rw_fn, "\n".join(lines)) |
619 | + util.write_file(ssh_util.DEF_SSHD_CFG, "\n".join(lines)) |
620 | |
621 | try: |
622 | cmd = ['service'] |
623 | |
624 | === modified file 'cloudinit/config/cc_ssh.py' |
625 | --- cloudinit/config/cc_ssh.py 2012-09-28 21:06:22 +0000 |
626 | +++ cloudinit/config/cc_ssh.py 2012-10-28 02:29:21 +0000 |
627 | @@ -59,7 +59,7 @@ |
628 | |
629 | # remove the static keys from the pristine image |
630 | if cfg.get("ssh_deletekeys", True): |
631 | - key_pth = cloud.paths.join(False, "/etc/ssh/", "ssh_host_*key*") |
632 | + key_pth = os.path.join("/etc/ssh/", "ssh_host_*key*") |
633 | for f in glob.glob(key_pth): |
634 | try: |
635 | util.del_file(f) |
636 | @@ -72,8 +72,7 @@ |
637 | if key in KEY_2_FILE: |
638 | tgt_fn = KEY_2_FILE[key][0] |
639 | tgt_perms = KEY_2_FILE[key][1] |
640 | - util.write_file(cloud.paths.join(False, tgt_fn), |
641 | - val, tgt_perms) |
642 | + util.write_file(tgt_fn, val, tgt_perms) |
643 | |
644 | for (priv, pub) in PRIV_2_PUB.iteritems(): |
645 | if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: |
646 | @@ -94,7 +93,7 @@ |
647 | 'ssh_genkeytypes', |
648 | GENERATE_KEY_NAMES) |
649 | for keytype in genkeys: |
650 | - keyfile = cloud.paths.join(False, KEY_FILE_TPL % (keytype)) |
651 | + keyfile = KEY_FILE_TPL % (keytype) |
652 | util.ensure_dir(os.path.dirname(keyfile)) |
653 | if not os.path.exists(keyfile): |
654 | cmd = ['ssh-keygen', '-t', keytype, '-N', '', '-f', keyfile] |
655 | @@ -118,17 +117,16 @@ |
656 | cfgkeys = cfg["ssh_authorized_keys"] |
657 | keys.extend(cfgkeys) |
658 | |
659 | - apply_credentials(keys, user, cloud.paths, |
660 | - disable_root, disable_root_opts) |
661 | + apply_credentials(keys, user, disable_root, disable_root_opts) |
662 | except: |
663 | util.logexc(log, "Applying ssh credentials failed!") |
664 | |
665 | |
666 | -def apply_credentials(keys, user, paths, disable_root, disable_root_opts): |
667 | +def apply_credentials(keys, user, disable_root, disable_root_opts): |
668 | |
669 | keys = set(keys) |
670 | if user: |
671 | - ssh_util.setup_user_keys(keys, user, '', paths) |
672 | + ssh_util.setup_user_keys(keys, user, '') |
673 | |
674 | if disable_root: |
675 | if not user: |
676 | @@ -137,4 +135,4 @@ |
677 | else: |
678 | key_prefix = '' |
679 | |
680 | - ssh_util.setup_user_keys(keys, 'root', key_prefix, paths) |
681 | + ssh_util.setup_user_keys(keys, 'root', key_prefix) |
682 | |
683 | === modified file 'cloudinit/config/cc_ssh_authkey_fingerprints.py' |
684 | --- cloudinit/config/cc_ssh_authkey_fingerprints.py 2012-09-28 21:21:02 +0000 |
685 | +++ cloudinit/config/cc_ssh_authkey_fingerprints.py 2012-10-28 02:29:21 +0000 |
686 | @@ -97,9 +97,8 @@ |
687 | "logging of ssh fingerprints disabled"), name) |
688 | |
689 | hash_meth = util.get_cfg_option_str(cfg, "authkey_hash", "md5") |
690 | - extract_func = ssh_util.extract_authorized_keys |
691 | (users, _groups) = ds.normalize_users_groups(cfg, cloud.distro) |
692 | for (user_name, _cfg) in users.items(): |
693 | - (auth_key_fn, auth_key_entries) = extract_func(user_name, cloud.paths) |
694 | - _pprint_key_entries(user_name, auth_key_fn, |
695 | - auth_key_entries, hash_meth) |
696 | + (key_fn, key_entries) = ssh_util.extract_authorized_keys(user_name) |
697 | + _pprint_key_entries(user_name, key_fn, |
698 | + key_entries, hash_meth) |
699 | |
700 | === modified file 'cloudinit/config/cc_update_etc_hosts.py' |
701 | --- cloudinit/config/cc_update_etc_hosts.py 2012-08-22 18:12:32 +0000 |
702 | +++ cloudinit/config/cc_update_etc_hosts.py 2012-10-28 02:29:21 +0000 |
703 | @@ -42,8 +42,7 @@ |
704 | raise RuntimeError(("No hosts template could be" |
705 | " found for distro %s") % (cloud.distro.name)) |
706 | |
707 | - out_fn = cloud.paths.join(False, '/etc/hosts') |
708 | - templater.render_to_file(tpl_fn_name, out_fn, |
709 | + templater.render_to_file(tpl_fn_name, '/etc/hosts', |
710 | {'hostname': hostname, 'fqdn': fqdn}) |
711 | |
712 | elif manage_hosts == "localhost": |
713 | |
714 | === modified file 'cloudinit/distros/__init__.py' |
715 | --- cloudinit/distros/__init__.py 2012-10-23 16:58:32 +0000 |
716 | +++ cloudinit/distros/__init__.py 2012-10-28 02:29:21 +0000 |
717 | @@ -122,8 +122,7 @@ |
718 | new_etchosts = StringIO() |
719 | need_write = False |
720 | need_change = True |
721 | - hosts_ro_fn = self._paths.join(True, "/etc/hosts") |
722 | - for line in util.load_file(hosts_ro_fn).splitlines(): |
723 | + for line in util.load_file("/etc/hosts").splitlines(): |
724 | if line.strip().startswith(header): |
725 | continue |
726 | if not line.strip() or line.strip().startswith("#"): |
727 | @@ -147,8 +146,7 @@ |
728 | need_write = True |
729 | if need_write: |
730 | contents = new_etchosts.getvalue() |
731 | - util.write_file(self._paths.join(False, "/etc/hosts"), |
732 | - contents, mode=0644) |
733 | + util.write_file("/etc/hosts", contents, mode=0644) |
734 | |
735 | def _bring_up_interface(self, device_name): |
736 | cmd = ['ifup', device_name] |
737 | @@ -262,7 +260,7 @@ |
738 | # Import SSH keys |
739 | if 'ssh_authorized_keys' in kwargs: |
740 | keys = set(kwargs['ssh_authorized_keys']) or [] |
741 | - ssh_util.setup_user_keys(keys, name, None, self._paths) |
742 | + ssh_util.setup_user_keys(keys, name, key_prefix=None) |
743 | |
744 | return True |
745 | |
746 | |
747 | === modified file 'cloudinit/distros/debian.py' |
748 | --- cloudinit/distros/debian.py 2012-09-20 22:55:52 +0000 |
749 | +++ cloudinit/distros/debian.py 2012-10-28 02:29:21 +0000 |
750 | @@ -43,7 +43,7 @@ |
751 | |
752 | def apply_locale(self, locale, out_fn=None): |
753 | if not out_fn: |
754 | - out_fn = self._paths.join(False, '/etc/default/locale') |
755 | + out_fn = '/etc/default/locale' |
756 | util.subp(['locale-gen', locale], capture=False) |
757 | util.subp(['update-locale', locale], capture=False) |
758 | lines = ["# Created by cloud-init", 'LANG="%s"' % (locale), ""] |
759 | @@ -54,8 +54,7 @@ |
760 | self.package_command('install', pkglist) |
761 | |
762 | def _write_network(self, settings): |
763 | - net_fn = self._paths.join(False, "/etc/network/interfaces") |
764 | - util.write_file(net_fn, settings) |
765 | + util.write_file("/etc/network/interfaces", settings) |
766 | return ['all'] |
767 | |
768 | def _bring_up_interfaces(self, device_names): |
769 | @@ -69,12 +68,9 @@ |
770 | return distros.Distro._bring_up_interfaces(self, device_names) |
771 | |
772 | def set_hostname(self, hostname): |
773 | - out_fn = self._paths.join(False, "/etc/hostname") |
774 | - self._write_hostname(hostname, out_fn) |
775 | - if out_fn == '/etc/hostname': |
776 | - # Only do this if we are running in non-adjusted root mode |
777 | - LOG.debug("Setting hostname to %s", hostname) |
778 | - util.subp(['hostname', hostname]) |
779 | + self._write_hostname(hostname, "/etc/hostname") |
780 | + LOG.debug("Setting hostname to %s", hostname) |
781 | + util.subp(['hostname', hostname]) |
782 | |
783 | def _write_hostname(self, hostname, out_fn): |
784 | # "" gives trailing newline. |
785 | @@ -82,16 +78,14 @@ |
786 | |
787 | def update_hostname(self, hostname, prev_fn): |
788 | hostname_prev = self._read_hostname(prev_fn) |
789 | - read_fn = self._paths.join(True, "/etc/hostname") |
790 | - hostname_in_etc = self._read_hostname(read_fn) |
791 | + hostname_in_etc = self._read_hostname("/etc/hostname") |
792 | update_files = [] |
793 | if not hostname_prev or hostname_prev != hostname: |
794 | update_files.append(prev_fn) |
795 | if (not hostname_in_etc or |
796 | (hostname_in_etc == hostname_prev and |
797 | hostname_in_etc != hostname)): |
798 | - write_fn = self._paths.join(False, "/etc/hostname") |
799 | - update_files.append(write_fn) |
800 | + update_files.append("/etc/hostname") |
801 | for fn in update_files: |
802 | try: |
803 | self._write_hostname(hostname, fn) |
804 | @@ -103,7 +97,6 @@ |
805 | LOG.debug(("%s differs from /etc/hostname." |
806 | " Assuming user maintained hostname."), prev_fn) |
807 | if "/etc/hostname" in update_files: |
808 | - # Only do this if we are running in non-adjusted root mode |
809 | LOG.debug("Setting hostname to %s", hostname) |
810 | util.subp(['hostname', hostname]) |
811 | |
812 | @@ -130,9 +123,8 @@ |
813 | " no file found at %s") % (tz, tz_file)) |
814 | # "" provides trailing newline during join |
815 | tz_lines = ["# Created by cloud-init", str(tz), ""] |
816 | - tz_fn = self._paths.join(False, "/etc/timezone") |
817 | - util.write_file(tz_fn, "\n".join(tz_lines)) |
818 | - util.copy(tz_file, self._paths.join(False, "/etc/localtime")) |
819 | + util.write_file("/etc/timezone", "\n".join(tz_lines)) |
820 | + util.copy(tz_file, "/etc/localtime") |
821 | |
822 | def package_command(self, command, args=None): |
823 | e = os.environ.copy() |
824 | |
825 | === modified file 'cloudinit/helpers.py' |
826 | --- cloudinit/helpers.py 2012-07-10 03:34:10 +0000 |
827 | +++ cloudinit/helpers.py 2012-10-28 02:29:21 +0000 |
828 | @@ -302,14 +302,10 @@ |
829 | def __init__(self, path_cfgs, ds=None): |
830 | self.cfgs = path_cfgs |
831 | # Populate all the initial paths |
832 | - self.cloud_dir = self.join(False, |
833 | - path_cfgs.get('cloud_dir', |
834 | - '/var/lib/cloud')) |
835 | + self.cloud_dir = path_cfgs.get('cloud_dir', '/var/lib/cloud') |
836 | self.instance_link = os.path.join(self.cloud_dir, 'instance') |
837 | self.boot_finished = os.path.join(self.instance_link, "boot-finished") |
838 | self.upstart_conf_d = path_cfgs.get('upstart_dir') |
839 | - if self.upstart_conf_d: |
840 | - self.upstart_conf_d = self.join(False, self.upstart_conf_d) |
841 | self.seed_dir = os.path.join(self.cloud_dir, 'seed') |
842 | # This one isn't joined, since it should just be read-only |
843 | template_dir = path_cfgs.get('templates_dir', '/etc/cloud/templates/') |
844 | @@ -328,29 +324,6 @@ |
845 | # Set when a datasource becomes active |
846 | self.datasource = ds |
847 | |
848 | - # joins the paths but also appends a read |
849 | - # or write root if available |
850 | - def join(self, read_only, *paths): |
851 | - if read_only: |
852 | - root = self.cfgs.get('read_root') |
853 | - else: |
854 | - root = self.cfgs.get('write_root') |
855 | - if not paths: |
856 | - return root |
857 | - if len(paths) > 1: |
858 | - joined = os.path.join(*paths) |
859 | - else: |
860 | - joined = paths[0] |
861 | - if root: |
862 | - pre_joined = joined |
863 | - # Need to remove any starting '/' since this |
864 | - # will confuse os.path.join |
865 | - joined = joined.lstrip("/") |
866 | - joined = os.path.join(root, joined) |
867 | - LOG.debug("Translated %s to adjusted path %s (read-only=%s)", |
868 | - pre_joined, joined, read_only) |
869 | - return joined |
870 | - |
871 | # get_ipath_cur: get the current instance path for an item |
872 | def get_ipath_cur(self, name=None): |
873 | ipath = self.instance_link |
874 | |
875 | === modified file 'cloudinit/sources/__init__.py' |
876 | --- cloudinit/sources/__init__.py 2012-10-05 20:38:54 +0000 |
877 | +++ cloudinit/sources/__init__.py 2012-10-28 02:29:21 +0000 |
878 | @@ -20,8 +20,6 @@ |
879 | # You should have received a copy of the GNU General Public License |
880 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
881 | |
882 | -from email.mime.multipart import MIMEMultipart |
883 | - |
884 | import abc |
885 | import os |
886 | |
887 | |
888 | === modified file 'cloudinit/ssh_util.py' |
889 | --- cloudinit/ssh_util.py 2012-08-19 04:15:52 +0000 |
890 | +++ cloudinit/ssh_util.py 2012-10-28 02:29:21 +0000 |
891 | @@ -212,17 +212,15 @@ |
892 | return '\n'.join(lines) |
893 | |
894 | |
895 | -def users_ssh_info(username, paths): |
896 | +def users_ssh_info(username): |
897 | pw_ent = pwd.getpwnam(username) |
898 | - if not pw_ent: |
899 | + if not pw_ent or not pw_ent.pw_dir: |
900 | raise RuntimeError("Unable to get ssh info for user %r" % (username)) |
901 | - ssh_dir = paths.join(False, os.path.join(pw_ent.pw_dir, '.ssh')) |
902 | - return (ssh_dir, pw_ent) |
903 | - |
904 | - |
905 | -def extract_authorized_keys(username, paths): |
906 | - (ssh_dir, pw_ent) = users_ssh_info(username, paths) |
907 | - sshd_conf_fn = paths.join(True, DEF_SSHD_CFG) |
908 | + return (os.path.join(pw_ent.pw_dir, '.ssh'), pw_ent) |
909 | + |
910 | + |
911 | +def extract_authorized_keys(username): |
912 | + (ssh_dir, pw_ent) = users_ssh_info(username) |
913 | auth_key_fn = None |
914 | with util.SeLinuxGuard(ssh_dir, recursive=True): |
915 | try: |
916 | @@ -231,7 +229,7 @@ |
917 | # The following tokens are defined: %% is replaced by a literal |
918 | # '%', %h is replaced by the home directory of the user being |
919 | # authenticated and %u is replaced by the username of that user. |
920 | - ssh_cfg = parse_ssh_config_map(sshd_conf_fn) |
921 | + ssh_cfg = parse_ssh_config_map(DEF_SSHD_CFG) |
922 | auth_key_fn = ssh_cfg.get("authorizedkeysfile", '').strip() |
923 | if not auth_key_fn: |
924 | auth_key_fn = "%h/.ssh/authorized_keys" |
925 | @@ -240,7 +238,6 @@ |
926 | auth_key_fn = auth_key_fn.replace("%%", '%') |
927 | if not auth_key_fn.startswith('/'): |
928 | auth_key_fn = os.path.join(pw_ent.pw_dir, auth_key_fn) |
929 | - auth_key_fn = paths.join(False, auth_key_fn) |
930 | except (IOError, OSError): |
931 | # Give up and use a default key filename |
932 | auth_key_fn = os.path.join(ssh_dir, 'authorized_keys') |
933 | @@ -248,14 +245,13 @@ |
934 | " in ssh config" |
935 | " from %r, using 'AuthorizedKeysFile' file" |
936 | " %r instead"), |
937 | - sshd_conf_fn, auth_key_fn) |
938 | - auth_key_entries = parse_authorized_keys(auth_key_fn) |
939 | - return (auth_key_fn, auth_key_entries) |
940 | - |
941 | - |
942 | -def setup_user_keys(keys, username, key_prefix, paths): |
943 | + DEF_SSHD_CFG, auth_key_fn) |
944 | + return (auth_key_fn, parse_authorized_keys(auth_key_fn)) |
945 | + |
946 | + |
947 | +def setup_user_keys(keys, username, key_prefix): |
948 | # Make sure the users .ssh dir is setup accordingly |
949 | - (ssh_dir, pwent) = users_ssh_info(username, paths) |
950 | + (ssh_dir, pwent) = users_ssh_info(username) |
951 | if not os.path.isdir(ssh_dir): |
952 | util.ensure_dir(ssh_dir, mode=0700) |
953 | util.chownbyid(ssh_dir, pwent.pw_uid, pwent.pw_gid) |
954 | @@ -267,7 +263,7 @@ |
955 | key_entries.append(parser.parse(str(k), def_opt=key_prefix)) |
956 | |
957 | # Extract the old and make the new |
958 | - (auth_key_fn, auth_key_entries) = extract_authorized_keys(username, paths) |
959 | + (auth_key_fn, auth_key_entries) = extract_authorized_keys(username) |
960 | with util.SeLinuxGuard(ssh_dir, recursive=True): |
961 | content = update_authorized_keys(auth_key_entries, key_entries) |
962 | util.ensure_dir(os.path.dirname(auth_key_fn), mode=0700) |
963 | |
964 | === added file 'pylintrc' |
965 | --- pylintrc 1970-01-01 00:00:00 +0000 |
966 | +++ pylintrc 2012-10-28 02:29:21 +0000 |
967 | @@ -0,0 +1,19 @@ |
968 | +[General] |
969 | +init-hook='import sys; sys.path.append("tests/")' |
970 | + |
971 | +[MESSAGES CONTROL] |
972 | +# See: http://pylint-messages.wikidot.com/all-codes |
973 | +# W0142: *args and **kwargs are fine. |
974 | +# W0511: TODOs in code comments are fine. |
975 | +# W0702: No exception type(s) specified |
976 | +# W0703: Catch "Exception" |
977 | +# C0103: Invalid name |
978 | +# C0111: Missing docstring |
979 | +disable=W0142,W0511,W0702,W0703,C0103,C0111 |
980 | + |
981 | +[REPORTS] |
982 | +reports=no |
983 | +include-ids=yes |
984 | + |
985 | +[FORMAT] |
986 | +max-line-length=79 |
987 | |
988 | === added file 'tests/__init__.py' |
989 | === added file 'tests/unittests/__init__.py' |
990 | === added file 'tests/unittests/test_datasource/__init__.py' |
991 | === added file 'tests/unittests/test_distros/__init__.py' |
992 | === added file 'tests/unittests/test_filters/__init__.py' |
993 | === modified file 'tests/unittests/test_filters/test_launch_index.py' |
994 | --- tests/unittests/test_filters/test_launch_index.py 2012-09-26 23:40:07 +0000 |
995 | +++ tests/unittests/test_filters/test_launch_index.py 2012-10-28 02:29:21 +0000 |
996 | @@ -1,14 +1,6 @@ |
997 | import copy |
998 | -import os |
999 | -import sys |
1000 | - |
1001 | -top_dir = os.path.join(os.path.dirname(__file__), os.pardir, "helpers.py") |
1002 | -top_dir = os.path.abspath(top_dir) |
1003 | -if os.path.exists(top_dir): |
1004 | - sys.path.insert(0, os.path.dirname(top_dir)) |
1005 | - |
1006 | - |
1007 | -import helpers |
1008 | + |
1009 | +from tests.unittests import helpers |
1010 | |
1011 | import itertools |
1012 | |
1013 | |
1014 | === added file 'tests/unittests/test_handler/__init__.py' |
1015 | === modified file 'tests/unittests/test_handler/test_handler_ca_certs.py' |
1016 | --- tests/unittests/test_handler/test_handler_ca_certs.py 2012-08-22 18:12:32 +0000 |
1017 | +++ tests/unittests/test_handler/test_handler_ca_certs.py 2012-10-28 02:29:21 +0000 |
1018 | @@ -77,7 +77,7 @@ |
1019 | """Test that a single cert gets passed to add_ca_certs.""" |
1020 | config = {"ca-certs": {"trusted": ["CERT1"]}} |
1021 | |
1022 | - self.mock_add(self.paths, ["CERT1"]) |
1023 | + self.mock_add(["CERT1"]) |
1024 | self.mock_update() |
1025 | self.mocker.replay() |
1026 | |
1027 | @@ -87,7 +87,7 @@ |
1028 | """Test that multiple certs get passed to add_ca_certs.""" |
1029 | config = {"ca-certs": {"trusted": ["CERT1", "CERT2"]}} |
1030 | |
1031 | - self.mock_add(self.paths, ["CERT1", "CERT2"]) |
1032 | + self.mock_add(["CERT1", "CERT2"]) |
1033 | self.mock_update() |
1034 | self.mocker.replay() |
1035 | |
1036 | @@ -97,7 +97,7 @@ |
1037 | """Test remove_defaults works as expected.""" |
1038 | config = {"ca-certs": {"remove-defaults": True}} |
1039 | |
1040 | - self.mock_remove(self.paths) |
1041 | + self.mock_remove() |
1042 | self.mock_update() |
1043 | self.mocker.replay() |
1044 | |
1045 | @@ -116,8 +116,8 @@ |
1046 | """Test remove_defaults is not called when config value is False.""" |
1047 | config = {"ca-certs": {"remove-defaults": True, "trusted": ["CERT1"]}} |
1048 | |
1049 | - self.mock_remove(self.paths) |
1050 | - self.mock_add(self.paths, ["CERT1"]) |
1051 | + self.mock_remove() |
1052 | + self.mock_add(["CERT1"]) |
1053 | self.mock_update() |
1054 | self.mocker.replay() |
1055 | |
1056 | @@ -136,7 +136,7 @@ |
1057 | """Test that no certificate are written if not provided.""" |
1058 | self.mocker.replace(util.write_file, passthrough=False) |
1059 | self.mocker.replay() |
1060 | - cc_ca_certs.add_ca_certs(self.paths, []) |
1061 | + cc_ca_certs.add_ca_certs([]) |
1062 | |
1063 | def test_single_cert(self): |
1064 | """Test adding a single certificate to the trusted CAs.""" |
1065 | @@ -149,7 +149,7 @@ |
1066 | "\ncloud-init-ca-certs.crt", omode="ab") |
1067 | self.mocker.replay() |
1068 | |
1069 | - cc_ca_certs.add_ca_certs(self.paths, [cert]) |
1070 | + cc_ca_certs.add_ca_certs([cert]) |
1071 | |
1072 | def test_multiple_certs(self): |
1073 | """Test adding multiple certificates to the trusted CAs.""" |
1074 | @@ -163,7 +163,7 @@ |
1075 | "\ncloud-init-ca-certs.crt", omode="ab") |
1076 | self.mocker.replay() |
1077 | |
1078 | - cc_ca_certs.add_ca_certs(self.paths, certs) |
1079 | + cc_ca_certs.add_ca_certs(certs) |
1080 | |
1081 | |
1082 | class TestUpdateCaCerts(MockerTestCase): |
1083 | @@ -198,4 +198,4 @@ |
1084 | "ca-certificates ca-certificates/trust_new_crts select no") |
1085 | self.mocker.replay() |
1086 | |
1087 | - cc_ca_certs.remove_default_ca_certs(self.paths) |
1088 | + cc_ca_certs.remove_default_ca_certs() |
1089 | |
1090 | === added file 'tests/unittests/test_runs/__init__.py' |
1091 | === modified file 'tests/unittests/test_runs/test_simple_run.py' |
1092 | --- tests/unittests/test_runs/test_simple_run.py 2012-10-23 16:58:32 +0000 |
1093 | +++ tests/unittests/test_runs/test_simple_run.py 2012-10-28 02:29:21 +0000 |
1094 | @@ -1,14 +1,6 @@ |
1095 | import os |
1096 | -import sys |
1097 | - |
1098 | -# Allow running this test individually |
1099 | -top_dir = os.path.join(os.path.dirname(__file__), os.pardir, "helpers.py") |
1100 | -top_dir = os.path.abspath(top_dir) |
1101 | -if os.path.exists(top_dir): |
1102 | - sys.path.insert(0, os.path.dirname(top_dir)) |
1103 | - |
1104 | - |
1105 | -import helpers |
1106 | + |
1107 | +from tests.unittests import helpers |
1108 | |
1109 | from cloudinit.settings import (PER_INSTANCE) |
1110 | from cloudinit import stages |
1111 | |
1112 | === modified file 'tools/run-pylint' |
1113 | --- tools/run-pylint 2012-07-09 17:33:26 +0000 |
1114 | +++ tools/run-pylint 2012-10-28 02:29:21 +0000 |
1115 | @@ -6,23 +6,16 @@ |
1116 | files=( "$@" ); |
1117 | fi |
1118 | |
1119 | +RC_FILE="pylintrc" |
1120 | +if [ ! -f $RC_FILE ]; then |
1121 | + RC_FILE="../pylintrc" |
1122 | +fi |
1123 | + |
1124 | cmd=( |
1125 | pylint |
1126 | - --reports=n |
1127 | - --include-ids=y |
1128 | - --max-line-length=79 |
1129 | - |
1130 | + --rcfile=$RC_FILE |
1131 | --disable=R |
1132 | --disable=I |
1133 | - |
1134 | - --disable=W0142 # Used * or ** magic |
1135 | - --disable=W0511 # TODO/FIXME note |
1136 | - --disable=W0702 # No exception type(s) specified |
1137 | - --disable=W0703 # Catch "Exception" |
1138 | - |
1139 | - --disable=C0103 # Invalid name |
1140 | - --disable=C0111 # Missing docstring |
1141 | - |
1142 | "${files[@]}" |
1143 | ) |
1144 |