Merge pull request #1497 from jbw976/keep-default-osd-dir

osd: ensure default dir is always used when no dirs or devices are sp…
This commit is contained in:
Jared Watts authored and GitHub committed 2018-02-14 12:13:04 -08:00
commit 09dc9b8ce8
2 files changed
+36 -8

No files matched your search

+8 -8
View File
@@ -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
+28
View File
@@ -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) {