ceph-volume: don't exit before empty report can be printed

get_plan() called exit in case of an empty plan. This prevented a report
being printed under these circumstances. Avoid exit in this case. Also
adds tests to ensure an empty report is printed.

Fixes: https://tracker.ceph.com/issues/47760

Signed-off-by: Jan Fajerski <jfajerski@suse.com>
This commit is contained in:
Jan Fajerski 2020-10-08 08:45:26 +02:00
parent 821b66e67c
commit 0cc5604843
2 changed files with 56 additions and 4 deletions

View File

@ -459,7 +459,7 @@ class Batch(object):
num_osds = len(plan)
if num_osds == 0:
mlogger.info('All data devices are unavailable')
exit(0)
return plan
requested_osds = args.osds_per_device * len(phys_devs) + len(lvm_devs)
fast_type = 'block_db' if args.bluestore else 'journal'
@ -469,7 +469,7 @@ class Batch(object):
fast_type)
if fast_devices and not fast_allocations:
mlogger.info('{} fast devices were passed, but none are available'.format(len(fast_devices)))
exit(0)
return []
if fast_devices and not len(fast_allocations) == num_osds:
mlogger.error('{} fast allocations != {} num_osds'.format(
len(fast_allocations), num_osds))
@ -481,7 +481,7 @@ class Batch(object):
'block_wal')
if very_fast_devices and not very_fast_allocations:
mlogger.info('{} very fast devices were passed, but none are available'.format(len(very_fast_devices)))
exit(0)
return []
if very_fast_devices and not len(very_fast_allocations) == num_osds:
mlogger.error('{} very fast allocations != {} num_osds'.format(
len(very_fast_allocations), num_osds))

View File

@ -45,7 +45,7 @@ class TestBatch(object):
def test_json_report_valid_empty(self, format_, factory, conf_ceph_stub, mock_device_generator):
# ensure json reports are valid when empty
conf_ceph_stub('[global]\nfsid=asdf-lkjh')
devs = [mock_device_generator() for _ in range(5)]
devs = []
args = factory(data_slots=1,
osds_per_device=1,
osd_ids=[],
@ -64,6 +64,58 @@ class TestBatch(object):
report = b._create_report(plan)
json.loads(report)
@pytest.mark.parametrize('format_', ['json', 'json-pretty'])
def test_json_report_valid_empty_unavailable_fast(self, format_, factory, conf_ceph_stub, mock_device_generator):
# ensure json reports are valid when empty
conf_ceph_stub('[global]\nfsid=asdf-lkjh')
devs = [mock_device_generator() for _ in range(5)]
fast_devs = [mock_device_generator()]
fast_devs[0].available_lvm = False
args = factory(data_slots=1,
osds_per_device=1,
osd_ids=[],
report=True,
format=format_,
devices=devs,
db_devices=fast_devs,
wal_devices=[],
bluestore=True,
block_db_size="1G",
dmcrypt=True,
)
b = batch.Batch([])
plan = b.get_plan(args)
b.args = args
report = b._create_report(plan)
json.loads(report)
@pytest.mark.parametrize('format_', ['json', 'json-pretty'])
def test_json_report_valid_empty_unavailable_very_fast(self, format_, factory, conf_ceph_stub, mock_device_generator):
# ensure json reports are valid when empty
conf_ceph_stub('[global]\nfsid=asdf-lkjh')
devs = [mock_device_generator() for _ in range(5)]
fast_devs = [mock_device_generator()]
very_fast_devs = [mock_device_generator()]
very_fast_devs[0].available_lvm = False
args = factory(data_slots=1,
osds_per_device=1,
osd_ids=[],
report=True,
format=format_,
devices=devs,
db_devices=fast_devs,
wal_devices=very_fast_devs,
bluestore=True,
block_db_size="1G",
dmcrypt=True,
)
b = batch.Batch([])
plan = b.get_plan(args)
b.args = args
report = b._create_report(plan)
json.loads(report)
def test_get_physical_osds_return_len(self, factory,
mock_devices_available,
conf_ceph_stub,