Use ``ceph-conf`` to retrieve default values
The ``ceph`` command expects connection to a running cluster even if it does not use it. Change-Id: Ied3edf63706e2d48d2ea09056bc6d6508e9e3e0f Closes-Bug: #1819852
This commit is contained in:
parent
17de051792
commit
f3acd81a31
|
@ -12,6 +12,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import re
|
||||
import socket
|
||||
import subprocess
|
||||
|
@ -183,14 +184,12 @@ def get_default_rbd_features():
|
|||
|
||||
:returns: Installed Ceph's Default vaule for ``rbd_default_features``
|
||||
:rtype: int
|
||||
:raises: subprocess.CalledProcessError
|
||||
:raises: IndexError, json.JSONDecodeError, subprocess.CalledProcessError
|
||||
"""
|
||||
output = subprocess.check_output(
|
||||
['ceph', '-c', '/dev/null', '--show-config'],
|
||||
universal_newlines=True)
|
||||
for line in output.splitlines():
|
||||
if 'rbd_default_features' in line:
|
||||
return int(line.split('=')[1].lstrip().rstrip())
|
||||
ceph_conf = json.loads(subprocess.check_output(
|
||||
['ceph-conf', '-c', '/dev/null', '-D', '--format', 'json'],
|
||||
universal_newlines=True))
|
||||
return int(ceph_conf['rbd_default_features'])
|
||||
|
||||
|
||||
def add_rbd_mirror_features(rbd_features):
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import mock
|
||||
|
||||
import test_utils
|
||||
|
@ -40,13 +41,15 @@ class CephUtilsTestCase(test_utils.CharmTestCase):
|
|||
|
||||
@mock.patch.object(utils.subprocess, 'check_output')
|
||||
def test_get_default_rbd_features(self, _check_output):
|
||||
_check_output.return_value = ('a = b\nrbd_default_features = 61\n'
|
||||
'c = d\n')
|
||||
_check_output.return_value = json.dumps(
|
||||
{'a': 'b',
|
||||
'rbd_default_features': '61',
|
||||
'c': 'd'})
|
||||
self.assertEquals(
|
||||
utils.get_default_rbd_features(),
|
||||
61)
|
||||
_check_output.assert_called_once_with(
|
||||
['ceph', '-c', '/dev/null', '--show-config'],
|
||||
['ceph-conf', '-c', '/dev/null', '-D', '--format', 'json'],
|
||||
universal_newlines=True)
|
||||
|
||||
def test_add_mirror_rbd_features(self):
|
||||
|
|
Loading…
Reference in New Issue