plugins/ceph: Handle Ceph versions prior to Mimic

The command line tool ``ceph-authtool`` grew the ``--mode``
command line argument in the Ceph Mimic release.

We need to support versions prior to that as well.

Change-Id: I163581f3133e2c6033a55f389411b9309a6562d2
Closes-Bug: #1822114
This commit is contained in:
Frode Nordahl 2019-03-28 15:32:10 +01:00
parent 3e9f4096f9
commit e57acaacdb
No known key found for this signature in database
GPG Key ID: 6A5D59A3BA48373F
2 changed files with 37 additions and 2 deletions

View File

@ -142,10 +142,20 @@ class BaseOpenStackCephCharm(object):
self.ceph_key_name))
keyring_absolute_path = os.path.join(self.ceph_keyring_path,
keyring_name)
subprocess.check_call([
cmd = [
'ceph-authtool', keyring_absolute_path,
'--create-keyring', '--name={}'.format(self.ceph_key_name),
'--add-key', interface.key, '--mode', '0600'])
'--add-key', interface.key, '--mode', '0600',
]
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError as cp:
if not cp.returncode == 1:
raise
# the version of ceph-authtool on the system does not have
# --mode command line argument
subprocess.check_call(cmd[:-2])
os.chmod(keyring_absolute_path, 0o600)
shutil.chown(keyring_absolute_path, user=self.user, group=self.group)
return keyring_absolute_path

View File

@ -1,5 +1,6 @@
import mock
import os
import subprocess
from unit_tests.charms_openstack.charm.utils import BaseOpenStackCharmTest
@ -89,6 +90,30 @@ class TestOpenStackCephConsumingCharm(BaseOpenStackCharmTest):
'/etc/ceph/ceph.client.sarepta.keyring',
user='ceph', group='ceph')
self.patch_object(cpl.os, 'chmod')
self.check_call.side_effect = [
subprocess.CalledProcessError(42, [], ''), None]
with self.assertRaises(subprocess.CalledProcessError):
self.target.configure_ceph_keyring(interface)
self.check_call.reset_mock()
self.check_call.side_effect = [
subprocess.CalledProcessError(1, [], ''), None]
self.target.configure_ceph_keyring(interface)
self.check_call.assert_has_calls([
mock.call([
'ceph-authtool',
'/etc/ceph/ceph.client.sarepta.keyring',
'--create-keyring', '--name=client.sarepta', '--add-key',
'KEY', '--mode', '0600']),
mock.call([
'ceph-authtool',
'/etc/ceph/ceph.client.sarepta.keyring',
'--create-keyring', '--name=client.sarepta', '--add-key',
'KEY']),
])
self.chmod.assert_called_with('/etc/ceph/ceph.client.sarepta.keyring',
0o600)
class TestCephCharm(BaseOpenStackCharmTest):