Skip to content

Commit

Permalink
Handle properly ceph osd lspools output
Browse files Browse the repository at this point in the history
The output of the `ceph osd lspools` can be:
* 1 glance,2rbd, or
* 1 glance
  2 rbd
  • Loading branch information
n-pochet committed Sep 21, 2018
1 parent 3409a15 commit 43f4fb6
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 69 deletions.
13 changes: 13 additions & 0 deletions unit_tests/utilities/test_zaza_utilities_ceph.py
Expand Up @@ -88,3 +88,16 @@ def test_get_ceph_pools(self):
}
actual = ceph_utils.get_ceph_pools('ceph-mon/0')
self.assertEqual(expected, actual)
# Bionic Queens output
result = {
'Code': '0',
'Stdout': '1 cinder-ceph\n2 glance',
'Stderr': ''
}
self.run_on_unit.return_value = result
expected = {
'cinder-ceph': 1,
'glance': 2
}
actual = ceph_utils.get_ceph_pools('ceph-mon/0')
self.assertEqual(expected, actual)
145 changes: 76 additions & 69 deletions zaza/utilities/ceph.py
Expand Up @@ -7,81 +7,88 @@


def get_expected_pools(radosgw=False):
"""Get expected ceph pools.
"""Get expected ceph pools.
Return a list of expected ceph pools in a ceph + cinder + glance
test scenario, based on OpenStack release and whether ceph radosgw
is flagged as present or not.
:param radosgw: If radosgw is used or not
:type radosgw: boolean
:returns: List of pools that are expected
:rtype: list
"""
current_release = openstack_utils.get_os_release()
trusty_icehouse = openstack_utils.get_os_release('trusty_icehouse')
trusty_kilo = openstack_utils.get_os_release('trusty_kilo')
zesty_ocata = openstack_utils.get_os_release('zesty_ocata')
if current_release == trusty_icehouse:
# Icehouse
pools = [
'data',
'metadata',
'rbd',
'cinder-ceph',
'glance'
]
elif (trusty_kilo <= current_release <= zesty_ocata):
# Kilo through Ocata
pools = [
'rbd',
'cinder-ceph',
'glance'
]
else:
# Pike and later
pools = [
'cinder-ceph',
'glance'
]
Return a list of expected ceph pools in a ceph + cinder + glance
test scenario, based on OpenStack release and whether ceph radosgw
is flagged as present or not.
:param radosgw: If radosgw is used or not
:type radosgw: boolean
:returns: List of pools that are expected
:rtype: list
"""
current_release = openstack_utils.get_os_release()
trusty_icehouse = openstack_utils.get_os_release('trusty_icehouse')
trusty_kilo = openstack_utils.get_os_release('trusty_kilo')
zesty_ocata = openstack_utils.get_os_release('zesty_ocata')
if current_release == trusty_icehouse:
# Icehouse
pools = [
'data',
'metadata',
'rbd',
'cinder-ceph',
'glance'
]
elif (trusty_kilo <= current_release <= zesty_ocata):
# Kilo through Ocata
pools = [
'rbd',
'cinder-ceph',
'glance'
]
else:
# Pike and later
pools = [
'cinder-ceph',
'glance'
]

if radosgw:
pools.extend([
'.rgw.root',
'.rgw.control',
'.rgw',
'.rgw.gc',
'.users.uid'
])
if radosgw:
pools.extend([
'.rgw.root',
'.rgw.control',
'.rgw',
'.rgw.gc',
'.users.uid'
])

return pools
return pools


def get_ceph_pools(unit_name):
"""Get ceph pools.
"""Get ceph pools.
Return a dict of ceph pools from a single ceph unit, with
pool name as keys, pool id as vals.
:param unit_name: Name of the unit to get the pools on
:type unit_name: string
:returns: Dict of ceph pools
:rtype: dict
:raise: zaza_model.CommandRunFailed
"""
pools = {}
cmd = 'sudo ceph osd lspools'
result = zaza_model.run_on_unit(unit_name, cmd)
output = result.get('Stdout').strip()
code = int(result.get('Code'))
if code != 0:
raise zaza_model.CommandRunFailed(cmd, result)
Return a dict of ceph pools from a single ceph unit, with
pool name as keys, pool id as vals.
:param unit_name: Name of the unit to get the pools on
:type unit_name: string
:returns: Dict of ceph pools
:rtype: dict
:raise: zaza_model.CommandRunFailed
"""
pools = {}
cmd = 'sudo ceph osd lspools'
result = zaza_model.run_on_unit(unit_name, cmd)
output = result.get('Stdout').strip()
code = int(result.get('Code'))
if code != 0:
raise zaza_model.CommandRunFailed(cmd, result)

# Example output: 0 data,1 metadata,2 rbd,3 cinder,4 glance,
for pool in str(output).split(','):
pool_id_name = pool.split(' ')
if len(pool_id_name) == 2:
pool_id = pool_id_name[0]
pool_name = pool_id_name[1]
pools[pool_name] = int(pool_id)
# Example output: 0 data,1 metadata,2 rbd,3 cinder,4 glance,
# It can also be something link 0 data\n1 metadata

logging.debug('Pools on {}: {}'.format(unit_name, pools))
return pools
# First split on new lines
osd_pools = str(output).split('\n')
# If we have a len of 1, no new lines found -> splitting on commas
if len(osd_pools) == 1:
osd_pools = osd_pools[0].split(',')
for pool in osd_pools:
pool_id_name = pool.split(' ')
if len(pool_id_name) == 2:
pool_id = pool_id_name[0]
pool_name = pool_id_name[1]
pools[pool_name] = int(pool_id)

logging.debug('Pools on {}: {}'.format(unit_name, pools))
return pools

0 comments on commit 43f4fb6

Please sign in to comment.