]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: Verify data_devices is not None
authorSebastian Wagner <sebastian.wagner@suse.com>
Thu, 11 Feb 2021 10:05:12 +0000 (11:05 +0100)
committerSage Weil <sage@newdream.net>
Fri, 23 Apr 2021 12:24:14 +0000 (07:24 -0500)
Add validation to verify that `data_devices` is not None

Fixes: https://tracker.ceph.com/issues/49191
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
(cherry picked from commit 55e9ecbc88bf6a33fe185e8b54491b9048d66adb)

src/python-common/ceph/deployment/drive_group.py
src/python-common/ceph/tests/test_drive_group.py

index 48be66aa0e2878b8c23c892483b66bc500c70bf5..58123ea0538387ee25fc2f42c1dbf166ec6e8054 100644 (file)
@@ -286,6 +286,9 @@ class DriveGroupSpec(ServiceSpec):
                 self.placement.host_pattern is not None:
             raise DriveGroupValidationError('host_pattern must be of type string')
 
+        if self.data_devices is None:
+            raise DriveGroupValidationError("`data_devices` element is required.")
+
         specs = [self.data_devices, self.db_devices, self.wal_devices, self.journal_devices]
         for s in filter(None, specs):
             s.validate()
index a98c178e7d37335ec5e1d517c41df2ad86201286..579b18975ce4d9c6d04d5b0ba763faebb7a25399 100644 (file)
@@ -30,22 +30,24 @@ def test_DriveGroup(test_input):
     assert all([isinstance(x, Device) for x in dg.data_devices.paths])
     assert dg.data_devices.paths[0].path == '/dev/sda'
 
-@pytest.mark.parametrize("test_input",
+@pytest.mark.parametrize("match,test_input",
 [
     (
-        {}
+        "Failed to validate Drive Group: OSD spec needs a `placement` key.",
+        '{}'
     ),
     (
-        yaml.safe_load("""
+        'Failed to validate Drive Group: DeviceSelection cannot be empty', """
 service_type: osd
 service_id: mydg
 placement:
   host_pattern: '*'
 data_devices:
   limit: 1
-"""),
-
-        yaml.safe_load("""
+"""
+    ),
+    (
+        'Failed to validate Drive Group: filter_logic must be either <AND> or <OR>', """
 service_type: osd
 service_id: mydg
 placement:
@@ -53,13 +55,24 @@ placement:
 data_devices:
   all: True
 filter_logic: XOR
-""")
-    )
+"""
+    ),
+    (
+        'Failed to validate Drive Group: `data_devices` element is required.', """
+service_type: osd
+service_id: mydg
+placement:
+  host_pattern: '*'
+spec:
+  db_devices:
+    model: model
+"""
+    ),
 ])
-def test_DriveGroup_fail(test_input):
-    with pytest.raises(ServiceSpecValidationError):
-        DriveGroupSpec.from_json(test_input)
-
+def test_DriveGroup_fail(match, test_input):
+    with pytest.raises(ServiceSpecValidationError, match=match):
+        osd_spec = DriveGroupSpec.from_json(yaml.safe_load(test_input))
+        osd_spec.validate()
 
 
 def test_drivegroup_pattern():