Merge lp:~wgrant/charms/trusty/turnip/storage-really into lp:~canonical-launchpad-branches/charms/trusty/turnip/devel

Proposed by William Grant
Status: Merged
Merged at revision: 54
Proposed branch: lp:~wgrant/charms/trusty/turnip/storage-really
Merge into: lp:~canonical-launchpad-branches/charms/trusty/turnip/devel
Diff against target: 92 lines (+28/-18)
4 files modified
config.yaml (+7/-4)
hooks/actions.py (+7/-1)
hooks/services.py (+13/-3)
hooks/turnip_helpers.py (+1/-10)
To merge this branch: bzr merge lp:~wgrant/charms/trusty/turnip/storage-really
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+254377@code.launchpad.net

Commit message

Rework storage support: the storage_external config option now requests a volume and waits until the volume is mounted.

Description of the change

Redesign storage subordinate support, ignoring the services framework even harder.

Previously we'd request a volume (setting the relation's mountpoint value) after service startup, and not wait until it was mounted. Now, instead, if the storage_external option is set we emit the request and wait until it's mounted (ie. the mountpoint value is set from the other end). If the option is not set, we assume local storage and ignore the data relation entirely.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

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 2015-03-19 02:49:15 +0000
3+++ config.yaml 2015-03-27 10:53:18 +0000
4@@ -45,10 +45,13 @@
5 type: string
6 default: '/srv/turnip'
7 description: Root checkout/srv directory.
8- data_dir:
9- type: string
10- default: '/srv/data'
11- description: Block storage mountpoint.
12+ storage_external:
13+ type: boolean
14+ default: false
15+ description: |
16+ Connect to the storage subordinate charm for repo storage.
17+ A volume will be requested and mounted at ${base_dir}/data/repos.
18+ The service will not start until the volume is attached.
19 code_user:
20 type: string
21 default: webops_deploy
22
23=== modified file 'hooks/actions.py'
24--- hooks/actions.py 2015-03-27 07:43:45 +0000
25+++ hooks/actions.py 2015-03-27 10:53:18 +0000
26@@ -111,7 +111,13 @@
27 '-e', CODE_DIR])
28
29
30-def publish_wsgi_relations(self):
31+def ensure_repo_store_writable(service_name):
32+ repo_dir = os.path.join(hookenv.config()['base_dir'], 'data', 'repos')
33+ os.chown(repo_dir, pwd.getpwnam(USER).pw_uid, grp.getgrnam(GROUP).gr_gid)
34+ os.chmod(repo_dir, 0o755)
35+
36+
37+def publish_wsgi_relations(service_name):
38 # Publish the wsgi-file relation so the gunicorn subordinate can
39 # serve us. Other WSGI containers could be made to work, as the most
40 # gunicorn-specific thing is the --paste hack.
41
42=== modified file 'hooks/services.py'
43--- hooks/services.py 2015-03-27 07:43:45 +0000
44+++ hooks/services.py 2015-03-27 10:53:18 +0000
45@@ -37,15 +37,25 @@
46 actions.unpack_source('turnip')
47 actions.install_python_packages('turnip')
48
49+ extra_requirements = []
50+
51+ if hookenv.config()['storage_external']:
52+ # Request a volume from the storage subordinate, and ensure the
53+ # service doesn't try to start until it's present.
54+ repo_dir = os.path.join(hookenv.config()['base_dir'], 'data', 'repos')
55+ for relid in hookenv.relation_ids('data'):
56+ hookenv.relation_set(relid, mountpoint=repo_dir)
57+ extra_requirements.append(turnip_helpers.TurnipStorageRelation())
58+
59 config = hookenv.config()
60 manager = ServiceManager([
61 {
62 'service': 'turnip',
63 'ports': actions.get_ports(),
64- 'provided_data': [turnip_helpers.TurnipApiRelation(),
65- turnip_helpers.TurnipStorageRelation()],
66- 'required_data': [config],
67+ 'provided_data': [turnip_helpers.TurnipApiRelation()],
68+ 'required_data': [config] + extra_requirements,
69 'data_ready': [
70+ actions.ensure_repo_store_writable,
71 helpers.render_template(
72 source='turnip.conf.j2',
73 target='/etc/init/turnip.conf',
74
75=== modified file 'hooks/turnip_helpers.py'
76--- hooks/turnip_helpers.py 2015-03-19 02:49:15 +0000
77+++ hooks/turnip_helpers.py 2015-03-27 10:53:18 +0000
78@@ -18,13 +18,4 @@
79 class TurnipStorageRelation(helpers.RelationContext):
80 name = 'data'
81 interface = 'block-storage'
82-
83- def provide_data(self):
84- config = hookenv.config()
85- mount_point = config['data_dir']
86- data = {
87- 'mountpoint': mount_point
88- }
89- hookenv.log('Allocating block storage volume at mountpoint: {}.'.format(
90- mount_point))
91- return data
92+ required_keys = ['mountpoint']

Subscribers

People subscribed via source and target branches

to all changes: