rados: standardize error naming

RadosError-prefixes are not recommended, instead just Err as prefix is
used.

Also, errors are constants, not variables.

For existing users, backwards compatible constants are available. These
will need to be removed in a future go-ceph release.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-01-28 16:00:52 +01:00
parent c6b65af9ec
commit 5adb04909d
3 changed files with 34 additions and 17 deletions

View File

@ -686,7 +686,7 @@ func (iter *Iter) Namespace() string {
// Err checks whether the iterator has encountered an error. // Err checks whether the iterator has encountered an error.
func (iter *Iter) Err() error { func (iter *Iter) Err() error {
if iter.err == RadosErrorNotFound { if iter.err == ErrNotFound {
return nil return nil
} }
return iter.err return iter.err

View File

@ -26,16 +26,33 @@ func (e RadosError) Error() string {
return fmt.Sprintf("rados: ret=%d, %s", errno, s) return fmt.Sprintf("rados: ret=%d, %s", errno, s)
} }
var ( const (
// RadosAllNamespaces is used to reset a selected namespace to all namespaces. See the IOContext SetNamespace function. // AllNamespaces is used to reset a selected namespace to all
RadosAllNamespaces = C.LIBRADOS_ALL_NSPACES // namespaces. See the IOContext SetNamespace function.
AllNamespaces = C.LIBRADOS_ALL_NSPACES
// RadosErrorNotFound indicates a missing resource. // ErrNotFound indicates a missing resource.
RadosErrorNotFound = RadosError(-C.ENOENT) ErrNotFound = RadosError(-C.ENOENT)
// RadosErrorPermissionDenied indicates a permissions issue. // ErrPermissionDenied indicates a permissions issue.
RadosErrorPermissionDenied = RadosError(-C.EPERM) ErrPermissionDenied = RadosError(-C.EPERM)
// ErrObjectExists indicates that an exclusive object creation failed. // ErrObjectExists indicates that an exclusive object creation failed.
ErrObjectExists = RadosError(-C.EEXIST) ErrObjectExists = RadosError(-C.EEXIST)
// FIXME: for backwards compatibility
// RadosAllNamespaces is used to reset a selected namespace to all
// namespaces. See the IOContext SetNamespace function.
//
// Deprecated: use AllNamespaces instead
RadosAllNamespaces = AllNamespaces
// RadosErrorNotFound indicates a missing resource.
//
// Deprecated: use ErrNotFound instead
RadosErrorNotFound = ErrNotFound
// RadosErrorPermissionDenied indicates a permissions issue.
//
// Deprecated: use ErrPermissionDenied instead
RadosErrorPermissionDenied = ErrPermissionDenied
) )
func getRadosError(err int) error { func getRadosError(err int) error {

View File

@ -514,7 +514,7 @@ func (suite *RadosTestSuite) TestReadNotFound() {
var bytes []byte var bytes []byte
oid := suite.GenObjectName() oid := suite.GenObjectName()
_, err := suite.ioctx.Read(oid, bytes, 0) _, err := suite.ioctx.Read(oid, bytes, 0)
assert.Equal(suite.T(), err, RadosErrorNotFound) assert.Equal(suite.T(), err, ErrNotFound)
} }
func (suite *RadosTestSuite) TestDeleteNotFound() { func (suite *RadosTestSuite) TestDeleteNotFound() {
@ -522,7 +522,7 @@ func (suite *RadosTestSuite) TestDeleteNotFound() {
oid := suite.GenObjectName() oid := suite.GenObjectName()
err := suite.ioctx.Delete(oid) err := suite.ioctx.Delete(oid)
assert.Equal(suite.T(), err, RadosErrorNotFound) assert.Equal(suite.T(), err, ErrNotFound)
} }
func (suite *RadosTestSuite) TestStatNotFound() { func (suite *RadosTestSuite) TestStatNotFound() {
@ -530,7 +530,7 @@ func (suite *RadosTestSuite) TestStatNotFound() {
oid := suite.GenObjectName() oid := suite.GenObjectName()
_, err := suite.ioctx.Stat(oid) _, err := suite.ioctx.Stat(oid)
assert.Equal(suite.T(), err, RadosErrorNotFound) assert.Equal(suite.T(), err, ErrNotFound)
} }
func (suite *RadosTestSuite) TestObjectStat() { func (suite *RadosTestSuite) TestObjectStat() {
@ -763,7 +763,7 @@ func (suite *RadosTestSuite) TestObjectIteratorAcrossNamespaces() {
objectListNS2 := []string{} objectListNS2 := []string{}
// populate list of current objects // populate list of current objects
suite.ioctx.SetNamespace(RadosAllNamespaces) suite.ioctx.SetNamespace(AllNamespaces)
existingList := []string{} existingList := []string{}
iter, err := suite.ioctx.Iter() iter, err := suite.ioctx.Iter()
assert.NoError(suite.T(), err) assert.NoError(suite.T(), err)
@ -796,7 +796,7 @@ func (suite *RadosTestSuite) TestObjectIteratorAcrossNamespaces() {
} }
assert.True(suite.T(), len(createdList) == 20) assert.True(suite.T(), len(createdList) == 20)
suite.ioctx.SetNamespace(RadosAllNamespaces) suite.ioctx.SetNamespace(AllNamespaces)
iter, err = suite.ioctx.Iter() iter, err = suite.ioctx.Iter()
assert.NoError(suite.T(), err) assert.NoError(suite.T(), err)
rogueList := []string{} rogueList := []string{}
@ -1033,7 +1033,7 @@ func (suite *RadosTestSuite) TestSetNamespace() {
// oid isn't seen in space1 ns // oid isn't seen in space1 ns
suite.ioctx.SetNamespace("space1") suite.ioctx.SetNamespace("space1")
stat, err = suite.ioctx.Stat(oid) stat, err = suite.ioctx.Stat(oid)
assert.Equal(suite.T(), err, RadosErrorNotFound) assert.Equal(suite.T(), err, ErrNotFound)
// create oid2 in space1 ns // create oid2 in space1 ns
oid2 := suite.GenObjectName() oid2 := suite.GenObjectName()
@ -1043,7 +1043,7 @@ func (suite *RadosTestSuite) TestSetNamespace() {
suite.ioctx.SetNamespace("") suite.ioctx.SetNamespace("")
stat, err = suite.ioctx.Stat(oid2) stat, err = suite.ioctx.Stat(oid2)
assert.Equal(suite.T(), err, RadosErrorNotFound) assert.Equal(suite.T(), err, ErrNotFound)
stat, err = suite.ioctx.Stat(oid) stat, err = suite.ioctx.Stat(oid)
assert.Equal(suite.T(), uint64(len(bytes_in)), stat.Size) assert.Equal(suite.T(), uint64(len(bytes_in)), stat.Size)
@ -1081,7 +1081,7 @@ func (suite *RadosTestSuite) TestListAcrossNamespaces() {
assert.EqualValues(suite.T(), 1, nsFoundObjects) assert.EqualValues(suite.T(), 1, nsFoundObjects)
// count objects in pool // count objects in pool
suite.ioctx.SetNamespace(RadosAllNamespaces) suite.ioctx.SetNamespace(AllNamespaces)
allFoundObjects := 0 allFoundObjects := 0
err = suite.ioctx.ListObjects(func(oid string) { err = suite.ioctx.ListObjects(func(oid string) {
allFoundObjects++ allFoundObjects++
@ -1184,7 +1184,7 @@ func (suite *RadosTestSuite) TestOmapOnNonexistentObjectError() {
suite.SetupConnection() suite.SetupConnection()
oid := suite.GenObjectName() oid := suite.GenObjectName()
_, err := suite.ioctx.GetAllOmapValues(oid, "", "", 100) _, err := suite.ioctx.GetAllOmapValues(oid, "", "", 100)
assert.Equal(suite.T(), err, RadosErrorNotFound) assert.Equal(suite.T(), err, ErrNotFound)
} }
func (suite *RadosTestSuite) TestOpenIOContextInvalidPool() { func (suite *RadosTestSuite) TestOpenIOContextInvalidPool() {