summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Holcombe <xfactor973@gmail.com>2017-02-16 11:00:50 -0800
committerChris Holcombe <xfactor973@gmail.com>2017-02-16 11:00:52 -0800
commite422e65fc98b60417573ce2a6f10e447a9f7d54f (patch)
treed190b9415ef3f60130daa062ea915891ec5304c5
parent9780ddb866f530d180ad3ab75b1271da567f9fe6 (diff)
Fix parse_key
If the returned cephx key from ceph contains [caps] the parse_key function returns the wrong output. Partial-Bug: 1665149 Change-Id: Icca4c174fa15b9637732a919ab5149f34260ae0f
Notes
Notes (review): Code-Review+2: Chris MacNaughton <chris.macnaughton@canonical.com> Workflow+1: Chris MacNaughton <chris.macnaughton@canonical.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 16 Feb 2017 19:22:37 +0000 Reviewed-on: https://review.openstack.org/435066 Project: openstack/charms.ceph Branch: refs/heads/master
-rw-r--r--ceph/__init__.py2
-rw-r--r--unit_tests/test_ceph.py22
2 files changed, 19 insertions, 5 deletions
diff --git a/ceph/__init__.py b/ceph/__init__.py
index 26f1b91..a453b44 100644
--- a/ceph/__init__.py
+++ b/ceph/__init__.py
@@ -960,7 +960,7 @@ def parse_key(raw_key):
960 else: 960 else:
961 for element in raw_key.splitlines(): 961 for element in raw_key.splitlines():
962 if 'key' in element: 962 if 'key' in element:
963 key = element.split(' = ')[1].strip() # IGNORE:E1103 963 return element.split(' = ')[1].strip() # IGNORE:E1103
964 return key 964 return key
965 965
966 966
diff --git a/unit_tests/test_ceph.py b/unit_tests/test_ceph.py
index dde1147..d4de0a2 100644
--- a/unit_tests/test_ceph.py
+++ b/unit_tests/test_ceph.py
@@ -19,7 +19,6 @@ from subprocess import CalledProcessError
19 19
20 20
21class TestDevice(): 21class TestDevice():
22
23 """Test class to mock out pyudev Device""" 22 """Test class to mock out pyudev Device"""
24 23
25 def __getitem__(**kwargs): 24 def __getitem__(**kwargs):
@@ -36,7 +35,6 @@ class TestDevice():
36 35
37 36
38class CephTestCase(unittest.TestCase): 37class CephTestCase(unittest.TestCase):
39
40 def setUp(self): 38 def setUp(self):
41 super(CephTestCase, self).setUp() 39 super(CephTestCase, self).setUp()
42 40
@@ -153,6 +151,23 @@ class CephTestCase(unittest.TestCase):
153 'mon', 'allow r', 'osd', 151 'mon', 'allow r', 'osd',
154 'allow rwx'])]) 152 'allow rwx'])])
155 153
154 def test_parse_key_with_caps_existing_key(self):
155 expected = "AQCm7aVYQFXXFhAAj0WIeqcag88DKOvY4UKR/g=="
156 with_caps = "[client.osd-upgrade]\n"\
157 " key = AQCm7aVYQFXXFhAAj0WIeqcag88DKOvY4UKR/g==\n"\
158 " caps mon = \"allow command \"config-key\";"
159 key = ceph.parse_key(with_caps)
160 print("key: {}".format(key))
161 self.assertEqual(key, expected)
162
163 def test_parse_key_without_caps(self):
164 expected = "AQCm7aVYQFXXFhAAj0WIeqcag88DKOvY4UKR/g=="
165 without_caps = "[client.osd-upgrade]\n"\
166 " key = AQCm7aVYQFXXFhAAj0WIeqcag88DKOvY4UKR/g=="
167 key = ceph.parse_key(without_caps)
168 print("key: {}".format(key))
169 self.assertEqual(key, expected)
170
156 def test_list_unmounted_devices(self): 171 def test_list_unmounted_devices(self):
157 dev1 = mock.MagicMock(spec=TestDevice) 172 dev1 = mock.MagicMock(spec=TestDevice)
158 dev1.__getitem__.return_value = "block" 173 dev1.__getitem__.return_value = "block"
@@ -165,7 +180,7 @@ class CephTestCase(unittest.TestCase):
165 dev3.device_node = '/dev/loop1' 180 dev3.device_node = '/dev/loop1'
166 devices = [dev1, dev2, dev3] 181 devices = [dev1, dev2, dev3]
167 with mock.patch( 182 with mock.patch(
168 'pyudev.Context.list_devices', 183 'pyudev.Context.list_devices',
169 return_value=devices): 184 return_value=devices):
170 with mock.patch.object(ceph, 185 with mock.patch.object(ceph,
171 'is_device_mounted', 186 'is_device_mounted',
@@ -180,7 +195,6 @@ class CephTestCase(unittest.TestCase):
180 195
181 196
182class CephVersionTestCase(unittest.TestCase): 197class CephVersionTestCase(unittest.TestCase):
183
184 @mock.patch.object(ceph, 'get_os_codename_install_source') 198 @mock.patch.object(ceph, 'get_os_codename_install_source')
185 def test_resolve_ceph_version_trusty(self, get_os_codename_install_source): 199 def test_resolve_ceph_version_trusty(self, get_os_codename_install_source):
186 get_os_codename_install_source.return_value = 'juno' 200 get_os_codename_install_source.return_value = 'juno'