]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: don't exit before empty report can be printed 37522/head
authorJan Fajerski <jfajerski@suse.com>
Thu, 8 Oct 2020 06:45:26 +0000 (08:45 +0200)
committerJan Fajerski <jfajerski@suse.com>
Thu, 8 Oct 2020 09:54:33 +0000 (11:54 +0200)
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>
(cherry picked from commit 0cc5604843b215709a681fa402145c9fa403b1dd)

src/ceph-volume/ceph_volume/devices/lvm/batch.py
src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py

index a6ced6a1085047833e418e33577b20f2a085f1ca..37e099fda01e50b42826a4c9ff21a83376b356b3 100644 (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))
index 29d23fd72b64e0dd2a73ea074fde1becb00debf9..4987a85f5eae99009c259f85c740080f2818104f 100644 (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,