From fae473416b9600c7d4f93f356e7ef70b703678f7 Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Sat, 30 Aug 2014 10:28:24 -0700 Subject: [PATCH] lib: add make/delete pool interfaces Signed-off-by: Noah Watkins --- conn.go | 24 +++++++++++++++++++ rados_test.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/conn.go b/conn.go index c3f2e81..5b07b2f 100644 --- a/conn.go +++ b/conn.go @@ -220,3 +220,27 @@ func (c *Conn) GetInstanceID() uint64 { // FIXME: are there any error cases for this? return uint64(C.rados_get_instance_id(c.cluster)) } + +// MakePool creates a new pool with default settings. +func (c *Conn) MakePool(name string) error { + c_name :=C.CString(name) + defer C.free(unsafe.Pointer(c_name)) + ret := int(C.rados_pool_create(c.cluster, c_name)) + if ret == 0 { + return nil + } else { + return RadosError(ret) + } +} + +// DeletePool deletes a pool and all the data inside the pool. +func (c *Conn) DeletePool(name string) error { + c_name :=C.CString(name) + defer C.free(unsafe.Pointer(c_name)) + ret := int(C.rados_pool_delete(c.cluster, c_name)) + if ret == 0 { + return nil + } else { + return RadosError(ret) + } +} diff --git a/rados_test.go b/rados_test.go index 6fbd104..dafcc53 100644 --- a/rados_test.go +++ b/rados_test.go @@ -6,6 +6,12 @@ import "github.com/noahdesu/rados" import "github.com/stretchr/testify/assert" import "fmt" import "os" +import "os/exec" + +func GetUUID() string { + out, _ := exec.Command("uuidgen").Output() + return string(out[:36]) +} func TestVersion(t *testing.T) { var major, minor, patch = rados.Version() @@ -94,7 +100,66 @@ func TestGetInstanceID(t *testing.T) { assert.NotEqual(t, id, 0) } +func TestMakeDeletePool(t *testing.T) { + conn, _ := rados.NewConn() + conn.ReadDefaultConfigFile() + conn.Connect() + // get current list of pool + pools, err := conn.ListPools() + assert.NoError(t, err) + + // check that new pool name is unique + new_name := GetUUID() + for _, poolname := range pools { + if new_name == poolname { + t.Error("Random pool name exists!") + return + } + } + + // create pool + err = conn.MakePool(new_name) + assert.NoError(t, err) + + // get updated list of pools + pools, err = conn.ListPools() + assert.NoError(t, err) + + // verify that the new pool name exists + found := false + for _, poolname := range pools { + if new_name == poolname { + found = true + } + } + + if !found { + t.Error("Cannot find newly created pool") + } + + // delete the pool + err = conn.DeletePool(new_name) + assert.NoError(t, err) + + // verify that it is gone + + // get updated list of pools + pools, err = conn.ListPools() + assert.NoError(t, err) + + // verify that the new pool name exists + found = false + for _, poolname := range pools { + if new_name == poolname { + found = true + } + } + + if found { + t.Error("Deleted pool still exists") + } +} //func TestOpen(t *testing.T) {