add pool create pg_num override support
This commit is contained in:
parent
562bde334a
commit
aaa849bc64
@ -12,6 +12,7 @@ from charmhelpers.core.hookenv import (
|
|||||||
)
|
)
|
||||||
from charmhelpers.contrib.storage.linux.ceph import (
|
from charmhelpers.contrib.storage.linux.ceph import (
|
||||||
create_pool,
|
create_pool,
|
||||||
|
get_osds,
|
||||||
pool_exists,
|
pool_exists,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,6 +91,11 @@ def process_requests_v1(reqs):
|
|||||||
# Optional params
|
# Optional params
|
||||||
pg_num = req.get('pg_num')
|
pg_num = req.get('pg_num')
|
||||||
if pg_num:
|
if pg_num:
|
||||||
|
# Cap pg_num to max allowed just in case.
|
||||||
|
osds = get_osds(svc)
|
||||||
|
if osds:
|
||||||
|
pg_num = min(pg_num, (len(osds) * 100 // replicas))
|
||||||
|
|
||||||
# Ensure string
|
# Ensure string
|
||||||
pg_num = str(pg_num)
|
pg_num = str(pg_num)
|
||||||
|
|
||||||
|
@ -56,12 +56,15 @@ class CephBrokerTestCase(unittest.TestCase):
|
|||||||
replicas=3, pg_num=None)
|
replicas=3, pg_num=None)
|
||||||
self.assertEqual(json.loads(rc), {'exit-code': 0})
|
self.assertEqual(json.loads(rc), {'exit-code': 0})
|
||||||
|
|
||||||
|
@mock.patch('ceph_broker.get_osds')
|
||||||
@mock.patch('ceph_broker.create_pool')
|
@mock.patch('ceph_broker.create_pool')
|
||||||
@mock.patch('ceph_broker.pool_exists')
|
@mock.patch('ceph_broker.pool_exists')
|
||||||
@mock.patch('ceph_broker.log')
|
@mock.patch('ceph_broker.log')
|
||||||
def test_process_requests_create_pool_w_pg_num(self, mock_log,
|
def test_process_requests_create_pool_w_pg_num(self, mock_log,
|
||||||
mock_pool_exists,
|
mock_pool_exists,
|
||||||
mock_create_pool):
|
mock_create_pool,
|
||||||
|
mock_get_osds):
|
||||||
|
mock_get_osds.return_value = [0, 1, 2]
|
||||||
mock_pool_exists.return_value = False
|
mock_pool_exists.return_value = False
|
||||||
reqs = json.dumps({'api-version': 1,
|
reqs = json.dumps({'api-version': 1,
|
||||||
'ops': [{'op': 'create-pool', 'name':
|
'ops': [{'op': 'create-pool', 'name':
|
||||||
@ -73,6 +76,26 @@ class CephBrokerTestCase(unittest.TestCase):
|
|||||||
replicas=3, pg_num='100')
|
replicas=3, pg_num='100')
|
||||||
self.assertEqual(json.loads(rc), {'exit-code': 0})
|
self.assertEqual(json.loads(rc), {'exit-code': 0})
|
||||||
|
|
||||||
|
@mock.patch('ceph_broker.get_osds')
|
||||||
|
@mock.patch('ceph_broker.create_pool')
|
||||||
|
@mock.patch('ceph_broker.pool_exists')
|
||||||
|
@mock.patch('ceph_broker.log')
|
||||||
|
def test_process_requests_create_pool_w_pg_num_capped(self, mock_log,
|
||||||
|
mock_pool_exists,
|
||||||
|
mock_create_pool,
|
||||||
|
mock_get_osds):
|
||||||
|
mock_get_osds.return_value = [0, 1, 2]
|
||||||
|
mock_pool_exists.return_value = False
|
||||||
|
reqs = json.dumps({'api-version': 1,
|
||||||
|
'ops': [{'op': 'create-pool', 'name':
|
||||||
|
'foo', 'replicas': 3,
|
||||||
|
'pg_num': 300}]})
|
||||||
|
rc = ceph_broker.process_requests(reqs)
|
||||||
|
mock_pool_exists.assert_called_with(service='admin', name='foo')
|
||||||
|
mock_create_pool.assert_called_with(service='admin', name='foo',
|
||||||
|
replicas=3, pg_num='100')
|
||||||
|
self.assertEqual(json.loads(rc), {'exit-code': 0})
|
||||||
|
|
||||||
@mock.patch('ceph_broker.create_pool')
|
@mock.patch('ceph_broker.create_pool')
|
||||||
@mock.patch('ceph_broker.pool_exists')
|
@mock.patch('ceph_broker.pool_exists')
|
||||||
@mock.patch('ceph_broker.log')
|
@mock.patch('ceph_broker.log')
|
||||||
|
Loading…
Reference in New Issue
Block a user