Merge lp:~caio1982/charms/trusty/system-image-server/productionizing-story-1332 into lp:~caio1982/charms/trusty/system-image-server/trunk

Proposed by Caio Begotti
Status: Merged
Merged at revision: 21
Proposed branch: lp:~caio1982/charms/trusty/system-image-server/productionizing-story-1332
Merge into: lp:~caio1982/charms/trusty/system-image-server/trunk
Diff against target: 205 lines (+97/-18)
3 files modified
README (+5/-0)
config.yaml (+13/-1)
hooks/hooks.py (+79/-17)
To merge this branch: bzr merge lp:~caio1982/charms/trusty/system-image-server/productionizing-story-1332
Reviewer Review Type Date Requested Status
Caio Begotti Pending
Review via email: mp+258192@code.launchpad.net

Description of the change

Merge changes needed for story #1332 of Capomastro development and testing on production.

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 'README'
2--- README 2015-02-27 19:45:00 +0000
3+++ README 2015-05-04 16:24:20 +0000
4@@ -14,6 +14,11 @@
5
6 From this point on it follows the standard operation of System Image Server through si-shell.
7
8+TODO
9+----
10+
11+* Amulet tests
12+
13 Contact Information
14 -------------------
15
16
17=== modified file 'config.yaml'
18--- config.yaml 2015-03-02 18:10:42 +0000
19+++ config.yaml 2015-05-04 16:24:20 +0000
20@@ -16,7 +16,7 @@
21 packages:
22 type: string
23 description: "Packages required for this service"
24- default: "bzr abootimg android-tools-fsutils python-gnupg python-gpgme fakeroot pxz pep8 pyflakes python-mock haveged tree"
25+ default: "bzr abootimg android-tools-fsutils python-gnupg python-gpgme fakeroot pxz pep8 pyflakes python-mock haveged tree cron"
26 install_root:
27 type: string
28 description: "The root directory the service will be installed in"
29@@ -25,6 +25,10 @@
30 type: string
31 description: "FQDN of the host unit that this charm relates to, used with install_root to determine the installation path too"
32 default: "system-image.staging.ubuntu.com"
33+ shell:
34+ type: string
35+ description: "A batch of commands to be passed to si-shell during post-deployment (base64 encoded)"
36+ default: ""
37 config_template:
38 type: string
39 description: "Image server config template (base64 encoded)"
40@@ -33,3 +37,11 @@
41 type: string
42 description: "List of pairs with devices for creation and their channel relation"
43 default: "ubuntu-touch/devel:mydevice ubuntu-touch/devel-current:mydevice ubuntu-touch/qa:otherdevice"
44+ cronjob:
45+ type: string
46+ description: "Cronjob of the image server, useful for periodic importing of images (base64 encoded)"
47+ default: ""
48+ keyowner:
49+ type: string
50+ description: "E-mail to be used when generating the service GPG keys (if empty it will use testing keys)"
51+ default: ""
52
53=== modified file 'hooks/hooks.py'
54--- hooks/hooks.py 2015-04-23 14:49:58 +0000
55+++ hooks/hooks.py 2015-05-04 16:24:20 +0000
56@@ -8,14 +8,17 @@
57 import sys
58 import grp
59 import pwd
60+import tempfile
61
62 import charmhelpers.fetch
63
64-from charmhelpers.core.hookenv import log, config, relation_set, Hooks, UnregisteredHookError
65+from charmhelpers.core.hookenv import (log, config, relation_set,
66+ Hooks, UnregisteredHookError)
67 from jinja2 import Template
68
69 hooks = Hooks()
70
71+
72 def _service_dir():
73 unit = os.environ['JUJU_UNIT_NAME'].split('/')[0]
74 for x in (':', '-', '/', '"', "'"):
75@@ -53,7 +56,6 @@
76
77
78 def _setup_config():
79- log('Saving config file...', 'INFO')
80 sdir = _service_dir()
81 config_file = os.path.join(sdir, 'etc', 'config')
82
83@@ -67,22 +69,38 @@
84 charmconfig = config()
85 with open(config_file, 'w') as conf:
86 conf.write(str(template.render(charmconfig)))
87+ conf.close()
88
89
90 def _setup_keys():
91- log('Generating server keys...', 'INFO')
92 subprocess.check_output(['haveged'])
93- srvdir = _service_dir()
94- #the system-image tools unfortunately really want to run from this dir
95- os.chdir(srvdir)
96- out = subprocess.check_output(['{}/tests/generate-keys'.format(srvdir)])
97- log(out, 'INFO')
98- #copy the keys we just generated into the proper location
99- shutil.rmtree('{}/secret/gpg/keys/'.format(srvdir))
100- shutil.copytree('{}/tests/keys'.format(srvdir),
101- '{}/secret/gpg/keys/'.format(srvdir))
102- out = subprocess.check_output(['{}/bin/generate-keyrings'.format(srvdir)])
103- log(out, 'INFO')
104+
105+ # the system-image tools unfortunately
106+ # really want to run from this dir
107+ sdir = _service_dir()
108+ os.chdir(sdir)
109+
110+ fqdn = config('fqdn')
111+ keyowner = config('keyowner')
112+
113+ if keyowner:
114+ command = '{}/bin/generate-keys --email={} ' \
115+ '--prefix={}'.format(sdir, keyowner, fqdn)
116+ log('Generating production-ready keys with {}'.format(command), 'INFO')
117+ res = subprocess.check_output(command, shell=True)
118+ log(str(res), 'INFO')
119+ else:
120+ log('Generating & copying testing keys as necessary...', 'INFO')
121+ res = subprocess.check_output(['{}/tests/generate-keys'.format(sdir)])
122+ log(str(res), 'INFO')
123+
124+ #copy the keys we just generated into the proper location
125+ shutil.rmtree('{}/secret/gpg/keys/'.format(sdir))
126+ shutil.copytree('{}/tests/keys'.format(sdir),
127+ '{}/secret/gpg/keys/'.format(sdir))
128+
129+ res = subprocess.check_output(['{}/bin/generate-keyrings'.format(sdir)])
130+ log(str(res), 'INFO')
131
132
133 def _setup_webserver():
134@@ -128,17 +146,59 @@
135 channels = [pair.split(':')[0] for pair in config_pairs]
136 for channel in channels:
137 if channel not in pub.list_channels():
138- log('Creating channel {}...'.format(channel), 'INFO')
139- res = pub.create_channel(channel)
140+ log('Creating channel {}...'.format(channel), 'INFO')
141+ res = pub.create_channel(channel)
142+ log(str(res), 'INFO')
143
144 for channel, device in [pair.split(':') for pair in config_pairs]:
145 if device not in pub.list_devices(channel):
146- log('Creating device {} in channel {}'.format(device, channel), 'INFO')
147+ log('Creating device {} in channel {}'.format(device, channel),
148+ 'INFO')
149 res = pub.create_device(channel, device)
150+ log(str(res), 'INFO')
151
152 log('Publishing keyring...', 'INFO')
153 for keyring in ("archive-master", "image-master", "image-signing"):
154 res = pub.publish_keyring(keyring)
155+ log(str(res), 'INFO')
156+
157+
158+def _setup_cron():
159+ if not config('cronjob'):
160+ log("Missing cronjob template, skipping periodic schedule setup")
161+ return
162+
163+ cronjob = '/etc/cron.d/system-image-server'
164+ log("Writing cronjob {}".format(cronjob), 'INFO')
165+
166+ template_str = config('cronjob')
167+ template = Template(str(base64.b64decode(template_str)))
168+ charmconfig = config()
169+ with open(cronjob, 'w') as conf:
170+ conf.write(str(template.render(charmconfig)))
171+ conf.close()
172+
173+
174+def _setup_sishell():
175+ if not config('shell'):
176+ log("Missing commands file, skipping si-shell batch")
177+ return
178+
179+ sdir = _service_dir()
180+ fd, batchfile = tempfile.mkstemp()
181+ template_str = config('shell')
182+ template = Template(str(base64.b64decode(template_str)))
183+ charmconfig = config()
184+ with open(batchfile, 'w') as batch:
185+ batch.write(str(template.render(charmconfig)))
186+ os.close(fd)
187+
188+ log('Executing {}/bin/si-shell < {}'.format(sdir, batchfile), 'INFO')
189+ res = subprocess.check_output(
190+ '{}/bin/si-shell < {}'.format(sdir, batchfile),
191+ stderr=subprocess.STDOUT,
192+ shell=True)
193+ log(str(res), 'INFO')
194
195
196 @hooks.hook('install')
197@@ -162,6 +222,8 @@
198 def config_changed():
199 _setup_config()
200 _setup_channels()
201+ _setup_cron()
202+ _setup_sishell()
203
204
205 @hooks.hook('upgrade-charm')

Subscribers

People subscribed via source and target branches

to all changes: