rbd: add a test helper to get a conn for a given cluster by config

This function can be used to connect to a non-default ceph cluster,
in a simple, convenient way similar to the function we have for
connecting to the default cluster.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2021-04-06 13:41:05 -04:00 committed by mergify[bot]
parent f84140356a
commit de9505f862
1 changed files with 15 additions and 2 deletions

View File

@ -37,8 +37,22 @@ func radosConnect(t *testing.T) *rados.Conn {
require.NoError(t, err) require.NoError(t, err)
err = conn.ReadDefaultConfigFile() err = conn.ReadDefaultConfigFile()
require.NoError(t, err) require.NoError(t, err)
waitForRadosConn(t, conn)
return conn
}
timeout := time.After(time.Second * 5) func radosConnectConfig(t *testing.T, p string) *rados.Conn {
conn, err := rados.NewConn()
require.NoError(t, err)
err = conn.ReadConfigFile(p)
require.NoError(t, err)
waitForRadosConn(t, conn)
return conn
}
func waitForRadosConn(t *testing.T, conn *rados.Conn) {
var err error
timeout := time.After(time.Second * 15)
ch := make(chan error) ch := make(chan error)
go func(conn *rados.Conn) { go func(conn *rados.Conn) {
ch <- conn.Connect() ch <- conn.Connect()
@ -49,7 +63,6 @@ func radosConnect(t *testing.T) *rados.Conn {
err = fmt.Errorf("timed out waiting for connect") err = fmt.Errorf("timed out waiting for connect")
} }
require.NoError(t, err) require.NoError(t, err)
return conn
} }
func TestImageCreate(t *testing.T) { func TestImageCreate(t *testing.T) {