Skip to content

Commit

Permalink
OCM-5508 | test: automate id:OCP-70859 validation for operator-roles …
Browse files Browse the repository at this point in the history
…and oidc-provider
  • Loading branch information
aaraj7 committed May 3, 2024
1 parent b9094f8 commit 687dba6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
49 changes: 49 additions & 0 deletions tests/e2e/test_rosacli_iam_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,4 +1000,53 @@ var _ = Describe("Edit IAM",
textData = rosaClient.Parser.TextData.Input(output).Parse().Tip()
Expect(textData).To(ContainSubstring("WARN: There are no hosted CP account roles to be deleted"))
})

It("Validation for operator roles and oidc provider will work well - [id:70859]",
labels.Medium,
func() {
By("Check cluster is sts cluster")
isSTS, err := clusterService.IsSTSCluster(clusterID)
Expect(err).ToNot(HaveOccurred())

if isSTS {
By("Create operator roles to the cluster again")
output, err := ocmResourceService.CreateOperatorRoles("-c", clusterID, "-y", "--mode", "auto")
Expect(err).ToNot(HaveOccurred())
Expect(rosaClient.Parser.TextData.Input(output).Parse().Tip()).To(ContainSubstring("Operator Roles already exists"))

By("Create oidc config to the cluster again")
output, err = ocmResourceService.CreateOIDCProvider("-c", clusterID, "-y", "--mode", "auto")
Expect(err).ToNot(HaveOccurred())
Expect(rosaClient.Parser.TextData.Input(output).Parse().Tip()).To(ContainSubstring("OIDC provider already exists"))

By("Delete the oidc-provider to the cluster")
output, err = ocmResourceService.DeleteOIDCProvider("-c", clusterID, "-y", "--mode", "auto")
Expect(err).To(HaveOccurred())
Expect(rosaClient.Parser.TextData.Input(output).Parse().Tip()).To(ContainSubstring("ERR: Cluster '%s' is in 'ready' state. OIDC provider can be deleted only for the uninstalled clusters", clusterID))

By("Delete the operator-roles to the cluster")
output, err = ocmResourceService.DeleteOperatorRoles("-c", clusterID, "-y", "--mode", "auto")
Expect(err).To(HaveOccurred())
Expect(rosaClient.Parser.TextData.Input(output).Parse().Tip()).To(ContainSubstring("ERR: Cluster '%s' is in 'ready' state. Operator roles can be deleted only for the uninstalled clusters", clusterID))

By("Get the --oidc-config-id from the cluster and it's issuer url")
rosaClient.Runner.JsonFormat()
jsonOutput, err := clusterService.DescribeCluster(clusterID)
Expect(err).To(BeNil())
rosaClient.Runner.UnsetFormat()
jsonData := rosaClient.Parser.JsonData.Input(jsonOutput).Parse()
oidcConfigID := jsonData.DigString("aws", "sts", "oidc_config", "id")
issuerURL := jsonData.DigString("aws", "sts", "oidc_config", "issuer_url")

By("Try to delete oidc provider with --oidc-config-id")
output, err = ocmResourceService.DeleteOIDCProvider("--oidc-config-id", oidcConfigID, "-y", "--mode", "auto")
Expect(err).To(HaveOccurred())
Expect(rosaClient.Parser.TextData.Input(output).Parse().Tip()).To(ContainSubstring("ERR: There are clusters using OIDC config '%s', can't delete the provider", issuerURL))

By("Try to create oidc provider with --oidc-config-id")
output, err = ocmResourceService.CreateOIDCProvider("--oidc-config-id", oidcConfigID, "-y", "--mode", "auto")
Expect(err).ToNot(HaveOccurred())
Expect(rosaClient.Parser.TextData.Input(output).Parse().Tip()).To(ContainSubstring("OIDC provider already exists"))
}
})
})
14 changes: 11 additions & 3 deletions tests/utils/exec/rosacli/ocm_resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type OCMResourceService interface {
ReflectOperatorRoleList(result bytes.Buffer) (opl OperatorRoleList, err error)

CreateOIDCProvider(flags ...string) (bytes.Buffer, error)
DeleteOIDCProvider(flags ...string) (bytes.Buffer, error)
}

type ocmResourceService struct {
Expand Down Expand Up @@ -581,9 +582,16 @@ func (ors *ocmResourceService) ReflectOperatorRoleList(result bytes.Buffer) (opl

// run `rosa create oidc-provider` command
func (ors *ocmResourceService) CreateOIDCProvider(flags ...string) (bytes.Buffer, error) {
createODICProvider := ors.client.Runner
createODICProvider = createODICProvider.Cmd("create", "oidc-provider").CmdFlags(flags...)
return createODICProvider.Run()
createOIDCProvider := ors.client.Runner
createOIDCProvider = createOIDCProvider.Cmd("create", "oidc-provider").CmdFlags(flags...)
return createOIDCProvider.Run()
}

// run `rosa delete oidc-provider` command
func (ors *ocmResourceService) DeleteOIDCProvider(flags ...string) (bytes.Buffer, error) {
deleteOIDCProvider := ors.client.Runner
deleteOIDCProvider = deleteOIDCProvider.Cmd("delete", "oidc-provider").CmdFlags(flags...)
return deleteOIDCProvider.Run()
}

func (ors *ocmResourceService) CleanResources(clusterID string) (errors []error) {
Expand Down

0 comments on commit 687dba6

Please sign in to comment.