Skip to content

Commit

Permalink
Merge pull request #9371 from rook/mergify/bp/release-1.8/pr-9169
Browse files Browse the repository at this point in the history
test: add more test cases for bucket notfication (backport #9169)
  • Loading branch information
mergify[bot] committed Dec 9, 2021
2 parents 1469c3c + 971f9b6 commit 934a575
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 58 deletions.
32 changes: 32 additions & 0 deletions tests/framework/clients/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
b64 "encoding/base64"
"fmt"

"github.com/aws/aws-sdk-go/service/s3"
bktv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1"
rgw "github.com/rook/rook/pkg/operator/ceph/object"
"github.com/rook/rook/tests/framework/installer"
"github.com/rook/rook/tests/framework/utils"
)
Expand Down Expand Up @@ -146,3 +148,33 @@ func (b *BucketOperation) CheckOBMaxObject(obcName, maxobject string) bool {
fetchMaxObject, _ := b.k8sh.GetResource("ob", obName, "--output", "jsonpath={.spec.endpoint.additionalConfig.maxObjects}")
return maxobject == fetchMaxObject
}

// Checks the bucket notifications set on RGW backend bucket
func (b *BucketOperation) CheckBucketNotificationSetonRGW(namespace, storeName, obcName, bucketname, notificationName, s3endpoint string) bool {
var s3client *rgw.S3Agent
s3AccessKey, _ := b.GetAccessKey(obcName)
s3SecretKey, _ := b.GetSecretKey(obcName)

//TODO : add TLS check
s3client, err := rgw.NewS3Agent(s3AccessKey, s3SecretKey, s3endpoint, "", true, nil)
if err != nil {
logger.Errorf("S3 client creation failed with error %v", err)
return false
}

notifications, err := s3client.Client.GetBucketNotificationConfiguration(&s3.GetBucketNotificationConfigurationRequest{
Bucket: &bucketname,
})
if err != nil {
logger.Infof("failed to fetch bucket notifications configuration due to %v", err)
return false
}
logger.Infof("%d bucket notifications found in: %+v", len(notifications.TopicConfigurations), notifications)
for _, notification := range notifications.TopicConfigurations {
if *notification.Id == notificationName {
return true
}
logger.Infof("bucket notifications name mismatch %q != %q", *notification.Id, notificationName)
}
return false
}
4 changes: 2 additions & 2 deletions tests/framework/clients/notification.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
Copyright 2021 The Rook Authors. All rights reserved.
Expand Down Expand Up @@ -46,7 +45,8 @@ func (n *NotificationOperation) UpdateNotification(notificationName string, topi
}

// CheckNotification if notification was set
func (t *NotificationOperation) CheckNotification(notificationName string) bool {
func (t *NotificationOperation) CheckNotificationCR(notificationName string) bool {
// TODO: return result based on reconcile status of the CR
const resourceName = "cephbucketnotification"
_, err := t.k8sh.GetResource(resourceName, notificationName)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion tests/framework/utils/k8s_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"time"

"github.com/coreos/pkg/capnslog"
bktclient "github.com/kube-object-storage/lib-bucket-provisioner/pkg/client/clientset/versioned"
"github.com/pkg/errors"
rookclient "github.com/rook/rook/pkg/client/clientset/versioned"
"github.com/rook/rook/pkg/clusterd"
Expand All @@ -56,6 +57,7 @@ type K8sHelper struct {
remoteExecutor *exec.RemotePodCommandExecutor
Clientset *kubernetes.Clientset
RookClientset *rookclient.Clientset
BucketClientset *bktclient.Clientset
RunningInCluster bool
T func() *testing.T
}
Expand Down Expand Up @@ -94,13 +96,17 @@ func CreateK8sHelper(t func() *testing.T) (*K8sHelper, error) {
if err != nil {
return nil, fmt.Errorf("failed to get rook clientset. %+v", err)
}
bucketClientset, err := bktclient.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("failed to get lib-bucket-provisioner clientset. %+v", err)
}

remoteExecutor := &exec.RemotePodCommandExecutor{
ClientSet: clientset,
RestClient: config,
}

h := &K8sHelper{executor: executor, Clientset: clientset, RookClientset: rookClientset, T: t, remoteExecutor: remoteExecutor}
h := &K8sHelper{executor: executor, Clientset: clientset, RookClientset: rookClientset, BucketClientset: bucketClientset, T: t, remoteExecutor: remoteExecutor}
if strings.Contains(config.Host, "//10.") {
h.RunningInCluster = true
}
Expand Down

0 comments on commit 934a575

Please sign in to comment.