diff --git a/tests/e2e/account_roles_test.go b/tests/e2e/account_roles_test.go index ca08ce00..25d3ba67 100644 --- a/tests/e2e/account_roles_test.go +++ b/tests/e2e/account_roles_test.go @@ -7,11 +7,11 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" - "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" @@ -164,15 +164,15 @@ var _ = Describe("Create Account roles with shared vpc role", ci.Exclude, func() vpcArgs := &exec.VPCArgs{ NamePrefix: helper.StringPointer(clusterName), AWSRegion: helper.StringPointer(profileHandler.Profile().GetRegion()), - VPCCIDR: helper.StringPointer(constants.DefaultVPCCIDR), - AWSSharedCredentialsFiles: helper.StringSlicePointer([]string{constants.SharedVpcAWSSharedCredentialsFileENV}), + VPCCIDR: helper.StringPointer(profilehandler.DefaultVPCCIDR), + AWSSharedCredentialsFiles: helper.StringSlicePointer([]string{config.GetSharedVpcAWSSharedCredentialsFile()}), } _, err = vpcService.Apply(vpcArgs) Expect(err).ToNot(HaveOccurred()) vpcOutput, err := vpcService.Output() Expect(err).ToNot(HaveOccurred()) sharedVPCArgs := &exec.SharedVpcPolicyAndHostedZoneArgs{ - SharedVpcAWSSharedCredentialsFiles: helper.StringSlicePointer([]string{constants.SharedVpcAWSSharedCredentialsFileENV}), + SharedVpcAWSSharedCredentialsFiles: helper.StringSlicePointer([]string{config.GetSharedVpcAWSSharedCredentialsFile()}), Region: helper.StringPointer(profileHandler.Profile().GetRegion()), ClusterName: helper.StringPointer(clusterName), DnsDomainId: helper.StringPointer(dnsDomainOutput.DnsDomainId), diff --git a/tests/e2e/cluster_creation_test.go b/tests/e2e/cluster_creation_test.go index 0613c103..3dbfbb9b 100644 --- a/tests/e2e/cluster_creation_test.go +++ b/tests/e2e/cluster_creation_test.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" @@ -27,7 +28,7 @@ var _ = Describe("Create cluster", func() { Expect(err).ToNot(HaveOccurred()) Expect(clusterID).ToNot(BeEmpty()) //TODO: implement waiter for the private cluster once bastion is implemented - if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profileHandler.Profile().IsPrivate() { + if config.IsWaitForOperators() && !profileHandler.Profile().IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) diff --git a/tests/e2e/cluster_destroy_test.go b/tests/e2e/cluster_destroy_test.go index bfef2efc..cfbca9f3 100644 --- a/tests/e2e/cluster_destroy_test.go +++ b/tests/e2e/cluster_destroy_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" - "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) @@ -14,8 +14,8 @@ var _ = Describe("Delete cluster", func() { It("DestroyClusterByProfile", ci.Destroy, func() { // Destroy kubeconfig folder - if _, err := os.Stat(constants.RHCS.KubeConfigDir); err == nil { - os.RemoveAll(constants.RHCS.KubeConfigDir) + if _, err := os.Stat(config.GetKubeConfigDir()); err == nil { + os.RemoveAll(config.GetKubeConfigDir()) } // Generate/build cluster by profile selected diff --git a/tests/e2e/cluster_misc_day2_test.go b/tests/e2e/cluster_misc_day2_test.go index 1cdae1c0..98c29182 100644 --- a/tests/e2e/cluster_misc_day2_test.go +++ b/tests/e2e/cluster_misc_day2_test.go @@ -8,7 +8,6 @@ import ( . "github.com/onsi/gomega" "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" - "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" @@ -59,7 +58,7 @@ var _ = Describe("Cluster miscellaneous", func() { } By("Adding additional custom property to the existing cluster") - updatedCustomProperties := constants.CustomProperties + updatedCustomProperties := profilehandler.CustomProperties updatedCustomProperties["second_custom_property"] = "test2" // Apply updated custom properties to the cluster diff --git a/tests/e2e/cluster_upgrade_test.go b/tests/e2e/cluster_upgrade_test.go index f7911a96..411910b0 100644 --- a/tests/e2e/cluster_upgrade_test.go +++ b/tests/e2e/cluster_upgrade_test.go @@ -11,6 +11,7 @@ import ( . "github.com/onsi/gomega" "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" @@ -102,7 +103,7 @@ var _ = Describe("Upgrade", func() { Expect(string(clusterResp.Body().State())).To(Equal(constants.Ready)) Expect(string(clusterResp.Body().Version().RawID())).To(Equal(targetV)) - if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() { + if config.IsWaitForOperators() && !profile.IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) @@ -171,7 +172,7 @@ var _ = Describe("Upgrade", func() { Expect(string(clusterResp.Body().State())).To(Equal(constants.Ready)) Expect(string(clusterResp.Body().Version().RawID())).To(Equal(targetV)) - if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() { + if config.IsWaitForOperators() && !profile.IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) @@ -218,7 +219,7 @@ var _ = Describe("Upgrade", func() { Expect(string(clusterResp.Body().State())).To(Equal(constants.Ready)) Expect(string(clusterResp.Body().Version().RawID())).To(Equal(targetV)) - if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() { + if config.IsWaitForOperators() && !profile.IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) @@ -266,7 +267,7 @@ var _ = Describe("Upgrade", func() { Expect(string(clusterResp.Body().State())).To(Equal(constants.Ready)) Expect(string(clusterResp.Body().Version().RawID())).To(Equal(targetV)) - if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() { + if config.IsWaitForOperators() && !profile.IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 72ec980f..b179c72e 100644 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -2,13 +2,11 @@ package e2e import ( "context" - "os" "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" - "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) @@ -23,10 +21,10 @@ func TestRHCSProvider(t *testing.T) { } var _ = BeforeSuite(func() { - token = os.Getenv(constants.TokenENVName) + token = config.GetRHCSOCMToken() var err error - err = helper.AlignRHCSSourceVersion(manifests.ManifestsConfigurationDir) + err = helper.AlignRHCSSourceVersion(config.GetManifestsDir()) Expect(err).ToNot(HaveOccurred()) profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() diff --git a/tests/e2e/hcp_machine_pool_test.go b/tests/e2e/hcp_machine_pool_test.go index 9a9a4ca5..4e919ed2 100644 --- a/tests/e2e/hcp_machine_pool_test.go +++ b/tests/e2e/hcp_machine_pool_test.go @@ -594,7 +594,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { MachineType: helper.StringPointer(machineType), AutoRepair: helper.BoolPointer(true), TuningConfigs: helper.StringSlicePointer(tuningconfigs), - Tags: helper.StringMapPointer(constants.Tags), + Tags: helper.StringMapPointer(profilehandler.Tags), } _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) diff --git a/tests/e2e/idps_test.go b/tests/e2e/idps_test.go index d719466a..434b0060 100644 --- a/tests/e2e/idps_test.go +++ b/tests/e2e/idps_test.go @@ -12,6 +12,7 @@ import ( . "github.com/openshift-online/ocm-sdk-go/testing" "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" @@ -65,7 +66,7 @@ func getDefaultLDAPArgs(idpName string) *exec.IDPArgs { ClusterID: helper.StringPointer(clusterID), Name: helper.StringPointer(idpName), CA: helper.EmptyStringPointer, - URL: helper.StringPointer(constants.LdapURL), + URL: helper.StringPointer(profilehandler.LdapURL), LDAPAttributes: &exec.LDAPAttributes{}, Insecure: helper.BoolPointer(true), } @@ -76,7 +77,7 @@ func getDefaultGitHubArgs(idpName string) *exec.IDPArgs { Name: helper.StringPointer(idpName), ClientID: helper.StringPointer(defaultGithubIDPClientId), ClientSecret: helper.StringPointer(defaultGithubIDPClientSecret), - Organizations: helper.StringSlicePointer(constants.Organizations), + Organizations: helper.StringSlicePointer(profilehandler.Organizations), } } func getDefaultGitlabArgs(idpName string) *exec.IDPArgs { @@ -85,7 +86,7 @@ func getDefaultGitlabArgs(idpName string) *exec.IDPArgs { Name: helper.StringPointer(idpName), ClientID: helper.StringPointer(defaultGitlabIDPClientId), ClientSecret: helper.StringPointer(defaultGitlabIDPClientSecret), - URL: helper.StringPointer(constants.GitLabURL), + URL: helper.StringPointer(profilehandler.GitLabURL), } } func getDefaultGoogleArgs(idpName string) *exec.IDPArgs { @@ -94,7 +95,7 @@ func getDefaultGoogleArgs(idpName string) *exec.IDPArgs { Name: helper.StringPointer(idpName), ClientID: helper.StringPointer(defaultGoogleIDPClientId), ClientSecret: helper.StringPointer(defaultGoogleIDPClientSecret), - HostedDomain: helper.StringPointer(constants.HostedDomain), + HostedDomain: helper.StringPointer(profilehandler.HostedDomain), } } @@ -179,9 +180,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Username: defaultHTPUsername, Password: defaultHTPPassword, ClusterID: clusterID, - AdditioanlFlags: []string{ + AdditionalFlags: []string{ "--insecure-skip-tls-verify", - fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))), + fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))), }, Timeout: 7, } @@ -286,7 +287,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { ClusterID: helper.StringPointer(clusterID), Name: helper.StringPointer("OCP-63332-ldap-idp-test"), CA: helper.EmptyStringPointer, - URL: helper.StringPointer(constants.LdapURL), + URL: helper.StringPointer(profilehandler.LdapURL), LDAPAttributes: &exec.LDAPAttributes{}, Insecure: helper.BoolPointer(true), } @@ -306,9 +307,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Username: defaultLDAPUsername, Password: defaultLDAPPassword, ClusterID: clusterID, - AdditioanlFlags: []string{ + AdditionalFlags: []string{ "--insecure-skip-tls-verify", - fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))), + fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))), }, Timeout: 7, } @@ -334,7 +335,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Name: helper.StringPointer("OCP-64028-gitlab-idp-test"), ClientID: helper.StringPointer(defaultGitlabIDPClientId), ClientSecret: helper.StringPointer(defaultGitlabIDPClientSecret), - URL: helper.StringPointer(constants.GitLabURL), + URL: helper.StringPointer(profilehandler.GitLabURL), } _, err := idpServices.gitlab.Apply(idpParam) Expect(err).ToNot(HaveOccurred()) @@ -363,7 +364,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Name: helper.StringPointer("OCP-64027-github-idp-test"), ClientID: helper.StringPointer(defaultGithubIDPClientId), ClientSecret: helper.StringPointer(defaultGithubIDPClientSecret), - Organizations: helper.StringSlicePointer(constants.Organizations), + Organizations: helper.StringSlicePointer(profilehandler.Organizations), } _, err := idpServices.github.Apply(idpParam) Expect(err).ToNot(HaveOccurred()) @@ -392,7 +393,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Name: helper.StringPointer("OCP-64029-google-idp-test"), ClientID: helper.StringPointer(defaultGoogleIDPClientId), ClientSecret: helper.StringPointer(defaultGoogleIDPClientSecret), - HostedDomain: helper.StringPointer(constants.HostedDomain), + HostedDomain: helper.StringPointer(profilehandler.HostedDomain), } _, err := idpServices.google.Apply(idpParam) Expect(err).ToNot(HaveOccurred()) @@ -427,9 +428,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Name: helper.StringPointer("OCP-64030"), ClientID: helper.StringPointer(defaultGoogleIDPClientId), ClientSecret: helper.StringPointer(defaultGoogleIDPClientSecret), - HostedDomain: helper.StringPointer(constants.HostedDomain), + HostedDomain: helper.StringPointer(profilehandler.HostedDomain), CA: helper.EmptyStringPointer, - URL: helper.StringPointer(constants.LdapURL), + URL: helper.StringPointer(profilehandler.LdapURL), LDAPAttributes: &exec.LDAPAttributes{}, Insecure: helper.BoolPointer(true), } @@ -449,9 +450,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Username: defaultLDAPUsername, Password: defaultLDAPPassword, ClusterID: clusterID, - AdditioanlFlags: []string{ + AdditionalFlags: []string{ "--insecure-skip-tls-verify", - fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))), + fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))), }, Timeout: 7, } @@ -463,7 +464,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { } // login to the cluster using cluster-admin creds - username := constants.ClusterAdminUser + username := profilehandler.ClusterAdminUser password, _ := helper.GetClusterAdminPassword() Expect(password).ToNot(BeEmpty()) @@ -472,9 +473,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Username: username, Password: password, ClusterID: clusterID, - AdditioanlFlags: []string{ + AdditionalFlags: []string{ "--insecure-skip-tls-verify", - fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, username))), + fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, username))), }, Timeout: 10, } @@ -513,9 +514,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Username: defaultHTPUsername, Password: defaultHTPPassword, ClusterID: clusterID, - AdditioanlFlags: []string{ + AdditionalFlags: []string{ "--insecure-skip-tls-verify", - fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))), + fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))), }, Timeout: 10, } @@ -544,9 +545,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Username: defaultHTPUsername, Password: defaultHTPPassword, ClusterID: clusterID, - AdditioanlFlags: []string{ + AdditionalFlags: []string{ "--insecure-skip-tls-verify", - fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))), + fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultHTPUsername))), }, Timeout: 10, } @@ -774,7 +775,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { output, err := importService.ShowState(importParam.Resource) Expect(err).ToNot(HaveOccurred()) Expect(output).To(ContainSubstring(defaultGoogleIDPClientId)) - Expect(output).To(ContainSubstring(constants.HostedDomain)) + Expect(output).To(ContainSubstring(profilehandler.HostedDomain)) By("Validate terraform import with no idp object name returns error") var unknownIdpName = "unknown_idp_name" @@ -833,9 +834,9 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Username: defaultLDAPUsername, Password: defaultLDAPPassword, ClusterID: clusterID, - AdditioanlFlags: []string{ + AdditionalFlags: []string{ "--insecure-skip-tls-verify", - fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))), + fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, defaultLDAPUsername))), }, Timeout: 7, } @@ -888,7 +889,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Gitlab(cmsv1.NewGitlabIdentityProvider(). ClientID(defaultGitlabIDPClientId). ClientSecret(defaultGitlabIDPClientSecret). - URL(constants.GitLabURL)). + URL(profilehandler.GitLabURL)). MappingMethod("claim"). Build() res, err := cms.CreateClusterIDP(cms.RHCSConnection, clusterID, requestBody) @@ -936,7 +937,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Gitlab(cmsv1.NewGitlabIdentityProvider(). ClientID(defaultGitlabIDPClientSecret). ClientSecret(newClientSecret). - URL(constants.GitLabURL)). + URL(profilehandler.GitLabURL)). MappingMethod("claim"). Build() diff --git a/tests/e2e/verification_post_day1_test.go b/tests/e2e/verification_post_day1_test.go index adc83bb4..7eb73732 100644 --- a/tests/e2e/verification_post_day1_test.go +++ b/tests/e2e/verification_post_day1_test.go @@ -16,6 +16,7 @@ import ( cmsv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" @@ -125,9 +126,6 @@ var _ = Describe("Verify cluster", func() { It("compute_machine_type is correctly set - [id:64023]", ci.Day1Post, ci.Medium, func() { computeMachineType := profile.GetComputeMachineType() - if constants.RHCS.ComputeMachineType != "" { - computeMachineType = constants.RHCS.ComputeMachineType - } if computeMachineType == "" { Skip("No compute_machine_type is configured for the cluster. skipping the test.") } @@ -158,9 +156,9 @@ var _ = Describe("Verify cluster", func() { It("compute_labels are correctly set - [id:68423]", ci.Day1Post, ci.High, func() { if profile.IsLabeling() { - Expect(cluster.Nodes().ComputeLabels()).To(Equal(constants.DefaultMPLabels)) + Expect(cluster.Nodes().ComputeLabels()).To(Equal(profilehandler.DefaultMPLabels)) } else { - Expect(cluster.Nodes().ComputeLabels()).To(Equal(constants.NilMap)) + Expect(cluster.Nodes().ComputeLabels()).To(Equal(helper.NilMap)) } }) @@ -174,7 +172,7 @@ var _ = Describe("Verify cluster", func() { Expect(err).ToNot(HaveOccurred()) if profile.IsTagging() { - allClusterTags := helper.MergeMaps(buildInTags, constants.Tags) + allClusterTags := helper.MergeMaps(buildInTags, profilehandler.Tags) Expect(len(getResp.Body().AWS().Tags())).To(Equal(len(allClusterTags))) // compare cluster tags to the expected tags to appear @@ -267,7 +265,7 @@ var _ = Describe("Verify cluster", func() { Expect(err).ToNot(HaveOccurred()) server := getResp.Body().API().URL() - username := constants.ClusterAdminUser + username := profilehandler.ClusterAdminUser password, _ := helper.GetClusterAdminPassword() Expect(password).ToNot(BeEmpty()) @@ -276,9 +274,9 @@ var _ = Describe("Verify cluster", func() { Username: username, Password: password, ClusterID: clusterID, - AdditioanlFlags: []string{ + AdditionalFlags: []string{ "--insecure-skip-tls-verify", - fmt.Sprintf("--kubeconfig %s", path.Join(constants.RHCS.KubeConfigDir, fmt.Sprintf("%s.%s", clusterID, username))), + fmt.Sprintf("--kubeconfig %s", path.Join(config.GetKubeConfigDir(), fmt.Sprintf("%s.%s", clusterID, username))), }, Timeout: 10, } diff --git a/tests/utils/cms/connection.go b/tests/utils/cms/connection.go index 40da7996..0f296501 100644 --- a/tests/utils/cms/connection.go +++ b/tests/utils/cms/connection.go @@ -18,21 +18,17 @@ limitations under the License. import ( "fmt" - "os" . "github.com/onsi/ginkgo/v2" - CON "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" client "github.com/openshift-online/ocm-sdk-go" ) -var ( - RHCSOCMToken = os.Getenv(CON.TokenENVName) -) - // Regular users in the organization 'Red Hat-Service Delivery-tester' var ( - RHCSConnection = createConnectionWithToken(RHCSOCMToken) + RHCSConnection = createConnectionWithToken(config.GetRHCSOCMToken()) ) var ( @@ -45,9 +41,9 @@ func createConnectionWithToken(token string) *client.Connection { connection, err := client.NewConnectionBuilder(). Logger(logger). Insecure(true). - TokenURL(CON.TokenURL). - URL(CON.RHCS.RHCSURL). - Client(CON.ClientID, CON.ClientSecret). + TokenURL(constants.TokenURL). + URL(config.GetRHCSURL()). + Client(constants.ClientID, constants.ClientSecret). Tokens(token). Build() if err != nil { diff --git a/tests/utils/config/config.go b/tests/utils/config/config.go new file mode 100644 index 00000000..e3f2df08 --- /dev/null +++ b/tests/utils/config/config.go @@ -0,0 +1,205 @@ +package config + +import ( + "fmt" + "os" + "path" + "strings" + + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" +) + +const ( + EnvWorkspace = "WORKSPACE" + EnvQEUsage = "QE_USAGE" + EnvTestOutput = "TEST_OUTPUT" + + EnvRHCSToken = "RHCS_TOKEN" + EnvRHCSURL = "RHCS_URL" + + EnvClusterID = "CLUSTER_ID" + + EnvClusterProfile = "CLUSTER_PROFILE" + EnvClusterProfileDir = "CLUSTER_PROFILE_DIR" + + EnvRegion = "REGION" + EnvMajorVersion = "MAJOR_VERSION" + EnvVersion = "VERSION" + EnvChannelGroup = "CHANNEL_GROUP" + EnvRHCSVersion = "RHCS_VERSION" + EnvRHCSSource = "RHCS_SOURCE" + EnvRHCSModuleVersion = "RHCS_MODULE_VERSION" // Set this to update the version for the terraform-redhat/rosa-classic/rhcs module + EnvRHCSModuleSource = "RHCS_MODULE_SOURCE" // Set this to update the source for the terraform-redhat/rosa-classic/rhcs module + EnvRHCSModuleSourceLocal = "RHCS_MODULE_SOURCE_LOCAL" // Set this to any value if `RHCS_MODULE_SOURCE` refers to a local path, in which case `RHCS_MODULE_VERSION` will be ignored + EnvWaitOperators = "WAIT_OPERATORS" + EnvRHCSClusterName = "RHCS_CLUSTER_NAME" + EnvRHCSClusterNamePrefix = "RHCS_CLUSTER_NAME_PREFIX" + EnvRHCSClusterNameSuffix = "RHCS_CLUSTER_NAME_SUFFIX" + EnvComputeMachineType = "COMPUTE_MACHINE_TYPE" + + EnvManifestsFolder = "MANIFESTS_FOLDER" + EnvSharedVpcAWSSharedCredentialsFile = "SHARED_VPC_AWS_SHARED_CREDENTIALS_FILE" + + EnvNoClusterDestroy = "NO_CLUSTER_DESTROY" + + EnvSubnetIDs = "SUBNET_IDS" + EnvAvailabilityZones = "AVAILABILITY_ZONES" +) + +func GetRootDir() string { + currentDir, _ := os.Getwd() + project := "terraform-provider-rhcs" + return GetEnvWithDefault(EnvWorkspace, strings.SplitAfter(currentDir, project)[0]) +} + +func GetClusterProfilesDir() string { + return GetEnvWithDefault(EnvClusterProfileDir, path.Join(GetRootDir(), "tests", "ci", "profiles")) +} + +func GetRHCSOutputDir() string { + var rhcsNewOutPath string + + if rhcsNewOutPath := GetEnvWithDefault(EnvTestOutput, ""); rhcsNewOutPath != "" { + return rhcsNewOutPath + } + rhcsNewOutPath = path.Join(GetRootDir(), "tests", "rhcs_output") + os.MkdirAll(rhcsNewOutPath, 0777) + return rhcsNewOutPath +} + +func GetKubeConfigDir() string { + outputDIR := GetRHCSOutputDir() + configDir := path.Join(outputDIR, "kubeconfig") + if _, err := os.Stat(configDir); err != nil { + os.MkdirAll(configDir, 0777) + } + return configDir +} + +func GetQEUsage() string { + return GetEnvWithDefault(EnvQEUsage, "") +} + +func GetClusterProfile() string { + return GetEnvWithDefault(EnvClusterProfile, "") +} + +func GetRHCSURL() string { + return GetEnvWithDefault(EnvRHCSURL, constants.DefaultRHCSURL) +} + +func GetRHCSOCMToken() string { + return GetEnvWithDefault(EnvRHCSToken, "") +} + +func GetRHCSClusterName() string { + return GetEnvWithDefault(EnvRHCSClusterName, "") +} + +func GetRHCSClusterNamePrefix() string { + return GetEnvWithDefault(EnvRHCSClusterNamePrefix, "") +} + +func GetRHCSClusterNameSuffix() string { + return GetEnvWithDefault(EnvRHCSClusterNameSuffix, "") +} + +func GetRegion() string { + return GetEnvWithDefault(EnvRegion, "") +} + +func GetChannelGroup() string { + return GetEnvWithDefault(EnvChannelGroup, "") +} + +func GetVersion() string { + return GetEnvWithDefault(EnvVersion, "") +} + +func GetMajorVersion() string { + return GetEnvWithDefault(EnvMajorVersion, "") +} + +func GetComputeMachineType() string { + return GetEnvWithDefault(EnvComputeMachineType, "") +} + +func GetSubnetIDs() string { + return GetEnvWithDefault(EnvSubnetIDs, "") +} + +func GetAvailabilityZones() string { + return GetEnvWithDefault(EnvAvailabilityZones, "") +} + +func GetRHCSSource() string { + return GetEnvWithDefault(EnvRHCSSource, "") +} + +func GetRHCSVersion() string { + return GetEnvWithDefault(EnvRHCSVersion, "") +} + +func GetRHCSModuleVersion() string { + return GetEnvWithDefault(EnvRHCSModuleVersion, "") +} + +func GetRHCSModuleSource() string { + return GetEnvWithDefault(EnvRHCSModuleSource, "") +} + +func GetRHCSModuleSourceLocal() string { + return GetEnvWithDefault(EnvRHCSModuleSourceLocal, "") +} + +func IsWaitForOperators() bool { + return GetEnvWithDefault(EnvWaitOperators, "false") == "true" +} + +func IsNoClusterDestroy() bool { + return GetEnvWithDefault(EnvNoClusterDestroy, "false") == "true" +} + +func GetManifestsDir() string { + manifestsDir := GetEnvWithDefault(EnvManifestsFolder, "") + if manifestsDir != "" { + return manifestsDir + } + currentDir, _ := os.Getwd() + manifestsDir = path.Join(strings.SplitAfter(currentDir, "tests")[0], "tf-manifests") + if _, err := os.Stat(manifestsDir); err != nil { + panic(fmt.Sprintf("Manifests dir %s doesn't exist. Make sure you have the manifests dir in testing repo or set the correct env MANIFESTS_DIR value", manifestsDir)) + } + return manifestsDir +} + +func GetSharedVpcAWSSharedCredentialsFile() string { + return GetEnvWithDefault(EnvSharedVpcAWSSharedCredentialsFile, "") +} + +func GetEnvWithDefault(key string, defaultValue string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return defaultValue +} + +func GetEnvOrFail(key string) string { + if value := GetEnvWithDefault(key, ""); value != "" { + return value + } else { + panic(fmt.Errorf("ENV Variable %s is empty, please make sure you set the env value", key)) + } +} + +func GetClusterNameFilename() string { + return path.Join(GetRHCSOutputDir(), "cluster-name") +} + +func GetClusterTrustBundleFilename() string { + return path.Join(GetRHCSOutputDir(), "ca.cert") +} + +func GetClusterAdminUserFilename() string { + return path.Join(GetRHCSOutputDir(), "cluster-admin-user") +} diff --git a/tests/utils/constants/config.go b/tests/utils/constants/config.go deleted file mode 100644 index cb606968..00000000 --- a/tests/utils/constants/config.go +++ /dev/null @@ -1,119 +0,0 @@ -package constants - -import ( - "fmt" - "os" - "path" - "strings" - - . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" -) - -const ( - TokenURL = "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token" - ClientID = "cloud-services" - ClientSecret = "" - SkipAuth = true - Integration = false - HealthcheckURL = "http://localhost:8083" -) - -var RHCS = new(RHCSconfig) - -// RHCSConfig contains platforms info for the RHCS testing -type RHCSconfig struct { - // Env is the OpenShift Cluster Management environment used to provision clusters. - RHCSURL string `env:"RHCS_URL" yaml:"rhcsURL,omitempty"` - OCMEnv string `env:"OCM_ENV" default:"staging" yaml:"ocmENV,omitempty"` - ClusterProfile string `env:"CLUSTER_PROFILE" yaml:"clusterProfile,omitempty"` - ClusterProfileDir string `env:"CLUSTER_PROFILE_DIR" yaml:"clusterProfileDir,omitempty"` - RhcsOutputDir string - YAMLProfilesDir string - RootDir string - KubeConfigDir string - RHCSSource string `env:"RHCS_SOURCE" default:"staging" yaml:"rhcsSource,omitempty"` - RHCSVersion string `env:"RHCS_VERSION" default:"staging" yaml:"rhcsVersion,omitempty"` - RHCSClusterName string `env:"RHCS_CLUSTER_NAME" yaml:"clusterName,omitempty"` - RHCSClusterNamePrefix string `env:"RHCS_CLUSTER_NAME_PREFIX" yaml:"clusterNamePrefix,omitempty"` - RHCSClusterNameSuffix string `env:"RHCS_CLUSTER_NAME_SUFFIX" yaml:"clusterNameSuffix,omitempty"` - ClusterNameFile string - ComputeMachineType string `env:"COMPUTE_MACHINE_TYPE" yaml:"computeMachineType,omitempty"` -} - -func init() { - currentDir, _ := os.Getwd() - project := "terraform-provider-rhcs" - RHCS.RootDir = GetEnvWithDefault(WorkSpace, strings.SplitAfter(currentDir, project)[0]) - - // defaulted to staging - RHCS.RHCSURL = GetEnvWithDefault(RHCSURL, "https://api.openshift.com") - Logger.Infof("Running against RHCS URL: %s", RHCS.RHCSURL) - RHCS.OCMEnv = ocmEnv(RHCS.RHCSURL) - - RHCS.RHCSClusterName = GetEnvWithDefault(RHCS_CLUSTER_NAME, RHCS.RHCSClusterName) - RHCS.RHCSClusterNamePrefix = GetEnvWithDefault(RHCS_CLUSTER_NAME_PREFIX, RHCS.RHCSClusterNamePrefix) - RHCS.RHCSClusterNameSuffix = GetEnvWithDefault(RHCS_CLUSTER_NAME_SUFFIX, RHCS.RHCSClusterNameSuffix) - - RHCS.ComputeMachineType = GetEnvWithDefault(COMPUTE_MACHINE_TYPE, RHCS.ComputeMachineType) - - if os.Getenv("CLUSTER_PROFILE") != "" { - RHCS.ClusterProfile = os.Getenv("CLUSTER_PROFILE") - } - if os.Getenv("CLUSTER_PROFILE_DIR") != "" { - RHCS.ClusterProfileDir = os.Getenv("CLUSTER_PROFILE_DIR") - } - - RHCS.RhcsOutputDir = GetRHCSOutputDir() - RHCS.KubeConfigDir = GetKubeConfigDir() - RHCS.YAMLProfilesDir = path.Join(RHCS.RootDir, "tests", "ci", "profiles") - RHCS.ClusterNameFile = path.Join(RHCS.RhcsOutputDir, "cluster-name") -} - -// ocmEnv retrieve the env name based on -// Values: production, staging, integration, local -func ocmEnv(rhcsURL string) (ocmENV string) { - switch rhcsURL { - case "https://api.openshift.com", "api.openshift.com": - return "production" - case "https://api.stage.openshift.com", "api.stage.openshift.com": - return "staging" - case "https://api.integration.openshift.com", "api.integration.openshift.com": - return "integration" - case "": - return "local" - default: - return "staging" - } -} - -func GetEnvWithDefault(key string, defaultValue string) string { - if value, ok := os.LookupEnv(key); ok { - return value - } else { - if key == TokenENVName { - panic(fmt.Errorf("ENV Variable RHCS_TOKEN is empty, please make sure you set the env value")) - } - } - return defaultValue -} - -func GetRHCSOutputDir() string { - var rhcsNewOutPath string - - if GetEnvWithDefault("RHCS_OUTPUT", "") != "" { - rhcsNewOutPath = os.Getenv("RHCS_OUTPUT") - return rhcsNewOutPath - } - rhcsNewOutPath = path.Join(RHCS.RootDir, "tests", "rhcs_output") - os.MkdirAll(rhcsNewOutPath, 0777) - return rhcsNewOutPath -} - -func GetKubeConfigDir() string { - outputDIR := GetRHCSOutputDir() - configDir := path.Join(outputDIR, "kubeconfig") - if _, err := os.Stat(configDir); err != nil { - os.MkdirAll(configDir, 0777) - } - return configDir -} diff --git a/tests/utils/constants/constants.go b/tests/utils/constants/constants.go index b3c54768..591a23b7 100644 --- a/tests/utils/constants/constants.go +++ b/tests/utils/constants/constants.go @@ -2,7 +2,6 @@ package constants import ( "fmt" - "os" cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" ) @@ -42,43 +41,25 @@ var ( ManualScheduleType cmv1.ScheduleType = "manual" ) -// Below constants is the env variable name defined to run on different testing requirements const ( - TokenENVName = "RHCS_TOKEN" - ClusterIDEnv = "CLUSTER_ID" - RHCSURL = "RHCS_URL" - RhcsClusterProfileENV = "CLUSTER_PROFILE" - QEUsage = "QE_USAGE" - ClusterTypeManifestDirEnv = "CLUSTER_ROSA_TYPE" - MajorVersion = "MAJOR_VERSION_ENV" - RHCSVersion = "RHCS_VERSION" - RHCSSource = "RHCS_SOURCE" - // Set this to update the version for the terraform-redhat/rosa-classic/rhcs module - ModuleVersion = "MODULE_VERSION" - // Set this to update the source for the terraform-redhat/rosa-classic/rhcs module - ModuleSource = "MODULE_SOURCE" - // Set this to any value if `MODULE_SOURCE` refers to a local path, in which case `MODULE_VERSION` will be ignored - ModuleSourceLocal = "MODULE_SOURCE_LOCAL" - WaitOperators = "WAIT_OPERATORS" - RHCS_CLUSTER_NAME = "RHCS_CLUSTER_NAME" - RHCS_CLUSTER_NAME_PREFIX = "RHCS_CLUSTER_NAME_PREFIX" - RHCS_CLUSTER_NAME_SUFFIX = "RHCS_CLUSTER_NAME_SUFFIX" - COMPUTE_MACHINE_TYPE = "COMPUTE_MACHINE_TYPE" + TokenURL = "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token" + ClientID = "cloud-services" + ClientSecret = "" + SkipAuth = true + Integration = false + HealthcheckURL = "http://localhost:8083" ) var ( - DefaultMajorVersion = "4.14" - CharsBytes = "abcdefghijklmnopqrstuvwxyz123456789" - WorkSpace = "WORKSPACE" - RHCSPrefix = "rhcs" - ConfigSuffix = "kubeconfig" - DefaultAccountRolesPrefix = "account-role-" - ManifestsDirENV = os.Getenv("MANIFESTS_FOLDER") - SharedVpcAWSSharedCredentialsFileENV = os.Getenv("SHARED_VPC_AWS_SHARED_CREDENTIALS_FILE") + CharsBytes = "abcdefghijklmnopqrstuvwxyz123456789" + RHCSPrefix = "rhcs" + ConfigSuffix = "kubeconfig" + DefaultAccountRolesPrefix = "account-role-" ) var ( DefaultAWSRegion = "us-east-2" + DefaultRHCSURL = "https://api.openshift.com" ) // Machine pool taints effect diff --git a/tests/utils/exec/manifests/manifests.go b/tests/utils/exec/manifests/manifests.go index 56ca38f1..705a6b17 100644 --- a/tests/utils/exec/manifests/manifests.go +++ b/tests/utils/exec/manifests/manifests.go @@ -1,28 +1,12 @@ package manifests import ( - "fmt" - "os" "path" - "strings" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" ) -func initManifestsDir() string { - if constants.ManifestsDirENV != "" { - return constants.ManifestsDirENV - } - currentDir, _ := os.Getwd() - manifestsDir := path.Join(strings.SplitAfter(currentDir, "tests")[0], "tf-manifests") - if _, err := os.Stat(manifestsDir); err != nil { - panic(fmt.Sprintf("Manifests dir %s doesn't exist. Make sure you have the manifests dir in testing repo or set the correct env MANIFESTS_DIR value", manifestsDir)) - } - return manifestsDir -} - -var ManifestsConfigurationDir = initManifestsDir() - // Provider dirs' name definition const ( awsProviderDir = "aws" @@ -32,82 +16,82 @@ const ( // AWS dirs func GetAWSAccountRolesManifestDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, awsProviderDir, "account-roles", clusterType.String()) + return path.Join(config.GetManifestsDir(), awsProviderDir, "account-roles", clusterType.String()) } func GetAWSKMSManifestDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, awsProviderDir, "kms") + return path.Join(config.GetManifestsDir(), awsProviderDir, "kms") } func GetAWSOIDCProviderOperatorRolesManifestDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, awsProviderDir, "oidc-provider-operator-roles", clusterType.String()) + return path.Join(config.GetManifestsDir(), awsProviderDir, "oidc-provider-operator-roles", clusterType.String()) } func GetAWSProxyManifestDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, awsProviderDir, "proxy") + return path.Join(config.GetManifestsDir(), awsProviderDir, "proxy") } func GetAWSSecurityGroupManifestDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, awsProviderDir, "security-groups") + return path.Join(config.GetManifestsDir(), awsProviderDir, "security-groups") } func GetAWSSharedVPCPolicyAndHostedZoneManifestDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, awsProviderDir, "shared-vpc-policy-and-hosted-zone") + return path.Join(config.GetManifestsDir(), awsProviderDir, "shared-vpc-policy-and-hosted-zone") } func GetAWSVPCManifestDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, awsProviderDir, "vpc", clusterType.String()) + return path.Join(config.GetManifestsDir(), awsProviderDir, "vpc", clusterType.String()) } func GetAWSVPCTagManifestDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, awsProviderDir, "vpc-tags") + return path.Join(config.GetManifestsDir(), awsProviderDir, "vpc-tags") } // RHCS provider dirs func GetClusterManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "clusters", clusterType.String()) + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "clusters", clusterType.String()) } func GetClusterWaiterManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "cluster-waiter") + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "cluster-waiter") } func GetClusterAutoscalerManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "cluster-autoscaler", clusterType.String()) + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "cluster-autoscaler", clusterType.String()) } func GetDnsDomainManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "dns") + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "dns") } func GetIDPManifestsDir(clusterType constants.ClusterType, idpType constants.IDPType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, idpsDir, string(idpType)) + return path.Join(config.GetManifestsDir(), rhcsProviderDir, idpsDir, string(idpType)) } func GetIngressManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "ingresses", clusterType.String()) + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "ingresses", clusterType.String()) } func GetImportManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "resource-import") + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "resource-import") } func GetKubeletConfigManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "kubelet-config") + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "kubelet-config") } func GetMachinePoolsManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "machine-pools", clusterType.String()) + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "machine-pools", clusterType.String()) } func GetRHCSInfoManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "rhcs-info") + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "rhcs-info") } func GetTuningConfigManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "tuning-config") + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "tuning-config") } func GetTrustedIPsManifestsDir(clusterType constants.ClusterType) string { - return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "trusted-ips") + return path.Join(config.GetManifestsDir(), rhcsProviderDir, "trusted-ips") } diff --git a/tests/utils/helper/helper.go b/tests/utils/helper/helper.go index a115b0e4..8f0b3639 100644 --- a/tests/utils/helper/helper.go +++ b/tests/utils/helper/helper.go @@ -10,7 +10,6 @@ import ( "math/rand" "os" "os/exec" - "path" "regexp" "strconv" "strings" @@ -18,6 +17,7 @@ import ( . "github.com/onsi/gomega" "github.com/sethvargo/go-password/password" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" ) @@ -500,12 +500,12 @@ func Subfix(length int) string { func GenerateClusterName(profileName string) string { var clusterNameParts []string - if constants.RHCS.RHCSClusterNamePrefix != "" { - clusterNameParts = append(clusterNameParts, constants.RHCS.RHCSClusterNamePrefix) + if config.GetRHCSClusterNamePrefix() != "" { + clusterNameParts = append(clusterNameParts, config.GetRHCSClusterNamePrefix()) } clusterNameParts = append(clusterNameParts, constants.RHCSPrefix, profileName[5:], Subfix(3)) - if constants.RHCS.RHCSClusterNameSuffix != "" { - clusterNameParts = append(clusterNameParts, constants.RHCS.RHCSClusterNameSuffix) + if config.GetRHCSClusterNameSuffix() != "" { + clusterNameParts = append(clusterNameParts, config.GetRHCSClusterNameSuffix()) } return strings.Join(clusterNameParts, constants.HyphenConnector) } @@ -517,14 +517,15 @@ func ReadFile(absPath string) (string, error) { } return string(b), nil } + func GetClusterAdminPassword() (string, error) { - path := fmt.Sprintf(path.Join(constants.GetRHCSOutputDir(), constants.ClusterAdminUser)) - return ReadFile(path) + return ReadFile(config.GetClusterAdminUserFilename()) } var ( emptyStringValue = "" emptyStringSliceValue = []string{} + NilMap map[string]string ) var EmptyStringPointer = StringPointer(emptyStringValue) diff --git a/tests/utils/helper/manifests_handler.go b/tests/utils/helper/manifests_handler.go index 1c2db73e..c0fb1f08 100644 --- a/tests/utils/helper/manifests_handler.go +++ b/tests/utils/helper/manifests_handler.go @@ -7,7 +7,7 @@ import ( "path/filepath" - CON "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" ) @@ -90,31 +90,27 @@ func ScanManifestsDir(dir string) ([]string, error) { } func AlignRHCSSourceVersion(dir string) error { - rhcsSource := os.Getenv(CON.RHCSSource) - rhcsVersion := os.Getenv(CON.RHCSVersion) - moduleSource := os.Getenv(CON.ModuleSource) - moduleSourceLocal := os.Getenv(CON.ModuleSourceLocal) - moduleVersion := os.Getenv(CON.ModuleVersion) - if rhcsSource == "" && rhcsVersion == "" && moduleSource == "" && moduleVersion == "" && moduleSourceLocal == "" { - return nil - } - if rhcsSource != "" { - Logger.Warnf("Got a global ENV variable %s set to %s. Going to replace all of the manifests files", CON.RHCSSource, rhcsSource) - } - if rhcsVersion != "" { - Logger.Warnf("Got a global ENV variable %s set to %s. Going to replace all of the manifests files", CON.RHCSVersion, rhcsVersion) - } - if moduleSource != "" { - Logger.Warnf("Got a global ENV variable %s set to %s. Going to replace all of the manifests files", CON.ModuleSource, moduleSource) - } - if moduleSourceLocal != "" { - Logger.Warnf("Got a global ENV variable %s set. Going to replace all of the manifests files", CON.ModuleVersion, moduleVersion) + var foundEnv bool + retrieveRHCSEnvVar := func(name string, retriever func() string) string { + value := retriever() + if value != "" { + foundEnv = true + Logger.Warnf("Got a global ENV variable for %s set to %s. Going to replace all of the manifests files", name, value) + } + return value } - if moduleVersion != "" { - Logger.Warnf("Got a global ENV variable %s set to %s. Going to replace all of the manifests files", CON.ModuleVersion, moduleVersion) + + rhcsSource := retrieveRHCSEnvVar("RHCS Source", config.GetRHCSSource) + rhcsVersion := retrieveRHCSEnvVar("RHCS Version", config.GetRHCSVersion) + rhcsModuleSource := retrieveRHCSEnvVar("RHCS Module Source", config.GetRHCSModuleSource) + rhcsModuleSourceLocal := retrieveRHCSEnvVar("RHCS Module Source Local", config.GetRHCSSource) + rhcsModuleVersion := retrieveRHCSEnvVar("RHCS Module Version", config.GetRHCSModuleVersion) + if !foundEnv { + return nil } + Logger.Warnf("RHCS Source: %s, RHCS Version: %s", rhcsSource, rhcsVersion) - Logger.Warnf("Module Source: %s, Module Version: %s", moduleSource, moduleVersion) + Logger.Warnf("Module Source: %s, Module Version: %s", rhcsModuleSource, rhcsModuleVersion) files, err := ScanManifestsDir(dir) if err != nil { return err @@ -124,7 +120,7 @@ func AlignRHCSSourceVersion(dir string) error { if err != nil { return err } - err = ModuleSourceAlignment(file, moduleSource, moduleSourceLocal, moduleVersion) + err = ModuleSourceAlignment(file, rhcsModuleSource, rhcsModuleSourceLocal, rhcsModuleVersion) if err != nil { return err } diff --git a/tests/utils/openshift/console.go b/tests/utils/openshift/console.go index 9fbdf0b7..3f379503 100644 --- a/tests/utils/openshift/console.go +++ b/tests/utils/openshift/console.go @@ -10,9 +10,10 @@ import ( "github.com/goinggo/mapstructure" client "github.com/openshift-online/ocm-sdk-go" - CMS "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" - CON "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" - h "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" ) // Console is openshift webconsole struct @@ -27,14 +28,14 @@ type Console struct { func NewConsole(clusterID string, connection *client.Connection) (console *Console, err error) { console = &Console{ClusterID: clusterID} - // detailResp, err := CMS.RetrieveClusterDetail(connection, clusterID) + // detailResp, err := cms.RetrieveClusterDetail(connection, clusterID) if err != nil { return } if console.IsConfiged() { return console, nil } - resp, err := CMS.RetrieveClusterCredentials(connection, clusterID) + resp, err := cms.RetrieveClusterCredentials(connection, clusterID) if err != nil { return } @@ -52,7 +53,7 @@ func NewConsole(clusterID string, connection *client.Connection) (console *Conso // IsConfiged will return whether the config file of the console is existed func (c *Console) IsConfiged() bool { - configFile := filepath.Join(CON.GetRHCSOutputDir(), h.Join(c.ClusterID, CON.ConfigSuffix)) + configFile := filepath.Join(config.GetRHCSOutputDir(), helper.Join(c.ClusterID, constants.ConfigSuffix)) _, err := os.Stat(configFile) if err != nil { return false @@ -63,7 +64,7 @@ func (c *Console) IsConfiged() bool { // Config will return the console which had been configured func (c *Console) Config(kubeConfig string) (*Console, error) { - configFile := filepath.Join(CON.GetRHCSOutputDir(), h.Join(c.ClusterID, CON.ConfigSuffix)) + configFile := filepath.Join(config.GetRHCSOutputDir(), helper.Join(c.ClusterID, constants.ConfigSuffix)) wf, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0766) if err == nil { _, err = wf.Write([]byte(kubeConfig)) @@ -75,12 +76,12 @@ func (c *Console) Config(kubeConfig string) (*Console, error) { // GetClusterVersion will return the Cluster version func (c *Console) GetClusterVersion() (version string, err error) { - stdout, _, err := h.RunCMD("oc version -o json") + stdout, _, err := helper.RunCMD("oc version -o json") fmt.Println(stdout) if err != nil { return } - version = h.DigString(h.Parse([]byte(stdout)), "openshiftVersion") + version = helper.DigString(helper.Parse([]byte(stdout)), "openshiftVersion") return } @@ -99,7 +100,7 @@ func (c *Console) GetPods(namespace ...string) ([]*Pod, error) { if len(namespace) == 1 { CMD = fmt.Sprintf("oc get pod -n %s -o json --kubeconfig %s", namespace[0], c.KubePath) } - stdout, _, err := h.RunCMD(CMD) + stdout, _, err := helper.RunCMD(CMD) if err != nil { return pods, err } diff --git a/tests/utils/openshift/openshift.go b/tests/utils/openshift/openshift.go index 11dce26c..0ec0326a 100644 --- a/tests/utils/openshift/openshift.go +++ b/tests/utils/openshift/openshift.go @@ -20,7 +20,7 @@ type OcAttributes struct { Username string Password string ClusterID string - AdditioanlFlags []string + AdditionalFlags []string Timeout time.Duration } @@ -65,7 +65,7 @@ func OcLogin(ocLoginAtter OcAttributes) (string, error) { ocLoginAtter.Username, ocLoginAtter.Password, ocLoginAtter.ClusterID, - ocLoginAtter.AdditioanlFlags...) + ocLoginAtter.AdditionalFlags...) output, err := RetryCMDRun(cmd, ocLoginAtter.Timeout) return output, err diff --git a/tests/utils/profilehandler/file.go b/tests/utils/profilehandler/file.go index fc4f6f21..f92507a8 100644 --- a/tests/utils/profilehandler/file.go +++ b/tests/utils/profilehandler/file.go @@ -3,12 +3,12 @@ package profilehandler import ( "encoding/json" "fmt" - "os" "slices" "sort" "strings" rosa "github.com/terraform-redhat/terraform-provider-rhcs/provider/clusterrosa/common" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" h "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" @@ -17,10 +17,8 @@ import ( ) // The cfg will be used to define the testing environment -var cfg = constants.RHCS - func loadProfileYamlFile(profileName string) (*Profile, error) { - p, err := helper.GetProfile(profileName, GetYAMLProfilesDir()) + p, err := helper.GetProfile(profileName, config.GetClusterProfilesDir()) if err != nil { return nil, err } @@ -33,7 +31,7 @@ func loadProfileYamlFile(profileName string) (*Profile, error) { } func LoadProfileYamlFileByENV() (profile *Profile, err error) { - profileEnv := os.Getenv(constants.RhcsClusterProfileENV) + profileEnv := config.GetClusterProfile() if profileEnv == "" { panic(fmt.Errorf("ENV Variable CLUSTER_PROFILE is empty, please make sure you set the env value")) } @@ -43,19 +41,33 @@ func LoadProfileYamlFileByENV() (profile *Profile, err error) { } // Supporting global env setting to overrite profile settings - if os.Getenv("CHANNEL_GROUP") != "" { - Logger.Infof("Got global env settings for CHANNEL_GROUP, overwritten the profile setting with value %s", os.Getenv("CHANNEL_GROUP")) - profile.ChannelGroup = os.Getenv("CHANNEL_GROUP") - } - if os.Getenv("VERSION") != "" { - Logger.Infof("Got global env settings for VERSION, overwritten the profile setting with value %s", os.Getenv("VERSION")) - profile.Version = os.Getenv("VERSION") - } - if os.Getenv("REGION") != "" { - Logger.Infof("Got global env settings for REGION, overwritten the profile setting with value %s", os.Getenv("REGION")) - profile.Region = os.Getenv("REGION") + setProfileFromEnv := func(name string, envRetriever func() string, profileSetter func(profile *Profile, value string)) { + value := envRetriever() + if value != "" { + profileSetter(profile, value) + Logger.Infof("Got global env settings for %s, overwritten the profile setting with value %s", name, value) + } } + setProfileFromEnv("Channel Group", config.GetChannelGroup, func(profile *Profile, value string) { + profile.ChannelGroup = value + }) + setProfileFromEnv("Version", config.GetVersion, func(profile *Profile, value string) { + profile.Version = value + }) + setProfileFromEnv("Major Version", config.GetMajorVersion, func(profile *Profile, value string) { + profile.MajorVersion = value + }) + setProfileFromEnv("Region", config.GetRegion, func(profile *Profile, value string) { + profile.Region = value + }) + setProfileFromEnv("Compute Machine Type", config.GetComputeMachineType, func(profile *Profile, value string) { + profile.ComputeMachineType = value + }) + setProfileFromEnv("Cluster Name", config.GetRHCSClusterName, func(profile *Profile, value string) { + profile.ClusterName = value + }) + if len(profile.AllowedRegistries) > 0 || len(profile.BlockedRegistries) > 0 { profile.UseRegistryConfig = true } @@ -63,10 +75,6 @@ func LoadProfileYamlFileByENV() (profile *Profile, err error) { return } -func GetYAMLProfilesDir() string { - return cfg.YAMLProfilesDir -} - // ConvertToStringArray will convert the []interface to []string func ConvertToStringArray(interfaceList []interface{}) []string { var stringList []string @@ -129,7 +137,7 @@ func getRandomProfile(clusterTypes ...constants.ClusterType) (profile *Profile, Logger.Info("Get random profile from all profiles") } - profilesMap, err := helper.ParseProfiles(GetYAMLProfilesDir()) + profilesMap, err := helper.ParseProfiles(config.GetClusterProfilesDir()) if err != nil { return } diff --git a/tests/utils/profilehandler/handler.go b/tests/utils/profilehandler/handler.go index 57f7708b..a2b22e38 100644 --- a/tests/utils/profilehandler/handler.go +++ b/tests/utils/profilehandler/handler.go @@ -4,12 +4,12 @@ import ( "errors" "fmt" "os" - "path" "regexp" "strings" "time" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" @@ -326,7 +326,7 @@ func (ctx *profileContext) PrepareVPC(multiZone bool, azIDs []string, name strin } vpcArgs := &exec.VPCArgs{ AWSRegion: helper.StringPointer(region), - VPCCIDR: helper.StringPointer(constants.DefaultVPCCIDR), + VPCCIDR: helper.StringPointer(DefaultVPCCIDR), } if len(azIDs) != 0 { @@ -448,7 +448,7 @@ func (ctx *profileContext) PrepareProxy(VPCID string, subnetPublicID string, key Region: helper.StringPointer(ctx.profile.Region), VPCID: helper.StringPointer(VPCID), PublicSubnetID: helper.StringPointer(subnetPublicID), - TrustBundleFilePath: helper.StringPointer(path.Join(constants.RHCS.RhcsOutputDir, "ca.cert")), + TrustBundleFilePath: helper.StringPointer(config.GetClusterTrustBundleFilename()), KeyPairID: helper.StringPointer(keyPairID), } @@ -608,7 +608,7 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg clusterArgs.MultiAZ = helper.BoolPointer(ctx.profile.MultiAZ) if ctx.profile.NetWorkingSet { - clusterArgs.MachineCIDR = helper.StringPointer(constants.DefaultVPCCIDR) + clusterArgs.MachineCIDR = helper.StringPointer(DefaultVPCCIDR) } if ctx.profile.Autoscale { @@ -619,9 +619,7 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg } } - if constants.RHCS.ComputeMachineType != "" { - clusterArgs.ComputeMachineType = helper.StringPointer(constants.RHCS.ComputeMachineType) - } else if ctx.profile.ComputeMachineType != "" { + if ctx.profile.ComputeMachineType != "" { clusterArgs.ComputeMachineType = helper.StringPointer(ctx.profile.ComputeMachineType) } @@ -638,20 +636,20 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg } if ctx.profile.Labeling { - clusterArgs.DefaultMPLabels = helper.StringMapPointer(constants.DefaultMPLabels) + clusterArgs.DefaultMPLabels = helper.StringMapPointer(DefaultMPLabels) } if ctx.profile.Tagging { - clusterArgs.Tags = helper.StringMapPointer(constants.Tags) + clusterArgs.Tags = helper.StringMapPointer(Tags) } if ctx.profile.AdminEnabled { - userName := constants.ClusterAdminUser + userName := ClusterAdminUser password := helper.GenerateRandomPassword(14) adminPasswdMap := map[string]string{"username": userName, "password": password} clusterArgs.AdminCredentials = helper.StringMapPointer(adminPasswdMap) pass := []byte(password) - err = os.WriteFile(path.Join(cfg.RhcsOutputDir, constants.ClusterAdminUser), pass, 0644) + err = os.WriteFile(config.GetClusterAdminUserFilename(), pass, 0644) if err != nil { Logger.Error("Error happens when try to record the admin password") return @@ -665,9 +663,7 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg } var clusterName string - if constants.RHCS.RHCSClusterName != "" { - clusterName = constants.RHCS.RHCSClusterName - } else if ctx.profile.ClusterName != "" { + if ctx.profile.ClusterName != "" { clusterName = ctx.profile.ClusterName } else { // Generate random chars later cluster name with profile name @@ -683,14 +679,14 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg } clusterArgs.ClusterName = &clusterName - err = os.WriteFile(cfg.ClusterNameFile, []byte(clusterName), 0644) + err = os.WriteFile(config.GetClusterNameFilename(), []byte(clusterName), 0644) if err != nil { Logger.Errorf("Error happens when try to record the cluster name file: %s ", err.Error()) return } Logger.Infof("Recorded cluster name file: %s with name %s", - cfg.ClusterNameFile, clusterName) + config.GetClusterNameFilename(), clusterName) // short and re-generate the clusterName when it is longer than 15 chars if ctx.profile.DomainPrefix != "" { clusterArgs.DomainPrefix = &ctx.profile.DomainPrefix @@ -747,9 +743,11 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg // Supports ENV set passed to make cluster provision more flexy in prow // Export the subnetIDs via env variable if you have existing ones export SubnetIDs=,, // Export the availability zones via env variable export AvailabilitiZones=,, - if os.Getenv("SubnetIDs") != "" && os.Getenv("AvailabilitiZones") != "" { - subnetIDs := strings.Split(os.Getenv("SubnetIDs"), ",") - azs := strings.Split(os.Getenv("AvailabilitiZones"), ",") + subnetIDs := config.GetSubnetIDs() + availabilityZones := config.GetAvailabilityZones() + if subnetIDs != "" && availabilityZones != "" { + subnetIDs := strings.Split(subnetIDs, ",") + azs := strings.Split(availabilityZones, ",") clusterArgs.AWSAvailabilityZones = &azs clusterArgs.AWSSubnetIDs = &subnetIDs } else { @@ -760,11 +758,10 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg sharedVPCAWSSharedCredentialsFile := "" if ctx.profile.SharedVpc { - if constants.SharedVpcAWSSharedCredentialsFileENV == "" { - panic(fmt.Errorf("SHARED_VPC_AWS_SHARED_CREDENTIALS_FILE env is not set or empty, it's requried by Shared-VPC cluster")) + sharedVPCAWSSharedCredentialsFile = config.GetSharedVpcAWSSharedCredentialsFile() + if sharedVPCAWSSharedCredentialsFile == "" { + panic(fmt.Errorf("Shared VPC Credentials File environment is not set, it's requried by Shared-VPC cluster")) } - - sharedVPCAWSSharedCredentialsFile = constants.SharedVpcAWSSharedCredentialsFileENV } vpcOutput, err = ctx.PrepareVPC(ctx.profile.MultiAZ, zones, clusterName, sharedVPCAWSSharedCredentialsFile) if err != nil { @@ -798,7 +795,7 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg // Resources for Shared-VPC var sharedVpcPolicyAndHostedZoneOutput *exec.SharedVpcPolicyAndHostedZoneOutput sharedVpcPolicyAndHostedZoneOutput, err = ctx.PrepareSharedVpcPolicyAndHostedZone( - constants.SharedVpcAWSSharedCredentialsFileENV, + config.GetSharedVpcAWSSharedCredentialsFile(), clusterName, baseDnsDomain, ingressRoleArn, @@ -903,7 +900,7 @@ func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArg clusterArgs.WorkerDiskSize = helper.IntPointer(ctx.profile.WorkerDiskSize) } clusterArgs.UnifiedAccRolesPath = helper.StringPointer(ctx.profile.UnifiedAccRolesPath) - clusterArgs.CustomProperties = helper.StringMapPointer(constants.CustomProperties) // id:72450 + clusterArgs.CustomProperties = helper.StringMapPointer(CustomProperties) // id:72450 if ctx.profile.FullResources { clusterArgs.FullResources = helper.BoolPointer(true) @@ -952,8 +949,8 @@ func (ctx *profileContext) CreateRHCSClusterByProfile(token string) (string, err } func (ctx *profileContext) DestroyRHCSClusterResources(token string) error { - if os.Getenv("NO_CLUSTER_DESTROY") == "true" { - Logger.Warn("`NO_CLUSTER_DESTROY` is configured, thus no destroy of resources will happen") + if config.IsNoClusterDestroy() { + Logger.Warn("No Cluster Destroy is configured, thus no destroy of resources will happen") return nil } @@ -969,7 +966,7 @@ func (ctx *profileContext) DestroyRHCSClusterResources(token string) error { } } // Get the cluster name from backend to double check cluster deleted - clusterName, _ := helper.ReadFile(cfg.ClusterNameFile) + clusterName, _ := helper.ReadFile(config.GetClusterNameFilename()) Logger.Infof("Double checking with the cluster name %s", clusterName) if clusterName != "" { parameter := map[string]interface{}{ @@ -1109,18 +1106,7 @@ func (ctx *profileContext) DestroyRHCSClusterResources(token string) error { } // RetrieveClusterID will be used for all day2 tests. It needs an existing cluster. -// Two ways: -// - If you created a cluster by other way, you can Export CLUSTER_ID= -// - If you are using this CI created the cluster, just need to Export CLUSTER_PROFILE= func (ctx *profileContext) RetrieveClusterID() (string, error) { - // Support the cluster ID to set to ENV in case somebody created cluster by other way - if os.Getenv(constants.ClusterIDEnv) != "" { - return os.Getenv(constants.ClusterIDEnv), nil - } - if os.Getenv(constants.RhcsClusterProfileENV) == "" { - Logger.Warnf("Either env variables %s and %s set. Will return an empty string.", constants.ClusterIDEnv, constants.RhcsClusterProfileENV) - return "", nil - } clusterService, err := ctx.Services().GetClusterService() if err != nil { return "", err diff --git a/tests/utils/constants/profile_defaults.go b/tests/utils/profilehandler/profile_defaults.go similarity index 78% rename from tests/utils/constants/profile_defaults.go rename to tests/utils/profilehandler/profile_defaults.go index d48bf76f..dec71bf7 100644 --- a/tests/utils/constants/profile_defaults.go +++ b/tests/utils/profilehandler/profile_defaults.go @@ -1,17 +1,18 @@ -package constants +package profilehandler + +import "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/config" const ( DefaultVPCCIDR = "10.0.0.0/16" ) var ( - NilMap map[string]string Tags = map[string]string{"tag1": "test_tag1", "tag2": "test_tag2"} ClusterAdminUser = "rhcs-clusteradmin" DefaultMPLabels = map[string]string{ "test1": "testdata1", } - CustomProperties = map[string]string{"custom_property": "test", "qe_usage": GetEnvWithDefault(QEUsage, "")} + CustomProperties = map[string]string{"custom_property": "test", "qe_usage": config.GetQEUsage()} LdapURL = "ldap://ldap.forumsys.com/dc=example,dc=com?uid" GitLabURL = "https://gitlab.cee.redhat.com" Organizations = []string{"openshift"}