2021-10-01 15:39:45 +00:00
|
|
|
//go:build !nautilus
|
2021-03-03 19:44:17 +00:00
|
|
|
// +build !nautilus
|
|
|
|
|
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2022-01-17 21:26:35 +00:00
|
|
|
"github.com/ceph/go-ceph/internal/admintest"
|
2021-03-03 19:44:17 +00:00
|
|
|
"github.com/ceph/go-ceph/rados"
|
|
|
|
"github.com/ceph/go-ceph/rbd"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
defaultPoolName = "rbd"
|
|
|
|
testImageSize = uint64(1 << 22)
|
|
|
|
testImageOrder = 22
|
|
|
|
alreadyExists = -0x11
|
|
|
|
|
2022-01-17 21:26:35 +00:00
|
|
|
radosConnector = admintest.NewConnector()
|
2021-03-03 19:44:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getConn(t *testing.T) *rados.Conn {
|
2022-01-17 21:26:35 +00:00
|
|
|
return radosConnector.GetConn(t)
|
2021-03-03 19:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getAdmin(t *testing.T) *RBDAdmin {
|
2022-01-17 21:26:35 +00:00
|
|
|
return NewFromConn(radosConnector.Get(t))
|
2021-03-03 19:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ensureDefaultPool(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
conn := getConn(t)
|
|
|
|
err := conn.MakePool(defaultPoolName)
|
|
|
|
if err == nil {
|
|
|
|
t.Logf("created pool: %s", defaultPoolName)
|
|
|
|
ioctx, err := conn.OpenIOContext(defaultPoolName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ioctx.Destroy()
|
|
|
|
// initialize rbd for the pool. if this is not done all mirror
|
|
|
|
// schedules can not be used on the pool or images in the pool
|
|
|
|
err = rbd.PoolInit(ioctx, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
// enable per image mirroring for the new pool
|
|
|
|
err = rbd.SetMirrorMode(ioctx, rbd.MirrorModeImage)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ec, ok := err.(interface{ ErrorCode() int })
|
|
|
|
if ok && ec.ErrorCode() == alreadyExists {
|
|
|
|
t.Logf("pool already exists: %s", defaultPoolName)
|
|
|
|
} else {
|
|
|
|
t.Logf("failed to create pool: %s", defaultPoolName)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|