[hopem, r=chris.macnaughton] Add support for RGW relation to handle broker requests.
Partially-Closes-Bug: 1476749
This commit is contained in:
commit
5b5e6dca54
@ -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,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,12 +84,26 @@ def process_requests_v1(reqs):
|
|||||||
log(msg, level=ERROR)
|
log(msg, level=ERROR)
|
||||||
return {'exit-code': 1, 'stderr': msg}
|
return {'exit-code': 1, 'stderr': msg}
|
||||||
|
|
||||||
|
# Mandatory params
|
||||||
pool = params['pool']
|
pool = params['pool']
|
||||||
replicas = params['replicas']
|
replicas = params['replicas']
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
if not pool_exists(service=svc, name=pool):
|
if not pool_exists(service=svc, name=pool):
|
||||||
log("Creating pool '%s' (replicas=%s)" % (pool, replicas),
|
log("Creating pool '%s' (replicas=%s)" % (pool, replicas),
|
||||||
level=INFO)
|
level=INFO)
|
||||||
create_pool(service=svc, name=pool, replicas=replicas)
|
create_pool(service=svc, name=pool, replicas=replicas,
|
||||||
|
pg_num=pg_num)
|
||||||
else:
|
else:
|
||||||
log("Pool '%s' already exists - skipping create" % (pool),
|
log("Pool '%s' already exists - skipping create" % (pool),
|
||||||
level=DEBUG)
|
level=DEBUG)
|
||||||
|
@ -316,20 +316,31 @@ def osd_relation(relid=None):
|
|||||||
log('mon cluster not in quorum - deferring fsid provision')
|
log('mon cluster not in quorum - deferring fsid provision')
|
||||||
|
|
||||||
|
|
||||||
|
@hooks.hook('radosgw-relation-changed')
|
||||||
@hooks.hook('radosgw-relation-joined')
|
@hooks.hook('radosgw-relation-joined')
|
||||||
def radosgw_relation(relid=None):
|
def radosgw_relation(relid=None):
|
||||||
# Install radosgw for admin tools
|
# Install radosgw for admin tools
|
||||||
apt_install(packages=filter_installed_packages(['radosgw']))
|
apt_install(packages=filter_installed_packages(['radosgw']))
|
||||||
|
|
||||||
|
"""Process broker request(s)."""
|
||||||
if ceph.is_quorum():
|
if ceph.is_quorum():
|
||||||
log('mon cluster in quorum - providing radosgw with keys')
|
settings = relation_get(rid=relid)
|
||||||
data = {
|
if 'broker_req' in settings:
|
||||||
'fsid': config('fsid'),
|
if not ceph.is_leader():
|
||||||
'radosgw_key': ceph.get_radosgw_key(),
|
log("Not leader - ignoring broker request", level=DEBUG)
|
||||||
'auth': config('auth-supported'),
|
else:
|
||||||
'ceph-public-address': get_public_addr(),
|
rsp = process_requests(settings['broker_req'])
|
||||||
}
|
unit_id = remote_unit().replace('/', '-')
|
||||||
relation_set(relation_id=relid,
|
unit_response_key = 'broker-rsp-' + unit_id
|
||||||
relation_settings=data)
|
log('mon cluster in quorum - providing radosgw with keys')
|
||||||
|
data = {
|
||||||
|
'fsid': config('fsid'),
|
||||||
|
'radosgw_key': ceph.get_radosgw_key(),
|
||||||
|
'auth': config('auth-supported'),
|
||||||
|
'ceph-public-address': get_public_addr(),
|
||||||
|
unit_response_key: rsp,
|
||||||
|
}
|
||||||
|
relation_set(relation_id=relid, relation_settings=data)
|
||||||
else:
|
else:
|
||||||
log('mon cluster not in quorum - deferring key provision')
|
log('mon cluster not in quorum - deferring key provision')
|
||||||
|
|
||||||
|
1
hooks/radosgw-relation-changed
Symbolic link
1
hooks/radosgw-relation-changed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
ceph_hooks.py
|
@ -53,7 +53,47 @@ class CephBrokerTestCase(unittest.TestCase):
|
|||||||
rc = ceph_broker.process_requests(reqs)
|
rc = ceph_broker.process_requests(reqs)
|
||||||
mock_pool_exists.assert_called_with(service='admin', name='foo')
|
mock_pool_exists.assert_called_with(service='admin', name='foo')
|
||||||
mock_create_pool.assert_called_with(service='admin', name='foo',
|
mock_create_pool.assert_called_with(service='admin', name='foo',
|
||||||
replicas=3)
|
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_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': 100}]})
|
||||||
|
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.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})
|
self.assertEqual(json.loads(rc), {'exit-code': 0})
|
||||||
|
|
||||||
@mock.patch('ceph_broker.create_pool')
|
@mock.patch('ceph_broker.create_pool')
|
||||||
@ -84,7 +124,7 @@ class CephBrokerTestCase(unittest.TestCase):
|
|||||||
rc = ceph_broker.process_requests(reqs)
|
rc = ceph_broker.process_requests(reqs)
|
||||||
mock_pool_exists.assert_called_with(service='admin', name='foo')
|
mock_pool_exists.assert_called_with(service='admin', name='foo')
|
||||||
mock_create_pool.assert_called_with(service='admin', name='foo',
|
mock_create_pool.assert_called_with(service='admin', name='foo',
|
||||||
replicas=3)
|
replicas=3, pg_num=None)
|
||||||
self.assertEqual(json.loads(rc)['exit-code'], 0)
|
self.assertEqual(json.loads(rc)['exit-code'], 0)
|
||||||
self.assertEqual(json.loads(rc)['request-id'], '1ef5aede')
|
self.assertEqual(json.loads(rc)['request-id'], '1ef5aede')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user