Skip to content

Commit

Permalink
rgwadmin: add test for versioning and object lock
Browse files Browse the repository at this point in the history
Signed-off-by: Seena Fallah <[email protected]>
  • Loading branch information
clwluvw committed Feb 3, 2025
1 parent e20ef3b commit 0c4d6cc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 6 deletions.
6 changes: 6 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
CephOctopus
CephPacific
CephQuincy
CephReef
CephSquid
CephUnknown
)

Expand All @@ -31,6 +33,10 @@ func CephVersionOfString(vname string) CephVersion {
return CephPacific
case "quincy":
return CephQuincy
case "reef":
return CephReef
case "squid":
return CephSquid
default:
return CephUnknown
}
Expand Down
6 changes: 3 additions & 3 deletions rgw/admin/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type Bucket struct {
ID string `json:"id"`
Marker string `json:"marker"`
IndexType string `json:"index_type"`
Versioned *bool `json:"versioned"` // pre-squid
VersioningEnabled *bool `json:"versioning_enabled"` // pre-squid
Versioning *string `json:"versioning"` // squid+
Versioned *bool `json:"versioned"` // reef
VersioningEnabled *bool `json:"versioning_enabled"` // reef
Versioning *string `json:"versioning"` // non-reef
ObjectLockEnabled bool `json:"object_lock_enabled"`
Owner string `json:"owner"`
Ver string `json:"ver"`
Expand Down
71 changes: 68 additions & 3 deletions rgw/admin/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/ceph/go-ceph/internal/util"
"github.com/stretchr/testify/assert"
)
Expand All @@ -16,11 +19,11 @@ func (suite *RadosGWTestSuite) TestBucket() {
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, newDebugHTTPClient(http.DefaultClient))
assert.NoError(suite.T(), err)

s3, err := newS3Agent(suite.accessKey, suite.secretKey, suite.endpoint, true)
s3Agent, err := newS3Agent(suite.accessKey, suite.secretKey, suite.endpoint, true)
assert.NoError(suite.T(), err)

beforeCreate := time.Now()
err = s3.createBucket(suite.bucketTestName)
err = s3Agent.createBucket(suite.bucketTestName)
assert.NoError(suite.T(), err)

suite.T().Run("list buckets", func(_ *testing.T) {
Expand All @@ -36,7 +39,69 @@ func (suite *RadosGWTestSuite) TestBucket() {
})

suite.T().Run("info existing bucket", func(_ *testing.T) {
_, err := co.GetBucketInfo(context.Background(), Bucket{Bucket: suite.bucketTestName})
bucketInfo, err := co.GetBucketInfo(context.Background(), Bucket{Bucket: suite.bucketTestName})
assert.NoError(suite.T(), err)

// check if versioning is disabled
switch {
case util.CurrentCephVersion() < util.CephQuincy:
// No action needed for versions below CephQuincy
case util.CurrentCephVersion() == util.CephReef:
assert.False(suite.T(), *bucketInfo.VersioningEnabled)
assert.False(suite.T(), *bucketInfo.Versioned)
default:
assert.Equal(suite.T(), "off", *bucketInfo.Versioning)
}

// check if object lock is
if util.CurrentCephVersion() >= util.CephQuincy {
assert.False(suite.T(), bucketInfo.ObjectLockEnabled)
}
})

suite.T().Run("enable versioning", func(_ *testing.T) {
if util.CurrentCephVersion() < util.CephQuincy {
suite.T().Skip("versioning is not reported in bucket stats")
}

_, err := s3Agent.Client.PutBucketVersioning(context.Background(), &s3.PutBucketVersioningInput{
Bucket: &suite.bucketTestName,
VersioningConfiguration: &types.VersioningConfiguration{Status: types.BucketVersioningStatusEnabled},
})
assert.NoError(suite.T(), err)

// check if versioning is enabled
bucketInfo, err := co.GetBucketInfo(context.Background(), Bucket{Bucket: suite.bucketTestName})
assert.NoError(suite.T(), err)
if util.CurrentCephVersion() == util.CephReef {
assert.True(suite.T(), *bucketInfo.VersioningEnabled)
assert.True(suite.T(), *bucketInfo.Versioned)
} else {
assert.Equal(suite.T(), "enabled", *bucketInfo.Versioning)
}
})

suite.T().Run("enable bucket object lock", func(_ *testing.T) {
if util.CurrentCephVersion() < util.CephQuincy {
suite.T().Skip("bucket object lock is not reported in bucket stats")
}

const bucketName = "bucket-object-lock"

// create bucket with object lock enabled
_, err := s3Agent.Client.CreateBucket(context.Background(), &s3.CreateBucketInput{
Bucket: aws.String(bucketName),
ObjectLockEnabledForBucket: aws.Bool(true),
})
assert.NoError(suite.T(), err)

// check if object lock is enabled
bucketInfo, err := co.GetBucketInfo(context.Background(), Bucket{Bucket: bucketName})
assert.NoError(suite.T(), err)
assert.True(suite.T(), bucketInfo.ObjectLockEnabled)

// remove bucket
err = co.RemoveBucket(context.Background(), Bucket{Bucket: bucketName})
assert.NoError(suite.T(), err)
})

Expand Down

0 comments on commit 0c4d6cc

Please sign in to comment.