Merge lp:~cprov/charms/precise/uci-engine-key-secret-subordinate/warn-principal into lp:~canonical-ci-engineering/charms/precise/uci-engine-key-secret-subordinate/trunk

Proposed by Celso Providelo
Status: Merged
Merged at revision: 4
Proposed branch: lp:~cprov/charms/precise/uci-engine-key-secret-subordinate/warn-principal
Merge into: lp:~canonical-ci-engineering/charms/precise/uci-engine-key-secret-subordinate/trunk
Diff against target: 84 lines (+31/-1)
3 files modified
hooks/hooks.py (+9/-0)
metadata.yaml (+5/-0)
unit_tests/test_hooks.py (+17/-1)
To merge this branch: bzr merge lp:~cprov/charms/precise/uci-engine-key-secret-subordinate/warn-principal
Reviewer Review Type Date Requested Status
Paul Larson Approve
Review via email: mp+243969@code.launchpad.net

Description of the change

Implements a 'secrets' relation which is only established once the keys (secrets, really) are available.

This way additionally to the internal/container scoped relation the principals using k-s-s can be aware of secret content availability for completing its installation (see jenkins charm example).

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

This seemed to work fine when I tried it on Friday. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-12-04 18:45:32 +0000
+++ hooks/hooks.py 2014-12-08 10:51:58 +0000
@@ -88,6 +88,15 @@
88 juju_info('Container joined: {}'.format(unit))88 juju_info('Container joined: {}'.format(unit))
89 _install_keys(unit)89 _install_keys(unit)
9090
91 # Signal units (normally principal) that secrets are available.
92 local_unit = charmhelpers.core.hookenv.local_unit()
93 relids = charmhelpers.core.hookenv.relation_ids('secrets')
94 for rid in relids:
95 relation = charmhelpers.core.hookenv.relation_get(
96 rid=rid, unit=local_unit)
97 if relation:
98 charmhelpers.core.hookenv.relation_set(
99 rid, {'location': _service_dir(unit)})
91100
92if __name__ == "__main__":101if __name__ == "__main__":
93 hooks.execute(sys.argv)102 hooks.execute(sys.argv)
94103
=== modified file 'metadata.yaml'
--- metadata.yaml 2014-11-25 16:46:29 +0000
+++ metadata.yaml 2014-12-08 10:51:58 +0000
@@ -7,6 +7,11 @@
7categories:7categories:
8 - misc8 - misc
9subordinate: true9subordinate: true
10provides:
11 secrets:
12 interface: secrets
13 scope: container
14 optional: true
10requires:15requires:
11 juju-info:16 juju-info:
12 interface: juju-info17 interface: juju-info
1318
=== modified file 'unit_tests/test_hooks.py'
--- unit_tests/test_hooks.py 2014-12-04 19:04:24 +0000
+++ unit_tests/test_hooks.py 2014-12-08 10:51:58 +0000
@@ -26,9 +26,15 @@
2626
27PATCHES = [27PATCHES = [
28 'charmhelpers.core.hookenv.config',28 'charmhelpers.core.hookenv.config',
29 'charmhelpers.core.hookenv.local_unit',
29 'charmhelpers.core.hookenv.log',30 'charmhelpers.core.hookenv.log',
31 'charmhelpers.core.hookenv.relation_get',
32 'charmhelpers.core.hookenv.relation_id',
33 'charmhelpers.core.hookenv.relation_ids',
34 'charmhelpers.core.hookenv.relation_set',
30 'charmhelpers.core.hookenv.relations_of_type',35 'charmhelpers.core.hookenv.relations_of_type',
31 'charmhelpers.core.hookenv.remote_unit',36 'charmhelpers.core.hookenv.remote_unit',
37 'charmhelpers.core.hookenv.unit_get',
32 'charmhelpers.core.host.mkdir',38 'charmhelpers.core.host.mkdir',
33]39]
3440
@@ -50,13 +56,19 @@
50 setattr(self, attr_name, _m.start())56 setattr(self, attr_name, _m.start())
51 self.addCleanup(_m.stop)57 self.addCleanup(_m.stop)
5258
59 self.local_unit.return_value = 'bazinga'
53 self.unit_name = 'bazinga/0'60 self.unit_name = 'bazinga/0'
54 self.service_dir = os.path.join(self.tmpdir, 'bazinga')61 self.service_dir = os.path.join(self.tmpdir, 'bazinga')
55 self.keys_dir = os.path.join(self.service_dir, 'keys')62 self.keys_dir = os.path.join(self.service_dir, 'keys')
56 self.remote_unit.return_value = self.unit_name63 self.relation_get.side_effect = lambda rid, unit=None: 'something'
64 self.relation_id.return_value = '1'
65 self.relation_ids.side_effect = (
66 lambda rel_id: ["{}:{}".format(rel_id, self.relation_id())])
57 self.relations_of_type.side_effect = (67 self.relations_of_type.side_effect = (
58 lambda rel_type: [{'__unit__': self.unit_name}])68 lambda rel_type: [{'__unit__': self.unit_name}])
69 self.remote_unit.return_value = self.unit_name
59 self.mkdir.side_effect = lambda d, perms=None: os.mkdir(d)70 self.mkdir.side_effect = lambda d, perms=None: os.mkdir(d)
71 self.unit_get.return_value = '127.0.0.1'
6072
61 self._set_default_config()73 self._set_default_config()
6274
@@ -121,3 +133,7 @@
121 hooks.hooks.execute(['hooks/juju-info-relation-joined'])133 hooks.hooks.execute(['hooks/juju-info-relation-joined'])
122 self.assertEqual(['keys'], os.listdir(self.service_dir))134 self.assertEqual(['keys'], os.listdir(self.service_dir))
123 self.assertEqual(['id_rsa'], os.listdir(self.keys_dir))135 self.assertEqual(['id_rsa'], os.listdir(self.keys_dir))
136 # Once the keys are in place the subordinate updates the 'secrets'
137 # relations established.
138 self.relation_set.assert_called_once_with(
139 'secrets:1', {'location': self.service_dir})

Subscribers

People subscribed via source and target branches