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 on 2014-12-08
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 2014-12-08 Approve on 2014-12-08
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.
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
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2014-12-04 18:45:32 +0000
3+++ hooks/hooks.py 2014-12-08 10:51:58 +0000
4@@ -88,6 +88,15 @@
5 juju_info('Container joined: {}'.format(unit))
6 _install_keys(unit)
7
8+ # Signal units (normally principal) that secrets are available.
9+ local_unit = charmhelpers.core.hookenv.local_unit()
10+ relids = charmhelpers.core.hookenv.relation_ids('secrets')
11+ for rid in relids:
12+ relation = charmhelpers.core.hookenv.relation_get(
13+ rid=rid, unit=local_unit)
14+ if relation:
15+ charmhelpers.core.hookenv.relation_set(
16+ rid, {'location': _service_dir(unit)})
17
18 if __name__ == "__main__":
19 hooks.execute(sys.argv)
20
21=== modified file 'metadata.yaml'
22--- metadata.yaml 2014-11-25 16:46:29 +0000
23+++ metadata.yaml 2014-12-08 10:51:58 +0000
24@@ -7,6 +7,11 @@
25 categories:
26 - misc
27 subordinate: true
28+provides:
29+ secrets:
30+ interface: secrets
31+ scope: container
32+ optional: true
33 requires:
34 juju-info:
35 interface: juju-info
36
37=== modified file 'unit_tests/test_hooks.py'
38--- unit_tests/test_hooks.py 2014-12-04 19:04:24 +0000
39+++ unit_tests/test_hooks.py 2014-12-08 10:51:58 +0000
40@@ -26,9 +26,15 @@
41
42 PATCHES = [
43 'charmhelpers.core.hookenv.config',
44+ 'charmhelpers.core.hookenv.local_unit',
45 'charmhelpers.core.hookenv.log',
46+ 'charmhelpers.core.hookenv.relation_get',
47+ 'charmhelpers.core.hookenv.relation_id',
48+ 'charmhelpers.core.hookenv.relation_ids',
49+ 'charmhelpers.core.hookenv.relation_set',
50 'charmhelpers.core.hookenv.relations_of_type',
51 'charmhelpers.core.hookenv.remote_unit',
52+ 'charmhelpers.core.hookenv.unit_get',
53 'charmhelpers.core.host.mkdir',
54 ]
55
56@@ -50,13 +56,19 @@
57 setattr(self, attr_name, _m.start())
58 self.addCleanup(_m.stop)
59
60+ self.local_unit.return_value = 'bazinga'
61 self.unit_name = 'bazinga/0'
62 self.service_dir = os.path.join(self.tmpdir, 'bazinga')
63 self.keys_dir = os.path.join(self.service_dir, 'keys')
64- self.remote_unit.return_value = self.unit_name
65+ self.relation_get.side_effect = lambda rid, unit=None: 'something'
66+ self.relation_id.return_value = '1'
67+ self.relation_ids.side_effect = (
68+ lambda rel_id: ["{}:{}".format(rel_id, self.relation_id())])
69 self.relations_of_type.side_effect = (
70 lambda rel_type: [{'__unit__': self.unit_name}])
71+ self.remote_unit.return_value = self.unit_name
72 self.mkdir.side_effect = lambda d, perms=None: os.mkdir(d)
73+ self.unit_get.return_value = '127.0.0.1'
74
75 self._set_default_config()
76
77@@ -121,3 +133,7 @@
78 hooks.hooks.execute(['hooks/juju-info-relation-joined'])
79 self.assertEqual(['keys'], os.listdir(self.service_dir))
80 self.assertEqual(['id_rsa'], os.listdir(self.keys_dir))
81+ # Once the keys are in place the subordinate updates the 'secrets'
82+ # relations established.
83+ self.relation_set.assert_called_once_with(
84+ 'secrets:1', {'location': self.service_dir})

Subscribers

People subscribed via source and target branches