Merge lp:~cjohnston/uci-engine/p-d-flake8 into lp:uci-engine
- p-d-flake8
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Andy Doan |
Approved revision: | 534 |
Merged at revision: | 537 |
Proposed branch: | lp:~cjohnston/uci-engine/p-d-flake8 |
Merge into: | lp:uci-engine |
Diff against target: |
621 lines (+134/-83) 1 file modified
charms/precise/python-django/hooks/hooks.py (+134/-83) |
To merge this branch: | bzr merge lp:~cjohnston/uci-engine/p-d-flake8 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andy Doan (community) | Approve | ||
Evan (community) | Needs Fixing | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+222105@code.launchpad.net |
Commit message
flake8 fixes to python-
Description of the change
Lets make working on the charm easier.
PS Jenkins bot (ps-jenkins) wrote : | # |
Could you do another pass on this converting it completely to charm-helpers? If we're going to spend the time cleaning up whitespace, we might as well change around some easy library calls.
I've highlighted some with inline comments, but this is by no means comprehensive. We should be able to greatly simplify the charm, making it easier as you had initially set out to do.
Chris Johnston (cjohnston) wrote : | # |
Happy to do that but would prefer to do it as a separate MP.
Andy Doan (doanac) wrote : | # |
On 06/05/2014 04:37 AM, Evan Dandrea wrote:
> Could you do another pass on this converting it completely to charm-helpers? If we're going to spend the time cleaning up whitespace, we might as well change around some easy library calls.
lets not do this. make them 2 different MPs so its easier to review.
Andy Doan (doanac) wrote : | # |
also - note. i'm changing some of this to use charmhelpers for the apt-get-
Preview Diff
1 | === modified file 'charms/precise/python-django/hooks/hooks.py' |
2 | --- charms/precise/python-django/hooks/hooks.py 2014-05-30 14:46:01 +0000 |
3 | +++ charms/precise/python-django/hooks/hooks.py 2014-06-04 21:05:30 +0000 |
4 | @@ -17,7 +17,7 @@ |
5 | from random import choice |
6 | |
7 | from charmhelpers.contrib.charmsupport.nrpe import NRPE |
8 | - |
9 | +from charmhelpers.core import host |
10 | |
11 | CHARM_PACKAGES = ["python-pip", "python-jinja2", "mercurial", "git-core", |
12 | "subversion", "bzr", "gettext"] |
13 | @@ -42,6 +42,7 @@ |
14 | def juju_log(level, msg): |
15 | subprocess.call(['juju-log', '-l', level, msg]) |
16 | |
17 | + |
18 | #------------------------------------------------------------------------------ |
19 | # run: Run a command, return the output |
20 | #------------------------------------------------------------------------------ |
21 | @@ -74,10 +75,8 @@ |
22 | # install_dir: create a directory |
23 | #------------------------------------------------------------------------------ |
24 | def install_dir(dirname, owner="root", group="root", mode=0700): |
25 | - command = \ |
26 | - '/usr/bin/install -o {} -g {} -m {} -d {}'.format(owner, group, oct(mode), |
27 | - dirname) |
28 | - return run(command) |
29 | + host.mkdir(dirname, owner, group, mode) |
30 | + |
31 | |
32 | #------------------------------------------------------------------------------ |
33 | # config_get: Returns a dictionary containing all of the config information |
34 | @@ -207,7 +206,7 @@ |
35 | for unit in json.loads(json_units): |
36 | unit_data = \ |
37 | json.loads(relation_json(relation_id=relid, |
38 | - unit_name=unit)) |
39 | + unit_name=unit)) |
40 | for key in unit_data: |
41 | if key.endswith('-list'): |
42 | unit_data[key] = unit_data[key].split() |
43 | @@ -216,6 +215,7 @@ |
44 | relation_data.append(unit_data) |
45 | return relation_data |
46 | |
47 | + |
48 | def apt_get_update(): |
49 | cmd_line = ['apt-get', 'update'] |
50 | return(subprocess.call(cmd_line)) |
51 | @@ -257,6 +257,7 @@ |
52 | cmd_line.append('--use-mirrors') |
53 | return(subprocess.call(cmd_line)) |
54 | |
55 | + |
56 | #------------------------------------------------------------------------------ |
57 | # pip_install_req( path ): Installs a requirements file |
58 | #------------------------------------------------------------------------------ |
59 | @@ -273,6 +274,7 @@ |
60 | cmd_line.append('--use-mirrors') |
61 | return(subprocess.call(cmd_line, cwd=cwd)) |
62 | |
63 | + |
64 | #------------------------------------------------------------------------------ |
65 | # open_port: Convenience function to open a port in juju to |
66 | # expose a service |
67 | @@ -281,7 +283,7 @@ |
68 | if port is None: |
69 | return(None) |
70 | return(subprocess.call(['open-port', "%d/%s" % |
71 | - (int(port), protocol)])) |
72 | + (int(port), protocol)])) |
73 | |
74 | |
75 | #------------------------------------------------------------------------------ |
76 | @@ -292,7 +294,7 @@ |
77 | if port is None: |
78 | return(None) |
79 | return(subprocess.call(['close-port', "%d/%s" % |
80 | - (int(port), protocol)])) |
81 | + (int(port), protocol)])) |
82 | |
83 | |
84 | #------------------------------------------------------------------------------ |
85 | @@ -311,6 +313,7 @@ |
86 | # Utils |
87 | # |
88 | |
89 | + |
90 | def install_or_append(contents, dest, owner="root", group="root", mode=0600): |
91 | if os.path.exists(dest): |
92 | uid = getpwnam(owner)[2] |
93 | @@ -322,12 +325,14 @@ |
94 | else: |
95 | install_file(contents, dest, owner, group, mode) |
96 | |
97 | + |
98 | def token_sql_safe(value): |
99 | # Only allow alphanumeric + underscore in database identifiers |
100 | if re.search('[^A-Za-z0-9_]', value): |
101 | return False |
102 | return True |
103 | |
104 | + |
105 | def sanitize(s): |
106 | s = s.replace(':', '_') |
107 | s = s.replace('-', '_') |
108 | @@ -336,6 +341,7 @@ |
109 | s = s.replace("'", '_') |
110 | return s |
111 | |
112 | + |
113 | def user_name(relid, remote_unit, admin=False, schema=False): |
114 | components = [sanitize(relid), sanitize(remote_unit)] |
115 | if admin: |
116 | @@ -344,6 +350,7 @@ |
117 | components.append("schema") |
118 | return "_".join(components) |
119 | |
120 | + |
121 | def get_relation_host(): |
122 | remote_host = run("relation-get ip") |
123 | if not remote_host: |
124 | @@ -357,12 +364,13 @@ |
125 | this_host = run("unit-get private-address") |
126 | return this_host.strip() |
127 | |
128 | + |
129 | def process_template(template_name, template_vars, destination): |
130 | # --- exported service configuration file |
131 | from jinja2 import Environment, FileSystemLoader |
132 | template_env = Environment( |
133 | loader=FileSystemLoader(os.path.join(os.environ['CHARM_DIR'], |
134 | - 'templates'))) |
135 | + 'templates'))) |
136 | |
137 | template = \ |
138 | template_env.get_template(template_name).render(template_vars) |
139 | @@ -370,6 +378,7 @@ |
140 | with open(destination, 'w') as inject_file: |
141 | inject_file.write(str(template)) |
142 | |
143 | + |
144 | def configure_and_install(rel): |
145 | |
146 | def _import_key(id): |
147 | @@ -390,16 +399,18 @@ |
148 | return apt_get_install("python-django") |
149 | elif rel[:3] == "deb": |
150 | l = len(rel.split('|')) |
151 | - if l == 2: |
152 | + if l == 2: |
153 | src, key = rel.split('|') |
154 | - juju_log(MSG_DEBUG, "Importing PPA key from keyserver for %s" % src) |
155 | + juju_log( |
156 | + MSG_DEBUG, "Importing PPA key from keyserver for %s" % src) |
157 | _import_key(key) |
158 | elif l == 1: |
159 | src = rel |
160 | else: |
161 | juju_log(MSG_ERROR, "Invalid django-release: %s" % rel) |
162 | |
163 | - with open('/etc/apt/sources.list.d/juju_python_django_deb.list', 'w') as f: |
164 | + with open('/etc/apt/sources.list.d/juju_python_django_deb.list', |
165 | + 'w') as f: |
166 | f.write(src) |
167 | apt_get_update() |
168 | |
169 | @@ -409,9 +420,10 @@ |
170 | else: |
171 | return pip_install(rel) |
172 | |
173 | + |
174 | # |
175 | # from: |
176 | -# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python |
177 | +# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python |
178 | # |
179 | def which(program): |
180 | def is_exe(fpath): |
181 | @@ -425,6 +437,7 @@ |
182 | |
183 | return False |
184 | |
185 | + |
186 | def find_django_admin_cmd(): |
187 | for cmd in ['django-admin.py', 'django-admin']: |
188 | django_admin_cmd = which(cmd) |
189 | @@ -434,13 +447,14 @@ |
190 | |
191 | juju_log(MSG_ERROR, "No django-admin executable found.") |
192 | |
193 | + |
194 | def append_template(template_name, template_vars, path, try_append=False): |
195 | |
196 | # --- exported service configuration file |
197 | from jinja2 import Environment, FileSystemLoader |
198 | template_env = Environment( |
199 | loader=FileSystemLoader(os.path.join(os.environ['CHARM_DIR'], |
200 | - 'templates'))) |
201 | + 'templates'))) |
202 | |
203 | template = \ |
204 | template_env.get_template(template_name).render(template_vars) |
205 | @@ -453,7 +467,7 @@ |
206 | else: |
207 | append = True |
208 | |
209 | - if append == True: |
210 | + if append is True: |
211 | with open(path, 'a') as inject_file: |
212 | inject_file.write(INJECTED_WARNING) |
213 | inject_file.write(str(template)) |
214 | @@ -463,8 +477,9 @@ |
215 | juju_log(MSG_INFO, 'grabbing service from tarball...') |
216 | if not upgrade: |
217 | if os.path.exists(vcs_clone_dir): |
218 | - juju_log(MSG_INFO, |
219 | - 'deleting pre-existing service directory: %s' % vcs_clone_dir) |
220 | + juju_log( |
221 | + MSG_INFO, |
222 | + 'deleting pre-existing service directory: %s' % vcs_clone_dir) |
223 | shutil.rmtree(vcs_clone_dir) |
224 | os.mkdir(vcs_clone_dir) |
225 | cmd = 'curl %s | tar -xzC %s' % (repos_url, vcs_clone_dir) |
226 | @@ -481,7 +496,7 @@ |
227 | if os.path.isfile(f) and os.access(f, os.X_OK): |
228 | subprocess.check_call(['sh', '-c', f]) |
229 | |
230 | - for retry in xrange(0,24): |
231 | + for retry in xrange(0, 24): |
232 | if apt_get_install(CHARM_PACKAGES): |
233 | time.sleep(10) |
234 | else: |
235 | @@ -508,16 +523,21 @@ |
236 | 'repos_password': repos_password |
237 | } |
238 | from os.path import expanduser |
239 | - process_template('netrc.tmpl', template_vars, expanduser('~/.netrc')) |
240 | + process_template( |
241 | + 'netrc.tmpl', template_vars, expanduser('~/.netrc')) |
242 | else: |
243 | - juju_log(MSG_ERROR, '''Failed to process repos_username and repos_password:\n |
244 | - cannot identify domain in URL {0}'''.format(repos_url)) |
245 | + juju_log( |
246 | + MSG_ERROR, |
247 | + '''Failed to process repos_username and repos_password:\n |
248 | + cannot identify domain in URL {0}'''.format(repos_url)) |
249 | |
250 | if vcs == 'hg' or vcs == 'mercurial': |
251 | run('hg clone %s %s' % (repos_url, vcs_clone_dir)) |
252 | elif vcs == 'git' or vcs == 'git-core': |
253 | if repos_branch: |
254 | - run('git clone %s -b %s %s' % (repos_url, repos_branch, vcs_clone_dir)) |
255 | + run( |
256 | + 'git clone %s -b %s %s' % ( |
257 | + repos_url, repos_branch, vcs_clone_dir)) |
258 | else: |
259 | run('git clone %s %s' % (repos_url, vcs_clone_dir)) |
260 | elif vcs == 'bzr' or vcs == 'bazaar' or vcs == 'branch': |
261 | @@ -527,14 +547,16 @@ |
262 | elif vcs == 'tarball': |
263 | _install_from_tarball() |
264 | elif vcs == '' and repos_url == '': |
265 | - juju_log(MSG_INFO, "No version control using django-admin startproject") |
266 | + juju_log( |
267 | + MSG_INFO, "No version control using django-admin startproject") |
268 | cmd = '%s startproject' % django_admin_cmd |
269 | if project_template_url: |
270 | cmd = " ".join([cmd, '--template', project_template_url]) |
271 | if project_template_extension: |
272 | cmd = " ".join([cmd, '--extension', project_template_extension]) |
273 | try: |
274 | - run('%s %s %s' % (cmd, sanitized_unit_name, install_root), exit_on_error=False) |
275 | + run('%s %s %s' % (cmd, sanitized_unit_name, install_root), |
276 | + exit_on_error=False) |
277 | except subprocess.CalledProcessError: |
278 | run('%s %s' % (cmd, sanitized_unit_name), cwd=install_root) |
279 | |
280 | @@ -542,45 +564,57 @@ |
281 | juju_log(MSG_ERROR, "Unknown version control") |
282 | sys.exit(1) |
283 | |
284 | - run('chown -R %s:%s %s' % (wsgi_user,wsgi_group, working_dir)) |
285 | + run('chown -R %s:%s %s' % (wsgi_user, wsgi_group, working_dir)) |
286 | |
287 | - install_dir(settings_dir_path, owner=wsgi_user, group=wsgi_group, mode=0755) |
288 | + install_dir( |
289 | + settings_dir_path, owner=wsgi_user, group=wsgi_group, mode=0755) |
290 | install_dir(urls_dir_path, owner=wsgi_user, group=wsgi_group, mode=0755) |
291 | |
292 | #FIXME: Upgrades/pulls will mess those files |
293 | |
294 | - for path, dir in ((settings_py_path, 'juju_settings'), (urls_py_path, 'juju_urls')): |
295 | + for path, dir in ((settings_py_path, 'juju_settings'), |
296 | + (urls_py_path, 'juju_urls')): |
297 | append_template('conf_injection.tmpl', {'dir': dir}, path) |
298 | |
299 | if requirements_pip_files: |
300 | - for req_file in requirements_pip_files.split(','): |
301 | - pip_install_req(os.path.join(working_dir,req_file)) |
302 | + for req_file in requirements_pip_files.split(','): |
303 | + pip_install_req(os.path.join(working_dir, req_file)) |
304 | |
305 | wsgi_py_path = os.path.join(working_dir, 'wsgi.py') |
306 | if not os.path.exists(wsgi_py_path): |
307 | - process_template('wsgi.py.tmpl', {'project_name': sanitized_unit_name, \ |
308 | - 'django_settings': django_settings}, \ |
309 | - wsgi_py_path) |
310 | + process_template('wsgi.py.tmpl', |
311 | + {'project_name': sanitized_unit_name, |
312 | + 'django_settings': django_settings}, |
313 | + wsgi_py_path) |
314 | if unit_config: |
315 | with open(os.path.join(vcs_clone_dir, 'unit_config'), 'w') as f: |
316 | f.write(base64.b64decode(unit_config)) |
317 | |
318 | + |
319 | def start(): |
320 | - if os.path.exists(os.path.join('/etc/init/', sanitized_unit_name + '.conf')): |
321 | - run("service %s restart || service %s start" % (sanitized_unit_name, sanitized_unit_name)) |
322 | + if os.path.exists(os.path.join('/etc/init/', |
323 | + sanitized_unit_name + '.conf')): |
324 | + run("service %s restart || service %s start" % ( |
325 | + sanitized_unit_name, sanitized_unit_name)) |
326 | + |
327 | |
328 | def stop(): |
329 | - if os.path.exists(os.path.join('/etc/init/', sanitized_unit_name + '.conf')): |
330 | + if os.path.exists(os.path.join('/etc/init/', |
331 | + sanitized_unit_name + '.conf')): |
332 | run('service %s stop' % sanitized_unit_name) |
333 | |
334 | + |
335 | def config_changed(config_data): |
336 | os.environ['DJANGO_SETTINGS_MODULE'] = django_settings_modules |
337 | |
338 | site_secret_key = config_data['site_secret_key'] |
339 | if not site_secret_key: |
340 | - site_secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) |
341 | + site_secret_key = ''.join( |
342 | + [choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') |
343 | + for i in range(50)]) |
344 | |
345 | - process_template('secret.tmpl', {'site_secret_key': site_secret_key}, settings_secret_path) |
346 | + process_template('secret.tmpl', {'site_secret_key': site_secret_key}, |
347 | + settings_secret_path) |
348 | |
349 | dst = os.path.join(settings_dir_path, '30-allowed.py') |
350 | ip = run('unit-get public-address').strip() |
351 | @@ -605,13 +639,14 @@ |
352 | for relid in relation_ids('wsgi'): |
353 | relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
354 | |
355 | + |
356 | def upgrade(): |
357 | if extra_pip_pkgs: |
358 | for package in extra_pip_pkgs.split(','): |
359 | pip_install(package, upgrade=True) |
360 | |
361 | apt_get_update() |
362 | - for retry in xrange(0,24): |
363 | + for retry in xrange(0, 24): |
364 | if apt_get_install(CHARM_PACKAGES): |
365 | time.sleep(10) |
366 | else: |
367 | @@ -621,7 +656,8 @@ |
368 | run('hg pull %s %s' % (repos_url, vcs_clone_dir)) |
369 | elif vcs == 'git' or vcs == 'git-core': |
370 | if repos_branch: |
371 | - run('git pull %s -b %s %s' % (repos_url, repos_branch, vcs_clone_dir)) |
372 | + run('git pull %s -b %s %s' % ( |
373 | + repos_url, repos_branch, vcs_clone_dir)) |
374 | else: |
375 | run('git pull %s %s' % (repos_url, vcs_clone_dir)) |
376 | elif vcs == 'bzr' or vcs == 'bazaar': |
377 | @@ -634,21 +670,22 @@ |
378 | juju_log(MSG_ERROR, "Unknown version control") |
379 | sys.exit(1) |
380 | |
381 | - run('chown -R %s:%s %s' % (wsgi_user,wsgi_group, working_dir)) |
382 | + run('chown -R %s:%s %s' % (wsgi_user, wsgi_group, working_dir)) |
383 | |
384 | if requirements_pip_files: |
385 | - for req_file in requirements_pip_files.split(','): |
386 | - pip_install_req(os.path.join(working_dir,req_file), upgrade=True) |
387 | - |
388 | + for req_file in requirements_pip_files.split(','): |
389 | + pip_install_req(os.path.join(working_dir, req_file), upgrade=True) |
390 | |
391 | # Trigger WSGI reloading |
392 | for relid in relation_ids('wsgi'): |
393 | - relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
394 | + relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
395 | |
396 | for relid in relation_ids('django-settings'): |
397 | - relation_set({'django_settings_timestamp': time.time()}, relation_id=relid) |
398 | + relation_set({'django_settings_timestamp': time.time()}, |
399 | + relation_id=relid) |
400 | |
401 | - install_dir(settings_dir_path, owner=wsgi_user, group=wsgi_group, mode=0755) |
402 | + install_dir( |
403 | + settings_dir_path, owner=wsgi_user, group=wsgi_group, mode=0755) |
404 | install_dir(urls_dir_path, owner=wsgi_user, group=wsgi_group, mode=0755) |
405 | |
406 | if unit_config: |
407 | @@ -666,17 +703,19 @@ |
408 | 'django_admin_cmd': django_admin_cmd, |
409 | 'wsgi_user': wsgi_user, |
410 | 'wsgi_group': wsgi_group, |
411 | - }) |
412 | + }) |
413 | |
414 | - run('chown -R %s:%s %s' % (wsgi_user,wsgi_group, working_dir)) |
415 | + run('chown -R %s:%s %s' % (wsgi_user, wsgi_group, working_dir)) |
416 | |
417 | # Trigger WSGI reloading |
418 | for relid in relation_ids('wsgi'): |
419 | relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
420 | |
421 | + |
422 | def django_settings_relation_broken(): |
423 | pass |
424 | |
425 | + |
426 | def pgsql_relation_joined_changed(): |
427 | os.environ['DJANGO_SETTINGS_MODULE'] = django_settings_modules |
428 | django_admin_cmd = find_django_admin_cmd() |
429 | @@ -689,30 +728,32 @@ |
430 | return |
431 | |
432 | templ_vars = { |
433 | - 'db_engine': 'django.db.backends.postgresql_psycopg2', |
434 | - 'db_database': database, |
435 | - 'db_user': relation_get("user"), |
436 | - 'db_password': relation_get("password"), |
437 | - 'db_host': relation_get("host"), |
438 | + 'db_engine': 'django.db.backends.postgresql_psycopg2', |
439 | + 'db_database': database, |
440 | + 'db_user': relation_get("user"), |
441 | + 'db_password': relation_get("password"), |
442 | + 'db_host': relation_get("host"), |
443 | } |
444 | |
445 | - process_template('engine.tmpl', templ_vars, settings_database_path % {'engine_name': 'pgsql'}) |
446 | + process_template('engine.tmpl', templ_vars, |
447 | + settings_database_path % {'engine_name': 'pgsql'}) |
448 | |
449 | - run("%s syncdb --noinput --settings=%s" % \ |
450 | - (django_admin_cmd, django_settings_modules), |
451 | + run("%s syncdb --noinput --settings=%s" % |
452 | + (django_admin_cmd, django_settings_modules), |
453 | cwd=working_dir) |
454 | |
455 | if django_south: |
456 | - run("%s migrate --settings=%s" % \ |
457 | - (django_admin_cmd, django_settings_modules), |
458 | + run("%s migrate --settings=%s" % |
459 | + (django_admin_cmd, django_settings_modules), |
460 | cwd=working_dir) |
461 | |
462 | - run('chown -R %s:%s %s' % (wsgi_user,wsgi_group, working_dir)) |
463 | + run('chown -R %s:%s %s' % (wsgi_user, wsgi_group, working_dir)) |
464 | |
465 | # Trigger WSGI reloading |
466 | for relid in relation_ids('wsgi'): |
467 | relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
468 | |
469 | + |
470 | def pgsql_relation_broken(): |
471 | run('rm %s' % settings_database_path % {'engine_name': 'pgsql'}) |
472 | |
473 | @@ -720,6 +761,7 @@ |
474 | for relid in relation_ids('wsgi'): |
475 | relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
476 | |
477 | + |
478 | def mongodb_relation_joined_changed(): |
479 | packages = ["python-mongoengine"] |
480 | apt_get_install(packages) |
481 | @@ -728,19 +770,18 @@ |
482 | if not database: |
483 | return |
484 | |
485 | - templ_vars = { |
486 | - 'db_database': database, |
487 | - 'db_host': relation_get("host"), |
488 | - } |
489 | - |
490 | - process_template('mongodb_engine.tmpl', templ_vars, settings_database_path % {'engine_name': 'mongodb'}) |
491 | - |
492 | - run('chown -R %s:%s %s' % (wsgi_user,wsgi_group, working_dir)) |
493 | + templ_vars = {'db_database': database, 'db_host': relation_get("host")} |
494 | + |
495 | + process_template('mongodb_engine.tmpl', templ_vars, |
496 | + settings_database_path % {'engine_name': 'mongodb'}) |
497 | + |
498 | + run('chown -R %s:%s %s' % (wsgi_user, wsgi_group, working_dir)) |
499 | |
500 | # Trigger WSGI reloading |
501 | for relid in relation_ids('wsgi'): |
502 | relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
503 | |
504 | + |
505 | def mongodb_relation_broken(): |
506 | run('rm %s' % settings_database_path % {'engine_name': 'mongodb'}) |
507 | |
508 | @@ -748,8 +789,9 @@ |
509 | for relid in relation_ids('wsgi'): |
510 | relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
511 | |
512 | + |
513 | def wsgi_relation_joined_changed(): |
514 | - relation_set({'working_dir':working_dir}) |
515 | + relation_set({'working_dir': working_dir}) |
516 | |
517 | for var in config_data: |
518 | if var.startswith('wsgi_') or var in ['listen_ip', 'port']: |
519 | @@ -760,9 +802,11 @@ |
520 | |
521 | open_port(config_data['port']) |
522 | |
523 | + |
524 | def wsgi_relation_broken(): |
525 | close_port(config_data['port']) |
526 | |
527 | + |
528 | def cache_relation_joined_changed(): |
529 | os.environ['DJANGO_SETTINGS_MODULE'] = django_settings_modules |
530 | |
531 | @@ -774,20 +818,21 @@ |
532 | return |
533 | |
534 | templ_vars = { |
535 | - 'cache_engine': 'django.core.cache.backends.memcached.MemcachedCache', |
536 | - 'cache_host': relation_get("host"), |
537 | - 'cache_port': relation_get("port"), |
538 | + 'cache_engine': 'django.core.cache.backends.memcached.MemcachedCache', |
539 | + 'cache_host': relation_get("host"), |
540 | + 'cache_port': relation_get("port"), |
541 | } |
542 | |
543 | - process_template('cache.tmpl', templ_vars, settings_database_path % {'engine_name': 'memcache'}) |
544 | - |
545 | - run('chown -R %s:%s %s' % (wsgi_user,wsgi_group, working_dir)) |
546 | - |
547 | + process_template('cache.tmpl', templ_vars, |
548 | + settings_database_path % {'engine_name': 'memcache'}) |
549 | + |
550 | + run('chown -R %s:%s %s' % (wsgi_user, wsgi_group, working_dir)) |
551 | |
552 | # Trigger WSGI reloading |
553 | for relid in relation_ids('wsgi'): |
554 | relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
555 | |
556 | + |
557 | def cache_relation_broken(): |
558 | run('rm %s' % settings_database_path % {'engine_name': 'memcache'}) |
559 | |
560 | @@ -795,9 +840,11 @@ |
561 | for relid in relation_ids('wsgi'): |
562 | relation_set({'wsgi_timestamp': time.time()}, relation_id=relid) |
563 | |
564 | + |
565 | def website_relation_joined_changed(): |
566 | relation_set({'port': config_data["port"], 'hostname': get_unit_host()}) |
567 | |
568 | + |
569 | def website_relation_broken(): |
570 | pass |
571 | |
572 | @@ -893,17 +940,20 @@ |
573 | working_dir = vcs_clone_dir |
574 | |
575 | django_settings_modules = '.'.join([sanitized_unit_name, django_settings]) |
576 | -django_settings_modules = django_settings #andy hack |
577 | +django_settings_modules = django_settings # andy hack |
578 | django_run_dir = os.path.join(working_dir, "run/") |
579 | django_logs_dir = os.path.join(working_dir, "logs/") |
580 | settings_py_path = os.path.join(working_dir, 'settings.py') |
581 | urls_py_path = os.path.join(working_dir, 'urls.py') |
582 | settings_dir_path = os.path.join(working_dir, config_data["settings_dir_name"]) |
583 | urls_dir_path = os.path.join(working_dir, config_data["urls_dir_name"]) |
584 | -settings_secret_path = os.path.join(working_dir, config_data["settings_secret_key_path"]) |
585 | -settings_database_path = os.path.join(working_dir, config_data["settings_database_path"]) |
586 | +settings_secret_path = os.path.join( |
587 | + working_dir, config_data["settings_secret_key_path"]) |
588 | +settings_database_path = os.path.join( |
589 | + working_dir, config_data["settings_database_path"]) |
590 | hook_name = os.path.basename(sys.argv[0]) |
591 | |
592 | + |
593 | ############################################################################### |
594 | # Main section |
595 | ############################################################################### |
596 | @@ -913,20 +963,21 @@ |
597 | install() |
598 | |
599 | elif hook_name == "start": |
600 | - start() |
601 | + start() |
602 | |
603 | elif hook_name == "stop": |
604 | - stop() |
605 | + stop() |
606 | |
607 | elif hook_name == "config-changed": |
608 | - config_changed(config_data) |
609 | - update_nrpe_config() |
610 | + config_changed(config_data) |
611 | + update_nrpe_config() |
612 | |
613 | elif hook_name == "upgrade-charm": |
614 | upgrade() |
615 | config_changed(config_data) |
616 | |
617 | - elif hook_name in ["django-settings-relation-joined", "django-settings-relation-changed"]: |
618 | + elif hook_name in ["django-settings-relation-joined", |
619 | + "django-settings-relation-changed"]: |
620 | django_settings_relation_joined_changed() |
621 | config_changed(config_data) |
622 |
PASSED: Continuous integration, rev:534 s-jenkins. ubuntu- ci:8080/ job/uci- engine- ci/780/
http://
Executed test runs:
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/uci- engine- ci/780/ rebuild
http://