Add GetPoolByID() for calling rados_pool_reverse_lookup()

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2019-10-14 17:38:52 +02:00 committed by John Mulligan
parent bcf44fc782
commit 43a863d1cb
2 changed files with 58 additions and 0 deletions

View File

@ -296,6 +296,22 @@ func (c *Conn) GetPoolByName(name string) (int64, error) {
}
}
// GetPoolByID returns the name of a pool by a given ID.
func (c *Conn) GetPoolByID(id int64) (string, error) {
buf := make([]byte, 4096)
if err := c.ensure_connected(); err != nil {
fmt.Println("NOT CONNECTED WHOOPS")
return "", err
}
c_id := C.int64_t(id)
ret := int(C.rados_pool_reverse_lookup(c.cluster, c_id, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))))
if ret < 0 {
return "", RadosError(ret)
} else {
return C.GoString((*C.char)(unsafe.Pointer(&buf[0]))), 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

@ -351,6 +351,48 @@ func (suite *RadosTestSuite) TestGetPoolByName() {
}
}
func (suite *RadosTestSuite) TestGetPoolByID() {
suite.SetupConnection()
// check that new pool name is unique
new_name := uuid.Must(uuid.NewV4()).String()
pool, err := suite.conn.GetPoolByName(new_name)
if pool != 0 || 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
id, err := suite.conn.GetPoolByName(new_name)
assert.NoError(suite.T(), err)
if id == 0 {
suite.T().Error("Cannot find newly created pool")
}
// get the name of the pool
name, err := suite.conn.GetPoolByID(id)
assert.NoError(suite.T(), err)
if name == "" {
suite.T().Error("Cannot find name of newly created pool")
}
// delete the pool
err = suite.conn.DeletePool(new_name)
assert.NoError(suite.T(), err)
// verify that it is gone
name, err = suite.conn.GetPoolByID(id)
if name != "" || err == nil {
suite.T().Error("Deleted pool still exists")
}
}
func (suite *RadosTestSuite) TestPingMonitor() {
suite.SetupConnection()