From de9505f862edb09f4e8e64d6b8dfe187e749868c Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 6 Apr 2021 13:41:05 -0400 Subject: [PATCH] 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 --- rbd/rbd_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rbd/rbd_test.go b/rbd/rbd_test.go index 781bb99..80fa6c0 100644 --- a/rbd/rbd_test.go +++ b/rbd/rbd_test.go @@ -37,8 +37,22 @@ func radosConnect(t *testing.T) *rados.Conn { require.NoError(t, err) err = conn.ReadDefaultConfigFile() 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) go func(conn *rados.Conn) { ch <- conn.Connect() @@ -49,7 +63,6 @@ func radosConnect(t *testing.T) *rados.Conn { err = fmt.Errorf("timed out waiting for connect") } require.NoError(t, err) - return conn } func TestImageCreate(t *testing.T) {