Allow passing keyword arguments to create_*_pool

The CephBrokerRq class will be used to validate the arguments
passed so that the caller will get immediate feedback if any
unknown arguments or invalid values are used.

Note that we at some point in the future should attempt to
reconcile and move this interface over to the
openstack/charm-interface-ceph-client repository so that it can
reuse any code shared with the ceph-client and ceph-mds interfaces
hosted there.

Change-Id: I0d4ed457e1d59eabed3340f5dc7d8353d5d66f04
This commit is contained in:
Frode Nordahl 2020-10-02 14:27:21 +02:00
parent 7627eb2e85
commit 7d8eb5abe7
No known key found for this signature in database
GPG Key ID: 6A5D59A3BA48373F
4 changed files with 44 additions and 27 deletions

View File

@ -1,4 +1,3 @@
- project:
templates:
- python35-charm-jobs
- openstack-python3-ussuri-jobs
- openstack-python3-charm-jobs

View File

@ -85,7 +85,7 @@ class CephRBDMirrorRequires(Endpoint):
def create_replicated_pool(self, name, replicas=3, weight=None,
pg_num=None, group=None, namespace=None,
app_name=None, max_bytes=None,
max_objects=None):
max_objects=None, **kwargs):
"""Request replicated pool setup.
Refer to charm-helpers ``add_op_create_replicated_pool`` function for
@ -106,22 +106,24 @@ class CephRBDMirrorRequires(Endpoint):
if req['op'] == 'create-pool' and req['name'] == name:
# request already exists, don't create a new one
return
current_request.add_op_create_replicated_pool(
name="{}".format(name),
replica_count=replicas,
pg_num=pg_num,
weight=weight,
group=group,
namespace=namespace,
app_name=app_name,
max_bytes=max_bytes,
max_objects=max_objects)
kwargs.update({
'name': "{}".format(name),
'replica_count': replicas,
'pg_num': pg_num,
'weight': weight,
'group': group,
'namespace': namespace,
'app_name': app_name,
'max_bytes': max_bytes,
'max_objects': max_objects,
})
current_request.add_op_create_replicated_pool(**kwargs)
ch_ceph.send_request_if_needed(current_request,
relation=self.endpoint_name)
def create_erasure_pool(self, name, erasure_profile=None, weight=None,
group=None, app_name=None, max_bytes=None,
max_objects=None):
max_objects=None, **kwargs):
"""Request erasure coded pool setup.
Refer to charm-helpers ``add_op_create_erasure_pool``function for
@ -140,14 +142,16 @@ class CephRBDMirrorRequires(Endpoint):
if req['op'] == 'create-pool' and req['name'] == name:
# request already exists, don't create a new one
return
current_request.add_op_create_erasure_pool(
name="{}".format(name),
erasure_profile=erasure_profile,
weight=weight,
group=group,
app_name=app_name,
max_bytes=max_bytes,
max_objects=max_objects)
kwargs.update({
'name': "{}".format(name),
'erasure_profile': erasure_profile,
'weight': weight,
'group': group,
'app_name': app_name,
'max_bytes': max_bytes,
'max_objects': max_objects,
})
current_request.add_op_create_erasure_pool(**kwargs)
ch_ceph.send_request_if_needed(current_request,
relation=self.endpoint_name)

16
tox.ini
View File

@ -1,6 +1,6 @@
[tox]
skipsdist = True
envlist = pep8,py37
envlist = pep8,py3
# NOTE(beisner): Avoid build/test env pollution by not enabling sitepackages.
sitepackages = False
# NOTE(beisner): Avoid false positives by not skipping missing interpreters.
@ -69,6 +69,20 @@ commands =
coverage xml -o cover/coverage.xml
coverage report
[testenv:py38]
basepython = python3.8
deps = -r{toxinidir}/test-requirements.txt
setenv =
{[testenv]setenv}
PYTHON=coverage run
commands =
coverage erase
stestr run {posargs}
coverage combine
coverage html -d cover
coverage xml -o cover/coverage.xml
coverage report
[testenv:pep8]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt

View File

@ -129,11 +129,11 @@ class TestCephRBDMirrorRequires(test_utils.PatchHelper):
broker_req = mock.MagicMock()
self.CephBrokerRq.return_value = broker_req
self.patch_object(requires.ch_ceph, 'send_request_if_needed')
self.requires_class.create_replicated_pool('rbd')
self.requires_class.create_replicated_pool('rbd', fake='value')
broker_req.add_op_create_replicated_pool.assert_called_once_with(
app_name=None, group=None, max_bytes=None, max_objects=None,
name='rbd', namespace=None, pg_num=None, replica_count=3,
weight=None)
weight=None, fake='value')
self.send_request_if_needed.assert_called_once_with(
broker_req,
relation='some-endpoint')
@ -158,10 +158,10 @@ class TestCephRBDMirrorRequires(test_utils.PatchHelper):
broker_req = mock.MagicMock()
self.CephBrokerRq.return_value = broker_req
self.patch_object(requires.ch_ceph, 'send_request_if_needed')
self.requires_class.create_erasure_pool('rbd')
self.requires_class.create_erasure_pool('rbd', fake='value')
broker_req.add_op_create_erasure_pool.assert_called_once_with(
app_name=None, erasure_profile=None, group=None, max_bytes=None,
max_objects=None, name='rbd', weight=None)
max_objects=None, name='rbd', weight=None, fake='value')
self.send_request_if_needed.assert_called_once_with(
broker_req,
relation='some-endpoint')