From 0cc5604843b215709a681fa402145c9fa403b1dd Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Thu, 8 Oct 2020 08:45:26 +0200 Subject: [PATCH] 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 --- .../ceph_volume/devices/lvm/batch.py | 6 +-- .../tests/devices/lvm/test_batch.py | 54 ++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/ceph-volume/ceph_volume/devices/lvm/batch.py b/src/ceph-volume/ceph_volume/devices/lvm/batch.py index a6ced6a108504..37e099fda01e5 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/batch.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/batch.py @@ -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)) diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py index 29d23fd72b64e..4987a85f5eae9 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py @@ -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, -- 2.39.5