From 1024cff51a5148f765c28fee764c61d5d1164082 Mon Sep 17 00:00:00 2001 From: Jared Watts Date: Wed, 14 Feb 2018 09:27:07 -0800 Subject: [PATCH] osd: ensure default dir is always used when no dirs or devices are specified Signed-off-by: Jared Watts --- pkg/daemon/ceph/osd/daemon.go | 16 ++++++++-------- pkg/daemon/ceph/osd/daemon_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/pkg/daemon/ceph/osd/daemon.go b/pkg/daemon/ceph/osd/daemon.go index e5ab86fdd..7363a0d28 100644 --- a/pkg/daemon/ceph/osd/daemon.go +++ b/pkg/daemon/ceph/osd/daemon.go @@ -238,6 +238,11 @@ func getDataDirs(context *clusterd.Context, kv *k8sutil.ConfigMapKVStore, desire dirList = strings.Split(desiredDirs, ",") } + if len(dirList) == 0 && !devicesSpecified { + // user has not specified any dirs or any devices, give them the default dir at least + dirList = append(dirList, context.ConfigDir) + } + removedDirs = make(map[string]int) dirMap, err := config.LoadOSDDirMap(kv, nodeName) @@ -256,15 +261,10 @@ func getDataDirs(context *clusterd.Context, kv *k8sutil.ConfigMapKVStore, desire } // the osd dirs map doesn't exist yet - if len(dirList) == 0 { - // no dirs have been specified - if devicesSpecified { - // user is using devices instead of dirs - return map[string]int{}, removedDirs, nil - } - // no devices or dirs specified, return the default data dir - return map[string]int{context.ConfigDir: unassignedOSDID}, removedDirs, nil + if len(dirList) == 0 { + // no dirs should be used because the user has requested no dirs but they have requested devices + return map[string]int{}, removedDirs, nil } // add the specified dirs to the map and return it diff --git a/pkg/daemon/ceph/osd/daemon_test.go b/pkg/daemon/ceph/osd/daemon_test.go index 462950a7a..deefffae3 100644 --- a/pkg/daemon/ceph/osd/daemon_test.go +++ b/pkg/daemon/ceph/osd/daemon_test.go @@ -76,6 +76,13 @@ func TestGetDataDirs(t *testing.T) { assert.Equal(t, unassignedOSDID, dirMap["/rook/dir1"]) assert.Equal(t, 0, len(removedDirMap)) + // user has devices specified and also specifies dirs, those should be returned + dirMap, removedDirMap, err = getDataDirs(context, kv, "/rook/dir1", true, nodeName) + assert.Nil(t, err) + assert.Equal(t, 1, len(dirMap)) + assert.Equal(t, unassignedOSDID, dirMap["/rook/dir1"]) + assert.Equal(t, 0, len(removedDirMap)) + // simulate an OSD ID being assigned to the dir dirMap["/rook/dir1"] = 1 // save the directory config @@ -111,6 +118,27 @@ func TestGetDataDirs(t *testing.T) { assert.Equal(t, 1, len(removedDirMap)) assert.Equal(t, 23, removedDirMap["/tmp/mydir"]) + // clear the dir map and simulate the scenario where an OSD has been created in the default dir + kv.ClearStore(config.GetConfigStoreName(nodeName)) + osdID := 9802 + dirMap = map[string]int{context.ConfigDir: osdID} + err = config.SaveOSDDirMap(kv, nodeName, dirMap) + assert.Nil(t, err) + + // when an OSD has been created in the default dir, no dirs are specified, and no devices are specified, + // the default dir should still be in use (it should not come back as removed!) + dirMap, removedDirMap, err = getDataDirs(context, kv, "", false, nodeName) + assert.Nil(t, err) + assert.Equal(t, 1, len(dirMap)) + assert.Equal(t, osdID, dirMap[context.ConfigDir]) + assert.Equal(t, 0, len(removedDirMap)) + + // if devices are specified (but no dirs), the existing osd in the default dir will not be preserved + dirMap, removedDirMap, err = getDataDirs(context, kv, "", true, nodeName) + assert.Nil(t, err) + assert.Equal(t, 0, len(dirMap)) + assert.Equal(t, 1, len(removedDirMap)) + assert.Equal(t, osdID, removedDirMap[context.ConfigDir]) } func TestAvailableDevices(t *testing.T) {