Merge lp:~abentley/charms/trusty/juju-reports/auto-test-ini into lp:~juju-qa/charms/trusty/juju-reports/trunk

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 56
Proposed branch: lp:~abentley/charms/trusty/juju-reports/auto-test-ini
Merge into: lp:~juju-qa/charms/trusty/juju-reports/trunk
Diff against target: 72 lines (+29/-18)
1 file modified
hooks/common.py (+29/-18)
To merge this branch: bzr merge lp:~abentley/charms/trusty/juju-reports/auto-test-ini
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+251101@code.launchpad.net

Commit message

Generate test.ini with valid mongo.

Description of the change

This branch updates the charm to automatically supply a working test.ini

The test.ini supplied by jujureports is intended for use in a single-machine configuration, so a "make deploy" produces a jujureports without working tests. This branch updates mongo.url in test.ini to be the actual mongodb used by the charm. This is safe because test.ini uses a different database (juju_test rather than juju).

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/common.py'
2--- hooks/common.py 2015-02-25 15:26:36 +0000
3+++ hooks/common.py 2015-02-26 15:28:39 +0000
4@@ -1,6 +1,7 @@
5 from ConfigParser import (
6 ConfigParser,
7 NoSectionError)
8+from contextlib import contextmanager
9 import errno
10 import os
11 from pwd import getpwnam
12@@ -21,8 +22,8 @@
13 REVISION_INFO_FILE = os.path.join(HOME, 'last-source-revision')
14
15
16-def get_ini_path(source_path):
17- return os.path.join(source_path, INI)
18+def get_ini_path(source_path, base_filename=INI):
19+ return os.path.join(source_path, base_filename)
20
21
22 def get_ini(source_path):
23@@ -35,25 +36,35 @@
24 return os.path.join(source_path, 'resources/{}.template'.format(name))
25
26
27+@contextmanager
28+def update_ini(source_path, base_filename):
29+ template_path = get_template_path(base_filename, source_path)
30+ output_path = get_ini_path(source_path, base_filename)
31+ if not os.path.exists(template_path):
32+ template_path = output_path
33+ config = ConfigParser()
34+ config.read(template_path)
35+ yield config
36+ with open(output_path, 'w') as out_file:
37+ config.write(out_file)
38+
39+
40 def install_ini(mongo_url, gh_token, cidata_url, token,
41 error_email, error_email_from, cloud_health_failure_threshold,
42 source_path):
43- config = ConfigParser()
44- path = get_template_path(INI, source_path)
45- if not os.path.exists(path):
46- path = get_ini_path(source_path)
47- config.read(path)
48- config.set('app:main', 'mongo.url', mongo_url)
49- config.set('app:main', 'gh_token', gh_token)
50- config.set('app:main', 'cidata.url', cidata_url)
51- config.set('app:main', 'charm_bundle_test_token', token)
52- config.set('app:main', 'home', HOME)
53- config.set('app:main', 'error_email', error_email)
54- config.set('app:main', 'error_email_from', error_email_from)
55- config.set(
56- 'app:main', 'cloud_health_failure_threshold',
57- cloud_health_failure_threshold)
58- config.write(open(get_ini_path(source_path), 'w'))
59+ with update_ini(source_path, INI) as config:
60+ config.set('app:main', 'mongo.url', mongo_url)
61+ config.set('app:main', 'gh_token', gh_token)
62+ config.set('app:main', 'cidata.url', cidata_url)
63+ config.set('app:main', 'charm_bundle_test_token', token)
64+ config.set('app:main', 'home', HOME)
65+ config.set('app:main', 'error_email', error_email)
66+ config.set('app:main', 'error_email_from', error_email_from)
67+ config.set(
68+ 'app:main', 'cloud_health_failure_threshold',
69+ cloud_health_failure_threshold)
70+ with update_ini(source_path, 'test.ini') as config:
71+ config.set('app:main', 'mongo.url', mongo_url)
72 return config
73
74

Subscribers

People subscribed via source and target branches