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

Subscribers

People subscribed via source and target branches

to all changes: