Merge pull request #675 from openstack-charmers/osd-add-disk-test

Osd add disk test
This commit is contained in:
Chris MacNaughton
2022-02-22 07:47:52 +00:00
committed by GitHub
2 changed files with 43 additions and 1 deletions

View File

@@ -463,7 +463,7 @@ class CephTest(test_utils.OpenStackBaseTest):
The blacklist actions execute and behave as expected.
"""
logging.info('Checking blacklist-add-disk and'
logging.info('Checking blacklist-add-disk and '
'blacklist-remove-disk actions...')
unit_name = 'ceph-osd/0'
@@ -545,6 +545,29 @@ class CephTest(test_utils.OpenStackBaseTest):
)
logging.debug('OK')
def get_num_osds(self, osd):
"""Compute the number of active OSD's."""
result = zaza_model.run_on_unit(osd, 'ceph osd stat --format=json')
result = json.loads(result['Stdout'])
return int(result['num_osds'])
def test_cache_device(self):
"""Test adding a new disk with a caching device."""
logging.info('Running add-disk action with a caching device')
mon = next(iter(zaza_model.get_units('ceph-mon'))).entity_id
osds = [x.entity_id for x in zaza_model.get_units('ceph-osd')]
for unit in osds:
zaza_model.add_storage(unit, 'cache-devices', 'cinder', 10)
loop_dev = zaza_utils.add_loop_device(unit, 10)
action_obj = zaza_model.run_action(
unit_name=unit,
action_name='add-disk',
action_params={'osd-devices': loop_dev.get('Stdout'),
'partition-size': 5}
)
zaza_utils.assertActionRanOK(action_obj)
self.assertEqual(len(osds) * 2, self.get_num_osds(mon))
class CephRGWTest(test_utils.OpenStackBaseTest):
"""Ceph RADOS Gateway Daemons Test Class."""

View File

@@ -723,3 +723,22 @@ def get_leaders_and_non_leaders(application_name):
else:
non_leaders.append(unit)
return leader, non_leaders
def add_loop_device(unit, size=10):
"""Add a loopback device to a Juju unit.
:param unit: The unit name on which to create the device.
:type unit: str
:param size: The size in GB of the device.
:type size: int
:returns: The device name.
"""
loop_name = '/home/ubuntu/loop.img'
truncate = 'truncate --size {}GB {}'.format(size, loop_name)
losetup = 'losetup --find {}'.format(loop_name)
lofind = 'losetup -a | grep {} | cut -f1 -d ":"'.format(loop_name)
cmd = "sudo sh -c '{} && {} && {}'".format(truncate, losetup, lofind)
return model.run_on_unit(unit, cmd)