Merge lp:~gandelman-a/charm-helpers/ensure_ceph_keyring into lp:charm-helpers

Proposed by Adam Gandelman
Status: Merged
Merged at revision: 84
Proposed branch: lp:~gandelman-a/charm-helpers/ensure_ceph_keyring
Merge into: lp:charm-helpers
Diff against target: 99 lines (+66/-4)
2 files modified
charmhelpers/contrib/storage/linux/ceph.py (+22/-0)
tests/contrib/storage/test_linux_ceph.py (+44/-4)
To merge this branch: bzr merge lp:~gandelman-a/charm-helpers/ensure_ceph_keyring
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+187087@code.launchpad.net

Description of the change

Adds contrib.storage.linux.ceph:ensure_ceph_keyring().

To post a comment you must log in.
Revision history for this message
James Page (james-page) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/storage/linux/ceph.py'
2--- charmhelpers/contrib/storage/linux/ceph.py 2013-08-23 14:07:52 +0000
3+++ charmhelpers/contrib/storage/linux/ceph.py 2013-09-23 18:53:21 +0000
4@@ -334,3 +334,25 @@
5 log('ceph: Starting service {} after migrating data.'
6 .format(svc))
7 service_start(svc)
8+
9+
10+def ensure_ceph_keyring(service, user=None, group=None):
11+ '''
12+ Ensures a ceph keyring is created for a named service
13+ and optionally ensures user and group ownership.
14+
15+ Returns False if no ceph key is available in relation state.
16+ '''
17+ key = None
18+ for rid in relation_ids('ceph'):
19+ for unit in related_units(rid):
20+ key = relation_get('key', rid=rid, unit=unit)
21+ if key:
22+ break
23+ if not key:
24+ return False
25+ create_keyring(service=service, key=key)
26+ keyring = _keyring_path(service)
27+ if user and group:
28+ check_call(['chown', '%s.%s' % (user, group), keyring])
29+ return True
30
31=== modified file 'tests/contrib/storage/test_linux_ceph.py'
32--- tests/contrib/storage/test_linux_ceph.py 2013-09-23 10:50:53 +0000
33+++ tests/contrib/storage/test_linux_ceph.py 2013-09-23 18:53:21 +0000
34@@ -408,8 +408,8 @@
35 self.assertEquals(device, e.filename)
36 self.assertEquals(os.errno.ENOENT, e.errno)
37 self.assertEquals(os.strerror(os.errno.ENOENT), e.strerror)
38- self.log.assert_called_with('ceph: gave up waiting on block device %s' % device,
39- level='ERROR')
40+ self.log.assert_called_with(
41+ 'ceph: gave up waiting on block device %s' % device, level='ERROR')
42
43 @nose.plugins.attrib.attr('slow')
44 def test_make_filesystem_timeout(self):
45@@ -425,8 +425,8 @@
46 after = time.time()
47 duration = after - before
48 self.assertTrue(timeout - duration < 0.1)
49- self.log.assert_called_with('ceph: gave up waiting on block device %s' % device,
50- level='ERROR')
51+ self.log.assert_called_with(
52+ 'ceph: gave up waiting on block device %s' % device, level='ERROR')
53
54 @nose.plugins.attrib.attr('slow')
55 def test_device_is_formatted_if_it_appears(self):
56@@ -460,3 +460,43 @@
57 'ceph: Formatting block device %s as '
58 'filesystem %s.' % (device, fstype), level='INFO'
59 )
60+
61+ @patch.object(ceph_utils, 'relation_ids')
62+ @patch.object(ceph_utils, 'related_units')
63+ @patch.object(ceph_utils, 'relation_get')
64+ def test_ensure_ceph_keyring_no_relation_no_data(self, rget, runits, rids):
65+ rids.return_value = []
66+ self.assertEquals(False, ceph_utils.ensure_ceph_keyring(service='foo'))
67+ rids.return_value = ['ceph:0']
68+ runits.return_value = ['ceph/0']
69+ rget.return_value = ''
70+ self.assertEquals(False, ceph_utils.ensure_ceph_keyring(service='foo'))
71+
72+ @patch.object(ceph_utils, '_keyring_path')
73+ @patch.object(ceph_utils, 'create_keyring')
74+ @patch.object(ceph_utils, 'relation_ids')
75+ @patch.object(ceph_utils, 'related_units')
76+ @patch.object(ceph_utils, 'relation_get')
77+ def test_ensure_ceph_keyring_with_data(self, rget, runits,
78+ rids, create, _path):
79+ rids.return_value = ['ceph:0']
80+ runits.return_value = ['ceph/0']
81+ rget.return_value = 'fookey'
82+ self.assertEquals(True,
83+ ceph_utils.ensure_ceph_keyring(service='foo'))
84+ create.assert_called_with(service='foo', key='fookey')
85+ _path.assert_called_with('foo')
86+ self.assertFalse(self.check_call.called)
87+
88+ _path.return_value = '/etc/ceph/client.foo.keyring'
89+ self.assertEquals(
90+ True,
91+ ceph_utils.ensure_ceph_keyring(
92+ service='foo', user='adam', group='users'))
93+ create.assert_called_with(service='foo', key='fookey')
94+ _path.assert_called_with('foo')
95+ self.check_call.assert_called_with([
96+ 'chown',
97+ 'adam.users',
98+ '/etc/ceph/client.foo.keyring'
99+ ])

Subscribers

People subscribed via source and target branches