diff --git a/charms_openstack/plugins/classes.py b/charms_openstack/plugins/classes.py index 39b2554..64e813d 100644 --- a/charms_openstack/plugins/classes.py +++ b/charms_openstack/plugins/classes.py @@ -121,12 +121,11 @@ class BaseOpenStackCephCharm(object): return os.path.join(self.snap_path_prefix, self.ceph_keyring_path_prefix) - def configure_ceph_keyring(self, interface, - cluster_name=None): + def configure_ceph_keyring(self, key, cluster_name=None): """Creates or updates a Ceph keyring file. - :param interface: Interface with ``key`` property. - :type interface: Any class that has a property named ``key``. + :param key: Key data + :type key: str :param cluster_name: (Optional) Name of Ceph cluster to operate on. Defaults to value of ``self.ceph_cluster_name``. :type cluster_name: str @@ -145,7 +144,7 @@ class BaseOpenStackCephCharm(object): cmd = [ 'ceph-authtool', keyring_absolute_path, '--create-keyring', '--name={}'.format(self.ceph_key_name), - '--add-key', interface.key, '--mode', '0600', + '--add-key', key, '--mode', '0600', ] try: subprocess.check_call(cmd) @@ -231,10 +230,10 @@ class CephCharm(charms_openstack.charm.OpenStackCharm, self.ceph_keyring_path_prefix, self.ceph_service_name) - def configure_ceph_keyring(self, interface, cluster_name=None): + def configure_ceph_keyring(self, key, cluster_name=None): """Override parent function to add symlink in ``/etc/ceph``.""" keyring_absolute_path = super().configure_ceph_keyring( - interface, cluster_name=cluster_name) + key, cluster_name=cluster_name) symlink_absolute_path = os.path.join( '/etc/ceph', os.path.basename(keyring_absolute_path)) diff --git a/unit_tests/charms_openstack/plugins/test_classes.py b/unit_tests/charms_openstack/plugins/test_classes.py index c08491c..5476713 100644 --- a/unit_tests/charms_openstack/plugins/test_classes.py +++ b/unit_tests/charms_openstack/plugins/test_classes.py @@ -70,9 +70,8 @@ class TestOpenStackCephConsumingCharm(BaseOpenStackCharmTest): return_value='sarepta') self.patch_object(cpl.subprocess, 'check_call') self.patch_object(cpl.shutil, 'chown') - interface = mock.MagicMock() - interface.key = 'KEY' - self.assertEqual(self.target.configure_ceph_keyring(interface), + key = 'KEY' + self.assertEqual(self.target.configure_ceph_keyring(key), '/etc/ceph/ceph.client.sarepta.keyring') self.isdir.assert_called_with('/etc/ceph') self.mkdir.assert_called_with('/etc/ceph', @@ -85,7 +84,7 @@ class TestOpenStackCephConsumingCharm(BaseOpenStackCharmTest): ]) self.target.user = 'ceph' self.target.group = 'ceph' - self.target.configure_ceph_keyring(interface) + self.target.configure_ceph_keyring(key) self.chown.assert_called_with( '/etc/ceph/ceph.client.sarepta.keyring', user='ceph', group='ceph') @@ -94,11 +93,11 @@ class TestOpenStackCephConsumingCharm(BaseOpenStackCharmTest): self.check_call.side_effect = [ subprocess.CalledProcessError(42, [], ''), None] with self.assertRaises(subprocess.CalledProcessError): - self.target.configure_ceph_keyring(interface) + self.target.configure_ceph_keyring(key) self.check_call.reset_mock() self.check_call.side_effect = [ subprocess.CalledProcessError(1, [], ''), None] - self.target.configure_ceph_keyring(interface) + self.target.configure_ceph_keyring(key) self.check_call.assert_has_calls([ mock.call([ 'ceph-authtool', @@ -140,13 +139,12 @@ class TestCephCharm(BaseOpenStackCharmTest): self.patch_object(cpl.subprocess, 'check_call') self.patch_object(cpl.shutil, 'chown') self.patch_object(cpl.os, 'symlink') - interface = mock.MagicMock() - interface.key = 'KEY' + key = 'KEY' self.patch_object(cpl.os.path, 'exists', return_value=True) self.patch_object(cpl.os, 'readlink') self.patch_object(cpl.os, 'remove') self.readlink.side_effect = OSError - self.target.configure_ceph_keyring(interface) + self.target.configure_ceph_keyring(key) self.isdir.assert_called_with('/var/lib/ceph/sarepta') self.mkdir.assert_called_with('/var/lib/ceph/sarepta', owner='root', group='root', perms=0o750) @@ -166,7 +164,7 @@ class TestCephCharm(BaseOpenStackCharmTest): '/etc/ceph/ceph.client.sarepta.keyring') self.readlink.side_effect = None self.readlink.return_value = '/some/where/else' - self.target.configure_ceph_keyring(interface) + self.target.configure_ceph_keyring(key) self.remove.assert_called_with('/etc/ceph/ceph.client.sarepta.keyring') def test_install(self):