Add profile-name parameter in create-pool action

This change adds a profile name parameter in the create-pool action that
allows a replicated pool to be created with a CRUSH profile other than
the default replicated_rule.

Closes-Bug: #1905573

Change-Id: Ib21ded8f4a977b4a2d57c6b6b4bb82721b12c4ea
(cherry picked from commit da798bdd95)
This commit is contained in:
Aqsa Malik
2022-02-04 13:06:53 +01:00
committed by Nikhil Kshirsagar
parent 9cc367f551
commit a70dd46214
3 changed files with 24 additions and 1 deletions

View File

@@ -30,10 +30,12 @@ def create_pool():
try:
if pool_type == "replicated":
replicas = action_get("replicas")
crush_profile_name = action_get("profile-name")
replicated_pool = ReplicatedPool(name=pool_name,
service='admin',
replicas=replicas,
app_name=app_name,
profile_name=crush_profile_name,
percent_data=float(percent_data),
)
replicated_pool.create()

View File

@@ -648,7 +648,7 @@ class ReplicatedPool(BasePool):
# we will fail with KeyError if it is not provided.
self.replicas = op['replicas']
self.pg_num = op.get('pg_num')
self.profile_name = op.get('crush-profile') or profile_name
self.profile_name = op.get('crush-profile', profile_name)
else:
self.replicas = replicas or 2
self.pg_num = pg_num

View File

@@ -66,6 +66,27 @@ class TestCephOps(unittest.TestCase):
mock_delete_pool.assert_called_with(service='admin', name='foo')
self.assertEqual(json.loads(rc), {'exit-code': 0})
@patch('charmhelpers.contrib.storage.linux.ceph.cmp_pkgrevno')
@patch.object(broker, 'pool_exists')
@patch.object(broker.ReplicatedPool, 'create')
@patch.object(broker, 'log', lambda *args, **kwargs: None)
def test_process_requests_create_replicated_pool(self,
mock_replicated_pool,
mock_pool_exists,
mock_cmp_pkgrevno):
mock_pool_exists.return_value = False
mock_cmp_pkgrevno.return_value = 1
reqs = json.dumps({'api-version': 1,
'ops': [{
'op': 'create-pool',
'name': 'foo',
'replicas': 3
}]})
rc = broker.process_requests(reqs)
mock_pool_exists.assert_called_with(service='admin', name='foo')
mock_replicated_pool.assert_called_with()
self.assertEqual(json.loads(rc), {'exit-code': 0})
@patch('charmhelpers.contrib.storage.linux.ceph.cmp_pkgrevno')
@patch.object(broker, 'pool_exists')
@patch.object(broker.ErasurePool, 'create')