From: Sebastian Wagner Date: Thu, 11 Feb 2021 10:05:12 +0000 (+0100) Subject: python-common: Verify data_devices is not None X-Git-Tag: v17.1.0~2645^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=55e9ecbc88bf6a33fe185e8b54491b9048d66adb;p=ceph.git python-common: Verify data_devices is not None Add validation to verify that `data_devices` is not None Fixes: https://tracker.ceph.com/issues/49191 Signed-off-by: Sebastian Wagner --- diff --git a/src/python-common/ceph/deployment/drive_group.py b/src/python-common/ceph/deployment/drive_group.py index da59cbd353ee..92a89435fa29 100644 --- a/src/python-common/ceph/deployment/drive_group.py +++ b/src/python-common/ceph/deployment/drive_group.py @@ -284,6 +284,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() diff --git a/src/python-common/ceph/tests/test_drive_group.py b/src/python-common/ceph/tests/test_drive_group.py index a98c178e7d37..579b18975ce4 100644 --- a/src/python-common/ceph/tests/test_drive_group.py +++ b/src/python-common/ceph/tests/test_drive_group.py @@ -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 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():