Merge lp:~abentley/charms/precise/juju-reports/configure-s3 into lp:~juju-qa/charms/precise/juju-reports/trunk

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 39
Proposed branch: lp:~abentley/charms/precise/juju-reports/configure-s3
Merge into: lp:~juju-qa/charms/precise/juju-reports/trunk
Diff against target: 88 lines (+41/-3)
2 files modified
config.yaml (+8/-1)
hooks/common.py (+33/-2)
To merge this branch: bzr merge lp:~abentley/charms/precise/juju-reports/configure-s3
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+227631@code.launchpad.net

Commit message

Configure S3.

Description of the change

This branch enables configuring S3 for juju-reports, so that it can download data from s3.

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 'config.yaml'
2--- config.yaml 2014-07-15 14:31:47 +0000
3+++ config.yaml 2014-07-21 20:21:39 +0000
4@@ -40,4 +40,11 @@
5 type: string
6 default: http://juju-ci.vapour.ws:8080
7 description: "The Jenkins URL to use for retrieving Juju CI data."
8-
9+ aws-access-key:
10+ type: string
11+ default: ""
12+ description: "The access key to use for the s3 bucket."
13+ aws-secret-key:
14+ type: string
15+ default: ""
16+ description: "The secret key to use for the s3 bucket."
17
18=== modified file 'hooks/common.py'
19--- hooks/common.py 2014-07-15 14:31:47 +0000
20+++ hooks/common.py 2014-07-21 20:21:39 +0000
21@@ -18,7 +18,6 @@
22 HOME = '/home/ubuntu'
23 PROJECT_DIR = os.path.join(HOME, 'juju-reports')
24 INI = 'production.ini'
25-INI_TEMPLATE = 'resources/production.ini.template'
26
27
28 def get_ini_path():
29@@ -31,19 +30,50 @@
30 return config
31
32
33+def get_template_path(name):
34+ return os.path.join(PROJECT_DIR, 'resources/{}.template'.format(name))
35+
36+
37 def install_ini(mongo_url, gh_token, jujuci_url):
38 config = ConfigParser()
39- path = os.path.join(PROJECT_DIR, INI_TEMPLATE)
40+ path = get_template_path(INI)
41 if not os.path.exists(path):
42 path = get_ini_path()
43 config.read(path)
44 config.set('app:main', 'mongo.url', mongo_url)
45 config.set('app:main', 'gh_token', gh_token)
46 config.set('app:main', 'jujuci.url', jujuci_url)
47+ config.set('app:main', 'home', HOME)
48 config.write(open(get_ini_path(), 'w'))
49 return config
50
51
52+def configure_s3(config):
53+ template_path = get_template_path('juju-qa.s3cfg')
54+ try:
55+ template_cm = open(template_path)
56+ except IOError as e:
57+ if e.errno == errno.ENOENT:
58+ hookenv.log('Skipping s3 config due to missing template.')
59+ return
60+ with template_cm as template_file:
61+ template = template_file.read()
62+ config_path = os.path.join(PROJECT_DIR, 'juju-qa.s3cfg')
63+ s3config = template.format(access_key=config['aws-access-key'],
64+ secret_key=config['aws-secret-key'])
65+ update_file(config_path, s3config)
66+ ensure_dir(os.path.join(HOME, 'juju-qa-data'))
67+ ensure_dir(os.path.join(HOME, 'juju-qa-data/cbtest'))
68+
69+
70+def ensure_dir(path):
71+ try:
72+ os.mkdir(path)
73+ except OSError as e:
74+ if e.errno != errno.EEXIST:
75+ raise
76+
77+
78 def get_configured_port(ini):
79 return ini_get(ini, 'server:main', 'port')
80
81@@ -223,6 +253,7 @@
82 hookenv.log('No mongodb set up.')
83 return
84 ini = install_ini(mongo_url, config['gh-token'], config['jujuci-url'])
85+ configure_s3(config)
86 for key in ['lp-key', 'lp-oauth', 'gh-token']:
87 if config[key] == '':
88 hookenv.log('Not setting up cron because {} not set.'.format(key))

Subscribers

People subscribed via source and target branches

to all changes: