diff --git a/pkg/daemon/ceph/osd/volume.go b/pkg/daemon/ceph/osd/volume.go index 0d1b7a320..79bccb4db 100644 --- a/pkg/daemon/ceph/osd/volume.go +++ b/pkg/daemon/ceph/osd/volume.go @@ -558,6 +558,9 @@ func (a *OsdAgent) initializeDevicesRawMode(context *clusterd.Context, devices * deviceArg, }...) + // assign the device class specific to the device + immediateExecuteArgs = a.appendDeviceClassArg(device, immediateExecuteArgs) + // execute ceph-volume with the device op, err := context.Executor.ExecuteCommandWithCombinedOutput(baseCommand, immediateExecuteArgs...) if err != nil { @@ -668,17 +671,7 @@ func (a *OsdAgent) initializeDevicesLVMMode(context *clusterd.Context, devices * }...) // assign the device class specific to the device - deviceClass := device.Config.DeviceClass - if deviceClass == "" { - // fall back to the device class for all devices on the node - deviceClass = a.storeConfig.DeviceClass - } - if deviceClass != "" { - immediateExecuteArgs = append(immediateExecuteArgs, []string{ - crushDeviceClassFlag, - deviceClass, - }...) - } + immediateExecuteArgs = a.appendDeviceClassArg(device, immediateExecuteArgs) // Reporting immediateReportArgs := append(immediateExecuteArgs, []string{ @@ -800,6 +793,21 @@ func (a *OsdAgent) initializeDevicesLVMMode(context *clusterd.Context, devices * return nil } +func (a *OsdAgent) appendDeviceClassArg(device *DeviceOsdIDEntry, args []string) []string { + deviceClass := device.Config.DeviceClass + if deviceClass == "" { + // fall back to the device class for all devices on the node + deviceClass = a.storeConfig.DeviceClass + } + if deviceClass != "" { + args = append(args, []string{ + crushDeviceClassFlag, + deviceClass, + }...) + } + return args +} + func lvmPreReq(context *clusterd.Context, pvcBacked, lvBackedPV bool) error { // Check for the presence of LVM on the host when NOT running on PVC // since this scenario is still using LVM diff --git a/pkg/daemon/ceph/osd/volume_test.go b/pkg/daemon/ceph/osd/volume_test.go index ba963cd05..c544354f5 100644 --- a/pkg/daemon/ceph/osd/volume_test.go +++ b/pkg/daemon/ceph/osd/volume_test.go @@ -373,7 +373,7 @@ func TestConfigureCVDevices(t *testing.T) { CephVersion: cephver.CephVersion{Major: 14, Minor: 2, Extra: 8}, FSID: clusterFSID, } - agent := &OsdAgent{clusterInfo: clusterInfo, nodeName: nodeName, pvcBacked: true} + agent := &OsdAgent{clusterInfo: clusterInfo, nodeName: nodeName, pvcBacked: true, storeConfig: config.StoreConfig{DeviceClass: "myds"}} devices := createPVCAvailableDevices() deviceOSDs, err := agent.configureCVDevices(context, devices) assert.Nil(t, err) @@ -542,6 +542,56 @@ func TestConfigureCVDevices(t *testing.T) { assert.Equal(t, "lvm", deviceOSD.CVMode) assert.Equal(t, "bluestore", deviceOSD.Store) } + + { + // Test case for a raw mode OSD + t.Log("Test case for a raw mode OSD") + executor := &exectest.MockExecutor{} + executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) { + logger.Infof("[MockExecuteCommandWithOutput] %s %v", command, args) + if command == "lsblk" && args[0] == mountedDev { + return fmt.Sprintf(`SIZE="17179869184" ROTA="1" RO="0" TYPE="lvm" PKNAME="" NAME="%s" KNAME="/dev/dm-1"`, mapperDev), nil + } + if args[1] == "ceph-volume" && args[4] == "raw" && args[5] == "list" { + return cephVolumeRAWTestResult, nil + } + if args[1] == "ceph-volume" && args[4] == "lvm" && args[5] == "list" { + return `{}`, nil + } + return "", errors.Errorf("unknown command %s %s", command, args) + } + executor.MockExecuteCommandWithCombinedOutput = func(command string, args ...string) (string, error) { + logger.Infof("[MockExecuteCommandWithCombinedOutput] %s %v", command, args) + if args[1] == "ceph-volume" && args[2] == "raw" && args[3] == "prepare" && args[4] == "--bluestore" && args[7] == "--crush-device-class" { + assert.Equal(t, "myclass", args[8]) + return "", nil + } + return "", errors.Errorf("unknown command %s %s", command, args) + } + + context := &clusterd.Context{Executor: executor, ConfigDir: cephConfigDir} + clusterInfo := &cephclient.ClusterInfo{ + CephVersion: cephver.CephVersion{Major: 16, Minor: 2, Extra: 1}, // It supports raw mode OSD + FSID: clusterFSID, + } + agent := &OsdAgent{clusterInfo: clusterInfo, nodeName: nodeName, storeConfig: config.StoreConfig{DeviceClass: "myclass"}} + devices := &DeviceOsdMapping{ + Entries: map[string]*DeviceOsdIDEntry{ + "vdb": {Data: -1, Metadata: nil, Config: DesiredDevice{Name: "/dev/vdb"}}, + }, + } + deviceOSDs, err := agent.configureCVDevices(context, devices) + + assert.Nil(t, err) + deviceOSD := deviceOSDs[0] + logger.Infof("deviceOSDs: %+v", deviceOSDs) + assert.Equal(t, osdUUID, deviceOSD.UUID) + assert.Equal(t, "/dev/vdb", deviceOSD.BlockPath) + assert.Equal(t, true, deviceOSD.SkipLVRelease) + assert.Equal(t, false, deviceOSD.LVBackedPV) + assert.Equal(t, "raw", deviceOSD.CVMode) + assert.Equal(t, "bluestore", deviceOSD.Store) + } } func testBaseArgs(args []string) error { @@ -906,6 +956,7 @@ func TestInitializeBlockPVC(t *testing.T) { executor.MockExecuteCommandWithCombinedOutput = func(command string, args ...string) (string, error) { logger.Infof("%s %v", command, args) if args[1] == "ceph-volume" && args[2] == "raw" && args[3] == "prepare" && args[4] == "--bluestore" && args[7] == "--crush-device-class" { + assert.Equal(t, "foo", args[8]) return initializeBlockPVCTestResult, nil }