74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
/*
|
|
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 (
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
testceph "github.com/rook/rook/pkg/cephmgr/client/test"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetOSDInfo(t *testing.T) {
|
|
// error when no info is found on disk
|
|
config := &osdConfig{rootPath: "/tmp"}
|
|
|
|
err := loadOSDInfo(config)
|
|
assert.NotNil(t, err)
|
|
|
|
// write the info to disk
|
|
whoFile := "/tmp/whoami"
|
|
ioutil.WriteFile(whoFile, []byte("23"), 0644)
|
|
defer os.Remove(whoFile)
|
|
fsidFile := "/tmp/fsid"
|
|
testUUID, _ := uuid.NewUUID()
|
|
ioutil.WriteFile(fsidFile, []byte(testUUID.String()), 0644)
|
|
defer os.Remove(fsidFile)
|
|
|
|
// check the successful osd info
|
|
err = loadOSDInfo(config)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, 23, config.id)
|
|
assert.Equal(t, testUUID, config.uuid)
|
|
}
|
|
|
|
func TestOSDBootstrap(t *testing.T) {
|
|
clusterName := "mycluster"
|
|
targetPath := getBootstrapOSDKeyringPath("/tmp", clusterName)
|
|
defer os.Remove(targetPath)
|
|
|
|
factory := &testceph.MockConnectionFactory{}
|
|
conn, _ := factory.NewConnWithClusterAndUser(clusterName, "user")
|
|
conn.(*testceph.MockConnection).MockMonCommand = func(buf []byte) (buffer []byte, info string, err error) {
|
|
response := "{\"key\":\"mysecurekey\"}"
|
|
logger.Infof("Returning: %s", response)
|
|
return []byte(response), "", nil
|
|
}
|
|
|
|
err := createOSDBootstrapKeyring(conn, "/tmp", clusterName)
|
|
assert.Nil(t, err)
|
|
|
|
contents, err := ioutil.ReadFile(targetPath)
|
|
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\""))
|
|
}
|