2016-11-10 10:59:26 -08:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package osd
|
|
|
|
|
|
|
|
|
|
import (
|
2023-02-17 19:10:55 +05:30
|
|
|
"os"
|
2017-06-06 12:58:09 -07:00
|
|
|
"path"
|
2016-11-10 10:59:26 -08:00
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2017-01-11 20:19:47 -08:00
|
|
|
"github.com/rook/rook/pkg/clusterd"
|
2020-07-10 16:40:16 -06:00
|
|
|
"github.com/rook/rook/pkg/daemon/ceph/client"
|
2023-03-23 07:04:03 +00:00
|
|
|
"github.com/rook/rook/pkg/operator/ceph/cluster/osd"
|
2017-01-11 20:19:47 -08:00
|
|
|
exectest "github.com/rook/rook/pkg/util/exec/test"
|
2023-03-23 07:04:03 +00:00
|
|
|
"github.com/rook/rook/pkg/util/sys"
|
2016-11-10 10:59:26 -08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestOSDBootstrap(t *testing.T) {
|
2022-01-24 23:31:04 +08:00
|
|
|
configDir := t.TempDir()
|
2017-06-06 12:58:09 -07:00
|
|
|
|
2017-06-02 13:44:54 -07:00
|
|
|
executor := &exectest.MockExecutor{
|
2021-07-21 11:25:52 +02:00
|
|
|
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
|
2017-06-02 13:44:54 -07:00
|
|
|
return "{\"key\":\"mysecurekey\"}", nil
|
|
|
|
|
},
|
2016-11-10 10:59:26 -08:00
|
|
|
}
|
|
|
|
|
|
2017-06-06 12:58:09 -07:00
|
|
|
context := &clusterd.Context{Executor: executor, ConfigDir: configDir}
|
2021-11-18 15:22:56 -07:00
|
|
|
err := createOSDBootstrapKeyring(context, client.AdminTestClusterInfo("mycluster"), configDir)
|
2016-11-10 10:59:26 -08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
2018-12-07 08:28:47 -07:00
|
|
|
targetPath := path.Join(configDir, bootstrapOsdKeyring)
|
2023-02-17 19:10:55 +05:30
|
|
|
contents, err := os.ReadFile(targetPath)
|
2016-11-10 10:59:26 -08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.NotEqual(t, -1, strings.Index(string(contents), "[client.bootstrap-osd]"))
|
|
|
|
|
assert.NotEqual(t, -1, strings.Index(string(contents), "key = mysecurekey"))
|
|
|
|
|
assert.NotEqual(t, -1, strings.Index(string(contents), "caps mon = \"allow profile bootstrap-osd\""))
|
|
|
|
|
}
|
2023-03-23 07:04:03 +00:00
|
|
|
|
|
|
|
|
func TestUpdateDeviceClass(t *testing.T) {
|
|
|
|
|
d := &DesiredDevice{}
|
|
|
|
|
agent := &OsdAgent{}
|
|
|
|
|
disk := &sys.LocalDisk{}
|
|
|
|
|
|
|
|
|
|
d.DeviceClass = "test"
|
|
|
|
|
d.UpdateDeviceClass(agent, disk)
|
|
|
|
|
assert.Equal(t, "test", d.DeviceClass)
|
|
|
|
|
|
|
|
|
|
d.DeviceClass = ""
|
|
|
|
|
agent.pvcBacked = true
|
|
|
|
|
t.Setenv(osd.CrushDeviceClassVarName, "test")
|
|
|
|
|
d.UpdateDeviceClass(agent, disk)
|
|
|
|
|
assert.Equal(t, "test", d.DeviceClass)
|
|
|
|
|
|
|
|
|
|
d.DeviceClass = ""
|
|
|
|
|
t.Setenv(osd.CrushDeviceClassVarName, "")
|
|
|
|
|
d.UpdateDeviceClass(agent, disk)
|
|
|
|
|
t.Log(d)
|
|
|
|
|
t.Log(disk)
|
|
|
|
|
assert.Equal(t, "ssd", d.DeviceClass)
|
|
|
|
|
|
|
|
|
|
d.DeviceClass = ""
|
|
|
|
|
agent.pvcBacked = false
|
|
|
|
|
d.UpdateDeviceClass(agent, disk)
|
|
|
|
|
assert.Equal(t, "ssd", d.DeviceClass)
|
|
|
|
|
|
|
|
|
|
d.DeviceClass = ""
|
|
|
|
|
agent.storeConfig.DeviceClass = "test"
|
|
|
|
|
d.UpdateDeviceClass(agent, disk)
|
|
|
|
|
assert.Equal(t, "test", d.DeviceClass)
|
|
|
|
|
}
|