From f3594ffc5d347ba0741c3b80b592c644c557d673 Mon Sep 17 00:00:00 2001 From: Adam King Date: Wed, 31 May 2023 13:08:35 -0400 Subject: [PATCH] python-common/drive_group: handle fields outside of 'spec' even when 'spec' is provided Otherwise certain specs such as service_type: osd service_id: xxx service_name: osd.xxx placement: hosts: - vm-00 spec: osds_per_device: 2 data_devices: paths: - /dev/vde fail to apply with Error EINVAL: ServiceSpec: 'dict' object has no attribute 'validate' which is not a useful error message. This is caused by the spec assuming all osd specific fields are either defined in the 'spec' section or outside of it, but not mixed in. We could also just consider these specs to be invalid and just raise a better error message, but it seems easier to make the minor adjustment for it to work, given there doesn't seem to be an issue with mixing the styles for specs for other service types. Fixes: https://tracker.ceph.com/issues/61533 Signed-off-by: Adam King (cherry picked from commit 12901f617d9f21dcc4de9b039b7ab6484fbc99ca) --- src/python-common/ceph/deployment/drive_group.py | 4 ++-- src/python-common/ceph/tests/test_drive_group.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/python-common/ceph/deployment/drive_group.py b/src/python-common/ceph/deployment/drive_group.py index 5d77ee685e79..5363066344d9 100644 --- a/src/python-common/ceph/deployment/drive_group.py +++ b/src/python-common/ceph/deployment/drive_group.py @@ -284,8 +284,8 @@ class DriveGroupSpec(ServiceSpec): # spec: was not mandatory in octopus if 'spec' in args: args['spec'].update(cls._drive_group_spec_from_json(s_id, args['spec'])) - else: - args.update(cls._drive_group_spec_from_json(s_id, args)) + args.update(cls._drive_group_spec_from_json( + s_id, {k: v for k, v in args.items() if k != 'spec'})) return super(DriveGroupSpec, cls)._from_json_impl(args) diff --git a/src/python-common/ceph/tests/test_drive_group.py b/src/python-common/ceph/tests/test_drive_group.py index faa001a0233a..77e9b4083d49 100644 --- a/src/python-common/ceph/tests/test_drive_group.py +++ b/src/python-common/ceph/tests/test_drive_group.py @@ -35,6 +35,18 @@ data_devices: - path: /dev/sda crush_device_class: ssd""" ), + ( + """service_type: osd +service_id: testing_drivegroup +placement: + host_pattern: hostname +spec: + osds_per_device: 2 +data_devices: + paths: + - path: /dev/sda + crush_device_class: hdd""" + ), ]) def test_DriveGroup(test_input): -- 2.47.3