Add GetPoolByName() for calling rados_pool_lookup()

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2019-10-14 14:09:30 +02:00 committed by John Mulligan
parent ef655aa904
commit bcf44fc782
2 changed files with 69 additions and 0 deletions

View File

@ -280,6 +280,22 @@ func (c *Conn) DeletePool(name string) error {
}
}
// GetPoolByName returns the ID of the pool with a given name.
func (c *Conn) GetPoolByName(name string) (int64, error) {
if err := c.ensure_connected(); err != nil {
fmt.Println("NOT CONNECTED WHOOPS")
return 0, err
}
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
ret := int64(C.rados_pool_lookup(c.cluster, c_name))
if ret < 0 {
return 0, RadosError(ret)
} else {
return ret, nil
}
}
// MonCommand sends a command to one of the monitors
func (c *Conn) MonCommand(args []byte) (buffer []byte, info string, err error) {
return c.monCommand(args, nil)

View File

@ -246,6 +246,40 @@ func (suite *RadosTestSuite) TestGetInstanceID() {
func (suite *RadosTestSuite) TestMakeDeletePool() {
suite.SetupConnection()
// check that new pool name is unique
new_name := uuid.Must(uuid.NewV4()).String()
_, err := suite.conn.GetPoolByName(new_name)
if err == nil {
suite.T().Error("Random pool name exists!")
return
}
// create pool
err = suite.conn.MakePool(new_name)
assert.NoError(suite.T(), err)
// verify that the new pool name exists
pool, err := suite.conn.GetPoolByName(new_name)
assert.NoError(suite.T(), err)
if pool == 0 {
suite.T().Error("Cannot find newly created pool")
}
// delete the pool
err = suite.conn.DeletePool(new_name)
assert.NoError(suite.T(), err)
// verify that it is gone
pool, _ = suite.conn.GetPoolByName(new_name)
if pool != 0 {
suite.T().Error("Deleted pool still exists")
}
}
func (suite *RadosTestSuite) TestGetPoolByName() {
suite.SetupConnection()
// get current list of pool
pools, err := suite.conn.ListPools()
assert.NoError(suite.T(), err)
@ -259,6 +293,12 @@ func (suite *RadosTestSuite) TestMakeDeletePool() {
}
}
pool, _ := suite.conn.GetPoolByName(new_name)
if pool != 0 {
suite.T().Error("Pool does not exist, but was found!")
return
}
// create pool
err = suite.conn.MakePool(new_name)
assert.NoError(suite.T(), err)
@ -278,6 +318,13 @@ func (suite *RadosTestSuite) TestMakeDeletePool() {
suite.T().Error("Cannot find newly created pool")
}
pool, err = suite.conn.GetPoolByName(new_name)
assert.NoError(suite.T(), err)
if pool == 0 {
suite.T().Error("Pool not found!")
return
}
// delete the pool
err = suite.conn.DeletePool(new_name)
assert.NoError(suite.T(), err)
@ -296,6 +343,12 @@ func (suite *RadosTestSuite) TestMakeDeletePool() {
if found {
suite.T().Error("Deleted pool still exists")
}
pool, err = suite.conn.GetPoolByName(new_name)
if pool != 0 || err == nil {
suite.T().Error("Pool should have been deleted, but was found!")
return
}
}
func (suite *RadosTestSuite) TestPingMonitor() {