rbd admin: use the new admintest module to set up tests

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2022-01-17 16:26:35 -05:00 committed by mergify[bot]
parent d4c23eb19d
commit 69c8750e96
1 changed files with 4 additions and 54 deletions

View File

@ -4,16 +4,11 @@
package admin
import (
"errors"
"os"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/require"
ccom "github.com/ceph/go-ceph/common/commands"
"github.com/ceph/go-ceph/internal/commands"
"github.com/ceph/go-ceph/internal/admintest"
"github.com/ceph/go-ceph/rados"
"github.com/ceph/go-ceph/rbd"
)
@ -24,60 +19,15 @@ var (
testImageOrder = 22
alreadyExists = -0x11
cachedRadosConn *rados.Conn
cachedRBDAdmin *RBDAdmin
debugTrace bool
radosConnector = admintest.NewConnector()
)
func init() {
dt := os.Getenv("GO_CEPH_TEST_DEBUG_TRACE")
if ok, err := strconv.ParseBool(dt); ok && err == nil {
debugTrace = true
}
}
func getConn(t *testing.T) *rados.Conn {
if cachedRadosConn != nil {
return cachedRadosConn
}
conn, err := rados.NewConn()
require.NoError(t, err)
require.NotNil(t, conn)
err = conn.ReadDefaultConfigFile()
require.NoError(t, err)
timeout := time.After(time.Second * 5)
ch := make(chan error)
go func(conn *rados.Conn) {
ch <- conn.Connect()
}(conn)
select {
case err = <-ch:
case <-timeout:
err = errors.New("timed out waiting for connect")
}
require.NoError(t, err)
cachedRadosConn = conn
return cachedRadosConn
return radosConnector.GetConn(t)
}
func getAdmin(t *testing.T) *RBDAdmin {
if cachedRBDAdmin != nil {
return cachedRBDAdmin
}
var c ccom.RadosCommander = getConn(t)
if debugTrace {
c = commands.NewTraceCommander(c)
}
cachedRBDAdmin := NewFromConn(c)
require.NotNil(t, cachedRBDAdmin)
// We sleep briefly before returning in order to ensure we have a mgr map
// before we start executing the tests.
time.Sleep(50 * time.Millisecond)
return cachedRBDAdmin
return NewFromConn(radosConnector.Get(t))
}
func ensureDefaultPool(t *testing.T) {