Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rgw/admin: parse more fields by bucket struct #1068

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 14 additions & 10 deletions rgw/admin/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ type Bucket struct {
DataExtraPool string `json:"data_extra_pool"`
IndexPool string `json:"index_pool"`
} `json:"explicit_placement"`
ID string `json:"id"`
Marker string `json:"marker"`
IndexType string `json:"index_type"`
Owner string `json:"owner"`
Ver string `json:"ver"`
MasterVer string `json:"master_ver"`
Mtime string `json:"mtime"`
CreationTime *time.Time `json:"creation_time"`
MaxMarker string `json:"max_marker"`
Usage struct {
ID string `json:"id"`
Marker string `json:"marker"`
IndexType string `json:"index_type"`
Versioned *bool `json:"versioned"` // reef
VersioningEnabled *bool `json:"versioning_enabled"` // reef
Versioning *string `json:"versioning"` // quincy, squid+
ObjectLockEnabled bool `json:"object_lock_enabled"` // quincy+
Owner string `json:"owner"`
Ver string `json:"ver"`
MasterVer string `json:"master_ver"`
Mtime string `json:"mtime"`
CreationTime *time.Time `json:"creation_time"`
MaxMarker string `json:"max_marker"`
Usage struct {
RgwMain struct {
Size *uint64 `json:"size"`
SizeActual *uint64 `json:"size_actual"`
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 disabled
if util.CurrentCephVersion() >= util.CephQuincy {
assert.False(suite.T(), bucketInfo.ObjectLockEnabled)
}
})

suite.T().Run("enable versioning", func(t *testing.T) {
if util.CurrentCephVersion() < util.CephQuincy {
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(t *testing.T) {
if util.CurrentCephVersion() < util.CephQuincy {
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