diff --git a/tests/framework/clients/client.go b/tests/framework/clients/client.go index 67b20276a..ed1eb4304 100644 --- a/tests/framework/clients/client.go +++ b/tests/framework/clients/client.go @@ -18,6 +18,7 @@ package clients import ( "fmt" + "time" "github.com/rook/rook/pkg/daemon/ceph/client" "github.com/rook/rook/tests/framework/installer" @@ -38,9 +39,9 @@ func CreateClientOperation(k8sh *utils.K8sHelper, manifests installer.CephManife } // Create creates a client in Rook -func (c *ClientOperation) Create(name, namespace string) error { +func (c *ClientOperation) Create(name, namespace string, caps map[string]string) error { logger.Infof("creating the client via CRD") - if err := c.k8sh.ResourceOperation("apply", c.manifests.GetClient(namespace, name)); err != nil { + if err := c.k8sh.ResourceOperation("apply", c.manifests.GetClient(namespace, name, caps)); err != nil { return err } return nil @@ -70,13 +71,22 @@ func (c *ClientOperation) Get(namespace string, clientName string) (key string, } // Update updates provided user capabilities -func (c *ClientOperation) Update(namespace string, clientName string) (caps map[string]string, error error) { +func (c *ClientOperation) Update(namespace string, clientName string, caps map[string]string) (updatedcaps map[string]string, error error) { context := c.k8sh.MakeContext() logger.Infof("updating the client via CRD") - if err := c.k8sh.ResourceOperation("apply", c.manifests.UpdateClient(namespace, clientName)); err != nil { + if err := c.k8sh.ResourceOperation("apply", c.manifests.GetClient(namespace, clientName, caps)); err != nil { return nil, err } - caps, _ = client.AuthGetCaps(context, namespace, "client."+clientName) - return caps, nil + for i := 0; i < 30; i++ { + updatedcaps, _ = client.AuthGetCaps(context, namespace, "client."+clientName) + if caps["mon"] == updatedcaps["mon"] { + logger.Infof("Finished updating the client via CRD") + return updatedcaps, nil + } + logger.Info("Waiting for client CRD to finish updating caps") + time.Sleep(2 * time.Second) + } + + return nil, fmt.Errorf("Unable to update client") } diff --git a/tests/framework/installer/ceph_manifests.go b/tests/framework/installer/ceph_manifests.go index 1444f305f..6e4106c11 100644 --- a/tests/framework/installer/ceph_manifests.go +++ b/tests/framework/installer/ceph_manifests.go @@ -19,6 +19,7 @@ package installer import ( "fmt" "strconv" + "strings" "github.com/google/uuid" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" @@ -42,8 +43,7 @@ type CephManifests interface { GetObjectStoreUser(namespace, name string, displayName string, store string) string GetBucketStorageClass(namespace string, storeName string, storageClassName string, reclaimPolicy string, region string) string GetObc(obcName string, storageClassName string, bucketName string, createBucket bool) string - GetClient(namespace string, name string) string - UpdateClient(namespace string, name string) string + GetClient(namespace string, name string, caps map[string]string) string } type ClusterSettings struct { @@ -1971,7 +1971,12 @@ spec: } //GetClient returns the manifest to create client CRD -func (m *CephManifestsMaster) GetClient(namespace string, claimName string) string { +func (m *CephManifestsMaster) GetClient(namespace string, claimName string, caps map[string]string) string { + clientCaps := []string{} + for name, cap := range caps { + str := name + ": " + cap + clientCaps = append(clientCaps, str) + } return `apiVersion: ceph.rook.io/v1 kind: CephClient metadata: @@ -1979,21 +1984,5 @@ metadata: namespace: ` + namespace + ` spec: caps: - mon: allow rwx - mgr: allow rwx - osd: allow rwx` -} - -//UpdateClient returns the manifest to create client CRD -func (m *CephManifestsMaster) UpdateClient(namespace string, claimName string) string { - return `apiVersion: ceph.rook.io/v1 -kind: CephClient -metadata: - name: ` + claimName + ` - namespace: ` + namespace + ` -spec: - caps: - mon: allow r - mgr: allow rw - osd: allow *` + ` + strings.Join(clientCaps, "\n ") } diff --git a/tests/framework/installer/ceph_manifests_v1.0.go b/tests/framework/installer/ceph_manifests_v1.0.go index d2ad18fc7..d38605cf9 100644 --- a/tests/framework/installer/ceph_manifests_v1.0.go +++ b/tests/framework/installer/ceph_manifests_v1.0.go @@ -1416,10 +1416,6 @@ func (m *CephManifestsV1_0) GetObc(claimName string, storageClassName string, ob panic("upgrade test not supported for object bucket claim") } -func (m *CephManifestsV1_0) GetClient(claimName string, namespace string) string { - panic("upgrade test not supported for client") -} - -func (m *CephManifestsV1_0) UpdateClient(claimName string, namespace string) string { +func (m *CephManifestsV1_0) GetClient(claimName string, namespace string, caps map[string]string) string { panic("upgrade test not supported for client") } diff --git a/tests/integration/ceph_client_test.go b/tests/integration/ceph_client_test.go index c3cb15f0b..d86f65e42 100644 --- a/tests/integration/ceph_client_test.go +++ b/tests/integration/ceph_client_test.go @@ -27,7 +27,12 @@ func (suite *SmokeSuite) TestCreateClient() { logger.Infof("Create Client Smoke Test") clientName := "client1" - err := suite.helper.UserClient.Create(clientName, suite.namespace) + caps := map[string]string{ + "mon": "allow rwx", + "mgr": "allow rwx", + "osd": "allow rwx", + } + err := suite.helper.UserClient.Create(clientName, suite.namespace, caps) require.Nil(suite.T(), err) clientFound := false @@ -49,8 +54,12 @@ func (suite *SmokeSuite) TestCreateClient() { require.Equal(suite.T(), true, clientFound, "client not found") logger.Infof("Update Client Smoke Test") - - caps, _ := suite.helper.UserClient.Update(suite.namespace, clientName) + newcaps := map[string]string{ + "mon": "allow r", + "mgr": "allow rw", + "osd": "allow *", + } + caps, _ = suite.helper.UserClient.Update(suite.namespace, clientName, newcaps) require.Equal(suite.T(), "allow r", caps["mon"], "wrong caps") require.Equal(suite.T(), "allow rw", caps["mgr"], "wrong caps")