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