add pool create pg_num override support

This commit is contained in:
Edward Hope-Morley 2015-11-19 18:14:14 +00:00
parent 562bde334a
commit aaa849bc64
2 changed files with 30 additions and 1 deletions

View File

@ -12,6 +12,7 @@ from charmhelpers.core.hookenv import (
)
from charmhelpers.contrib.storage.linux.ceph import (
create_pool,
get_osds,
pool_exists,
)
@ -90,6 +91,11 @@ def process_requests_v1(reqs):
# Optional params
pg_num = req.get('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
pg_num = str(pg_num)

View File

@ -56,12 +56,15 @@ class CephBrokerTestCase(unittest.TestCase):
replicas=3, pg_num=None)
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(self, mock_log,
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
reqs = json.dumps({'api-version': 1,
'ops': [{'op': 'create-pool', 'name':
@ -73,6 +76,26 @@ class CephBrokerTestCase(unittest.TestCase):
replicas=3, pg_num='100')
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.pool_exists')
@mock.patch('ceph_broker.log')