From 43f4fb6cef3173c900d3eae6103d8e03ea0a1cf3 Mon Sep 17 00:00:00 2001 From: Nicolas Pochet Date: Fri, 21 Sep 2018 17:19:03 +0200 Subject: [PATCH] Handle properly ceph osd lspools output The output of the `ceph osd lspools` can be: * 1 glance,2rbd, or * 1 glance 2 rbd --- .../utilities/test_zaza_utilities_ceph.py | 13 ++ zaza/utilities/ceph.py | 145 +++++++++--------- 2 files changed, 89 insertions(+), 69 deletions(-) diff --git a/unit_tests/utilities/test_zaza_utilities_ceph.py b/unit_tests/utilities/test_zaza_utilities_ceph.py index 3d3f140fb..9e6658e8f 100644 --- a/unit_tests/utilities/test_zaza_utilities_ceph.py +++ b/unit_tests/utilities/test_zaza_utilities_ceph.py @@ -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) diff --git a/zaza/utilities/ceph.py b/zaza/utilities/ceph.py index 625a2420d..08f8b89e2 100644 --- a/zaza/utilities/ceph.py +++ b/zaza/utilities/ceph.py @@ -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