diff --git a/.gitignore b/.gitignore index 61c889db..ce752e3f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ .terraform* /dist/ terraform.tfstate* -/tests/**/terraform.*.tfvars +terraform.tfvars.d* /playground/* /vendor /tests/rhcs_output diff --git a/Makefile b/Makefile index 3f30e356..bd3a29cc 100644 --- a/Makefile +++ b/Makefile @@ -127,7 +127,7 @@ e2e_clean_tf_states: .PHONY: e2e_clean_tf_vars e2e_clean_tf_vars: - find tests/tf-manifests -name 'terraform.e2e.tfvars*' -exec rm -rf {} \; || true + find tests/tf-manifests -name 'terraform.tfvars*' -exec rm -rf {} \; || true .PHONY: e2e_clean_tf_init e2e_clean_tf_init: diff --git a/go.mod b/go.mod index 82f01c46..dcc123d7 100644 --- a/go.mod +++ b/go.mod @@ -30,6 +30,7 @@ require ( require ( github.com/agext/levenshtein v1.2.2 // indirect + github.com/apparentlymart/go-cidr v1.1.0 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect github.com/aws/aws-sdk-go-v2/config v1.27.9 // indirect diff --git a/go.sum b/go.sum index 4ffeb70a..fb7f2955 100644 --- a/go.sum +++ b/go.sum @@ -60,6 +60,7 @@ github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0 github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= +github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU= github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= @@ -789,6 +790,8 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/tests/ci/profile_handler.go b/tests/ci/profile_handler.go deleted file mode 100644 index 1e24649e..00000000 --- a/tests/ci/profile_handler.go +++ /dev/null @@ -1,971 +0,0 @@ -package ci - -import ( - "errors" - "fmt" - "os" - "path" - "regexp" - "slices" - "strings" - "time" - - . "github.com/onsi/gomega" - client "github.com/openshift-online/ocm-sdk-go" - - "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/log" -) - -// Profile Provides profile struct for cluster creation be matrix -type Profile struct { - Name string `ini:"name,omitempty" json:"name,omitempty"` - ClusterName string `ini:"cluster_name,omitempty" json:"cluster_name,omitempty"` - DomainPrefix string `ini:"domain_prefix,omitempty" json:"domain_prefix,omitempty"` - ClusterType string `ini:"cluster_type,omitempty" json:"cluster_type,omitempty"` - ProductID string `ini:"product_id,omitempty" json:"product_id,omitempty"` - MajorVersion string `ini:"major_version,omitempty" json:"major_version,omitempty"` - Version string `ini:"version,omitempty" json:"version,omitempty"` //Specific OCP version to be specified - VersionPattern string `ini:"version_pattern,omitempty" json:"version_pattern,omitempty"` //Version supports indicated version started with openshift-v or major-1 (y-1) or minor-1 (z-1) - ChannelGroup string `ini:"channel_group,omitempty" json:"channel_group,omitempty"` - CloudProvider string `ini:"cloud_provider,omitempty" json:"cloud_provider,omitempty"` - Region string `ini:"region,omitempty" json:"region,omitempty"` - InstanceType string `ini:"instance_type,omitempty" json:"instance_type,omitempty"` - Zones string `ini:"zones,omitempty" json:"zones,omitempty"` // zones should be like a,b,c,d - StorageLB bool `ini:"storage_lb,omitempty" json:"storage_lb,omitempty"` // the unit is GIB, don't support unit set - Tagging bool `ini:"tagging,omitempty" json:"tagging,omitempty"` - Labeling bool `ini:"labeling,omitempty" json:"labeling,omitempty"` - Etcd bool `ini:"etcd_encryption,omitempty" json:"etcd_encryption,omitempty"` - FIPS bool `ini:"fips,omitempty" json:"fips,omitempty"` - CCS bool `ini:"ccs,omitempty" json:"ccs,omitempty"` - STS bool `ini:"sts,omitempty" json:"sts,omitempty"` - Autoscale bool `ini:"autoscaling_enabled,omitempty" json:"autoscaling_enabled,omitempty"` - MultiAZ bool `ini:"multi_az,omitempty" json:"multi_az,omitempty"` - BYOVPC bool `ini:"byovpc,omitempty" json:"byovpc,omitempty"` - PrivateLink bool `ini:"private_link,omitempty" json:"private_link,omitempty"` - Private bool `ini:"private,omitempty" json:"private,omitempty"` - BYOK bool `ini:"byok,omitempty" json:"byok,omitempty"` - KMSKey bool `ini:"kms_key_arn,omitempty" json:"kms_key_arn,omitempty"` - DifferentEncryptionKeys bool `ini:"different_encryption_keys,omitempty" json:"different_encryption_keys,omitempty"` - NetWorkingSet bool `ini:"networking_set,omitempty" json:"networking_set,omitempty"` - Proxy bool `ini:"proxy,omitempty" json:"proxy,omitempty"` - OIDCConfig string `ini:"oidc_config,omitempty" json:"oidc_config,omitempty"` - ProvisionShard string `ini:"provisionShard,omitempty" json:"provisionShard,omitempty"` - Ec2MetadataHttpTokens string `ini:"ec2_metadata_http_tokens,omitempty" json:"ec2_metadata_http_tokens,omitempty"` - ComputeReplicas int `ini:"compute_replicas,omitempty" json:"compute_replicas,omitempty"` - ComputeMachineType string `ini:"compute_machine_type,omitempty" json:"compute_machine_type,omitempty"` - AuditLogForward bool `ini:"auditlog_forward,omitempty" json:"auditlog_forward,omitempty"` - AdminEnabled bool `ini:"admin_enabled,omitempty" json:"admin_enabled,omitempty"` - ManagedPolicies bool `ini:"managed_policies,omitempty" json:"managed_policies,omitempty"` - WorkerDiskSize int `ini:"worker_disk_size,omitempty" json:"worker_disk_size,omitempty"` - AdditionalSGNumber int `ini:"additional_sg_number,omitempty" json:"additional_sg_number,omitempty"` - UnifiedAccRolesPath string `ini:"unified_acc_role_path,omitempty" json:"unified_acc_role_path,omitempty"` - SharedVpc bool `ini:"shared_vpc,omitempty" json:"shared_vpc,omitempty"` - MachineCIDR string `ini:"machine_cidr,omitempty" json:"machine_cidr,omitempty"` - ServiceCIDR string `ini:"service_cidr,omitempty" json:"service_cidr,omitempty"` - PodCIDR string `ini:"pod_cidr,omitempty" json:"pod_cidr,omitempty"` - HostPrefix int `ini:"host_prefix,omitempty" json:"host_prefix,omitempty"` - FullResources bool `ini:"full_resources,omitempty" json:"full_resources,omitempty"` - DontWaitForCluster bool `ini:"no_wait_cluster,omitempty" json:"no_wait_cluster,omitempty"` -} - -func PrepareVPC(region string, multiZone bool, azIDs []string, clusterType constants.ClusterType, name string, sharedVpcAWSSharedCredentialsFile string) (*exec.VPCOutput, error) { - vpcService, err := exec.NewVPCService(constants.GetAWSVPCDefaultManifestDir(clusterType)) - if err != nil { - return nil, err - } - vpcArgs := &exec.VPCArgs{ - AWSRegion: helper.StringPointer(region), - VPCCIDR: helper.StringPointer(constants.DefaultVPCCIDR), - } - - if len(azIDs) != 0 { - turnedZoneIDs := []string{} - for _, zone := range azIDs { - if strings.Contains(zone, region) { - turnedZoneIDs = append(turnedZoneIDs, zone) - } else { - turnedZoneIDs = append(turnedZoneIDs, region+zone) - } - } - vpcArgs.AvailabilityZones = helper.StringSlicePointer(turnedZoneIDs) - } else { - azCount := 1 - if multiZone { - azCount = 3 - } - vpcArgs.AvailabilityZonesCount = helper.IntPointer(azCount) - } - if name != "" { - vpcArgs.NamePrefix = helper.StringPointer(name) - } - - if sharedVpcAWSSharedCredentialsFile != "" { - vpcArgs.AWSSharedCredentialsFiles = helper.StringSlicePointer([]string{sharedVpcAWSSharedCredentialsFile}) - } - - _, err = vpcService.Apply(vpcArgs) - if err != nil { - vpcService.Destroy() - return nil, err - } - output, err := vpcService.Output() - if err != nil { - vpcService.Destroy() - return nil, err - } - return output, err -} - -func PrepareAdditionalSecurityGroups(region string, vpcID string, sgNumbers int) ([]string, error) { - sgService, err := exec.NewSecurityGroupService() - if err != nil { - return nil, err - } - sgArgs := &exec.SecurityGroupArgs{ - AWSRegion: helper.StringPointer(region), - VPCID: helper.StringPointer(vpcID), - SGNumber: helper.IntPointer(sgNumbers), - NamePrefix: helper.StringPointer("rhcs-ci"), - } - _, err = sgService.Apply(sgArgs) - if err != nil { - sgService.Destroy() - return nil, err - } - output, err := sgService.Output() - if err != nil { - sgService.Destroy() - return nil, err - } - return output.SGIDs, err -} - -func PrepareAccountRoles(token string, accountRolePrefix string, accountRolesPath string, awsRegion string, openshiftVersion string, channelGroup string, clusterType constants.ClusterType, sharedVpcRoleArn string) ( - *exec.AccountRolesOutput, error) { - accService, err := exec.NewAccountRoleService(constants.GetAccountRoleDefaultManifestDir(clusterType)) - if err != nil { - return nil, err - } - args := &exec.AccountRolesArgs{ - AccountRolePrefix: helper.StringPointer(accountRolePrefix), - OpenshiftVersion: helper.StringPointer(openshiftVersion), - UnifiedAccRolesPath: helper.StringPointer(accountRolesPath), - } - - if sharedVpcRoleArn != "" { - args.SharedVpcRoleArn = helper.StringPointer(sharedVpcRoleArn) - } - - _, err = accService.Apply(args) - if err != nil { - accService.Destroy() - return nil, err - } - return accService.Output() -} - -func PrepareOIDCProviderAndOperatorRoles(token string, oidcConfigType string, operatorRolePrefix string, accountRolePrefix string, accountRolesPath string, clusterType constants.ClusterType, awsRegion string) ( - *exec.OIDCProviderOperatorRolesOutput, error) { - oidcOpService, err := exec.NewOIDCProviderOperatorRolesService(constants.GetOIDCProviderOperatorRolesDefaultManifestDir(clusterType)) - if err != nil { - return nil, err - } - args := &exec.OIDCProviderOperatorRolesArgs{ - AccountRolePrefix: helper.StringPointer(accountRolePrefix), - OperatorRolePrefix: helper.StringPointer(operatorRolePrefix), - OIDCConfig: helper.StringPointer(oidcConfigType), - UnifiedAccRolesPath: helper.StringPointer(accountRolesPath), - } - _, err = oidcOpService.Apply(args) - if err != nil { - oidcOpService.Destroy() - return nil, err - } - return oidcOpService.Output() - -} - -// PrepareVersion supports below types -// version with a openshift version like 4.13.12 -// version with latest -// verion with x-1, it means the version will choose one with x-1 version which can be used for x stream upgrade -// version with y-1, it means the version will choose one with y-1 version which can be used for y stream upgrade -func PrepareVersion(connection *client.Connection, versionTag string, channelGroup string, profile *Profile) string { - versionRegex := regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+\-*[\s\S]*$`) - // Check that the version is matching openshift version regexp - if versionRegex.MatchString(versionTag) { - return versionTag - } - var vResult string - switch versionTag { - case "", "latest": - versions := cms.EnabledVersions(connection, channelGroup, profile.MajorVersion, true) - versions = cms.SortVersions(versions) - vResult = versions[len(versions)-1].RawID - case "y-1": - versions, _ := cms.GetVersionsWithUpgrades(connection, channelGroup, constants.Y, true, false, 1) - vResult = versions[len(versions)-1].RawID - case "z-1": - versions, _ := cms.GetVersionsWithUpgrades(connection, channelGroup, constants.Z, true, false, 1) - vResult = versions[len(versions)-1].RawID - case "eol": - vResult = "" - } - Logger.Infof("Cluster OCP latest version is set to %s", vResult) - return vResult -} - -func GetMajorVersion(rawVersion string) string { - versionRegex := regexp.MustCompile(`^[0-9]+\.[0-9]+`) - vResults := versionRegex.FindAllStringSubmatch(rawVersion, 1) - vResult := "" - if len(vResults) != 0 { - vResult = vResults[0][0] - } - return vResult -} - -func PrepareProxy(region string, VPCID string, subnetPublicID string, keyPairID string) (*exec.ProxyOutput, error) { - if VPCID == "" { - return nil, fmt.Errorf("vpc ID is empty. Cannot prepare proxy") - } - proxyService, err := exec.NewProxyService() - if err != nil { - return nil, err - } - proxyArgs := &exec.ProxyArgs{ - ProxyCount: helper.IntPointer(1), - Region: helper.StringPointer(region), - VPCID: helper.StringPointer(VPCID), - PublicSubnetID: helper.StringPointer(subnetPublicID), - TrustBundleFilePath: helper.StringPointer(path.Join(cfg.RhcsOutputDir, "ca.cert")), - KeyPairID: helper.StringPointer(keyPairID), - } - - _, err = proxyService.Apply(proxyArgs) - if err != nil { - proxyService.Destroy() - return nil, err - } - proxyOutput, err := proxyService.Output() - if err != nil { - proxyService.Destroy() - return nil, err - } - - return proxyOutput.Proxies[0], err -} - -func PrepareKMSKey(manifestDir string, profile *Profile, kmsName string, accountRolePrefix string, accountRolePath string, clusterType constants.ClusterType) (string, error) { - kmsService, err := exec.NewKMSService(manifestDir) - if err != nil { - return "", err - } - kmsArgs := &exec.KMSArgs{ - KMSName: helper.StringPointer(kmsName), - AWSRegion: helper.StringPointer(profile.Region), - AccountRolePrefix: helper.StringPointer(accountRolePrefix), - AccountRolePath: helper.StringPointer(accountRolePath), - TagKey: helper.StringPointer("Purpose"), - TagValue: helper.StringPointer("RHCS automation test"), - TagDescription: helper.StringPointer("BYOK Test Key for API automation"), - HCP: helper.BoolPointer(clusterType.HCP), - } - - _, err = kmsService.Apply(kmsArgs) - if err != nil { - kmsService.Destroy() - return "", err - } - kmsOutput, err := kmsService.Output() - if err != nil { - kmsService.Destroy() - return "", err - } - return kmsOutput.KeyARN, err -} - -func PrepareRoute53() (string, error) { - dnsDomainService, err := exec.NewDnsDomainService() - if err != nil { - return "", err - } - a := &exec.DnsDomainArgs{} - - _, err = dnsDomainService.Apply(a) - if err != nil { - dnsDomainService.Destroy() - return "", err - } - output, err := dnsDomainService.Output() - if err != nil { - dnsDomainService.Destroy() - return "", err - } - return output.DnsDomainId, err -} - -func PrepareSharedVpcPolicyAndHostedZone(region string, - sharedVpcAWSSharedCredentialsFile string, - clusterName string, - dnsDomainID string, - ingressOperatorRoleArn string, - installerRoleArn string, - clusterAwsAccount string, - vpcID string, - subnets []string, - domainPrefix string) (*exec.SharedVpcPolicyAndHostedZoneOutput, error) { - - sharedVPCService, err := exec.NewSharedVpcPolicyAndHostedZoneService() - if err != nil { - return nil, err - } - - hostedZoneArgs := &exec.SharedVpcPolicyAndHostedZoneArgs{ - SharedVpcAWSSharedCredentialsFiles: helper.StringSlicePointer([]string{sharedVpcAWSSharedCredentialsFile}), - Region: helper.StringPointer(region), - ClusterName: helper.StringPointer(clusterName), - DnsDomainId: helper.StringPointer(dnsDomainID), - IngressOperatorRoleArn: helper.StringPointer(ingressOperatorRoleArn), - InstallerRoleArn: helper.StringPointer(installerRoleArn), - ClusterAWSAccount: helper.StringPointer(clusterAwsAccount), - VpcId: helper.StringPointer(vpcID), - Subnets: helper.StringSlicePointer(subnets), - } - if domainPrefix != "" { - hostedZoneArgs.DomainPrefix = helper.StringPointer(domainPrefix) - } - - _, err = sharedVPCService.Apply(hostedZoneArgs) - if err != nil { - sharedVPCService.Destroy() - return nil, err - } - output, err := sharedVPCService.Output() - if err != nil { - sharedVPCService.Destroy() - return nil, err - } - return output, err -} - -func GenerateClusterCreationArgsByProfile(token string, profile *Profile) (clusterArgs *exec.ClusterArgs, err error) { - profile.Version = PrepareVersion(RHCSConnection, profile.VersionPattern, profile.ChannelGroup, profile) - - clusterArgs = &exec.ClusterArgs{ - OpenshiftVersion: helper.StringPointer(profile.Version), - } - - // Init cluster's args by profile's attributes - - // For Shared VPC - var cluster_aws_account string - var installer_role_arn string - var ingress_role_arn string - - if profile.FIPS { - clusterArgs.Fips = helper.BoolPointer(profile.FIPS) - } - - if profile.MultiAZ { - clusterArgs.MultiAZ = helper.BoolPointer(profile.MultiAZ) - } - - if profile.NetWorkingSet { - clusterArgs.MachineCIDR = helper.StringPointer(constants.DefaultVPCCIDR) - } - - if profile.Autoscale { - clusterArgs.Autoscaling = &exec.Autoscaling{ - AutoscalingEnabled: helper.BoolPointer(true), - MinReplicas: helper.IntPointer(3), - MaxReplicas: helper.IntPointer(6), - } - } - - if constants.RHCS.ComputeMachineType != "" { - clusterArgs.ComputeMachineType = helper.StringPointer(constants.RHCS.ComputeMachineType) - } else if profile.ComputeMachineType != "" { - clusterArgs.ComputeMachineType = helper.StringPointer(profile.ComputeMachineType) - } - - if profile.ComputeReplicas > 0 { - clusterArgs.Replicas = helper.IntPointer(profile.ComputeReplicas) - } - - if profile.ChannelGroup != "" { - clusterArgs.ChannelGroup = helper.StringPointer(profile.ChannelGroup) - } - - if profile.Ec2MetadataHttpTokens != "" { - clusterArgs.Ec2MetadataHttpTokens = helper.StringPointer(profile.Ec2MetadataHttpTokens) - } - - if profile.Region == "" { - profile.Region = constants.DefaultAWSRegion - } - - if profile.Labeling { - clusterArgs.DefaultMPLabels = helper.StringMapPointer(constants.DefaultMPLabels) - } - - if profile.Tagging { - clusterArgs.Tags = helper.StringMapPointer(constants.Tags) - } - - if profile.AdminEnabled { - userName := constants.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) - if err != nil { - Logger.Error("Error happens when try to record the admin password") - return - } - Logger.Info("Admin password is written to the output directory") - - } - - if profile.AuditLogForward { - // ToDo - } - var clusterName string - if constants.RHCS.RHCSClusterName != "" { - clusterName = constants.RHCS.RHCSClusterName - } else if profile.ClusterName != "" { - clusterName = profile.ClusterName - } else { - // Generate random chars later cluster name with profile name - name := helper.GenerateClusterName(profile.Name) - clusterName = name - } - - // There are some problem for cluster created with name length - // longer than 15 chars with auto generated domain prefix - if profile.DomainPrefix == "" && profile.SharedVpc && len(clusterName) > 15 { - profile.DomainPrefix = helper.GenerateRandomName("shared-vpc", 4) - } - - clusterArgs.ClusterName = &clusterName - err = os.WriteFile(cfg.ClusterNameFile, []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) - // short and re-generate the clusterName when it is longer than 15 chars - if profile.DomainPrefix != "" { - clusterArgs.DomainPrefix = &profile.DomainPrefix - } - if profile.Region != "" { - clusterArgs.AWSRegion = &profile.Region - } else { - clusterArgs.AWSRegion = &constants.DefaultAWSRegion - } - - if profile.STS { - majorVersion := GetMajorVersion(profile.Version) - var accountRolesOutput *exec.AccountRolesOutput - var oidcOutput *exec.OIDCProviderOperatorRolesOutput - - shared_vpc_role_arn := "" - if profile.SharedVpc { - // FIXME: - // To create Shared-VPC compatible policies, we need to pass a role arn to create_account_roles module. - // But we got an chicken-egg prolems here: - // * The Shared-VPC compatible policie requries installer role - // * The install role (account roles) require Shared-VPC ARN. - // Use hardcode as a temporary solution. - shared_vpc_role_arn = fmt.Sprintf("arn:aws:iam::641733028092:role/%s-shared-vpc-role", *clusterArgs.ClusterName) - } - accountRolesOutput, err = PrepareAccountRoles(token, *clusterArgs.ClusterName, profile.UnifiedAccRolesPath, *clusterArgs.AWSRegion, majorVersion, profile.ChannelGroup, profile.GetClusterType(), shared_vpc_role_arn) - if err != nil { - return - } - clusterArgs.AccountRolePrefix = helper.StringPointer(accountRolesOutput.AccountRolePrefix) - clusterArgs.UnifiedAccRolesPath = helper.StringPointer(profile.UnifiedAccRolesPath) - Logger.Infof("Created account roles with prefix %s", accountRolesOutput.AccountRolePrefix) - - Logger.Infof("Sleep for 10 sec to let aws account role async creation finished") - time.Sleep(10 * time.Second) - - oidcOutput, err = PrepareOIDCProviderAndOperatorRoles(token, profile.OIDCConfig, *clusterArgs.ClusterName, accountRolesOutput.AccountRolePrefix, profile.UnifiedAccRolesPath, profile.GetClusterType(), *clusterArgs.AWSRegion) - if err != nil { - return - } - clusterArgs.OIDCConfigID = &oidcOutput.OIDCConfigID - clusterArgs.OperatorRolePrefix = &oidcOutput.OperatorRolePrefix - - cluster_aws_account = accountRolesOutput.AWSAccountId - installer_role_arn = accountRolesOutput.InstallerRoleArn - ingress_role_arn = oidcOutput.IngressOperatorRoleArn - } - - if profile.BYOVPC { - var zones []string - var vpcOutput *exec.VPCOutput - var sgIDs []string - - // 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"), ",") - clusterArgs.AWSAvailabilityZones = &azs - clusterArgs.AWSSubnetIDs = &subnetIDs - } else { - if profile.Zones != "" { - zones = strings.Split(profile.Zones, ",") - } - - shared_vpc_aws_shared_credentials_file := "" - - if 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")) - } - - shared_vpc_aws_shared_credentials_file = constants.SharedVpcAWSSharedCredentialsFileENV - } - vpcOutput, err = PrepareVPC(profile.Region, profile.MultiAZ, zones, profile.GetClusterType(), *clusterArgs.ClusterName, shared_vpc_aws_shared_credentials_file) - if err != nil { - return - } - - if vpcOutput.PrivateSubnets == nil { - err = fmt.Errorf("error when creating the vpc, check the previous log. The created resources had been destroyed") - return - } - if profile.Private { - clusterArgs.Private = helper.BoolPointer(profile.Private) - clusterArgs.PrivateLink = helper.BoolPointer(profile.PrivateLink) - if profile.IsPrivateLink() { - clusterArgs.AWSSubnetIDs = &vpcOutput.PrivateSubnets - } - } else { - subnetIDs := vpcOutput.PrivateSubnets - subnetIDs = append(subnetIDs, vpcOutput.PublicSubnets...) - clusterArgs.AWSSubnetIDs = &subnetIDs - } - - if profile.SharedVpc { - // Base domain - var base_dns_domain string - base_dns_domain, err = PrepareRoute53() - if err != nil { - return - } - - // Resources for Shared-VPC - var sharedVpcPolicyAndHostedZoneOutput *exec.SharedVpcPolicyAndHostedZoneOutput - sharedVpcPolicyAndHostedZoneOutput, err = PrepareSharedVpcPolicyAndHostedZone( - profile.Region, - constants.SharedVpcAWSSharedCredentialsFileENV, - *clusterArgs.ClusterName, - base_dns_domain, - ingress_role_arn, - installer_role_arn, - cluster_aws_account, - vpcOutput.VPCID, - *clusterArgs.AWSSubnetIDs, - profile.DomainPrefix) - if err != nil { - return - } - - clusterArgs.BaseDnsDomain = helper.StringPointer(base_dns_domain) - private_hosted_zone := exec.PrivateHostedZone{ - ID: sharedVpcPolicyAndHostedZoneOutput.HostedZoneId, - RoleArn: sharedVpcPolicyAndHostedZoneOutput.SharedRole, - } - clusterArgs.PrivateHostedZone = &private_hosted_zone - /* - The AZ us-east-1a for VPC-account might not have the same location as us-east-1a for Cluster-account. - For AZs which will be used in cluster configuration, the values should be the ones in Cluster-account. - */ - clusterArgs.AWSAvailabilityZones = &sharedVpcPolicyAndHostedZoneOutput.AvailabilityZones - } else { - clusterArgs.AWSAvailabilityZones = &vpcOutput.AvailabilityZones - } - - clusterArgs.MachineCIDR = helper.StringPointer(vpcOutput.VPCCIDR) - if profile.AdditionalSGNumber != 0 { - // Prepare profile.AdditionalSGNumber+5 security groups for negative testing - sgIDs, err = PrepareAdditionalSecurityGroups(profile.Region, vpcOutput.VPCID, profile.AdditionalSGNumber+5) - if err != nil { - return - } - clusterArgs.AdditionalComputeSecurityGroups = helper.StringSlicePointer(sgIDs[0:profile.AdditionalSGNumber]) - clusterArgs.AdditionalInfraSecurityGroups = helper.StringSlicePointer(sgIDs[0:profile.AdditionalSGNumber]) - clusterArgs.AdditionalControlPlaneSecurityGroups = helper.StringSlicePointer(sgIDs[0:profile.AdditionalSGNumber]) - } - - // in case Proxy is enabled - if profile.Proxy { - var proxyOutput *exec.ProxyOutput - proxyOutput, err = PrepareProxy(profile.Region, vpcOutput.VPCID, vpcOutput.PublicSubnets[0], *clusterArgs.ClusterName) - if err != nil { - return - } - proxy := exec.Proxy{ - AdditionalTrustBundle: &proxyOutput.AdditionalTrustBundle, - HTTPSProxy: &proxyOutput.HttpsProxy, - HTTPProxy: &proxyOutput.HttpProxy, - NoProxy: &proxyOutput.NoProxy, - } - clusterArgs.Proxy = &proxy - } - } - } - - // Prepare KMS key if needed - if profile.Etcd || profile.KMSKey { - var kmskey string - kmskey, err = PrepareKMSKey(constants.KMSDir, profile, *clusterArgs.ClusterName, *clusterArgs.AccountRolePrefix, profile.UnifiedAccRolesPath, profile.GetClusterType()) - if err != nil { - return - } - - if profile.Etcd { - clusterArgs.Etcd = &profile.Etcd - clusterArgs.EtcdKmsKeyARN = helper.StringPointer(kmskey) - } - if profile.KMSKey { - clusterArgs.KmsKeyARN = &kmskey - if profile.GetClusterType().HCP { - if profile.DifferentEncryptionKeys { - var etcdKMSKeyArn string - etcdKMSKeyArn, err = PrepareKMSKey(constants.KMSSecondDir, profile, fmt.Sprintf("%s-2", *clusterArgs.ClusterName), *clusterArgs.AccountRolePrefix, profile.UnifiedAccRolesPath, profile.GetClusterType()) - if err != nil { - return - } - clusterArgs.EtcdKmsKeyARN = helper.StringPointer(etcdKMSKeyArn) - } - } - - } - } - - if profile.MachineCIDR != "" { - clusterArgs.MachineCIDR = helper.StringPointer(profile.MachineCIDR) - } - if profile.ServiceCIDR != "" { - clusterArgs.ServiceCIDR = helper.StringPointer(profile.ServiceCIDR) - } - if profile.PodCIDR != "" { - clusterArgs.PodCIDR = helper.StringPointer(profile.PodCIDR) - } - if profile.HostPrefix > 0 { - clusterArgs.HostPrefix = helper.IntPointer(profile.HostPrefix) - } - - if profile.WorkerDiskSize != 0 { - clusterArgs.WorkerDiskSize = helper.IntPointer(profile.WorkerDiskSize) - } - clusterArgs.UnifiedAccRolesPath = helper.StringPointer(profile.UnifiedAccRolesPath) - clusterArgs.CustomProperties = helper.StringMapPointer(constants.CustomProperties) // id:72450 - - if profile.FullResources { - clusterArgs.FullResources = helper.BoolPointer(true) - } - if profile.DontWaitForCluster { - clusterArgs.WaitForCluster = helper.BoolPointer(false) - } - return clusterArgs, err -} - -func LoadProfileYamlFile(profileName string) *Profile { - p, err := helper.GetProfile(profileName, GetYAMLProfilesDir()) - Expect(err).ToNot(HaveOccurred()) - Logger.Infof("Loaded cluster profile configuration from profile %s : %v", profileName, p.Cluster) - profile := Profile{ - Name: profileName, - } - err = helper.MapStructure(p.Cluster, &profile) - Expect(err).ToNot(HaveOccurred()) - return &profile -} - -func LoadProfileYamlFileByENV() *Profile { - profileEnv := os.Getenv(constants.RhcsClusterProfileENV) - if profileEnv == "" { - panic(fmt.Errorf("ENV Variable CLUSTER_PROFILE is empty, please make sure you set the env value")) - } - profile := LoadProfileYamlFile(profileEnv) - - // 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") - } - return profile -} - -func CreateRHCSClusterByProfile(token string, profile *Profile) (string, error) { - creationArgs, err := GenerateClusterCreationArgsByProfile(token, profile) - if err != nil { - defer DestroyRHCSClusterResourcesByProfile(token, profile) - } - Expect(err).ToNot(HaveOccurred()) - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) - if err != nil { - defer DestroyRHCSClusterResourcesByProfile(token, profile) - } - Expect(err).ToNot(HaveOccurred()) - _, err = clusterService.Apply(creationArgs) - if err != nil { - clusterService.WriteTFVars(creationArgs) - defer DestroyRHCSClusterResourcesByProfile(token, profile) - return "", err - } - clusterOutput, err := clusterService.Output() - if err != nil { - clusterService.WriteTFVars(creationArgs) - defer DestroyRHCSClusterResourcesByProfile(token, profile) - return "", err - } - clusterID := clusterOutput.ClusterID - return clusterID, err -} - -func DestroyRHCSClusterResourcesByProfile(token string, profile *Profile) error { - if os.Getenv("NO_CLUSTER_DESTROY") == "true" { - Logger.Warn("`NO_CLUSTER_DESTROY` is configured, thus no destroy of resources will happen") - return nil - } - - // Destroy cluster - var errs []error - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) - if err != nil { - errs = append(errs, err) - } else { - _, err = clusterService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - // Get the cluster name from backend to double check cluster deleted - clusterName, _ := helper.ReadFile(cfg.ClusterNameFile) - Logger.Infof("Double checking with the cluster name %s", clusterName) - if clusterName != "" { - parameter := map[string]interface{}{ - "search": fmt.Sprintf("name is '%s'", clusterName), - } - resp, err := cms.ListClusters(RHCSConnection, parameter) - if err != nil { - errs = append(errs, err) - } else { - if resp.Size() != 0 { - Logger.Infof("Got the matched cluster with name %s, deleting via connection directly", - clusterName) - _, err = cms.DeleteCluster(RHCSConnection, resp.Items().Get(0).ID()) - if err != nil { - errs = append(errs, err) - } else { - err = cms.WaitClusterDeleted(RHCSConnection, resp.Items().Get(0).ID()) - if err != nil { - errs = append(errs, err) - } - } - - } - } - } - - // Destroy VPC - if profile.BYOVPC { - if profile.Proxy { - proxyService, err := exec.NewProxyService() - if err != nil { - errs = append(errs, err) - } else { - _, err = proxyService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - } - if profile.AdditionalSGNumber != 0 { - sgService, err := exec.NewSecurityGroupService() - if err != nil { - errs = append(errs, err) - } else { - _, err = sgService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - } - - if profile.SharedVpc { - sharedVpcPolicyAndHostedZoneService, err := exec.NewSharedVpcPolicyAndHostedZoneService() - if err != nil { - errs = append(errs, err) - } else { - _, err = sharedVpcPolicyAndHostedZoneService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - - // DNS domain - dnsDomainService, err := exec.NewDnsDomainService() - if err != nil { - errs = append(errs, err) - } else { - _, err = dnsDomainService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - } - - vpcService, _ := exec.NewVPCService(constants.GetAWSVPCDefaultManifestDir(profile.GetClusterType())) - if err != nil { - errs = append(errs, err) - } else { - _, err = vpcService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - } - if profile.STS { - // Destroy oidc and operator roles - oidcOpService, err := exec.NewOIDCProviderOperatorRolesService(constants.GetOIDCProviderOperatorRolesDefaultManifestDir(profile.GetClusterType())) - if err != nil { - errs = append(errs, err) - } else { - _, err = oidcOpService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - - // Destroy Account roles - accService, err := exec.NewAccountRoleService(constants.GetAccountRoleDefaultManifestDir(profile.GetClusterType())) - if err != nil { - errs = append(errs, err) - } else { - _, err = accService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - - } - if profile.KMSKey || profile.Etcd { - //Destroy KMS Key - kmsService, err := exec.NewKMSService(constants.KMSDir) - if err != nil { - errs = append(errs, err) - } else { - _, err = kmsService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - - if profile.DifferentEncryptionKeys { - kmsService, err = exec.NewKMSService(constants.KMSSecondDir) - if err != nil { - errs = append(errs, err) - } else { - _, err = kmsService.Destroy() - if err != nil { - errs = append(errs, err) - } - } - } - } - if len(errs) > 0 { - return errors.Join(errs...) - } - return nil -} - -// PrepareRHCSClusterByProfileENV will be used for all day2 tests. -// Do not need to create a cluster, 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 PrepareRHCSClusterByProfileENV() (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 - } - profile := LoadProfileYamlFileByENV() - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) - if err != nil { - return "", err - } - clusterOutput, err := clusterService.Output() - clusterID := clusterOutput.ClusterID - return clusterID, err -} - -func (profile *Profile) GetClusterType() constants.ClusterType { - return constants.FindClusterType(profile.ClusterType) -} - -func (profile *Profile) GetClusterManifestsDir() string { - manifestsDir := constants.GetClusterManifestsDir(profile.GetClusterType()) - return manifestsDir -} - -func (profile *Profile) IsPrivateLink() bool { - if profile.GetClusterType().HCP { - return profile.Private - } else { - return profile.PrivateLink - } -} - -func GetRandomProfile(clusterTypes ...constants.ClusterType) (profile *Profile, err error) { - if len(clusterTypes) > 0 { - Logger.Infof("Get random profile for cluster types: %v", clusterTypes) - } else { - Logger.Info("Get random profile from all profiles") - } - - profilesMap, err := helper.ParseProfiles(GetYAMLProfilesDir()) - if err != nil { - return - } - profilesNames := make([]string, 0, len(profilesMap)) - for k, v := range profilesMap { - clusterType := constants.FindClusterType(fmt.Sprintf("%v", v.Cluster["cluster_type"])) - if !v.NeedSpecificConfig { - if len(clusterTypes) <= 0 || slices.Contains(clusterTypes, clusterType) { - profilesNames = append(profilesNames, k) - } - } - } - Logger.Debugf("Got profile names %v", profilesNames) - profileName := profilesMap[profilesNames[helper.RandomInt(len(profilesNames))]].Name - profile = LoadProfileYamlFile(profileName) - Logger.Debugf("Choose profile: %s", profile.Name) - return profile, err -} diff --git a/tests/e2e/account_roles_test.go b/tests/e2e/account_roles_test.go index 35405270..b873b87f 100644 --- a/tests/e2e/account_roles_test.go +++ b/tests/e2e/account_roles_test.go @@ -8,25 +8,31 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "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" ) var _ = Describe("Edit Account roles", func() { // To improve with OCM-8602 defer GinkgoRecover() - var err error - var profile *ci.Profile - var accService exec.AccountRoleService + var ( + accService exec.AccountRoleService + profileHandler profilehandler.ProfileHandler + ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() Expect(err).ToNot(HaveOccurred()) - accService, err = exec.NewAccountRoleService(constants.GetAddAccountRoleDefaultManifestDir(profile.GetClusterType())) + accTFWorkspace := helper.GenerateRandomName("add-"+profileHandler.Profile().GetName(), 2) + accService, err = exec.NewAccountRoleService(accTFWorkspace, profileHandler.Profile().GetClusterType()) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { @@ -37,7 +43,7 @@ var _ = Describe("Edit Account roles", func() { By("Create account roles with empty prefix") args := &exec.AccountRolesArgs{ AccountRolePrefix: helper.EmptyStringPointer, - OpenshiftVersion: helper.StringPointer(profile.MajorVersion), + OpenshiftVersion: helper.StringPointer(profileHandler.Profile().GetMajorVersion()), } _, err := accService.Apply(args) Expect(err).ToNot(HaveOccurred()) @@ -48,7 +54,7 @@ var _ = Describe("Edit Account roles", func() { By("Create account roles with no prefix defined") args = &exec.AccountRolesArgs{ AccountRolePrefix: nil, - OpenshiftVersion: helper.StringPointer(profile.MajorVersion), + OpenshiftVersion: helper.StringPointer(profileHandler.Profile().GetMajorVersion()), } _, err = accService.Apply(args) Expect(err).ToNot(HaveOccurred()) @@ -61,7 +67,7 @@ var _ = Describe("Edit Account roles", func() { It("can delete account roles via account-role module - [id:63316]", ci.Day2, ci.Critical, func() { args := &exec.AccountRolesArgs{ AccountRolePrefix: helper.StringPointer("OCP-63316"), - OpenshiftVersion: helper.StringPointer(profile.MajorVersion), + OpenshiftVersion: helper.StringPointer(profileHandler.Profile().GetMajorVersion()), } _, err := accService.Apply(args) Expect(err).ToNot(HaveOccurred()) @@ -71,34 +77,39 @@ var _ = Describe("Edit Account roles", func() { }) var _ = Describe("Create Account roles with shared vpc role", ci.Exclude, func() { - // TODO Should be re-enabled with OCM-8602 and usage of different workspaces - // Else this test does alter the account role and VPC configuration ... defer GinkgoRecover() - var err error - var profile *ci.Profile - var accService exec.AccountRoleService - var oidcOpService exec.OIDCProviderOperatorRolesService - var dnsService exec.DnsDomainService - var vpcService exec.VPCService - var sharedVPCService exec.SharedVpcPolicyAndHostedZoneService + var ( + profileHandler profilehandler.ProfileHandler + accService exec.AccountRoleService + oidcOpService exec.OIDCProviderOperatorRolesService + dnsService exec.DnsDomainService + vpcService exec.VPCService + sharedVPCService exec.SharedVpcPolicyAndHostedZoneService + ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() + tempWorkspace := helper.GenerateRandomName("ocp-67574"+profileHandler.Profile().GetName(), 2) + Logger.Infof("Using temp workspace '%s' for creating resources", tempWorkspace) + + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() Expect(err).ToNot(HaveOccurred()) - accService, err = exec.NewAccountRoleService(constants.GetAccountRoleDefaultManifestDir(profile.GetClusterType())) + clusterType := profileHandler.Profile().GetClusterType() + + accService, err = exec.NewAccountRoleService(tempWorkspace, clusterType) Expect(err).ToNot(HaveOccurred()) - oidcOpService, err = exec.NewOIDCProviderOperatorRolesService(constants.GetOIDCProviderOperatorRolesDefaultManifestDir(profile.GetClusterType())) + oidcOpService, err = exec.NewOIDCProviderOperatorRolesService(tempWorkspace, clusterType) Expect(err).ToNot(HaveOccurred()) - dnsService, err = exec.NewDnsDomainService() + dnsService, err = exec.NewDnsDomainService(tempWorkspace, clusterType) Expect(err).ToNot(HaveOccurred()) - vpcService, err = exec.NewVPCService(constants.GetAWSVPCDefaultManifestDir(profile.GetClusterType())) + vpcService, err = exec.NewVPCService(tempWorkspace, clusterType) Expect(err).ToNot(HaveOccurred()) - sharedVPCService, err = exec.NewSharedVpcPolicyAndHostedZoneService() + sharedVPCService, err = exec.NewSharedVpcPolicyAndHostedZoneService(tempWorkspace, clusterType) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { @@ -110,13 +121,13 @@ var _ = Describe("Create Account roles with shared vpc role", ci.Exclude, func() }) It("create and destroy account roles for shared vpc - [id:67574]", ci.Day2, ci.Medium, func() { - if profile.GetClusterType().HCP { + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } By("Create account role without shared vpc role arn") accArgs := &exec.AccountRolesArgs{ - AccountRolePrefix: helper.StringPointer("OCP-67574"), - OpenshiftVersion: helper.StringPointer(profile.MajorVersion), + AccountRolePrefix: helper.StringPointer(helper.GenerateRandomName("OCP-67574", 2)), + OpenshiftVersion: helper.StringPointer(profileHandler.Profile().GetMajorVersion()), } _, err := accService.Apply(accArgs) Expect(err).ToNot(HaveOccurred()) @@ -128,7 +139,7 @@ var _ = Describe("Create Account roles with shared vpc role", ci.Exclude, func() oidcOpArgs := &exec.OIDCProviderOperatorRolesArgs{ AccountRolePrefix: helper.StringPointer(accRoleOutput.AccountRolePrefix), OperatorRolePrefix: helper.StringPointer(accRoleOutput.AccountRolePrefix), - OIDCConfig: helper.StringPointer(profile.OIDCConfig), + OIDCConfig: helper.StringPointer(profileHandler.Profile().GetOIDCConfig()), } _, err = oidcOpService.Apply(oidcOpArgs) Expect(err).ToNot(HaveOccurred()) @@ -152,7 +163,7 @@ var _ = Describe("Create Account roles with shared vpc role", ci.Exclude, func() clusterName := "OCP-67574" vpcArgs := &exec.VPCArgs{ NamePrefix: helper.StringPointer(clusterName), - AWSRegion: helper.StringPointer(profile.Region), + AWSRegion: helper.StringPointer(profileHandler.Profile().GetRegion()), VPCCIDR: helper.StringPointer(constants.DefaultVPCCIDR), AWSSharedCredentialsFiles: helper.StringSlicePointer([]string{constants.SharedVpcAWSSharedCredentialsFileENV}), } @@ -162,7 +173,7 @@ var _ = Describe("Create Account roles with shared vpc role", ci.Exclude, func() Expect(err).ToNot(HaveOccurred()) sharedVPCArgs := &exec.SharedVpcPolicyAndHostedZoneArgs{ SharedVpcAWSSharedCredentialsFiles: helper.StringSlicePointer([]string{constants.SharedVpcAWSSharedCredentialsFileENV}), - Region: helper.StringPointer(profile.Region), + Region: helper.StringPointer(profileHandler.Profile().GetRegion()), ClusterName: helper.StringPointer(clusterName), DnsDomainId: helper.StringPointer(dnsDomainOutput.DnsDomainId), IngressOperatorRoleArn: helper.StringPointer(oidcOpOutput.IngressOperatorRoleArn), @@ -179,7 +190,7 @@ var _ = Describe("Create Account roles with shared vpc role", ci.Exclude, func() By("Add shared vpc role arn to account role") accArgs = &exec.AccountRolesArgs{ AccountRolePrefix: helper.StringPointer(accRoleOutput.AccountRolePrefix), - OpenshiftVersion: helper.StringPointer(profile.MajorVersion), + OpenshiftVersion: helper.StringPointer(profileHandler.Profile().GetMajorVersion()), SharedVpcRoleArn: helper.StringPointer(sharedVPCOutput.SharedRole), } _, err = accService.Apply(accArgs) diff --git a/tests/e2e/classic_ingress_test.go b/tests/e2e/classic_ingress_test.go index 2fb839dc..2637ed57 100644 --- a/tests/e2e/classic_ingress_test.go +++ b/tests/e2e/classic_ingress_test.go @@ -11,31 +11,33 @@ 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/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" ) var _ = Describe("Classic Ingress", ci.FeatureIngress, func() { var ( - profile *ci.Profile + profileHandler profilehandler.ProfileHandler err error ingressBefore *cmsv1.Ingress ingressService exec.IngressService ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) - if profile.GetClusterType().HCP { + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } - ingressBefore, err = cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingressBefore, err = cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) - ingressService, err = exec.NewIngressService(constants.ClassicIngressDir) + ingressService, err = profileHandler.Services().GetIngressService() Expect(err).ToNot(HaveOccurred()) }) @@ -91,7 +93,7 @@ var _ = Describe("Classic Ingress", ci.FeatureIngress, func() { Expect(err).ToNot(HaveOccurred()) By("use API to check if ingress LB type updated") - ingress, err := cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err := cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(string(ingress.LoadBalancerType())).To(Equal("classic")) @@ -103,7 +105,7 @@ var _ = Describe("Classic Ingress", ci.FeatureIngress, func() { } _, err = ingressService.Apply(&args) Expect(err).ToNot(HaveOccurred()) - ingress, err = cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err = cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(string(ingress.LoadBalancerType())).To(Equal("nlb")) }) @@ -135,7 +137,7 @@ var _ = Describe("Classic Ingress", ci.FeatureIngress, func() { Expect(err).ToNot(HaveOccurred()) By("use ocm API to check if component routes updated") - ingress, err := cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err := cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(ingress.ComponentRoutes()["oauth"].Hostname()).To(Equal(*componentRoutes["oauth"].Hostname)) Expect(ingress.ComponentRoutes()["oauth"].TlsSecretRef()).To(Equal(*componentRoutes["oauth"].TlsSecretRef)) @@ -167,7 +169,7 @@ var _ = Describe("Classic Ingress", ci.FeatureIngress, func() { Expect(err).ToNot(HaveOccurred()) By("use ocm API to check if component routes updated") - ingress, err = cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err = cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(ingress.ComponentRoutes()["oauth"].Hostname()).To(Equal(*componentRoutes["oauth"].Hostname)) Expect(ingress.ComponentRoutes()["oauth"].TlsSecretRef()).To(Equal(*componentRoutes["oauth"].TlsSecretRef)) @@ -191,7 +193,7 @@ var _ = Describe("Classic Ingress", ci.FeatureIngress, func() { Expect(err).ToNot(HaveOccurred()) By("use ocm API to check if component routes updated") - ingress, err = cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err = cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(ingress.ComponentRoutes()["oauth"].Hostname()).To(Equal(*componentRoutes["oauth"].Hostname)) Expect(ingress.ComponentRoutes()["oauth"].TlsSecretRef()).To(Equal(*componentRoutes["oauth"].TlsSecretRef)) @@ -207,7 +209,7 @@ var _ = Describe("Classic Ingress", ci.FeatureIngress, func() { Expect(err).ToNot(HaveOccurred()) By("use ocm API to check if component routes deleted") - ingress, err = cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err = cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(len(ingress.ComponentRoutes())).To(Equal(0)) }) @@ -354,7 +356,7 @@ var _ = Describe("Classic Ingress", ci.FeatureIngress, func() { Expect(err).ToNot(HaveOccurred()) By("use ocm API to check if ingress config updated") - ingress, err := cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err := cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(string(ingress.RouteNamespaceOwnershipPolicy())).To(Equal(*args.RouteNamespaceOwnershipPolicy)) Expect(string(ingress.RouteWildcardPolicy())).To(Equal(*args.RouteWildcardPolicy)) diff --git a/tests/e2e/classic_machine_pool_test.go b/tests/e2e/classic_machine_pool_test.go index 7e473e4b..c0f6702b 100644 --- a/tests/e2e/classic_machine_pool_test.go +++ b/tests/e2e/classic_machine_pool_test.go @@ -16,24 +16,30 @@ import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" exe "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" + + "github.com/openshift-online/ocm-common/pkg/aws/aws_client" + "github.com/openshift-online/ocm-common/pkg/test/vpc_client" ) var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { defer GinkgoRecover() var ( - mpService exec.MachinePoolService - profile *ci.Profile + mpService exec.MachinePoolService + profileHandler profilehandler.ProfileHandler ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() - if profile.GetClusterType().HCP { + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } - var err error - mpService, err = exec.NewMachinePoolService(constants.ClassicMachinePoolDir) + mpService, err = profileHandler.Services().GetMachinePoolsService() Expect(err).ToNot(HaveOccurred()) }) @@ -64,7 +70,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(len(mpsOut.MachinePools)).To(Equal(1)) mpOut := mpsOut.MachinePools[0] - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Replicas()).To(Equal(mpOut.Replicas)) Expect(mpResponseBody.InstanceType()).To(Equal(mpOut.MachineType)) @@ -92,7 +98,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Labels()).To(Equal(creationLabels)) @@ -100,7 +106,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { mpArgs.Labels = helper.StringMapPointer(updatingLabels) _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Labels()).To(Equal(updatingLabels)) @@ -110,7 +116,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the updated machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Labels()).To(BeNil()) }) @@ -135,7 +141,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling().MinReplicas()).To(Equal(minReplicas)) Expect(mpResponseBody.Autoscaling().MaxReplicas()).To(Equal(maxReplicas)) @@ -149,7 +155,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the updated machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling().MinReplicas()).To(Equal(minReplicas)) Expect(mpResponseBody.Autoscaling().MaxReplicas()).To(Equal(maxReplicas)) @@ -166,7 +172,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the updated machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling()).To(BeNil()) }) @@ -192,7 +198,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) respTaints := mpResponseBody.Taints() for index, taint := range respTaints { @@ -214,7 +220,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the updated machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) respTaints = mpResponseBody.Taints() for index, taint := range respTaints { @@ -229,7 +235,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the updated machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Taints()).To(BeNil()) }) @@ -318,7 +324,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err.Error()).Should(ContainSubstring("when\ndisabling autoscaling, cannot set min_replicas and/or max_replicas")) By("Create machinepool with setting min-replicas large than max-replicas") - if profile.MultiAZ { + if profileHandler.Profile().IsMultiAZ() { By("Create machinepool with setting min-replicas and max-replicas not multiple 3 for multi-az") mpArgs = &exec.MachinePoolArgs{ Cluster: helper.StringPointer(clusterID), @@ -348,10 +354,10 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { }) It("can create single-az machinepool for multi-az cluster - [id:65063]", ci.High, func() { - if !profile.MultiAZ { + if !profileHandler.Profile().IsMultiAZ() { Skip("The test is configured for MultiAZ cluster only") } - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) azs := getResp.Body().Nodes().AvailabilityZones() By("Create additional machinepool with availability zone specified") @@ -370,7 +376,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.AvailabilityZones()[0]).To(Equal(azs[0])) @@ -391,7 +397,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Subnets()[0]).To(Equal(awsSubnetIds[0])) @@ -412,30 +418,45 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(len(mpResponseBody.AvailabilityZones())).To(Equal(1)) }) It("can create machinepool with subnet_id option for BYO VPC single-az cluster - [id:65071]", ci.High, func() { - if profile.MultiAZ || !profile.BYOVPC { + if profileHandler.Profile().IsMultiAZ() || !profileHandler.Profile().IsBYOVPC() { Skip("The test is configured for SingleAZ BYO VPC cluster only") } - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + By("Retrieve current availability Zone") + vpcService, err := profileHandler.Services().GetVPCService() Expect(err).ToNot(HaveOccurred()) - var zones []string - vpcOutput, err := ci.PrepareVPC(profile.Region, true, zones, profile.GetClusterType(), clusterResp.Body().Name(), "") + vpcOutput, err := vpcService.Output() Expect(err).ToNot(HaveOccurred()) + az := vpcOutput.AvailabilityZones[0] + + By("Add 2 subnets to VPC") + awsClient, err := aws_client.CreateAWSClient("", "") + Expect(err).ToNot(HaveOccurred()) + vpcClient, err := vpc_client.GenerateVPCBySubnet(vpcOutput.PrivateSubnets[0], profileHandler.Profile().GetRegion()) + Expect(err).ToNot(HaveOccurred()) + subnet, err := vpcClient.CreateSubnet(az) + Expect(err).ToNot(HaveOccurred()) + defer func() { + By("Remove added subnet from VPC") + awsClient.DeleteSubnet(subnet.ID) + }() By("Tag new subnet to be able to apply it to the machinepool") - vpcTagService, err := exec.NewVPCTagService() + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) + Expect(err).ToNot(HaveOccurred()) + vpcTagService, err := profileHandler.Services().GetVPCTagService() Expect(err).ToNot(HaveOccurred()) tagKey := fmt.Sprintf("kubernetes.io/cluster/%s", clusterResp.Body().InfraID()) tagValue := "shared" VPCTagArgs := &exec.VPCTagArgs{ AWSRegion: helper.StringPointer(clusterResp.Body().Region().ID()), - IDs: helper.StringSlicePointer(vpcOutput.PrivateSubnets), + IDs: helper.StringSlicePointer(append(vpcOutput.PrivateSubnets, subnet.ID)), TagKey: helper.StringPointer(tagKey), TagValue: helper.StringPointer(tagValue), } @@ -446,20 +467,21 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { replicas := 1 machineType := "r5.xlarge" name := "ocp-65071" - newZonePrivateSubnet := vpcOutput.PrivateSubnets[2] + mpArgs := &exec.MachinePoolArgs{ Cluster: helper.StringPointer(clusterID), Replicas: helper.IntPointer(replicas), MachineType: helper.StringPointer(machineType), Name: helper.StringPointer(name), - SubnetID: helper.StringPointer(newZonePrivateSubnet), + SubnetID: helper.StringPointer(subnet.ID), } _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) + defer mpService.Destroy() - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) - Expect(mpResponseBody.Subnets()[0]).To(Equal(newZonePrivateSubnet)) + Expect(mpResponseBody.Subnets()[0]).To(Equal(subnet.ID)) replicas = 4 mpArgs.Replicas = helper.IntPointer(replicas) @@ -467,7 +489,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the updated machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Replicas()).To(Equal(4)) }) @@ -494,7 +516,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { }() By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.RootVolume().AWS().Size()).To(Equal(diskSize)) Expect(mpResponseBody.InstanceType()).To(Equal(machineType)) @@ -528,29 +550,29 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.RootVolume().AWS().Size()).To(Equal(300)) Expect(mpResponseBody.InstanceType()).To(Equal("m5.2xlarge")) }) It("can create machinepool with additional security group - [id:69146]", ci.High, func() { - if !profile.BYOVPC { + if !profileHandler.Profile().IsBYOVPC() { Skip("This case only works for BYOVPC cluster profile") } By("Prepare additional security groups") - sgService, err := exec.NewSecurityGroupService() + sgService, err := profileHandler.Services().GetSecurityGroupService() Expect(err).ToNot(HaveOccurred()) output, err := sgService.Output() Expect(err).ToNot(HaveOccurred()) if output.SGIDs == nil { - vpcService, err := exec.NewVPCService(constants.GetAWSVPCDefaultManifestDir(profile.GetClusterType())) + vpcService, err := profileHandler.Services().GetVPCService() Expect(err).ToNot(HaveOccurred()) vpcOutput, err := vpcService.Output() Expect(err).ToNot(HaveOccurred()) sgArgs := &exec.SecurityGroupArgs{ - AWSRegion: helper.StringPointer(profile.Region), + AWSRegion: helper.StringPointer(profileHandler.Profile().GetRegion()), VPCID: helper.StringPointer(vpcOutput.VPCID), SGNumber: helper.IntPointer(4), } @@ -587,7 +609,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { }() By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(len(mpResponseBody.AWS().AdditionalSecurityGroupIds())).To(Equal(len(sgIDs))) for _, sg := range mpResponseBody.AWS().AdditionalSecurityGroupIds() { @@ -625,7 +647,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.AWS().AdditionalSecurityGroupIds()).To(BeNil()) Expect(mpResponseBody.InstanceType()).To(Equal("m5.2xlarge")) @@ -652,7 +674,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Check the machinepool detail state") - resp, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, name) + resp, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) for tagKey, tagValue := range validTags { Expect(tagValue).To(BeElementOf(resp.AWS().Tags()[tagKey])) @@ -684,12 +706,12 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - _, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, mpName) + _, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, mpName) Expect(err).ToNot(HaveOccurred()) By("Delete machinepool by OCM API") - cms.DeleteMachinePool(ci.RHCSConnection, clusterID, mpName) - _, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, mpName) + cms.DeleteMachinePool(cms.RHCSConnection, clusterID, mpName) + _, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, mpName) Expect(err).To(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring("Machine pool with id '%s' not found", mpName)) @@ -701,7 +723,7 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, mpName) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, mpName) Expect(err).ToNot(HaveOccurred()) respTaints := mpResponseBody.Taints() for index, taint := range respTaints { @@ -758,20 +780,23 @@ var _ = Describe("Create MachinePool", ci.Day2, ci.FeatureMachinepool, func() { }) var _ = Describe("Import MachinePool", ci.Day2, ci.FeatureImport, func() { + var profileHandler profilehandler.ProfileHandler var mpService exec.MachinePoolService var importService exec.ImportService BeforeEach(func() { - profile := ci.LoadProfileYamlFileByENV() - if profile.GetClusterType().HCP { + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } - var err error - mpService, err = exec.NewMachinePoolService(constants.ClassicMachinePoolDir) + mpService, err = profileHandler.Services().GetMachinePoolsService() Expect(err).ToNot(HaveOccurred()) - importService, err = exec.NewImportService(constants.ImportResourceDir) // init new import service + importService, err = profileHandler.Services().GetImportService() Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { @@ -824,6 +849,7 @@ var _ = Describe("Import MachinePool", ci.Day2, ci.FeatureImport, func() { var _ = Describe("Edit MachinePool", ci.Day2, ci.FeatureMachinepool, func() { var ( + profileHandler profilehandler.ProfileHandler dmpService exec.MachinePoolService mpService exec.MachinePoolService defaultMachinePoolNmae = "worker" @@ -832,18 +858,21 @@ var _ = Describe("Edit MachinePool", ci.Day2, ci.FeatureMachinepool, func() { ) BeforeEach(func() { - profile := ci.LoadProfileYamlFileByENV() - if profile.GetClusterType().HCP { + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } - var err error - dmpService, err = exec.NewMachinePoolService(constants.DefaultMachinePoolDir) + dmpTFWorkspace := helper.GenerateRandomName("dft-"+profileHandler.Profile().GetName(), 2) + dmpService, err = exec.NewMachinePoolService(dmpTFWorkspace, profileHandler.Profile().GetClusterType()) Expect(err).ToNot(HaveOccurred()) - mpService, err = exec.NewMachinePoolService(constants.ClassicMachinePoolDir) + mpService, err = profileHandler.Services().GetMachinePoolsService() Expect(err).ToNot(HaveOccurred()) - defaultMachinepoolResponse, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, defaultMachinePoolNmae) + defaultMachinepoolResponse, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, defaultMachinePoolNmae) if err != nil && strings.Contains(err.Error(), fmt.Sprintf("Machine pool with id '%s' not found", defaultMachinePoolNmae)) { Skip("The default machinepool does not exist") } @@ -901,7 +930,7 @@ var _ = Describe("Edit MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(out).To(ContainSubstring("machine_type, cannot be changed")) By("Delete dmp without additional mp exists") - resp, err := cms.ListMachinePool(ci.RHCSConnection, clusterID) + resp, err := cms.ListMachinePool(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(resp.Total()).To(Equal(1), "multiple machinepools found") @@ -941,7 +970,7 @@ var _ = Describe("Edit MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, defaultMPName) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, defaultMPName) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling().MinReplicas()).To(Equal(minReplicas)) Expect(mpResponseBody.Autoscaling().MaxReplicas()).To(Equal(maxReplicas)) @@ -953,7 +982,7 @@ var _ = Describe("Edit MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, defaultMPName) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, defaultMPName) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Replicas()).To(Equal(replicas)) } @@ -965,7 +994,7 @@ var _ = Describe("Edit MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, defaultMPName) + mpResponseBody, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, defaultMPName) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Labels()).To(Equal(creationLabels)) @@ -990,7 +1019,7 @@ var _ = Describe("Edit MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the default machinepool") - mpResponseBody, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, "worker") + mpResponseBody, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, "worker") Expect(err).ToNot(HaveOccurred()) respTaints := mpResponseBody.Taints() for index, taint := range respTaints { @@ -1004,6 +1033,7 @@ var _ = Describe("Edit MachinePool", ci.Day2, ci.FeatureMachinepool, func() { var _ = Describe("Destroy MachinePool", ci.Day3, ci.FeatureMachinepool, func() { var ( + profileHandler profilehandler.ProfileHandler dmpService exec.MachinePoolService defaultMachinePoolArgs *exec.MachinePoolArgs mpService exec.MachinePoolService @@ -1012,25 +1042,28 @@ var _ = Describe("Destroy MachinePool", ci.Day3, ci.FeatureMachinepool, func() { ) BeforeEach(func() { - profile := ci.LoadProfileYamlFileByENV() - if profile.GetClusterType().HCP { + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } - var err error - dmpService, err = exec.NewMachinePoolService(constants.DefaultMachinePoolDir) + dmpTFWorkspace := helper.GenerateRandomName("dft-"+profileHandler.Profile().GetName(), 2) + dmpService, err = exec.NewMachinePoolService(dmpTFWorkspace, profileHandler.Profile().GetClusterType()) Expect(err).ToNot(HaveOccurred()) - mpService, err = exec.NewMachinePoolService(constants.ClassicMachinePoolDir) + mpService, err = profileHandler.Services().GetMachinePoolsService() Expect(err).ToNot(HaveOccurred()) - defaultMachinepoolResponse, err = cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, defaultMachinePoolName) + defaultMachinepoolResponse, err = cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, defaultMachinePoolName) Expect(err).ToNot(HaveOccurred()) defaultMachinePoolArgs = exec.BuildMachinePoolArgsFromCSResponse(clusterID, defaultMachinepoolResponse) defaultMachinePoolName = *defaultMachinePoolArgs.Name By("Make sure the default machinepool imported from cluster state") - imported, _ := helper.CheckDefaultMachinePoolImported() - if !imported { + _, err = dmpService.ShowState("rhcs_machine_pool.mp") + if err != nil { By("Create default machinepool by importing from CMS ") _, err = dmpService.Apply(defaultMachinePoolArgs) Expect(err).ToNot(HaveOccurred()) @@ -1040,7 +1073,7 @@ var _ = Describe("Destroy MachinePool", ci.Day3, ci.FeatureMachinepool, func() { It("check the default machinepool edit/delete operations with additional mp exists it - [id:69727]", ci.Critical, func() { By("Destroy default machinepool without additional machinepool existing") - resp, err := cms.ListMachinePool(ci.RHCSConnection, clusterID) + resp, err := cms.ListMachinePool(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) num, _ := resp.GetSize() Expect(num).To(Equal(1)) diff --git a/tests/e2e/cluster_autoscaler_day2_test.go b/tests/e2e/cluster_autoscaler_day2_test.go index 2c715853..c5ec967c 100644 --- a/tests/e2e/cluster_autoscaler_day2_test.go +++ b/tests/e2e/cluster_autoscaler_day2_test.go @@ -13,23 +13,27 @@ 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/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/log" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var _ = Describe("Cluster Autoscaler", ci.Day2, ci.FeatureClusterAutoscaler, func() { defer GinkgoRecover() - var caService exec.ClusterAutoscalerService - var clusterAutoScalerBodyForRecreate *cmsv1.ClusterAutoscaler - var clusterAutoscalerStatusBefore int - var profile *ci.Profile + var ( + profileHandler profilehandler.ProfileHandler + caService exec.ClusterAutoscalerService + clusterAutoScalerBodyForRecreate *cmsv1.ClusterAutoscaler + clusterAutoscalerStatusBefore int + ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() - caRetrieveBody, _ := cms.RetrieveClusterAutoscaler(ci.RHCSConnection, clusterID) + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).NotTo(HaveOccurred()) + caRetrieveBody, _ := cms.RetrieveClusterAutoscaler(cms.RHCSConnection, clusterID) clusterAutoscalerStatusBefore = caRetrieveBody.Status() if clusterAutoscalerStatusBefore == http.StatusOK { clusterAutoScalerBodyForRecreate = caRetrieveBody.Body() @@ -37,33 +41,33 @@ var _ = Describe("Cluster Autoscaler", ci.Day2, ci.FeatureClusterAutoscaler, fun }) AfterEach(func() { By("Recover clusterautoscaler") - clusterAutoscalerAfter, _ := cms.RetrieveClusterAutoscaler(ci.RHCSConnection, clusterID) + clusterAutoscalerAfter, _ := cms.RetrieveClusterAutoscaler(cms.RHCSConnection, clusterID) if (clusterAutoscalerAfter.Status() == clusterAutoscalerStatusBefore) && clusterAutoscalerStatusBefore != http.StatusNotFound { - recreateAutoscaler, err := cms.PatchClusterAutoscaler(ci.RHCSConnection, clusterID, clusterAutoScalerBodyForRecreate) + recreateAutoscaler, err := cms.PatchClusterAutoscaler(cms.RHCSConnection, clusterID, clusterAutoScalerBodyForRecreate) Expect(err).NotTo(HaveOccurred()) Expect(recreateAutoscaler.Status()).To(Equal(http.StatusOK)) } else if clusterAutoscalerAfter.Status() == http.StatusOK && clusterAutoscalerStatusBefore == http.StatusNotFound { - deleteAutoscaler, err := cms.DeleteClusterAutoscaler(ci.RHCSConnection, clusterID) + deleteAutoscaler, err := cms.DeleteClusterAutoscaler(cms.RHCSConnection, clusterID) Expect(err).NotTo(HaveOccurred()) Expect(deleteAutoscaler.Status()).To(Equal(http.StatusNoContent)) } else if clusterAutoscalerAfter.Status() == http.StatusNotFound && clusterAutoscalerStatusBefore == http.StatusOK { - recreateAutoscaler, err := cms.CreateClusterAutoscaler(ci.RHCSConnection, clusterID, clusterAutoScalerBodyForRecreate) + recreateAutoscaler, err := cms.CreateClusterAutoscaler(cms.RHCSConnection, clusterID, clusterAutoScalerBodyForRecreate) Expect(err).NotTo(HaveOccurred()) Expect(recreateAutoscaler.Status()).To(Equal(http.StatusCreated)) } }) It("can be added/destroyed to Classic cluster - [id:69137]", ci.High, func() { - if profile.GetClusterType().HCP { + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } var err error - caService, err = exec.NewClusterAutoscalerService(constants.ClassicClusterAutoscalerDir) + caService, err = profileHandler.Services().GetClusterAutoscalerService() Expect(err).NotTo(HaveOccurred()) By("Delete clusterautoscaler when it exists in cluster") if clusterAutoscalerStatusBefore == http.StatusOK { - caDeleteBody, err := cms.DeleteClusterAutoscaler(ci.RHCSConnection, clusterID) + caDeleteBody, err := cms.DeleteClusterAutoscaler(cms.RHCSConnection, clusterID) Expect(err).NotTo(HaveOccurred()) Expect(caDeleteBody.Status()).To(Equal(http.StatusNoContent)) } @@ -124,7 +128,7 @@ var _ = Describe("Cluster Autoscaler", ci.Day2, ci.FeatureClusterAutoscaler, fun By("Verify the parameters of the createdautoscaler") caOut, err := caService.Output() Expect(err).ToNot(HaveOccurred()) - caResponse, err := cms.RetrieveClusterAutoscaler(ci.RHCSConnection, clusterID) + caResponse, err := cms.RetrieveClusterAutoscaler(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(caResponse.Body().BalanceSimilarNodeGroups()).To(Equal(caOut.BalanceSimilarNodeGroups)) Expect(caResponse.Body().SkipNodesWithLocalStorage()).To(Equal(caOut.SkipNodesWithLocalStorage)) @@ -146,17 +150,17 @@ var _ = Describe("Cluster Autoscaler", ci.Day2, ci.FeatureClusterAutoscaler, fun It("can be created/edited/deleted to HCP cluster - [id:72524][id:72525]", ci.High, func() { - if !profile.GetClusterType().HCP { + if !profileHandler.Profile().IsHCP() { Skip("Test can run only on Hosted cluster") } var err error - caService, err = exec.NewClusterAutoscalerService(constants.HCPClusterAutoscalerDir) + caService, err = profileHandler.Services().GetClusterAutoscalerService() Expect(err).NotTo(HaveOccurred()) if clusterAutoscalerStatusBefore == http.StatusOK { By("Delete current cluster autoscaler") - caDeleteBody, err := cms.DeleteClusterAutoscaler(ci.RHCSConnection, clusterID) + caDeleteBody, err := cms.DeleteClusterAutoscaler(cms.RHCSConnection, clusterID) Expect(err).NotTo(HaveOccurred()) Expect(caDeleteBody.Status()).To(Equal(http.StatusNoContent)) } @@ -220,23 +224,23 @@ var _ = Describe("Cluster Autoscaler", ci.Day2, ci.FeatureClusterAutoscaler, fun Expect(err).ToNot(HaveOccurred()) By("Check autoscaler is gone") - caResponse, err := cms.RetrieveClusterAutoscaler(ci.RHCSConnection, clusterID) + caResponse, err := cms.RetrieveClusterAutoscaler(cms.RHCSConnection, clusterID) Expect(err).To(HaveOccurred()) Expect(caResponse.Status()).To(Equal(http.StatusNotFound)) }) It("can be validated against HCP cluster - [id:72526]", ci.Medium, func() { - if !profile.GetClusterType().HCP { + if !profileHandler.Profile().IsHCP() { Skip("Test can run only on Hosted cluster") } var err error - caService, err = exec.NewClusterAutoscalerService(constants.HCPClusterAutoscalerDir) + caService, err = profileHandler.Services().GetClusterAutoscalerService() Expect(err).NotTo(HaveOccurred()) if clusterAutoscalerStatusBefore == http.StatusOK { By("Delete current cluster autoscaler") - caDeleteBody, err := cms.DeleteClusterAutoscaler(ci.RHCSConnection, clusterID) + caDeleteBody, err := cms.DeleteClusterAutoscaler(cms.RHCSConnection, clusterID) Expect(err).NotTo(HaveOccurred()) Expect(caDeleteBody.Status()).To(Equal(http.StatusNoContent)) } @@ -269,7 +273,7 @@ var _ = Describe("Cluster Autoscaler", ci.Day2, ci.FeatureClusterAutoscaler, fun Expect(err).ToNot(HaveOccurred()) By("Try to edit cluster with other cluster ID") - clustersResp, err := cms.ListClusters(ci.RHCSConnection) + clustersResp, err := cms.ListClusters(cms.RHCSConnection) Expect(err).ToNot(HaveOccurred()) var otherClusterID string for _, cluster := range clustersResp.Items().Slice() { diff --git a/tests/e2e/cluster_creation_test.go b/tests/e2e/cluster_creation_test.go index 9561e9c4..0613c103 100644 --- a/tests/e2e/cluster_creation_test.go +++ b/tests/e2e/cluster_creation_test.go @@ -14,43 +14,44 @@ import ( "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/openshift" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var _ = Describe("Create cluster", func() { It("CreateClusterByProfile", ci.Day1Prepare, func() { - // Generate/build cluster by profile selected - profile := ci.LoadProfileYamlFileByENV() - clusterID, err := ci.CreateRHCSClusterByProfile(token, profile) + profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + clusterID, err := profileHandler.CreateRHCSClusterByProfile(token) 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" && !profile.Private { + if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profileHandler.Profile().IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 - err = openshift.WaitForOperatorsToBeReady(ci.RHCSConnection, clusterID, timeout) + err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) Expect(err).ToNot(HaveOccurred()) } }) It("Cluster can be recreated if it was not deleted from tf - [id:66071]", ci.Day3, ci.Medium, func() { - - profile := ci.LoadProfileYamlFileByENV() + profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) originalClusterID := clusterID By("Delete cluster via OCM") - resp, err := cms.DeleteCluster(ci.RHCSConnection, clusterID) + resp, err := cms.DeleteCluster(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(resp.Status()).To(Equal(constants.HTTPNoContent)) By("Wait for the cluster deleted from OCM") - err = cms.WaitClusterDeleted(ci.RHCSConnection, clusterID) + err = cms.WaitClusterDeleted(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) By("Create cluster again") - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) clusterArgs, err := clusterService.ReadTFVars() Expect(err).ToNot(HaveOccurred()) @@ -64,12 +65,16 @@ var _ = Describe("Create cluster", func() { It("cluster waiter should fail on error/uninstalling cluster - [id:74472]", ci.Day1Supplemental, ci.Medium, func() { + By("Retrieve random profile") + profileHandler, err := profilehandler.NewRandomProfileHandler() + Expect(err).ToNot(HaveOccurred()) + By("Retrieve cluster with error/uninstalling status") params := map[string]interface{}{ "search": "status.state='error' or status.state='uninstalling'", "size": -1, } - resp, err := cms.ListClusters(ci.RHCSConnection, params) + resp, err := cms.ListClusters(cms.RHCSConnection, params) Expect(err).ToNot(HaveOccurred()) clusters := resp.Items().Slice() @@ -79,7 +84,7 @@ var _ = Describe("Create cluster", func() { cluster := clusters[0] By("Wait for cluster") - cwService, err := exec.NewClusterWaiterService() + cwService, err := profileHandler.Services().GetClusterWaiterService() Expect(err).ToNot(HaveOccurred()) clusterWaiterArgs := exec.ClusterWaiterArgs{ Cluster: helper.StringPointer(cluster.ID()), @@ -93,20 +98,20 @@ var _ = Describe("Create cluster", func() { It("Cluster can be created within internal cluster waiter - [id:74473]", ci.Day1Supplemental, ci.Medium, func() { By("Retrieve random profile") - profile, err := ci.GetRandomProfile() + profileHandler, err := profilehandler.NewRandomProfileHandler() Expect(err).ToNot(HaveOccurred()) By("Retrieve creation args") defer func() { By("Clean resources") - ci.DestroyRHCSClusterResourcesByProfile(token, profile) + profileHandler.DestroyRHCSClusterResources(token) }() - clusterArgs, err := ci.GenerateClusterCreationArgsByProfile(token, profile) + clusterArgs, err := profileHandler.GenerateClusterCreationArgs(token) Expect(err).ToNot(HaveOccurred()) clusterArgs.DisableClusterWaiter = helper.BoolPointer(true) By("Create cluster") - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) _, err = clusterService.Apply(clusterArgs) Expect(err).ToNot(HaveOccurred()) @@ -115,20 +120,20 @@ var _ = Describe("Create cluster", func() { It("Cluster can be created without cluster waiter - [id:74748]", ci.Day1Supplemental, ci.Medium, func() { By("Retrieve random profile") - profile, err := ci.GetRandomProfile() + profileHandler, err := profilehandler.NewRandomProfileHandler() Expect(err).ToNot(HaveOccurred()) By("Retrieve creation args") defer func() { By("Clean resources") - ci.DestroyRHCSClusterResourcesByProfile(token, profile) + profileHandler.DestroyRHCSClusterResources(token) }() - clusterArgs, err := ci.GenerateClusterCreationArgsByProfile(token, profile) + clusterArgs, err := profileHandler.GenerateClusterCreationArgs(token) Expect(err).ToNot(HaveOccurred()) clusterArgs.WaitForCluster = helper.BoolPointer(false) By("Create cluster") - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) _, err = clusterService.Apply(clusterArgs) Expect(err).ToNot(HaveOccurred()) @@ -137,7 +142,7 @@ var _ = Describe("Create cluster", func() { clusterOut, err := clusterService.Output() Expect(err).ToNot(HaveOccurred()) clusterID := clusterOut.ClusterID - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(clusterResp.Body().State()). // we did not wait for the cluster to be ready To( @@ -152,10 +157,11 @@ var _ = Describe("Create cluster", func() { It("HCP Cluster can be destroyed without waiting - [id:72500]", ci.Day3, ci.High, func() { - profile := ci.LoadProfileYamlFileByENV() + profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) By("Retrieve creation args") - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) clusterArgs, err := clusterService.ReadTFVars() Expect(err).ToNot(HaveOccurred()) @@ -173,7 +179,7 @@ var _ = Describe("Create cluster", func() { time.Sleep(5 * time.Second) By("Verify cluster is in uninstalling state") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(clusterResp.Body().State()).To(Equal(v1.ClusterStateUninstalling)) }) diff --git a/tests/e2e/cluster_destroy_test.go b/tests/e2e/cluster_destroy_test.go index c929c8c7..bfef2efc 100644 --- a/tests/e2e/cluster_destroy_test.go +++ b/tests/e2e/cluster_destroy_test.go @@ -7,6 +7,7 @@ import ( . "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/profilehandler" ) var _ = Describe("Delete cluster", func() { @@ -18,8 +19,9 @@ var _ = Describe("Delete cluster", func() { } // Generate/build cluster by profile selected - profile := ci.LoadProfileYamlFileByENV() - err := ci.DestroyRHCSClusterResourcesByProfile(token, profile) + profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + err = profileHandler.DestroyRHCSClusterResources(token) Expect(err).ToNot(HaveOccurred()) }) }) diff --git a/tests/e2e/cluster_edit_test.go b/tests/e2e/cluster_edit_test.go index 9d6325b4..44775e51 100644 --- a/tests/e2e/cluster_edit_test.go +++ b/tests/e2e/cluster_edit_test.go @@ -10,11 +10,12 @@ import ( "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" ) var _ = Describe("Edit cluster", ci.Day2, func() { - var profile *ci.Profile + var profileHandler profilehandler.ProfileHandler var clusterService exec.ClusterService var clusterArgs *exec.ClusterArgs var originalClusterArgs *exec.ClusterArgs @@ -27,13 +28,14 @@ var _ = Describe("Edit cluster", ci.Day2, func() { } BeforeEach(func() { + var err error By("Load profile") - profile = ci.LoadProfileYamlFileByENV() + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ShouldNot(HaveOccurred()) // Initialize the cluster service By("Create cluster service") - var err error - clusterService, err = exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err = profileHandler.Services().GetClusterService() Expect(err).ShouldNot(HaveOccurred()) clusterArgs = retrieveClusterArgs() @@ -46,12 +48,12 @@ var _ = Describe("Edit cluster", ci.Day2, func() { Context("can edit/delete", func() { It("proxy - [id:72489]", ci.High, ci.FeatureClusterProxy, func() { - if !profile.Proxy { + if !profileHandler.Profile().IsProxy() { Skip("No proxy configured") } By("Retrieve Proxy service") - proxyService, err := exec.NewProxyService() + proxyService, err := profileHandler.Services().GetProxyService() Expect(err).ShouldNot(HaveOccurred()) readProxyArgs := func() (*exec.ProxyArgs, error) { @@ -85,7 +87,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { Expect(err).ShouldNot(HaveOccurred()) By("Verify new proxy information are set") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) clusterProxy := clusterResp.Body().Proxy() Expect(clusterProxy.HTTPProxy()).To(Equal(newProxyOutput.HttpProxy)) @@ -104,7 +106,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { Expect(err).ShouldNot(HaveOccurred()) By("Check proxy is removed") - clusterResp, err = cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err = cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) clusterProxy = clusterResp.Body().Proxy() Expect(clusterProxy.HTTPProxy()).To(BeEmpty()) @@ -115,7 +117,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { Context("validate", func() { BeforeEach(func() { - if !profile.GetClusterType().HCP { + if !profileHandler.Profile().IsHCP() { Skip("Test can run only on Hosted cluster") } }) @@ -159,7 +161,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { By("Try to edit cloud region") validateClusterArgAgainstErrorSubstrings(func(args *exec.ClusterArgs) { region := "us-east-1" - if profile.Region == region { + if profileHandler.Profile().GetRegion() == region { region = "us-west-2" // make sure we are not in the same region } args.AWSRegion = helper.StringPointer(region) @@ -169,7 +171,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { validateClusterArgAgainstErrorSubstrings(func(args *exec.ClusterArgs) { region := "us-east-1" azs := []string{"us-east-1a"} - if profile.Region == region { + if profileHandler.Profile().GetRegion() == region { region = "us-west-2" // make sure we are not in the same region azs = []string{"us-west-2b"} } @@ -185,7 +187,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { It("compute fields - [id:72453]", ci.Medium, ci.FeatureClusterCompute, func() { By("Retrieve cluster information") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) By("Try to edit compute machine type") @@ -221,7 +223,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { args.CustomProperties = helper.StringMapPointer(props) }, func(err error) { Expect(err).ToNot(HaveOccurred()) - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(clusterResp.Body().Properties()["rosa_creator_arn"]).To(Equal(currentProperties["rosa_creator_arn"])) }) @@ -243,7 +245,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { It("network fields - [id:72470]", ci.Medium, ci.FeatureClusterNetwork, func() { By("Retrieve cluster information") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) originalAZs := clusterResp.Body().Nodes().AvailabilityZones() @@ -257,7 +259,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { args.AWSAvailabilityZones = helper.StringSlicePointer(azs) }, func(err error) { Expect(err).ToNot(HaveOccurred()) - clusterResp, err = cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err = cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(clusterResp.Body().Nodes().AvailabilityZones()).To(Equal(originalAZs)) }) @@ -291,18 +293,18 @@ var _ = Describe("Edit cluster", ci.Day2, func() { It("version fields - [id:72478]", ci.Medium, ci.FeatureClusterNetwork, func() { By("Retrieve cluster information") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) currentVersion := clusterResp.Body().Version().RawID() By("Get new channel group") - otherChannelGroup := exec.NightlyChannel - if profile.ChannelGroup == exec.NightlyChannel { - otherChannelGroup = exec.CandidateChannel + otherChannelGroup := constants.VersionNightlyChannel + if profileHandler.Profile().GetChannelGroup() == constants.VersionNightlyChannel { + otherChannelGroup = constants.VersionCandidateChannel } By("Retrieve latest version") - versions := cms.SortVersions(cms.HCPEnabledVersions(ci.RHCSConnection, otherChannelGroup)) + versions := cms.SortVersions(cms.HCPEnabledVersions(cms.RHCSConnection, otherChannelGroup)) lastVersion := versions[len(versions)-1] if lastVersion.RawID != currentVersion { @@ -314,9 +316,9 @@ var _ = Describe("Edit cluster", ci.Day2, func() { } By("Try to edit channel_group") - otherChannelGroup = "stable" - if profile.ChannelGroup == exec.StableChannel { - otherChannelGroup = exec.CandidateChannel + otherChannelGroup = constants.VersionStableChannel + if profileHandler.Profile().GetChannelGroup() == constants.VersionStableChannel { + otherChannelGroup = constants.VersionCandidateChannel } validateClusterArgAgainstErrorSubstrings(func(args *exec.ClusterArgs) { args.ChannelGroup = helper.StringPointer(otherChannelGroup) @@ -326,13 +328,13 @@ var _ = Describe("Edit cluster", ci.Day2, func() { It("private fields - [id:72480]", ci.Medium, ci.FeatureClusterPrivate, func() { By("Try to edit private") validateClusterArgAgainstErrorSubstrings(func(args *exec.ClusterArgs) { - args.Private = helper.BoolPointer(!profile.Private) + args.Private = helper.BoolPointer(!profileHandler.Profile().IsPrivate()) }, "Attribute private, cannot be changed from") }) It("imdsv2 fields - [id:75414]", ci.Medium, ci.FeatureClusterIMDSv2, func() { By("Try to edit ec2_metadata_http_tokens value") - otherHttpToken := profile.Ec2MetadataHttpTokens + otherHttpToken := profileHandler.Profile().GetImdsv2() if otherHttpToken == constants.RequiredEc2MetadataHttpTokens { otherHttpToken = constants.OptionalEc2MetadataHttpTokens } else { @@ -346,7 +348,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { It("encryption fields - [id:72487]", ci.Medium, ci.FeatureClusterEncryption, func() { By("Try to edit etcd_encryption") validateClusterArgAgainstErrorSubstrings(func(args *exec.ClusterArgs) { - args.Etcd = helper.BoolPointer(!profile.Etcd) + args.Etcd = helper.BoolPointer(!profileHandler.Profile().IsEtcd()) }, "Attribute etcd_encryption, cannot be changed from") By("Try to edit etcd_kms_key_arn") @@ -473,10 +475,10 @@ var _ = Describe("Edit cluster", ci.Day2, func() { It("security groups - [id:69145]", ci.Exclude, ci.Day2, func() { - if profile.GetClusterType().HCP { + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) output, err := clusterService.Output() Expect(err).ToNot(HaveOccurred()) @@ -485,19 +487,19 @@ var _ = Describe("Edit cluster", ci.Day2, func() { AdditionalComputeSecurityGroups: helper.StringSlicePointer(output.AdditionalComputeSecurityGroups[0:1]), AdditionalInfraSecurityGroups: helper.StringSlicePointer(output.AdditionalInfraSecurityGroups), AdditionalControlPlaneSecurityGroups: helper.StringSlicePointer(output.AdditionalControlPlaneSecurityGroups), - AWSRegion: helper.StringPointer(profile.Region), + AWSRegion: helper.StringPointer(profileHandler.Profile().GetRegion()), }, "aws_additional_infra_security_group_ids": { AdditionalInfraSecurityGroups: helper.StringSlicePointer(output.AdditionalInfraSecurityGroups[0:1]), AdditionalComputeSecurityGroups: helper.StringSlicePointer(output.AdditionalComputeSecurityGroups), AdditionalControlPlaneSecurityGroups: helper.StringSlicePointer(output.AdditionalControlPlaneSecurityGroups), - AWSRegion: helper.StringPointer(profile.Region), + AWSRegion: helper.StringPointer(profileHandler.Profile().GetRegion()), }, "aws_additional_control_plane_security_group_ids": { AdditionalControlPlaneSecurityGroups: helper.StringSlicePointer(output.AdditionalControlPlaneSecurityGroups[0:1]), AdditionalComputeSecurityGroups: helper.StringSlicePointer(output.AdditionalComputeSecurityGroups), AdditionalInfraSecurityGroups: helper.StringSlicePointer(output.AdditionalInfraSecurityGroups), - AWSRegion: helper.StringPointer(profile.Region), + AWSRegion: helper.StringPointer(profileHandler.Profile().GetRegion()), }, } for keyword, updatingArgs := range args { @@ -512,7 +514,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { It("autoscaling change - [id:63147]", ci.Medium, func() { - if profile.GetClusterType().HCP { + if profileHandler.Profile().IsHCP() { Skip("This case only works for classic now") } @@ -523,7 +525,7 @@ var _ = Describe("Edit cluster", ci.Day2, func() { MaxReplicas: helper.IntPointer(6), } - if profile.Autoscale { + if profileHandler.Profile().IsAutoscale() { clusterArgs.Autoscaling = &exec.Autoscaling{ AutoscalingEnabled: helper.BoolPointer(false), } diff --git a/tests/e2e/cluster_misc_day2_test.go b/tests/e2e/cluster_misc_day2_test.go index fac6207d..1cdae1c0 100644 --- a/tests/e2e/cluster_misc_day2_test.go +++ b/tests/e2e/cluster_misc_day2_test.go @@ -11,6 +11,7 @@ import ( "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" ) var _ = Describe("Cluster miscellaneous", func() { @@ -18,20 +19,21 @@ var _ = Describe("Cluster miscellaneous", func() { var ( clusterService exec.ClusterService - err error - profile *ci.Profile + profileHandler profilehandler.ProfileHandler originalCustomProperties map[string]string clusterArgs *exec.ClusterArgs ) BeforeEach(func() { + var err error // Load profile from YAML file based on environment By("Load profile") - profile = ci.LoadProfileYamlFileByENV() + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ShouldNot(HaveOccurred()) // Initialize the cluster service By("Create cluster service") - clusterService, err = exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err = profileHandler.Services().GetClusterService() Expect(err).ShouldNot(HaveOccurred()) // Read terraform.tfvars file and get its content as a map @@ -46,13 +48,13 @@ var _ = Describe("Cluster miscellaneous", func() { clusterArgs.CustomProperties = helper.StringMapPointer(originalCustomProperties) // Restore cluster state - _, err = clusterService.Apply(clusterArgs) + _, err := clusterService.Apply(clusterArgs) Expect(err).ShouldNot(HaveOccurred()) }) It("should validate custom property operations on cluster - [id:64907]", ci.Day2, ci.Medium, ci.FeatureClusterMisc, func() { - if profile.GetClusterType().HCP { + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } @@ -62,11 +64,11 @@ var _ = Describe("Cluster miscellaneous", func() { // Apply updated custom properties to the cluster clusterArgs.CustomProperties = helper.StringMapPointer(updatedCustomProperties) - _, err = clusterService.Apply(clusterArgs) + _, err := clusterService.Apply(clusterArgs) Expect(err).ShouldNot(HaveOccurred()) // Validating cluster's custom property update - clusterDetails, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterDetails, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ShouldNot(HaveOccurred()) Expect(clusterDetails.Body().Properties()["second_custom_property"]).Should(Equal(updatedCustomProperties["second_custom_property"])) @@ -81,7 +83,7 @@ var _ = Describe("Cluster miscellaneous", func() { }) It("can edit/delete cluster properties - [id:72451]", ci.Day2, ci.Medium, ci.FeatureClusterMisc, func() { - if !profile.GetClusterType().HCP { + if !profileHandler.Profile().IsHCP() { Skip("Test can run only on Hosted cluster") } @@ -91,11 +93,11 @@ var _ = Describe("Cluster miscellaneous", func() { updatedCustomProperties["some"] = "thing" updatedCustomProperties["nothing"] = "" clusterArgs.CustomProperties = helper.StringMapPointer(updatedCustomProperties) - _, err = clusterService.Apply(clusterArgs) + _, err := clusterService.Apply(clusterArgs) Expect(err).ShouldNot(HaveOccurred()) By("Verify new properties from cluster") - clusterDetails, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterDetails, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ShouldNot(HaveOccurred()) Expect(clusterDetails.Body().Properties()["some"]).Should(Equal(updatedCustomProperties["some"])) Expect(clusterDetails.Body().Properties()["nothing"]).Should(Equal(updatedCustomProperties["nothing"])) @@ -107,7 +109,7 @@ var _ = Describe("Cluster miscellaneous", func() { Expect(err).ShouldNot(HaveOccurred()) By("Verify updated properties from cluster") - clusterDetails, err = cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterDetails, err = cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ShouldNot(HaveOccurred()) Expect(clusterDetails.Body().Properties()["some"]).Should(Equal(updatedCustomProperties["some"])) Expect(clusterDetails.Body().Properties()["nothing"]).To(Equal(updatedCustomProperties["nothing"])) @@ -118,7 +120,7 @@ var _ = Describe("Cluster miscellaneous", func() { Expect(err).ShouldNot(HaveOccurred()) By("Verify properties are removed from cluster") - clusterDetails, err = cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterDetails, err = cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ShouldNot(HaveOccurred()) Expect(clusterDetails.Body().Properties()["some"]).To(BeEmpty()) Expect(clusterDetails.Body().Properties()["nothing"]).To(BeEmpty()) diff --git a/tests/e2e/cluster_upgrade_test.go b/tests/e2e/cluster_upgrade_test.go index 4252739c..5cacad3e 100644 --- a/tests/e2e/cluster_upgrade_test.go +++ b/tests/e2e/cluster_upgrade_test.go @@ -16,6 +16,7 @@ import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/openshift" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var _ = Describe("Upgrade", func() { @@ -24,20 +25,23 @@ var _ = Describe("Upgrade", func() { var ( targetV string clusterID string - profile *ci.Profile + profileHandler profilehandler.ProfileHandler + profile profilehandler.ProfileSpec clusterArgs *exec.ClusterArgs clusterService exec.ClusterService ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() - var err error - clusterID, err = ci.PrepareRHCSClusterByProfileENV() + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + profile = profileHandler.Profile() + + clusterID, err = profileHandler.RetrieveClusterID() Expect(err).ToNot(HaveOccurred()) By("Retrieve cluster args") - clusterService, err = exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err = profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) clusterArgs, err = clusterService.ReadTFVars() Expect(err).ToNot(HaveOccurred()) @@ -45,17 +49,17 @@ var _ = Describe("Upgrade", func() { Context("ROSA STS cluster", func() { BeforeEach(func() { - if profile.GetClusterType().HCP { + if profile.IsHCP() { Skip("Test can run only on Classic cluster") } }) It("on Z-stream - [id:63153]", ci.Upgrade, func() { - if profile.VersionPattern != "z-1" { + if profile.GetVersionPattern() != "z-1" { Skip("The test is configured only for Z-stream upgrade") } - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) targetV, err = cms.GetVersionUpgradeTarget(clusterResp.Body().Version().RawID(), constants.Z, clusterResp.Body().Version().AvailableUpgrades()) @@ -69,7 +73,7 @@ var _ = Describe("Upgrade", func() { downgradedVersion := fmt.Sprintf("%s.%s.%s", splittedVersion[0], splittedVersion[1], fmt.Sprint(zStreamV-1)) - imageVersionsList := cms.EnabledVersions(ci.RHCSConnection, profile.ChannelGroup, profile.MajorVersion, true) + imageVersionsList := cms.EnabledVersions(cms.RHCSConnection, profile.GetChannelGroup(), profile.GetMajorVersion(), true) versionsList := cms.GetRawVersionList(imageVersionsList) if slices.Contains(versionsList, downgradedVersion) { clusterArgs.OpenshiftVersion = helper.StringPointer(downgradedVersion) @@ -86,34 +90,33 @@ var _ = Describe("Upgrade", func() { Expect(err).ToNot(HaveOccurred()) By("Wait the upgrade finished") - err = openshift.WaitClassicClusterUpgradeFinished(ci.RHCSConnection, clusterID) + err = openshift.WaitClassicClusterUpgradeFinished(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred(), "Cluster upgrade %s failed with the error %v", clusterID, err) By("Wait for 10 minutes to be sure the version is synced in clusterdeployment") time.Sleep(10 * time.Minute) By("Check the cluster status and OCP version") - clusterResp, err = cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err = cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) 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.Private { + if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 - err = openshift.WaitForOperatorsToBeReady(ci.RHCSConnection, clusterID, timeout) + err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) Expect(err).ToNot(HaveOccurred()) } }) It("on Y-stream - [id:63152]", ci.Upgrade, func() { - - if profile.VersionPattern != "y-1" { + if profile.GetVersionPattern() != "y-1" { Skip("The test is configured only for Y-stream upgrade") } - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) targetV, err = cms.GetVersionUpgradeTarget(clusterResp.Body().Version().RawID(), constants.Y, clusterResp.Body().Version().AvailableUpgrades()) @@ -121,10 +124,18 @@ var _ = Describe("Upgrade", func() { Expect(targetV).ToNot(Equal("")) By("Upgrade account-roles") - majorVersion := ci.GetMajorVersion(targetV) + majorVersion := helper.GetMajorVersion(targetV) Expect(majorVersion).ToNot(Equal("")) - _, err = ci.PrepareAccountRoles(token, clusterResp.Body().Name(), profile.UnifiedAccRolesPath, profile.Region, majorVersion, profile.ChannelGroup, profile.GetClusterType(), "") + dupProfileHandler := profileHandler.DuplicateRandom() + _, err = dupProfileHandler.Prepare().PrepareAccountRoles(token, clusterResp.Body().Name(), profile.GetUnifiedAccRolesPath(), majorVersion, profile.GetChannelGroup(), "") Expect(err).ToNot(HaveOccurred()) + defer func() { + svc, err := dupProfileHandler.Services().GetAccountRolesService() + if err != nil { + return + } + svc.Destroy() + }() By("Validate invalid OCP version field - downgrade") currentVersion := string(clusterResp.Body().Version().RawID()) @@ -133,7 +144,7 @@ var _ = Describe("Upgrade", func() { Expect(err).ToNot(HaveOccurred()) downgradedVersion := fmt.Sprintf("%s.%s.%s", splittedVersion[0], fmt.Sprint(yStreamV-1), splittedVersion[2]) - imageVersionsList := cms.EnabledVersions(ci.RHCSConnection, profile.ChannelGroup, profile.MajorVersion, true) + imageVersionsList := cms.EnabledVersions(cms.RHCSConnection, profile.GetChannelGroup(), profile.GetMajorVersion(), true) versionsList := cms.GetRawVersionList(imageVersionsList) if slices.Contains(versionsList, downgradedVersion) { clusterArgs.OpenshiftVersion = helper.StringPointer(downgradedVersion) @@ -156,22 +167,22 @@ var _ = Describe("Upgrade", func() { Expect(err).ToNot(HaveOccurred()) By("Wait the upgrade finished") - err = openshift.WaitClassicClusterUpgradeFinished(ci.RHCSConnection, clusterID) + err = openshift.WaitClassicClusterUpgradeFinished(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred(), "Cluster %s failed with the error %v", clusterID, err) By("Wait for 10 minutes to be sure the version is synced in clusterdeployment") time.Sleep(10 * time.Minute) By("Check the cluster status and OCP version") - clusterResp, err = cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err = cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) 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.Private { + if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 - err = openshift.WaitForOperatorsToBeReady(ci.RHCSConnection, clusterID, timeout) + err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) Expect(err).ToNot(HaveOccurred()) } }) @@ -179,19 +190,19 @@ var _ = Describe("Upgrade", func() { Context("ROSA HCP cluster", func() { BeforeEach(func() { - if !profile.GetClusterType().HCP { + if !profile.IsHCP() { Skip("Test can run only on Hosted cluster") } }) It("ROSA HCP cluster on Z-stream - [id:72474]", ci.Upgrade, func() { - if profile.VersionPattern != "z-1" { + if profile.GetVersionPattern() != "z-1" { Skip("The test is configured only for Z-stream upgrade") } By("Retrieve cluster information and upgrade version") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) targetV, err = cms.GetVersionUpgradeTarget(clusterResp.Body().Version().RawID(), constants.Z, clusterResp.Body().Version().AvailableUpgrades()) @@ -206,37 +217,37 @@ var _ = Describe("Upgrade", func() { Expect(err).ToNot(HaveOccurred()) By("Wait the upgrade finished") - err = openshift.WaitHCPClusterUpgradeFinished(ci.RHCSConnection, clusterID) + err = openshift.WaitHCPClusterUpgradeFinished(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred(), "Cluster upgrade %s failed with the error %v", clusterID, err) By("Check the cluster status and OCP version") - clusterResp, err = cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err = cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) 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.Private { + if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 - err = openshift.WaitForOperatorsToBeReady(ci.RHCSConnection, clusterID, timeout) + err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) Expect(err).ToNot(HaveOccurred()) } }) It("ROSA HCP cluster on Y-stream - [id:72475]", ci.Upgrade, func() { - if profile.VersionPattern != "y-1" { + if profile.GetVersionPattern() != "y-1" { Skip("The test is configured only for Y-stream upgrade") } By("Retrieve cluster information and upgrade version") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) targetV, err = cms.GetVersionUpgradeTarget(clusterResp.Body().Version().RawID(), constants.Y, clusterResp.Body().Version().AvailableUpgrades()) Expect(err).ToNot(HaveOccurred()) Expect(targetV).ToNot(BeEmpty()) - majorVersion := ci.GetMajorVersion(targetV) + majorVersion := helper.GetMajorVersion(targetV) Expect(majorVersion).ToNot(BeEmpty()) Logger.Infof("Gonna upgrade to version %s", targetV) @@ -254,19 +265,19 @@ var _ = Describe("Upgrade", func() { Expect(err).ToNot(HaveOccurred()) By("Wait the upgrade finished") - err = openshift.WaitHCPClusterUpgradeFinished(ci.RHCSConnection, clusterID) + err = openshift.WaitHCPClusterUpgradeFinished(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred(), "Cluster %s failed with the error %v", clusterID, err) By("Check the cluster status and OCP version") - clusterResp, err = cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err = cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) 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.Private { + if constants.GetEnvWithDefault(constants.WaitOperators, "false") == "true" && !profile.IsPrivate() { // WaitClusterOperatorsToReadyStatus will wait for cluster operators ready timeout := 60 - err = openshift.WaitForOperatorsToBeReady(ci.RHCSConnection, clusterID, timeout) + err = openshift.WaitForOperatorsToBeReady(cms.RHCSConnection, clusterID, timeout) Expect(err).ToNot(HaveOccurred()) } }) diff --git a/tests/e2e/dns_test.go b/tests/e2e/dns_test.go index 6445071f..e07bbb7c 100644 --- a/tests/e2e/dns_test.go +++ b/tests/e2e/dns_test.go @@ -4,15 +4,21 @@ 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/exec" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var _ = Describe("DNS Domain", func() { - var dnsService exec.DnsDomainService + var ( + dnsService exec.DnsDomainService + profileHandler profilehandler.ProfileHandler + ) BeforeEach(func() { var err error - dnsService, err = exec.NewDnsDomainService(constants.DNSDir) + profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + + dnsService, err = profileHandler.Services().GetDnsDomainService() Expect(err).ToNot(HaveOccurred()) }) @@ -22,8 +28,7 @@ var _ = Describe("DNS Domain", func() { It("can create and destroy dnsdomain - [id:67570]", ci.Day2, ci.Medium, ci.FeatureIDP, func() { - profile := ci.LoadProfileYamlFileByENV() - if profile.GetClusterType().HCP { + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 72be69bc..72ec980f 100644 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -7,9 +7,10 @@ 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/exec/manifests" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var ctx context.Context @@ -25,10 +26,12 @@ var _ = BeforeSuite(func() { token = os.Getenv(constants.TokenENVName) var err error - err = helper.AlignRHCSSourceVersion(constants.ManifestsConfigurationDir) + err = helper.AlignRHCSSourceVersion(manifests.ManifestsConfigurationDir) Expect(err).ToNot(HaveOccurred()) - clusterID, err = ci.PrepareRHCSClusterByProfileENV() + profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + clusterID, err = profileHandler.RetrieveClusterID() Expect(err).ToNot(HaveOccurred()) ctx = context.Background() }) diff --git a/tests/e2e/hcp_ingress_test.go b/tests/e2e/hcp_ingress_test.go index c4992c9d..2f9fefe4 100644 --- a/tests/e2e/hcp_ingress_test.go +++ b/tests/e2e/hcp_ingress_test.go @@ -11,10 +11,10 @@ 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/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/log" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var internalListeningMethod = "internal" @@ -23,38 +23,41 @@ var externalListeningMethod = "external" var _ = Describe("HCP Ingress", ci.FeatureIngress, ci.Day2, func() { var ( - err error + profileHandler profilehandler.ProfileHandler ingressBefore *cmsv1.Ingress ingressService exec.IngressService ingressArgs *exec.IngressArgs ) - initializeIngressArgs := func() { - ingressArgs, err = ingressService.ReadTFVars() + getOriginalIngressArgs := func() *exec.IngressArgs { + args, err := ingressService.ReadTFVars() Expect(err).ToNot(HaveOccurred()) - if ingressArgs.Cluster == nil { - ingressArgs.Cluster = helper.StringPointer(clusterID) + if args.Cluster == nil { + args.Cluster = helper.StringPointer(clusterID) } + return args } BeforeEach(func() { - profile := ci.LoadProfileYamlFileByENV() - if !profile.GetClusterType().HCP { + if !profileHandler.Profile().IsHCP() { Skip("Test can run only on Hosted cluster") } + var err error + ingressBefore, err = cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) + Expect(err).ToNot(HaveOccurred()) - ingressBefore, err = cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() Expect(err).ToNot(HaveOccurred()) - ingressService, err = exec.NewIngressService(constants.HCPIngressDir) + ingressService, err = profileHandler.Services().GetIngressService() Expect(err).ToNot(HaveOccurred()) - initializeIngressArgs() + ingressArgs = getOriginalIngressArgs() }) AfterEach(func() { ingressArgs.ListeningMethod = helper.StringPointer(string(ingressBefore.Listening())) - _, err = ingressService.Apply(ingressArgs) + _, err := ingressService.Apply(ingressArgs) Expect(err).ToNot(HaveOccurred()) }) @@ -63,11 +66,11 @@ var _ = Describe("HCP Ingress", ci.FeatureIngress, ci.Day2, func() { func() { By("Set Listening method to internal") ingressArgs.ListeningMethod = helper.StringPointer(internalListeningMethod) - _, err = ingressService.Apply(ingressArgs) + _, err := ingressService.Apply(ingressArgs) Expect(err).ToNot(HaveOccurred()) By("Verify Cluster Ingress") - ingress, err := cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err := cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(string(ingress.Listening())).To(Equal("internal")) @@ -77,7 +80,7 @@ var _ = Describe("HCP Ingress", ci.FeatureIngress, ci.Day2, func() { Expect(err).ToNot(HaveOccurred()) By("Verify Cluster Ingress") - ingress, err = cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err = cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(string(ingress.Listening())).To(Equal("external")) @@ -86,27 +89,25 @@ var _ = Describe("HCP Ingress", ci.FeatureIngress, ci.Day2, func() { Expect(err).ToNot(HaveOccurred()) By("Verify Cluster Ingress is still present") - ingress, err = cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err = cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(string(ingress.Listening())).To(Equal("external")) }) It("validate edit - [id:72520]", ci.Medium, func() { By("Initialize ingress state") - initializeIngressArgs() ingressArgs.ListeningMethod = helper.StringPointer(string(ingressBefore.Listening())) - _, err = ingressService.Apply(ingressArgs) + _, err := ingressService.Apply(ingressArgs) Expect(err).ToNot(HaveOccurred()) By("Try to edit with empty cluster") - initializeIngressArgs() ingressArgs.Cluster = helper.EmptyStringPointer _, err = ingressService.Apply(ingressArgs) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Attribute cluster cluster ID may not be empty/blank string")) By("Try to edit cluster with other cluster ID") - clustersResp, err := cms.ListClusters(ci.RHCSConnection) + clustersResp, err := cms.ListClusters(cms.RHCSConnection) Expect(err).ToNot(HaveOccurred()) var otherClusterID string for _, cluster := range clustersResp.Items().Slice() { @@ -116,7 +117,7 @@ var _ = Describe("HCP Ingress", ci.FeatureIngress, ci.Day2, func() { } } if otherClusterID != "" { - initializeIngressArgs() + ingressArgs = getOriginalIngressArgs() ingressArgs.Cluster = helper.StringPointer(otherClusterID) _, err = ingressService.Apply(ingressArgs) Expect(err).To(HaveOccurred()) @@ -126,14 +127,14 @@ var _ = Describe("HCP Ingress", ci.FeatureIngress, ci.Day2, func() { } By("Try to edit cluster field with wrong value") - initializeIngressArgs() + ingressArgs = getOriginalIngressArgs() ingressArgs.Cluster = helper.StringPointer("wrong") _, err = ingressService.Apply(ingressArgs) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Cluster 'wrong' not")) By("Try to edit with empty listening_method") - initializeIngressArgs() + ingressArgs = getOriginalIngressArgs() ingressArgs.ListeningMethod = helper.EmptyStringPointer _, err = ingressService.Apply(ingressArgs) Expect(err).To(HaveOccurred()) @@ -141,7 +142,7 @@ var _ = Describe("HCP Ingress", ci.FeatureIngress, ci.Day2, func() { Expect(err.Error()).To(ContainSubstring("Options are")) By("Try to edit with wrong listening_method") - initializeIngressArgs() + ingressArgs = getOriginalIngressArgs() ingressArgs.ListeningMethod = helper.StringPointer("wrong") _, err = ingressService.Apply(ingressArgs) Expect(err).To(HaveOccurred()) diff --git a/tests/e2e/hcp_machine_pool_test.go b/tests/e2e/hcp_machine_pool_test.go index b433bb27..9a9a4ca5 100644 --- a/tests/e2e/hcp_machine_pool_test.go +++ b/tests/e2e/hcp_machine_pool_test.go @@ -18,30 +18,32 @@ import ( "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/log" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" "k8s.io/apimachinery/pkg/util/wait" ) var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { defer GinkgoRecover() var ( - mpService exec.MachinePoolService - vpcOutput *exec.VPCOutput - profile *ci.Profile + mpService exec.MachinePoolService + vpcOutput *exec.VPCOutput + profileHandler profilehandler.ProfileHandler ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) - if !profile.GetClusterType().HCP { + if !profileHandler.Profile().IsHCP() { Skip("Test can run only on Hosted cluster") } - var err error - mpService, err = exec.NewMachinePoolService(constants.HCPMachinePoolDir) + mpService, err = profileHandler.Services().GetMachinePoolsService() Expect(err).ToNot(HaveOccurred()) By("Get vpc output") - vpcService, err := exec.NewVPCService(constants.GetAWSVPCDefaultManifestDir(profile.GetClusterType())) + vpcService, err := profileHandler.Services().GetVPCService() Expect(err).ToNot(HaveOccurred()) vpcOutput, err = vpcService.Output() Expect(err).ToNot(HaveOccurred()) @@ -69,13 +71,13 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { It("can be created with only required attributes - [id:72504]", ci.Critical, func() { By("Retrieve current cluster information") - clusterRespBody, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterRespBody, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) var initialMinReplicas int var initialMaxReplicas int var initialReplicas int - if profile.Autoscale { + if profileHandler.Profile().IsAutoscale() { initialMinReplicas = clusterRespBody.Body().Nodes().AutoscaleCompute().MinReplicas() initialMaxReplicas = clusterRespBody.Body().Nodes().AutoscaleCompute().MaxReplicas() } else { @@ -100,7 +102,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify attributes are correctly set") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.ID()).To(Equal(name)) Expect(mpResponseBody.Autoscaling()).To(BeNil()) @@ -111,11 +113,11 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { By("Wait for machinepool replicas available") err = wait.PollUntilContextTimeout(context.Background(), 30*time.Second, 20*time.Minute, false, func(context.Context) (bool, error) { - clusterRespBody, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterRespBody, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) if err != nil { return false, err } - if profile.Autoscale { + if profileHandler.Profile().IsAutoscale() { return clusterRespBody.Body().Nodes().AutoscaleCompute().MaxReplicas() == (initialMaxReplicas+replicas) && clusterRespBody.Body().Nodes().AutoscaleCompute().MinReplicas() == (initialMinReplicas+replicas), nil } else { @@ -127,7 +129,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { By("Delete machinepool") _, err = mpService.Destroy() Expect(err).ToNot(HaveOccurred()) - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).To(HaveOccurred()) }) @@ -154,7 +156,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err := mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling()).ToNot(BeNil()) Expect(mpResponseBody.Autoscaling().MaxReplica()).To(Equal(maxReplicas)) @@ -168,7 +170,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling()).ToNot(BeNil()) Expect(mpResponseBody.Autoscaling().MaxReplica()).To(Equal(maxReplicas)) @@ -182,7 +184,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling()).To(BeNil()) Expect(mpResponseBody.Replicas()).To(Equal(replicas)) @@ -193,7 +195,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling()).To(BeNil()) Expect(mpResponseBody.Replicas()).To(Equal(replicas)) @@ -204,7 +206,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling()).To(BeNil()) Expect(mpResponseBody.Replicas()).To(Equal(replicas)) @@ -219,7 +221,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Autoscaling()).ToNot(BeNil()) Expect(mpResponseBody.Autoscaling().MaxReplica()).To(Equal(maxReplicas)) @@ -229,12 +231,12 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { It("can be created with security groups - [id:73068]", ci.High, func() { By("Prepare additional security groups") - sgService, err := exec.NewSecurityGroupService() + sgService, err := profileHandler.Services().GetSecurityGroupService() output, err := sgService.Output() Expect(err).ToNot(HaveOccurred()) if output.SGIDs == nil { sgArgs := &exec.SecurityGroupArgs{ - AWSRegion: helper.StringPointer(profile.Region), + AWSRegion: helper.StringPointer(profileHandler.Profile().GetRegion()), VPCID: helper.StringPointer(vpcOutput.VPCID), SGNumber: helper.IntPointer(4), } @@ -274,7 +276,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { }() By("Verify the parameters of the created machinepool") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(len(mpResponseBody.AWSNodePool().AdditionalSecurityGroupIds())).To(Equal(len(sgIDs))) for _, sg := range mpResponseBody.AWSNodePool().AdditionalSecurityGroupIds() { @@ -301,7 +303,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify the parameters of the created machinepool") - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.AWSNodePool().AdditionalSecurityGroupIds()).To(BeNil()) Expect(mpResponseBody.AWSNodePool().InstanceType()).To(Equal("m5.2xlarge")) @@ -372,7 +374,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err := mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) respTaints := mpResponseBody.Taints() for index, taint := range respTaints { @@ -394,7 +396,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) respTaints = mpResponseBody.Taints() for index, taint := range respTaints { @@ -411,7 +413,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { _, err = mpService.Apply(mpArgs) Expect(err).ToNot(HaveOccurred()) // Verify - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Taints()).To(BeEmpty()) Expect(mpResponseBody.AutoRepair()).To(BeTrue()) @@ -434,7 +436,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { } By("Retrieve cluster version") - clusterService, err := exec.NewClusterService(constants.GetClusterManifestsDir(profile.GetClusterType())) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) clusterOutput, err := clusterService.Output() Expect(err).ToNot(HaveOccurred()) @@ -443,7 +445,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Retrieve z-1 version") - zLowerVersions := cms.SortVersions(cms.GetHcpLowerVersions(ci.RHCSConnection, clusterVersion, profile.ChannelGroup)) + zLowerVersions := cms.SortVersions(cms.GetHcpLowerVersions(cms.RHCSConnection, clusterVersion, profileHandler.Profile().GetChannelGroup())) if len(zLowerVersions) > 0 { zversion := zLowerVersions[len(zLowerVersions)-1] zSemVer, err := semver.NewVersion(zversion.RawID) @@ -459,7 +461,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify machinepool with z-1") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Version().ID()).To(Equal(zversion.ID)) @@ -475,7 +477,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { By("Retrieve y-1 version") throttleVersion := fmt.Sprintf("%v.%v.0", clusterSemVer.Major(), clusterSemVer.Minor()) - yLowerVersions := cms.SortVersions(cms.GetHcpLowerVersions(ci.RHCSConnection, throttleVersion, profile.ChannelGroup)) + yLowerVersions := cms.SortVersions(cms.GetHcpLowerVersions(cms.RHCSConnection, throttleVersion, profileHandler.Profile().GetChannelGroup())) if len(yLowerVersions) > 0 { yVersion := yLowerVersions[len(yLowerVersions)-1] name := helper.GenerateRandomName("np-72509-z", 2) @@ -487,7 +489,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify machinepool with y-1") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Version().ID()).To(Equal(yVersion.ID)) @@ -522,7 +524,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify tags are correctly set") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.AWSNodePool().Tags()).To(HaveKeyWithValue("aaa", "bbb")) Expect(mpResponseBody.AWSNodePool().Tags()).To(HaveKeyWithValue("ccc", "ddd")) @@ -550,7 +552,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { var tuningconfigs []string var tcArgs *exec.TuningConfigArgs - tcService, err := exec.NewTuningConfigService(constants.TuningConfigDir) + tcService, err := profileHandler.Services().GetTuningConfigService() Expect(err).ToNot(HaveOccurred()) By("Create tuning configs") @@ -598,7 +600,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify tuning configs are correctly set") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.TuningConfigs()).To(Equal(tuningconfigs)) @@ -609,7 +611,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify tuning configs are correctly updated") - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.TuningConfigs()).To(Equal(tuningconfigs)) @@ -619,7 +621,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify tuning configs are correctly updated") - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.TuningConfigs()).To(BeEmpty()) }) @@ -633,7 +635,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { PodPidsLimit: helper.IntPointer(12345), Cluster: helper.StringPointer(clusterID), } - kubeService, err := exec.NewKubeletConfigService() + kubeService, err := profileHandler.Services().GetKubeletConfigService() Expect(err).ToNot(HaveOccurred()) _, err = kubeService.Apply(kubeArgs) Expect(err).ToNot(HaveOccurred()) @@ -662,7 +664,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { defer mpService.Destroy() By("Check the kubeleteconfig is applied to the machinepool") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.KubeletConfigs()[0]).To(Equal(kubeconfigs[0].Name)) @@ -672,7 +674,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Check the kubeleteconfig is applied to the machinepool") - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.KubeletConfigs()[0]).To(Equal(kubeconfigs[1].Name)) @@ -682,7 +684,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Check the kubeleteconfig is applied to the machinepool") - mpResponseBody, err = cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err = cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.KubeletConfigs()).To(BeEmpty()) }) @@ -713,7 +715,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Verify imdsv2 value is correctly set") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(string(mpResponseBody.AWSNodePool().Ec2MetadataHttpTokens())). To(Equal(imdsv2Value)) @@ -775,7 +777,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { mpName := helper.GenerateRandomName("np-72514", 2) By("Retrieve current cluster information") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) By("Try to create a nodepool with empty cluster") @@ -825,7 +827,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { By("Try to create a nodepool with version > CP version") currentVersion := clusterResp.Body().Version().RawID() currentSemVer, _ := semver.NewVersion(currentVersion) - versions := cms.GetHcpHigherVersions(ci.RHCSConnection, currentVersion, profile.ChannelGroup) + versions := cms.GetHcpHigherVersions(cms.RHCSConnection, currentVersion, profileHandler.Profile().GetChannelGroup()) if len(versions) > 0 { validateMPArgAgainstErrorSubstrings(mpName, func(args *exec.MachinePoolArgs) { args.OpenshiftVersion = helper.StringPointer(versions[0].RawID) @@ -836,7 +838,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { By("Try to create a nodepool with version < CP version-2") throttleVersion := fmt.Sprintf("%v.%v.0", currentSemVer.Major(), currentSemVer.Minor()-2) - versions = cms.GetHcpLowerVersions(ci.RHCSConnection, throttleVersion, profile.ChannelGroup) + versions = cms.GetHcpLowerVersions(cms.RHCSConnection, throttleVersion, profileHandler.Profile().GetChannelGroup()) if len(versions) > 0 { validateMPArgAgainstErrorSubstrings(mpName, func(args *exec.MachinePoolArgs) { args.OpenshiftVersion = helper.StringPointer(versions[0].RawID) @@ -1030,7 +1032,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { It("can import - [id:72960]", ci.Day2, ci.Medium, ci.FeatureImport, func() { - importService, err := exec.NewImportService(constants.ImportResourceDir) // init new import service + importService, err := profileHandler.Services().GetImportService() Expect(err).ToNot(HaveOccurred()) defer func() { By("Destroy import service") @@ -1082,7 +1084,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { mpArgs := getDefaultMPArgs(name) By("Retrieve cluster version") - clusterService, err := exec.NewClusterService((constants.GetClusterManifestsDir(profile.GetClusterType()))) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) clusterOut, err := clusterService.Output() Expect(err).ToNot(HaveOccurred()) @@ -1090,7 +1092,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Get version z-1") - zLowerVersions, err := cms.GetVersionsWithUpgradesToVersion(ci.RHCSConnection, clusterVersion, profile.ChannelGroup, constants.Z, true, true, 1) + zLowerVersions, err := cms.GetVersionsWithUpgradesToVersion(cms.RHCSConnection, clusterVersion, profileHandler.Profile().GetChannelGroup(), constants.Z, true, true, 1) Logger.Infof("Got versions %v", zLowerVersions) Expect(err).ToNot(HaveOccurred()) if len(zLowerVersions) <= 0 { @@ -1104,7 +1106,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Check created machine pool") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Version().ID()).To(Equal(zversion.ID)) @@ -1114,7 +1116,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Check upgrade policy") - npUpPolicies, err := cms.ListNodePoolUpgradePolicies(ci.RHCSConnection, clusterID, name) + npUpPolicies, err := cms.ListNodePoolUpgradePolicies(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(len(npUpPolicies.Items().Slice())).To(Equal(1)) Expect(npUpPolicies.Items().Get(0).Version()).To(Equal(clusterVersion)) @@ -1125,7 +1127,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { mpArgs := getDefaultMPArgs(name) By("Retrieve cluster version") - clusterService, err := exec.NewClusterService((constants.GetClusterManifestsDir(profile.GetClusterType()))) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) clusterOut, err := clusterService.Output() Expect(err).ToNot(HaveOccurred()) @@ -1133,7 +1135,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Get version z-1") - yLowerVersions, err := cms.GetVersionsWithUpgradesToVersion(ci.RHCSConnection, clusterVersion, profile.ChannelGroup, constants.Y, true, true, 1) + yLowerVersions, err := cms.GetVersionsWithUpgradesToVersion(cms.RHCSConnection, clusterVersion, profileHandler.Profile().GetChannelGroup(), constants.Y, true, true, 1) Expect(err).ToNot(HaveOccurred()) if len(yLowerVersions) <= 0 { Skip("No Available version for upgrading on y-stream") @@ -1146,7 +1148,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Check created machine pool") - mpResponseBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, name) + mpResponseBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(mpResponseBody.Version().ID()).To(Equal(yVersion.ID)) @@ -1156,7 +1158,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Expect(err).ToNot(HaveOccurred()) By("Check upgrade policy") - npUpPolicies, err := cms.ListNodePoolUpgradePolicies(ci.RHCSConnection, clusterID, name) + npUpPolicies, err := cms.ListNodePoolUpgradePolicies(cms.RHCSConnection, clusterID, name) Expect(err).ToNot(HaveOccurred()) Expect(len(npUpPolicies.Items().Slice())).To(Equal(1)) Expect(npUpPolicies.Items().Get(0).Version()).To(Equal(clusterVersion)) diff --git a/tests/e2e/idps_test.go b/tests/e2e/idps_test.go index f915687e..d719466a 100644 --- a/tests/e2e/idps_test.go +++ b/tests/e2e/idps_test.go @@ -17,6 +17,7 @@ import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/openshift" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) // all identity providers - declared for future cases @@ -100,11 +101,15 @@ func getDefaultGoogleArgs(idpName string) *exec.IDPArgs { var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { defer GinkgoRecover() - var profile *ci.Profile - var idpServices = IDPServices{} + var ( + profileHandler profilehandler.ProfileHandler + idpServices = IDPServices{} + ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) idpServices = IDPServices{} }) @@ -143,7 +148,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Context("Htpasswd", func() { BeforeEach(func() { var err error - idpServices.htpasswd, err = exec.NewIDPService(constants.HtpasswdDir) // init new htpasswd service + idpServices.htpasswd, err = profileHandler.Services().GetIDPService(constants.IDPHTPassword) // init new htpasswd service Expect(err).ToNot(HaveOccurred()) }) @@ -156,7 +161,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("List existing HtpasswdUsers and compare to the created one") - htpasswdUsersList, _ := cms.ListHtpasswdUsers(ci.RHCSConnection, clusterID, idpOutput.ID) + htpasswdUsersList, _ := cms.ListHtpasswdUsers(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(htpasswdUsersList.Status()).To(Equal(http.StatusOK)) respUserName, _ := htpasswdUsersList.Items().Slice()[0].GetUsername() Expect(respUserName).To(Equal(defaultHTPUsername)) @@ -164,8 +169,8 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { By("Login with created htpasswd idp") // this condition is for cases where the cluster profile // has private_link enabled, then regular login won't work - if !profile.IsPrivateLink() { - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + if !profileHandler.Profile().IsPrivateLink() { + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) server := getResp.Body().API().URL() @@ -197,7 +202,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("List existing HtpasswdUsers and compare to the created one") - htpasswdUsersList, _ := cms.ListHtpasswdUsers(ci.RHCSConnection, clusterID, idpOutput.ID) + htpasswdUsersList, _ := cms.ListHtpasswdUsers(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(htpasswdUsersList.Status()).To(Equal(http.StatusOK)) respUserName, _ := htpasswdUsersList.Items().Slice()[0].GetUsername() Expect(respUserName).To(Equal(defaultHTPUsername)) @@ -209,7 +214,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("Check resource state file is updated") - resource, err := helper.GetResource(constants.HtpasswdDir, "rhcs_identity_provider", "htpasswd_idp") + resource, err := idpServices.htpasswd.GetStateResource("rhcs_identity_provider", "htpasswd_idp") Expect(err).ToNot(HaveOccurred()) Expect(resource).To(MatchJQ(fmt.Sprintf(`.instances[0].attributes.htpasswd.users[] | select(.username == "%s") .password`, defaultHTPUsername), newPassword)) @@ -240,12 +245,12 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("Check resource state file is updated") - resource, err = helper.GetResource(constants.HtpasswdDir, "rhcs_identity_provider", "htpasswd_idp") + resource, err = idpServices.htpasswd.GetStateResource("rhcs_identity_provider", "htpasswd_idp") Expect(err).ToNot(HaveOccurred()) Expect(resource).To(MatchJQ(fmt.Sprintf(`.instances[0].attributes.htpasswd.users[] | select(.username == "%s") .password`, userName2), newPassword2)) By("List existing HtpasswdUsers and compare to the created one") - htpasswdUsersList, _ = cms.ListHtpasswdUsers(ci.RHCSConnection, clusterID, idpOutput.ID) + htpasswdUsersList, _ = cms.ListHtpasswdUsers(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(htpasswdUsersList.Status()).To(Equal(http.StatusOK)) Expect(htpasswdUsersList.Items().Len()).To(Equal(3)) @@ -268,7 +273,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { defaultLDAPPassword = "password" var err error - idpServices.ldap, err = exec.NewIDPService(constants.LdapDir) // init new ldap service + idpServices.ldap, err = profileHandler.Services().GetIDPService(constants.IDPLDAP) Expect(err).ToNot(HaveOccurred()) }) @@ -291,8 +296,8 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { By("Login with created ldap idp") // this condition is for cases where the cluster profile // has private_link enabled, then regular login won't work - if !profile.IsPrivateLink() { - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + if !profileHandler.Profile().IsPrivateLink() { + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) server := getResp.Body().API().URL() @@ -317,7 +322,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Context("GitLab", func() { BeforeEach(func() { var err error - idpServices.gitlab, err = exec.NewIDPService(constants.GitlabDir) // init new gitlab service + idpServices.gitlab, err = profileHandler.Services().GetIDPService(constants.IDPGitlab) Expect(err).ToNot(HaveOccurred()) }) @@ -338,7 +343,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { idpOutput, err := idpServices.gitlab.Output() Expect(err).ToNot(HaveOccurred()) - resp, err := cms.RetrieveClusterIDPDetail(ci.RHCSConnection, clusterID, idpOutput.ID) + resp, err := cms.RetrieveClusterIDPDetail(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(err).ToNot(HaveOccurred()) Expect(resp.Status()).To(Equal(http.StatusOK)) }) @@ -346,7 +351,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Context("GitHub", func() { BeforeEach(func() { var err error - idpServices.github, err = exec.NewIDPService(constants.GithubDir) // init new github service + idpServices.github, err = profileHandler.Services().GetIDPService(constants.IDPGithub) Expect(err).ToNot(HaveOccurred()) }) @@ -367,7 +372,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { idpOutput, err := idpServices.github.Output() Expect(err).ToNot(HaveOccurred()) - resp, err := cms.RetrieveClusterIDPDetail(ci.RHCSConnection, clusterID, idpOutput.ID) + resp, err := cms.RetrieveClusterIDPDetail(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(err).ToNot(HaveOccurred()) Expect(resp.Status()).To(Equal(http.StatusOK)) }) @@ -375,7 +380,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Context("Google", func() { BeforeEach(func() { var err error - idpServices.google, err = exec.NewIDPService(constants.GoogleDir) // init new google service + idpServices.google, err = profileHandler.Services().GetIDPService(constants.IDPGoogle) Expect(err).ToNot(HaveOccurred()) }) @@ -396,14 +401,14 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { idpOutput, err := idpServices.google.Output() Expect(err).ToNot(HaveOccurred()) - resp, err := cms.RetrieveClusterIDPDetail(ci.RHCSConnection, clusterID, idpOutput.ID) + resp, err := cms.RetrieveClusterIDPDetail(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(err).ToNot(HaveOccurred()) Expect(resp.Status()).To(Equal(http.StatusOK)) }) }) Context("Multi IDPs", func() { BeforeEach(func() { - if profile.IsPrivateLink() { + if profileHandler.Profile().IsPrivateLink() { Skip("private_link is enabled, skipping test.") } @@ -413,7 +418,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { It("will succeed - [id:64030]", ci.Medium, ci.Exclude, func() { var err error - idpServices.multi_idp, err = exec.NewIDPService(constants.MultiIDPDir) // init multi-idp service + idpServices.multi_idp, err = profileHandler.Services().GetIDPService(constants.IDPMulti) Expect(err).ToNot(HaveOccurred()) By("Applying google & ldap idps users using terraform") @@ -435,7 +440,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { By("Login to the ldap user created with terraform") By("& cluster-admin user created on cluster deployment") - resp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + resp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) server := resp.Body().API().URL() @@ -453,7 +458,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { _, err = openshift.OcLogin(*ocAtter) Expect(err).ToNot(HaveOccurred()) - if !profile.AdminEnabled { + if !profileHandler.Profile().IsAdminEnabled() { Skip("The test configured only for cluster admin profile") } @@ -478,7 +483,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { }) It("with multiple users will reconcile a multiuser config - [id:66408]", ci.Medium, ci.Exclude, func() { var err error - idpServices.htpasswd, err = exec.NewIDPService(constants.HtpasswdDir) // init new htpasswd service + idpServices.htpasswd, err = profileHandler.Services().GetIDPService(constants.IDPHTPassword) Expect(err).ToNot(HaveOccurred()) By("Create 3 htpasswd users for existing cluster") @@ -499,7 +504,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("Login to the cluster with one of the users created") - resp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + resp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) server := resp.Body().API().URL() @@ -520,7 +525,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("Delete one of the users using backend api") - _, err = cms.DeleteIDP(ci.RHCSConnection, clusterID, idpOutput.ID) + _, err = cms.DeleteIDP(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(err).ToNot(HaveOccurred()) // wait few minutes before trying to create the resource again @@ -562,15 +567,15 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { It("the mandatory idp's attributes must be set - [id:68939]", ci.Medium, func() { var err error - idpServices.htpasswd, err = exec.NewIDPService(constants.HtpasswdDir) // init new htpasswd service + idpServices.htpasswd, err = profileHandler.Services().GetIDPService(constants.IDPHTPassword) Expect(err).ToNot(HaveOccurred()) - idpServices.ldap, err = exec.NewIDPService(constants.LdapDir) // init new ldap service + idpServices.ldap, err = profileHandler.Services().GetIDPService(constants.IDPLDAP) Expect(err).ToNot(HaveOccurred()) - idpServices.github, err = exec.NewIDPService(constants.GithubDir) // init new github service + idpServices.github, err = profileHandler.Services().GetIDPService(constants.IDPGithub) Expect(err).ToNot(HaveOccurred()) - idpServices.gitlab, err = exec.NewIDPService(constants.GitlabDir) // init new gitlab service + idpServices.gitlab, err = profileHandler.Services().GetIDPService(constants.IDPGitlab) Expect(err).ToNot(HaveOccurred()) - idpServices.google, err = exec.NewIDPService(constants.GoogleDir) // init new google service + idpServices.google, err = profileHandler.Services().GetIDPService(constants.IDPGoogle) Expect(err).ToNot(HaveOccurred()) idpName := "ocp-68939-htp" @@ -677,7 +682,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { It("htpasswd with empty user-password list will fail - [id:66409]", ci.Medium, func() { var err error - idpServices.htpasswd, err = exec.NewIDPService(constants.HtpasswdDir) // init new htpasswd service + idpServices.htpasswd, err = profileHandler.Services().GetIDPService(constants.IDPHTPassword) Expect(err).ToNot(HaveOccurred()) idpName := "ocp-66409" @@ -689,7 +694,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { It("htpasswd password policy - [id:66410]", ci.Medium, func() { var err error - idpServices.htpasswd, err = exec.NewIDPService(constants.HtpasswdDir) // init new htpasswd service + idpServices.htpasswd, err = profileHandler.Services().GetIDPService(constants.IDPHTPassword) Expect(err).ToNot(HaveOccurred()) idpName := "ocp-66410" @@ -716,7 +721,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { It("htpasswd with duplicate usernames will fail - [id:66411]", ci.Medium, func() { var err error - idpServices.htpasswd, err = exec.NewIDPService(constants.HtpasswdDir) // init new htpasswd service + idpServices.htpasswd, err = profileHandler.Services().GetIDPService(constants.IDPHTPassword) Expect(err).ToNot(HaveOccurred()) idpName := "ocp-66411" @@ -734,11 +739,11 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { ci.Medium, ci.FeatureImport, func() { var err error - idpServices.gitlab, err = exec.NewIDPService(constants.GitlabDir) // init new gitlab service + idpServices.gitlab, err = profileHandler.Services().GetIDPService(constants.IDPGitlab) Expect(err).ToNot(HaveOccurred()) - idpServices.google, err = exec.NewIDPService(constants.GoogleDir) // init new google service + idpServices.google, err = profileHandler.Services().GetIDPService(constants.IDPGoogle) Expect(err).ToNot(HaveOccurred()) - importService, err := exec.NewImportService(constants.ImportResourceDir) + importService, err := profileHandler.Services().GetImportService() Expect(err).ToNot(HaveOccurred()) By("Create sample idps to test the import functionality") @@ -807,7 +812,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { It("verify basic flow - [id:65808]", ci.Medium, ci.Exclude, func() { var err error - idpServices.ldap, err = exec.NewIDPService(constants.LdapDir) // init new ldap service + idpServices.ldap, err = profileHandler.Services().GetIDPService(constants.IDPLDAP) Expect(err).ToNot(HaveOccurred()) idpName := "ocp-65808" @@ -819,7 +824,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("Login to the ldap user") - resp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + resp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) server := resp.Body().API().URL() @@ -838,8 +843,8 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("Delete ldap idp by OCM API") - cms.DeleteIDP(ci.RHCSConnection, clusterID, idpOutput.ID) - _, err = cms.RetrieveClusterIDPDetail(ci.RHCSConnection, clusterID, idpOutput.ID) + cms.DeleteIDP(cms.RHCSConnection, clusterID, idpOutput.ID) + _, err = cms.RetrieveClusterIDPDetail(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(err).To(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring( "Identity provider ID '%s' for cluster '%s' not found", idpOutput.ID, clusterID), @@ -858,7 +863,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { It("try to restore/duplicate an existing IDP - [id:65816]", ci.Medium, func() { var err error - idpServices.gitlab, err = exec.NewIDPService(constants.GitlabDir) // init new gitlab service + idpServices.gitlab, err = profileHandler.Services().GetIDPService(constants.IDPGitlab) Expect(err).ToNot(HaveOccurred()) gitLabIDPName := "OCP-65816-gitlab-idp-reconcil" @@ -870,8 +875,8 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { Expect(err).ToNot(HaveOccurred()) By("Delete gitlab idp using OCM API") - cms.DeleteIDP(ci.RHCSConnection, clusterID, idpOutput.ID) - _, err = cms.RetrieveClusterIDPDetail(ci.RHCSConnection, clusterID, idpOutput.ID) + cms.DeleteIDP(cms.RHCSConnection, clusterID, idpOutput.ID) + _, err = cms.RetrieveClusterIDPDetail(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(err).To(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring( "Identity provider ID '%s' for cluster '%s' not found", idpOutput.ID, clusterID), @@ -886,12 +891,12 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { URL(constants.GitLabURL)). MappingMethod("claim"). Build() - res, err := cms.CreateClusterIDP(ci.RHCSConnection, clusterID, requestBody) + res, err := cms.CreateClusterIDP(cms.RHCSConnection, clusterID, requestBody) Expect(err).ToNot(HaveOccurred()) Expect(res.Status()).To(Equal(http.StatusCreated)) // Delete gitlab idp from existing cluster after test end - defer cms.DeleteIDP(ci.RHCSConnection, clusterID, res.Body().ID()) + defer cms.DeleteIDP(cms.RHCSConnection, clusterID, res.Body().ID()) By("Re-apply gitlab idp using tf manifests with same ocm api args") _, err = idpServices.gitlab.Apply(idpParam) @@ -904,7 +909,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { It("try to restore to an updated IDP config - [id:65814]", ci.Medium, func() { var err error - idpServices.gitlab, err = exec.NewIDPService(constants.GitlabDir) // init new gitlab service + idpServices.gitlab, err = profileHandler.Services().GetIDPService(constants.IDPGitlab) Expect(err).ToNot(HaveOccurred()) gitLabIDPName := "OCP-65814-gitlab-idp-reconcil" @@ -917,8 +922,8 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { // Delete gitlab idp using OCM API after test end defer func() { - cms.DeleteIDP(ci.RHCSConnection, clusterID, idpOutput.ID) - _, err := cms.RetrieveClusterIDPDetail(ci.RHCSConnection, clusterID, idpOutput.ID) + cms.DeleteIDP(cms.RHCSConnection, clusterID, idpOutput.ID) + _, err := cms.RetrieveClusterIDPDetail(cms.RHCSConnection, clusterID, idpOutput.ID) Expect(err).To(HaveOccurred()) Expect(err.Error()).Should(ContainSubstring( "Identity provider ID '%s' for cluster '%s' not found", idpOutput.ID, clusterID), @@ -935,7 +940,7 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() { MappingMethod("claim"). Build() - resp, err := cms.PatchIDP(ci.RHCSConnection, clusterID, idpOutput.ID, requestBody) + resp, err := cms.PatchIDP(cms.RHCSConnection, clusterID, idpOutput.ID, requestBody) Expect(err).ToNot(HaveOccurred()) Expect(resp.Status()).To(Equal(http.StatusOK)) diff --git a/tests/e2e/info_test.go b/tests/e2e/info_test.go index 14cfa9c4..656e602f 100644 --- a/tests/e2e/info_test.go +++ b/tests/e2e/info_test.go @@ -5,17 +5,18 @@ 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" ) var _ = Describe("RHCS Info", func() { var rhcsInfoService exec.RhcsInfoService BeforeEach(func() { - var err error - rhcsInfoService, err = exec.NewRhcsInfoService(constants.RhcsInfoDir) + profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + rhcsInfoService, err = profileHandler.Services().GetRHCSInfoService() Expect(err).ToNot(HaveOccurred()) }) @@ -28,7 +29,7 @@ var _ = Describe("RHCS Info", func() { Expect(err).ShouldNot(HaveOccurred()) By("Comparing rhcs-info state output to OCM API output") - currentAccountInfo, err := cms.RetrieveCurrentAccount(ci.RHCSConnection) + currentAccountInfo, err := cms.RetrieveCurrentAccount(cms.RHCSConnection) Expect(err).ShouldNot(HaveOccurred()) // Address the resource's kind and name for the state command diff --git a/tests/e2e/kubelet_config_test.go b/tests/e2e/kubelet_config_test.go index 2073897e..1e2d79e2 100644 --- a/tests/e2e/kubelet_config_test.go +++ b/tests/e2e/kubelet_config_test.go @@ -9,9 +9,9 @@ import ( cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" ci "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" cms "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/cms" - CON "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" exe "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" ) var _ = Describe("Kubelet config", func() { @@ -22,12 +22,13 @@ var _ = Describe("Kubelet config", func() { var cluster *cmv1.Cluster BeforeEach(func() { - var err error - kcService, err = exe.NewKubeletConfigService(CON.KubeletConfigDir) + profileHandler, err := profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + kcService, err = profileHandler.Services().GetKubeletConfigService() Expect(err).ToNot(HaveOccurred()) - resp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + resp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) cluster = resp.Body() @@ -54,12 +55,12 @@ var _ = Describe("Kubelet config", func() { By("Verify the created kubeletconfig") if cluster.Hypershift().Enabled() { for _, kubeConfig := range kubeletconfigs { - kubeletConfig, err := cms.RetrieveHCPKubeletConfig(ci.RHCSConnection, clusterID, kubeConfig.ID) + kubeletConfig, err := cms.RetrieveHCPKubeletConfig(cms.RHCSConnection, clusterID, kubeConfig.ID) Expect(err).ToNot(HaveOccurred()) Expect(kubeletConfig.PodPidsLimit()).To(Equal(podPidsLimit)) } } else { - kubeletConfig, err := cms.RetrieveKubeletConfig(ci.RHCSConnection, clusterID) + kubeletConfig, err := cms.RetrieveKubeletConfig(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(kubeletConfig.PodPidsLimit()).To(Equal(podPidsLimit)) } @@ -73,12 +74,12 @@ var _ = Describe("Kubelet config", func() { By("Verify the updated kubeletconfig") if cluster.Hypershift().Enabled() { for _, kubeConfig := range kubeletconfigs { - kubeletConfig, err := cms.RetrieveHCPKubeletConfig(ci.RHCSConnection, clusterID, kubeConfig.ID) + kubeletConfig, err := cms.RetrieveHCPKubeletConfig(cms.RHCSConnection, clusterID, kubeConfig.ID) Expect(err).ToNot(HaveOccurred()) Expect(kubeletConfig.PodPidsLimit()).To(Equal(podPidsLimit)) } } else { - kubeletConfig, err := cms.RetrieveKubeletConfig(ci.RHCSConnection, clusterID) + kubeletConfig, err := cms.RetrieveKubeletConfig(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(kubeletConfig.PodPidsLimit()).To(Equal(podPidsLimit)) } @@ -90,11 +91,11 @@ var _ = Describe("Kubelet config", func() { By("Verify the created kubeletconfig") if cluster.Hypershift().Enabled() { for _, kubeConfig := range kubeletconfigs { - _, err := cms.RetrieveHCPKubeletConfig(ci.RHCSConnection, clusterID, kubeConfig.ID) + _, err := cms.RetrieveHCPKubeletConfig(cms.RHCSConnection, clusterID, kubeConfig.ID) Expect(err).To(HaveOccurred()) } } else { - _, err := cms.RetrieveKubeletConfig(ci.RHCSConnection, clusterID) + _, err := cms.RetrieveKubeletConfig(cms.RHCSConnection, clusterID) Expect(err).To(HaveOccurred()) } diff --git a/tests/e2e/negative_day_one_test.go b/tests/e2e/negative_day_one_test.go index d2b540e9..afff34f4 100644 --- a/tests/e2e/negative_day_one_test.go +++ b/tests/e2e/negative_day_one_test.go @@ -15,13 +15,14 @@ import ( . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" "github.com/openshift-online/ocm-common/pkg/aws/aws_client" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var _ = Describe("Negative Tests", Ordered, ContinueOnFailure, func() { defer GinkgoRecover() var ( - profile *ci.Profile + profileHandler profilehandler.ProfileHandler originalClusterVarsFile string clusterService exec.ClusterService ) @@ -49,17 +50,19 @@ var _ = Describe("Negative Tests", Ordered, ContinueOnFailure, func() { } BeforeAll(func() { - profile = ci.LoadProfileYamlFileByENV() + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) - originalClusterArgs, err := ci.GenerateClusterCreationArgsByProfile(token, profile) + originalClusterArgs, err := profileHandler.GenerateClusterCreationArgs(token) if err != nil { - defer ci.DestroyRHCSClusterResourcesByProfile(token, profile) + defer profileHandler.DestroyRHCSClusterResources(token) } Expect(err).ToNot(HaveOccurred()) - clusterService, err = exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err = profileHandler.Services().GetClusterService() if err != nil { - defer ci.DestroyRHCSClusterResourcesByProfile(token, profile) + defer profileHandler.DestroyRHCSClusterResources(token) } Expect(err).ToNot(HaveOccurred()) @@ -76,15 +79,15 @@ var _ = Describe("Negative Tests", Ordered, ContinueOnFailure, func() { exec.DeleteTFvarsFile(originalClusterVarsFile) } - ci.DestroyRHCSClusterResourcesByProfile(token, profile) + profileHandler.DestroyRHCSClusterResources(token) }) Describe("cluster admin", ci.Day1Negative, func() { BeforeEach(OncePerOrdered, func() { - if profile.GetClusterType().HCP { + if profileHandler.Profile().IsHCP() { Skip("Test can run only on Classic cluster") } - if !profile.AdminEnabled { + if !profileHandler.Profile().IsAdminEnabled() { Skip("The tests configured for cluster admin only") } }) @@ -132,7 +135,7 @@ var _ = Describe("Negative Tests", Ordered, ContinueOnFailure, func() { Describe("Create HCP cluster", ci.Day1Negative, func() { BeforeEach(OncePerOrdered, func() { - if !profile.GetClusterType().HCP { + if !profileHandler.Profile().IsHCP() { Skip("Test can run only on Hosted cluster") } }) @@ -230,12 +233,12 @@ var _ = Describe("Negative Tests", Ordered, ContinueOnFailure, func() { }, "Could not find versions") By("Create cluster with version from another channel group") - versions := cms.HCPEnabledVersions(ci.RHCSConnection, exec.CandidateChannel) + versions := cms.HCPEnabledVersions(cms.RHCSConnection, constants.VersionCandidateChannel) versions = cms.SortVersions(versions) vs := versions[len(versions)-1].RawID validateClusterArgAgainstErrorSubstrings(func(args *exec.ClusterArgs) { args.OpenshiftVersion = helper.StringPointer(vs) - args.ChannelGroup = helper.StringPointer(exec.StableChannel) + args.ChannelGroup = helper.StringPointer(constants.VersionStableChannel) }, fmt.Sprintf("version %s is not in the list of supported versions", vs)) }) @@ -354,7 +357,7 @@ var _ = Describe("Negative Tests", Ordered, ContinueOnFailure, func() { It("validate network fields - [id:72468]", ci.Medium, func() { By("Retrieve VPC output") - vpcService, err := exec.NewVPCService(constants.GetAWSVPCDefaultManifestDir(profile.GetClusterType())) + vpcService, err := profileHandler.Services().GetVPCService() Expect(err).ToNot(HaveOccurred()) vpcOutput, err := vpcService.Output() Expect(err).ToNot(HaveOccurred()) @@ -366,7 +369,7 @@ var _ = Describe("Negative Tests", Ordered, ContinueOnFailure, func() { By("Create cluster with AZ not in region name") az := "us-west-2a" - if profile.Region == "us-west-2" { + if profileHandler.Profile().GetRegion() == "us-west-2" { az = "us-east-1a" } validateClusterArgAgainstErrorSubstrings(func(args *exec.ClusterArgs) { @@ -540,7 +543,7 @@ var _ = Describe("Negative Tests", Ordered, ContinueOnFailure, func() { Describe("The EOL OCP version validation", ci.Day1Negative, func() { It("version validation - [id:64095]", ci.Medium, func() { - if profile.AdditionalSGNumber > 0 { + if profileHandler.Profile().GetAdditionalSGNumber() > 0 { Skip("Test is not made when security groups is enabled as the message will not be related to EOL support") } By("create cluster with an EOL OCP version") diff --git a/tests/e2e/trusted_ips_test.go b/tests/e2e/trusted_ips_test.go index e90d175e..b4e02ea1 100644 --- a/tests/e2e/trusted_ips_test.go +++ b/tests/e2e/trusted_ips_test.go @@ -6,8 +6,8 @@ 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/exec" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var _ = Describe("Trusted IPs", func() { @@ -16,10 +16,14 @@ var _ = Describe("Trusted IPs", func() { var ( err error trustedIPsService exec.TrustedIPsService + profileHandler profilehandler.ProfileHandler ) BeforeEach(func() { - trustedIPsService, err = exec.NewTrustedIPsService(constants.TrustedIPsDir) + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) + + trustedIPsService, err = profileHandler.Services().GetTrustedIPsService() Expect(err).ToNot(HaveOccurred()) }) diff --git a/tests/e2e/tuning_config_test.go b/tests/e2e/tuning_config_test.go index cef49188..6db61197 100644 --- a/tests/e2e/tuning_config_test.go +++ b/tests/e2e/tuning_config_test.go @@ -8,18 +8,18 @@ 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/log" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" "gopkg.in/yaml.v2" ) var _ = Describe("Tuning Config", ci.FeatureTuningConfig, ci.Day2, func() { var ( - tcService exec.TuningConfigService - mpService exec.MachinePoolService - profile *ci.Profile + profileHandler profilehandler.ProfileHandler + tcService exec.TuningConfigService + mpService exec.MachinePoolService ) verifyTuningConfigSpec := func(spec interface{}, profileName string, specVmDirtyRatio, specPriority int) { @@ -33,16 +33,17 @@ var _ = Describe("Tuning Config", ci.FeatureTuningConfig, ci.Day2, func() { } BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() + Expect(err).ToNot(HaveOccurred()) - if !profile.GetClusterType().HCP { + if !profileHandler.Profile().IsHCP() { Skip("Test can run only on Hosted cluster") } - var err error - mpService, err = exec.NewMachinePoolService(constants.HCPMachinePoolDir) + mpService, err = profileHandler.Services().GetMachinePoolsService() Expect(err).ToNot(HaveOccurred()) - tcService, err = exec.NewTuningConfigService(constants.TuningConfigDir) + tcService, err = profileHandler.Services().GetTuningConfigService() Expect(err).ToNot(HaveOccurred()) }) @@ -77,7 +78,7 @@ var _ = Describe("Tuning Config", ci.FeatureTuningConfig, ci.Day2, func() { Expect(err).ToNot(HaveOccurred()) By("Verify tuning config") - tcsResp, err := cms.ListTuningConfigs(ci.RHCSConnection, clusterID) + tcsResp, err := cms.ListTuningConfigs(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(tcsResp.Size()).To(Equal(tcCount)) tc := tcsResp.Items().Get(0) @@ -102,7 +103,7 @@ var _ = Describe("Tuning Config", ci.FeatureTuningConfig, ci.Day2, func() { Expect(err).ToNot(HaveOccurred()) By("Verify tuning configs") - tcsResp, err = cms.ListTuningConfigs(ci.RHCSConnection, clusterID) + tcsResp, err = cms.ListTuningConfigs(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(tcsResp.Size()).To(Equal(tcCount)) var expectedNames []string @@ -141,7 +142,7 @@ var _ = Describe("Tuning Config", ci.FeatureTuningConfig, ci.Day2, func() { Expect(err).ToNot(HaveOccurred()) By("Verify tuning configs") - tcsResp, err = cms.ListTuningConfigs(ci.RHCSConnection, clusterID) + tcsResp, err = cms.ListTuningConfigs(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(tcsResp.Size()).To(Equal(tcCount)) expectedNames = []string{} @@ -215,7 +216,7 @@ var _ = Describe("Tuning Config", ci.FeatureTuningConfig, ci.Day2, func() { Expect(err).ToNot(HaveOccurred()) By("Try to edit cluster with other cluster ID") - clustersResp, err := cms.ListClusters(ci.RHCSConnection) + clustersResp, err := cms.ListClusters(cms.RHCSConnection) Expect(err).ToNot(HaveOccurred()) var otherClusterID string for _, cluster := range clustersResp.Items().Slice() { @@ -257,7 +258,7 @@ var _ = Describe("Tuning Config", ci.FeatureTuningConfig, ci.Day2, func() { }, "cannot unmarshal string") By("Get vpc output") - vpcService, err := exec.NewVPCService(constants.GetAWSVPCDefaultManifestDir(profile.GetClusterType())) + vpcService, err := profileHandler.Services().GetVPCService() Expect(err).ToNot(HaveOccurred()) vpcOutput, err := vpcService.Output() Expect(err).ToNot(HaveOccurred()) diff --git a/tests/e2e/verification_post_day1_test.go b/tests/e2e/verification_post_day1_test.go index 694e01c4..c87fb2cb 100644 --- a/tests/e2e/verification_post_day1_test.go +++ b/tests/e2e/verification_post_day1_test.go @@ -20,29 +20,35 @@ import ( "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/openshift" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/profilehandler" ) var _ = Describe("Verify cluster", func() { defer GinkgoRecover() - var err error - var profile *ci.Profile - var cluster *cmsv1.Cluster + var ( + profileHandler profilehandler.ProfileHandler + profile profilehandler.ProfileSpec + cluster *cmsv1.Cluster + ) BeforeEach(func() { - profile = ci.LoadProfileYamlFileByENV() + var err error + profileHandler, err = profilehandler.NewProfileHandlerFromYamlFile() Expect(err).ToNot(HaveOccurred()) - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + profile = profile + + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) cluster = getResp.Body() }) It("proxy is correctly set - [id:67607]", ci.Day1Post, ci.High, func() { - if !profile.Proxy { + if !profile.IsProxy() { Skip("No proxy is configured for the cluster. skipping the test.") } - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(getResp.Body().Proxy().HTTPProxy()).To(ContainSubstring("http://")) Expect(getResp.Body().Proxy().HTTPSProxy()).To(ContainSubstring("https://")) @@ -51,7 +57,7 @@ var _ = Describe("Verify cluster", func() { }) It("is successfully installed - [id:63134]", ci.Day1Post, ci.High, func() { - getResp, err := cms.RetrieveClusterStatus(ci.RHCSConnection, clusterID) + getResp, err := cms.RetrieveClusterStatus(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(string(getResp.Body().State())).To(Equal("ready")) Expect(getResp.Status()).To(Equal(http.StatusOK)) @@ -67,7 +73,7 @@ var _ = Describe("Verify cluster", func() { It("custom properties is correctly set - [id:64906]", ci.Day1Post, ci.Medium, func() { By("Check custom_property field is present under cluster's properties") - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(getResp.Body().Properties()["custom_property"]).To(Equal("test")) @@ -79,7 +85,7 @@ var _ = Describe("Verify cluster", func() { }) It("fips is correctly enabled/disabled - [id:63140]", ci.Day1Post, ci.High, func() { - Expect(cluster.FIPS()).To(Equal(profile.FIPS)) + Expect(cluster.FIPS()).To(Equal(profile.IsFIPS())) }) It("private_link is correctly enabled/disabled - [id:63133]", ci.Day1Post, ci.High, func() { @@ -87,25 +93,25 @@ var _ = Describe("Verify cluster", func() { }) It("etcd-encryption is correctly enabled/disabled - [id:63143]", ci.Day1Post, ci.High, func() { - Expect(cluster.EtcdEncryption()).To(Equal(profile.Etcd)) + Expect(cluster.EtcdEncryption()).To(Equal(profile.IsEtcd())) }) It("etcd-encryption key is correctly set - [id:72485]", ci.Day1Post, ci.High, func() { - if !profile.GetClusterType().HCP { + if !profile.IsHCP() { Skip("This test is for Hosted cluster") } - if !profile.Etcd { + if !profile.IsEtcd() { Skip("Etcd is not activated. skipping the test.") } By("Retrieve etcd defined key") var kmsService exec.KMSService var err error - if profile.DifferentEncryptionKeys { - kmsService, err = exec.NewKMSService(constants.KMSSecondDir) + if profile.IsDifferentEncryptionKeys() { + kmsService, err = profileHandler.Duplicate().Services().GetKMSService() Expect(err).ToNot(HaveOccurred()) } else { - kmsService, err = exec.NewKMSService(constants.KMSDir) + kmsService, err = profileHandler.Services().GetKMSService() Expect(err).ToNot(HaveOccurred()) } kmsOutput, err := kmsService.Output() @@ -113,13 +119,13 @@ var _ = Describe("Verify cluster", func() { etcdKey := kmsOutput.KeyARN By("Check etcd Encryption key") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(clusterResp.Body().AWS().EtcdEncryption().KMSKeyARN()).To(Equal(etcdKey)) }) It("compute_machine_type is correctly set - [id:64023]", ci.Day1Post, ci.Medium, func() { - computeMachineType := profile.ComputeMachineType + computeMachineType := profile.GetComputeMachineType() if constants.RHCS.ComputeMachineType != "" { computeMachineType = constants.RHCS.ComputeMachineType } @@ -130,29 +136,29 @@ var _ = Describe("Verify cluster", func() { }) It("compute_replicas is correctly set - [id:73153]", ci.Day1Post, ci.Medium, func() { - if profile.ComputeReplicas <= 0 { + if profile.GetComputeReplicas() <= 0 { Skip("No compute_replicas is configured for the cluster. skipping the test.") } - Expect(cluster.Nodes().Compute()).To(Equal(profile.ComputeReplicas)) + Expect(cluster.Nodes().Compute()).To(Equal(profile.GetComputeReplicas())) }) It("availability zones and multi-az are correctly set - [id:63141]", ci.Day1Post, ci.Medium, func() { - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) - zonesArray := strings.Split(profile.Zones, ",") + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) + zonesArray := strings.Split(profile.GetZones(), ",") clusterAvailZones := getResp.Body().Nodes().AvailabilityZones() Expect(err).ToNot(HaveOccurred()) - Expect(getResp.Body().MultiAZ()).To(Equal(profile.MultiAZ)) + Expect(getResp.Body().MultiAZ()).To(Equal(profile.IsMultiAZ())) - if profile.Zones != "" { - Expect(clusterAvailZones).To(Equal(helper.JoinStringWithArray(profile.Region, zonesArray))) + if profile.GetZones() != "" { + Expect(clusterAvailZones).To(Equal(helper.JoinStringWithArray(profile.GetRegion(), zonesArray))) } else { // the default zone for each region - Expect(clusterAvailZones[0]).To(Equal(fmt.Sprintf("%sa", profile.Region))) + Expect(clusterAvailZones[0]).To(Equal(fmt.Sprintf("%sa", profile.GetRegion()))) } }) It("compute_labels are correctly set - [id:68423]", ci.Day1Post, ci.High, func() { - if profile.Labeling { + if profile.IsLabeling() { Expect(cluster.Nodes().ComputeLabels()).To(Equal(constants.DefaultMPLabels)) } else { Expect(cluster.Nodes().ComputeLabels()).To(Equal(constants.NilMap)) @@ -165,10 +171,10 @@ var _ = Describe("Verify cluster", func() { "red-hat-managed": "true", } - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) - if profile.Tagging { + if profile.IsTagging() { allClusterTags := helper.MergeMaps(buildInTags, constants.Tags) Expect(len(getResp.Body().AWS().Tags())).To(Equal(len(allClusterTags))) @@ -182,12 +188,11 @@ var _ = Describe("Verify cluster", func() { }) It("can be imported - [id:65684]", ci.Day2, ci.Medium, ci.FeatureImport, func() { - - if profile.GetClusterType().HCP { + if profile.IsHCP() { Skip("Test can run only on Classic cluster") } - importService, err := exec.NewImportService(constants.ImportResourceDir) // init new import service + importService, err := profileHandler.Services().GetImportService() Expect(err).ToNot(HaveOccurred()) By("Run the command to import cluster resource") @@ -195,7 +200,7 @@ var _ = Describe("Verify cluster", func() { importService.Destroy() }() resource := "rhcs_cluster_rosa_classic.rosa_sts_cluster_import" - if profile.GetClusterType().HCP { + if profile.IsHCP() { resource = "rhcs_cluster_rosa_hcp.rosa_hcp_cluster_import" } importParam := &exec.ImportArgs{ @@ -210,9 +215,9 @@ var _ = Describe("Verify cluster", func() { Expect(err).ToNot(HaveOccurred()) // validate import was successful by checking samples fields - Expect(output).To(ContainSubstring(profile.ClusterName)) - Expect(output).To(ContainSubstring(profile.Region)) - Expect(output).To(ContainSubstring(profile.ChannelGroup)) + Expect(output).To(ContainSubstring(cluster.Name())) + Expect(output).To(ContainSubstring(profile.GetRegion())) + Expect(output).To(ContainSubstring(cluster.Version().GetChannelGroup())) By("Remove state") _, err = importService.RemoveState(resource) @@ -233,31 +238,33 @@ var _ = Describe("Verify cluster", func() { ci.Day1Post, ci.High, ci.Exclude, func() { - if !profile.AdminEnabled { + if !profile.IsAdminEnabled() { Skip("The test configured only for cluster admin profile") } By("List existing Htpasswd IDP") - idpList, _ := cms.ListClusterIDPs(ci.RHCSConnection, clusterID) + idpList, _ := cms.ListClusterIDPs(cms.RHCSConnection, clusterID) Expect(idpList.Items().Len()).To(Equal(1)) Expect(idpList.Items().Slice()[0].Name()).To(Equal("cluster-admin")) By("List existing HtpasswdUsers and compare to the created one") idpID := idpList.Items().Slice()[0].ID() - htpasswdUsersList, _ := cms.ListHtpasswdUsers(ci.RHCSConnection, clusterID, idpID) + htpasswdUsersList, _ := cms.ListHtpasswdUsers(cms.RHCSConnection, clusterID, idpID) Expect(htpasswdUsersList.Status()).To(Equal(http.StatusOK)) respUserName, _ := htpasswdUsersList.Items().Slice()[0].GetUsername() Expect(respUserName).To(Equal("rhcs-clusteradmin")) By("Check resource state file is updated") - resource, err := helper.GetResource(profile.GetClusterManifestsDir(), "rhcs_cluster_rosa_classic", "rosa_sts_cluster") + clusterService, err := profileHandler.Services().GetClusterService() + Expect(err).ToNot(HaveOccurred()) + resource, err := clusterService.GetStateResource("rhcs_cluster_rosa_classic", "rosa_sts_cluster") Expect(err).ToNot(HaveOccurred()) passwordInState, _ := JQ(`.instances[0].attributes.admin_credentials.password`, resource) Expect(passwordInState).NotTo(BeEmpty()) Expect(resource).To(MatchJQ(`.instances[0].attributes.admin_credentials.username`, "rhcs-clusteradmin")) By("Login with created cluster admin password") - getResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + getResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) server := getResp.Body().API().URL() @@ -284,17 +291,17 @@ var _ = Describe("Verify cluster", func() { It("additional security group are correctly set - [id:69145]", ci.Day1Post, ci.Critical, func() { - if profile.GetClusterType().HCP { + if profile.IsHCP() { Skip("Test can run only on Classic cluster") } By("Check the profile settings") - if profile.AdditionalSGNumber == 0 { + if profile.GetAdditionalSGNumber() == 0 { Expect(cluster.AWS().AdditionalComputeSecurityGroupIds()).To(BeEmpty()) Expect(cluster.AWS().AdditionalControlPlaneSecurityGroupIds()).To(BeEmpty()) Expect(cluster.AWS().AdditionalInfraSecurityGroupIds()).To(BeEmpty()) } else { By("Verify CMS are using the correct configuration") - clusterService, err := exec.NewClusterService(profile.GetClusterManifestsDir()) + clusterService, err := profileHandler.Services().GetClusterService() Expect(err).ToNot(HaveOccurred()) output, err := clusterService.Output() Expect(err).ToNot(HaveOccurred()) @@ -312,37 +319,37 @@ var _ = Describe("Verify cluster", func() { It("worker disk size is set correctly - [id:69143]", ci.Day1Post, ci.Critical, func() { - if profile.GetClusterType().HCP { + + if profile.IsHCP() { Skip("Test can run only on Classic cluster") } - - switch profile.WorkerDiskSize { + switch profile.GetWorkerDiskSize() { case 0: Expect(cluster.Nodes().ComputeRootVolume().AWS().Size()).To(Equal(300)) default: - Expect(cluster.Nodes().ComputeRootVolume().AWS().Size()).To(Equal(profile.WorkerDiskSize)) + Expect(cluster.Nodes().ComputeRootVolume().AWS().Size()).To(Equal(profile.GetWorkerDiskSize())) } }) It("account roles/policies unified path is correctly set - [id:63138]", ci.Day1Post, ci.Medium, func() { unifiedPath, err := accountroles.GetPathFromAccountRole(cluster, accountroles.AccountRoles[accountroles.InstallerAccountRole].Name) Expect(err).ToNot(HaveOccurred()) - Expect(profile.UnifiedAccRolesPath).Should(ContainSubstring(unifiedPath)) + Expect(profile.GetUnifiedAccRolesPath()).Should(ContainSubstring(unifiedPath)) }) It("customer-managed KMS key is set correctly - [id:63334]", ci.Day1Post, ci.Medium, func() { - if !profile.KMSKey { + if !profile.IsKMSKey() { Skip("The test is configured only for the profile containing the KMS key") } By("Check the kmsKeyARN") - listRSresp, err := cms.ListClusterResources(ci.RHCSConnection, clusterID) + listRSresp, err := cms.ListClusterResources(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) - kmsService, err := exec.NewKMSService() + kmsService, err := profileHandler.Services().GetKMSService() Expect(err).ToNot(HaveOccurred()) kmsOutput, _ := kmsService.Output() expectedKeyArn := kmsOutput.KeyARN - if profile.GetClusterType().HCP { + if profile.IsHCP() { for key, value := range listRSresp.Body().Resources() { if strings.Contains(key, "workers") { Expect(value).Should(ContainSubstring(`"encryptionKey":"` + expectedKeyArn + `"`)) @@ -355,11 +362,11 @@ var _ = Describe("Verify cluster", func() { }) It("imdsv2 value is set correctly - [id:63950]", ci.Day1Post, ci.Critical, func() { - if profile.GetClusterType().HCP { + if profile.IsHCP() { Skip("Test can run only on Classic cluster") } - if profile.Ec2MetadataHttpTokens != "" { - Expect(string(cluster.AWS().Ec2MetadataHttpTokens())).To(Equal(profile.Ec2MetadataHttpTokens)) + if profile.GetEc2MetadataHttpTokens() != "" { + Expect(string(cluster.AWS().Ec2MetadataHttpTokens())).To(Equal(profile.GetEc2MetadataHttpTokens())) } else { Expect(cluster.AWS().Ec2MetadataHttpTokens()).To(Equal(cmsv1.Ec2MetadataHttpTokensOptional)) } @@ -367,17 +374,17 @@ var _ = Describe("Verify cluster", func() { It("host prefix and cidrs are set correctly - [id:72466]", ci.Day1Post, ci.Medium, func() { By("Retrieve profile information") - machineCIDR := profile.MachineCIDR - serviceCIDR := profile.ServiceCIDR - podCIDR := profile.PodCIDR - hostPrefix := profile.HostPrefix + machineCIDR := profile.GetMachineCIDR() + serviceCIDR := profile.GetServiceCIDR() + podCIDR := profile.GetPodCIDR() + hostPrefix := profile.GetHostPrefix() if machineCIDR == "" && serviceCIDR == "" && podCIDR == "" && hostPrefix <= 0 { Skip("The test is configured only for the profile containing the cidrs and host prefix") } By("Retrieve cluster detail") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) networkDetail := clusterResp.Body().Network() @@ -391,19 +398,19 @@ var _ = Describe("Verify cluster", func() { It("resources will wait for cluster ready - [id:74096]", ci.Day1Post, ci.Critical, func() { By("Check if cluster is full resources, if not skip") - if !profile.FullResources { + if !profile.IsFullResources() { Skip("This only work for full resources testing") } By("Check the created IDP") - resp, err := cms.ListClusterIDPs(ci.RHCSConnection, clusterID) + resp, err := cms.ListClusterIDPs(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(resp.Items().Len()).To(Equal(1)) Expect(resp.Items().Get(0).Name()).To(Equal("full-resource")) idpID := resp.Items().Get(0).ID() By("Check the group membership") - userResp, err := cms.ListHtpasswdUsers(ci.RHCSConnection, clusterID, idpID) + userResp, err := cms.ListHtpasswdUsers(cms.RHCSConnection, clusterID, idpID) Expect(err).ToNot(HaveOccurred()) Expect(userResp.Items().Len()).To(Equal(1)) Expect(userResp.Items().Get(0).Username()).To(Equal("full-resource")) @@ -411,20 +418,20 @@ var _ = Describe("Verify cluster", func() { By("Check the kubeletconfig") if cluster.Hypershift().Enabled() { - kubeletConfigs, err := cms.ListHCPKubeletConfigs(ci.RHCSConnection, clusterID) + kubeletConfigs, err := cms.ListHCPKubeletConfigs(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(len(kubeletConfigs)).To(Equal(1)) Expect(kubeletConfigs[0].PodPidsLimit()).To(Equal(4097)) } else { - kubeConfig, err := cms.RetrieveKubeletConfig(ci.RHCSConnection, clusterID) + kubeConfig, err := cms.RetrieveKubeletConfig(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(kubeConfig.PodPidsLimit()).To(Equal(4097)) } By("Check the default ingress") - ingress, err := cms.RetrieveClusterIngress(ci.RHCSConnection, clusterID) + ingress, err := cms.RetrieveClusterIngress(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) if !cluster.Hypershift().Enabled() { Expect(ingress.ExcludedNamespaces()).To(ContainElement("full-resource")) @@ -434,7 +441,7 @@ var _ = Describe("Verify cluster", func() { By("Check the created autoscaler") if !cluster.Hypershift().Enabled() { - autoscaler, err := cms.RetrieveClusterAutoscaler(ci.RHCSConnection, clusterID) + autoscaler, err := cms.RetrieveClusterAutoscaler(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(autoscaler.Body().MaxPodGracePeriod()).To(Equal(1000)) } @@ -442,11 +449,11 @@ var _ = Describe("Verify cluster", func() { By("Check the created machinepool") mpName := "full-resource" if !cluster.Hypershift().Enabled() { - mp, err := cms.RetrieveClusterMachinePool(ci.RHCSConnection, clusterID, mpName) + mp, err := cms.RetrieveClusterMachinePool(cms.RHCSConnection, clusterID, mpName) Expect(err).ToNot(HaveOccurred()) Expect(mp).ToNot(BeNil()) } else { - np, err := cms.RetrieveNodePool(ci.RHCSConnection, clusterID, mpName) + np, err := cms.RetrieveNodePool(cms.RHCSConnection, clusterID, mpName) Expect(err).ToNot(HaveOccurred()) Expect(np).ToNot(BeNil()) } @@ -454,7 +461,7 @@ var _ = Describe("Verify cluster", func() { By("Check the created tuningconfig") tunningConfigName := "full-resource" if cluster.Hypershift().Enabled() { - tunnings, err := cms.ListTuningConfigs(ci.RHCSConnection, clusterID) + tunnings, err := cms.ListTuningConfigs(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(tunnings.Total()).To(Equal(1)) Expect(tunnings.Items().Get(0).Name()).To(Equal(tunningConfigName)) @@ -464,10 +471,10 @@ var _ = Describe("Verify cluster", func() { It("multiarch is set correctly - [id:75107]", ci.Day1Post, ci.High, func() { By("Verify cluster configuration") - clusterResp, err := cms.RetrieveClusterDetail(ci.RHCSConnection, clusterID) + clusterResp, err := cms.RetrieveClusterDetail(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) - if profile.GetClusterType().HCP { + if profile.IsHCP() { Expect(clusterResp.Body().MultiArchEnabled()).To(BeTrue()) } else { Expect(clusterResp.Body().MultiArchEnabled()).To(BeFalse()) @@ -475,21 +482,21 @@ var _ = Describe("Verify cluster", func() { }) It("imdsv2 is set correctly - [id:75372]", ci.Day1Post, ci.Critical, func() { - if !profile.GetClusterType().HCP { + if !profile.IsHCP() { Skip("Test can run only on HCP cluster") } By("Check the cluster description value to match cluster profile configuration") - if profile.Ec2MetadataHttpTokens != "" { + if profile.GetEc2MetadataHttpTokens() != "" { Expect(string(cluster.AWS().Ec2MetadataHttpTokens())). - To(Equal(profile.Ec2MetadataHttpTokens)) + To(Equal(profile.GetEc2MetadataHttpTokens())) } else { Expect(string(cluster.AWS().Ec2MetadataHttpTokens())). To(Equal(constants.DefaultEc2MetadataHttpTokens)) } By("Get the default workers machinepool details") - npList, err := cms.ListNodePools(ci.RHCSConnection, clusterID) + npList, err := cms.ListNodePools(cms.RHCSConnection, clusterID) Expect(err).ToNot(HaveOccurred()) Expect(npList).ToNot(BeEmpty()) @@ -497,7 +504,7 @@ var _ = Describe("Verify cluster", func() { Expect(np.ID()).ToNot(BeNil()) if strings.HasPrefix(np.ID(), constants.DefaultNodePoolName) { By("Get the details of the nodepool") - npRespBody, err := cms.RetrieveClusterNodePool(ci.RHCSConnection, clusterID, np.ID()) + npRespBody, err := cms.RetrieveClusterNodePool(cms.RHCSConnection, clusterID, np.ID()) Expect(err).ToNot(HaveOccurred()) By("Check the default workers machinepool value to match cluster level spec attribute") diff --git a/tests/tf-manifests/aws/add-account-roles/rosa-classic/main.tf b/tests/tf-manifests/aws/add-account-roles/rosa-classic/main.tf deleted file mode 100644 index a801c161..00000000 --- a/tests/tf-manifests/aws/add-account-roles/rosa-classic/main.tf +++ /dev/null @@ -1,56 +0,0 @@ -terraform { - required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 4.20.0" - } - rhcs = { - version = ">= 1.6.3" - source = "terraform.local/local/rhcs" - } - } -} - -provider "rhcs" { -} - -data "aws_caller_identity" "current" { -} - -data "aws_partition" "current" { -} - -locals { - path = coalesce(var.path, "/") - aws_account_id = data.aws_caller_identity.current.account_id -} - -module "create_account_roles" { - source = "terraform-redhat/rosa-classic/rhcs//modules/account-iam-resources" - version = ">=1.6.3" - - account_role_prefix = var.account_role_prefix - openshift_version = var.openshift_version - path = local.path - permissions_boundary = var.permissions_boundary - tags = var.tags -} - -module "rosa-classic_operator-policies" { - source = "terraform-redhat/rosa-classic/rhcs//modules/operator-policies" - version = ">=1.6.3" - - account_role_prefix = module.create_account_roles.account_role_prefix - openshift_version = var.openshift_version - path = local.path - shared_vpc_role_arn = var.shared_vpc_role_arn - tags = var.tags -} - -resource "random_string" "random_suffix" { - count = var.account_role_prefix == "" || var.account_role_prefix == null ? 1 : 0 - - length = 4 - special = false - upper = false -} diff --git a/tests/tf-manifests/aws/add-account-roles/rosa-classic/output.tf b/tests/tf-manifests/aws/add-account-roles/rosa-classic/output.tf deleted file mode 100644 index ea107782..00000000 --- a/tests/tf-manifests/aws/add-account-roles/rosa-classic/output.tf +++ /dev/null @@ -1,11 +0,0 @@ -output "account_role_prefix" { - value = module.create_account_roles.account_role_prefix -} - -output "installer_role_arn" { - value = module.create_account_roles.account_roles_arn["Installer"] -} - -output "aws_account_id" { - value = local.aws_account_id -} diff --git a/tests/tf-manifests/aws/add-account-roles/rosa-classic/variables.tf b/tests/tf-manifests/aws/add-account-roles/rosa-classic/variables.tf deleted file mode 100644 index 05c3126a..00000000 --- a/tests/tf-manifests/aws/add-account-roles/rosa-classic/variables.tf +++ /dev/null @@ -1,33 +0,0 @@ -variable "openshift_version" { - type = string - default = "4.13.13" -} - -variable "account_role_prefix" { - type = string - default = null -} - -variable "path" { - description = "(Optional) The arn path for the account/operator roles as well as their policies." - type = string - default = null -} - -variable "permissions_boundary" { - description = "The ARN of the policy that is used to set the permissions boundary for the IAM roles in STS clusters." - type = string - default = "" -} - -variable "shared_vpc_role_arn" { - description = "(Optional) Create Shared-VPC policies." - type = string - default = "" -} - -variable "tags" { - description = "Map of AWS resource tags to apply." - type = map(string) - default = null -} diff --git a/tests/tf-manifests/aws/add-account-roles/rosa-hcp/main.tf b/tests/tf-manifests/aws/add-account-roles/rosa-hcp/main.tf deleted file mode 100644 index 81037684..00000000 --- a/tests/tf-manifests/aws/add-account-roles/rosa-hcp/main.tf +++ /dev/null @@ -1,37 +0,0 @@ -terraform { - required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 4.20.0" - } - rhcs = { - version = ">= 1.6.3" - source = "terraform.local/local/rhcs" - } - } -} - -provider "rhcs" { -} - -data "aws_caller_identity" "current" { -} - -data "aws_partition" "current" { -} - - -locals { - path = coalesce(var.path, "/") - aws_account_id = data.aws_caller_identity.current.account_id -} - -module "create_account_roles" { - source = "terraform-redhat/rosa-hcp/rhcs//modules/account-iam-resources" - version = ">=1.6.3" - - account_role_prefix = var.account_role_prefix - path = local.path - permissions_boundary = var.permissions_boundary - tags = var.tags -} diff --git a/tests/tf-manifests/aws/add-account-roles/rosa-hcp/output.tf b/tests/tf-manifests/aws/add-account-roles/rosa-hcp/output.tf deleted file mode 100644 index bc3b2b78..00000000 --- a/tests/tf-manifests/aws/add-account-roles/rosa-hcp/output.tf +++ /dev/null @@ -1,11 +0,0 @@ -output "account_role_prefix" { - value = module.create_account_roles.account_role_prefix -} - -output "installer_role_arn" { - value = module.create_account_roles.account_roles_arn["HCP-ROSA-Installer"] -} - -output "aws_account_id" { - value = local.aws_account_id -} diff --git a/tests/tf-manifests/aws/add-account-roles/rosa-hcp/variables.tf b/tests/tf-manifests/aws/add-account-roles/rosa-hcp/variables.tf deleted file mode 100644 index 05c3126a..00000000 --- a/tests/tf-manifests/aws/add-account-roles/rosa-hcp/variables.tf +++ /dev/null @@ -1,33 +0,0 @@ -variable "openshift_version" { - type = string - default = "4.13.13" -} - -variable "account_role_prefix" { - type = string - default = null -} - -variable "path" { - description = "(Optional) The arn path for the account/operator roles as well as their policies." - type = string - default = null -} - -variable "permissions_boundary" { - description = "The ARN of the policy that is used to set the permissions boundary for the IAM roles in STS clusters." - type = string - default = "" -} - -variable "shared_vpc_role_arn" { - description = "(Optional) Create Shared-VPC policies." - type = string - default = "" -} - -variable "tags" { - description = "Map of AWS resource tags to apply." - type = map(string) - default = null -} diff --git a/tests/tf-manifests/aws/kms-second/main.tf b/tests/tf-manifests/aws/kms-second/main.tf deleted file mode 100644 index 3a6c1785..00000000 --- a/tests/tf-manifests/aws/kms-second/main.tf +++ /dev/null @@ -1,63 +0,0 @@ -terraform { - required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 4.20.0" - } - } -} - -provider "aws" { - region = var.aws_region -} - -# Get current account ID -data "aws_caller_identity" "current" { -} - -locals { - path = coalesce(var.path, "/") - - iamRoles = var.hcp ? [ - "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root", - ] : [ - "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root", - "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role${local.path}${var.account_role_prefix}-Installer-Role", - "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role${local.path}${var.account_role_prefix}-Support-Role", - "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role${local.path}${var.account_role_prefix}-ControlPlane-Role", - "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role${local.path}${var.account_role_prefix}-Worker-Role" - ] - - defaultTags = { - Key = var.tag_key - Value = var.tag_value - Description = var.tag_description - } - optionalTags = var.hcp ? { red-hat = true } : {} -} - -resource "aws_kms_key" "cluster_kms_key" { - description = "BYOK Test Key for API automation" - tags = merge(local.defaultTags, local.optionalTags) - deletion_window_in_days = 7 -} - -resource "aws_kms_key_policy" "cluster_kms_key_policy" { - key_id = aws_kms_key.cluster_kms_key.id - policy = jsonencode({ - Id = var.kms_name - Statement = [ - { - Action = "kms:*" - Effect = "Allow" - Principal = { - AWS = local.iamRoles - } - Resource = "*" - Sid = "Enable IAM User Permissions" - }, - ] - Version = "2012-10-17" - }) - -} diff --git a/tests/tf-manifests/aws/kms-second/output.tf b/tests/tf-manifests/aws/kms-second/output.tf deleted file mode 100644 index c3c7007e..00000000 --- a/tests/tf-manifests/aws/kms-second/output.tf +++ /dev/null @@ -1,4 +0,0 @@ -output "arn" { - description = "The ARN of the key" - value = aws_kms_key.cluster_kms_key.arn -} \ No newline at end of file diff --git a/tests/tf-manifests/aws/kms-second/variables.tf b/tests/tf-manifests/aws/kms-second/variables.tf deleted file mode 100644 index b0736915..00000000 --- a/tests/tf-manifests/aws/kms-second/variables.tf +++ /dev/null @@ -1,41 +0,0 @@ -variable "aws_region" { - type = string -} - -variable "kms_name" { - type = string - default = "" -} - - -variable "tag_key" { - type = string - default = "" -} - -variable "tag_value" { - type = string - default = "" -} - -variable "tag_description" { - type = string - default = "" -} - -variable "account_role_prefix" { - type = string - default = "" -} - -variable "path" { - description = "(Optional) The arn path for the account/operator roles as well as their policies." - type = string - default = null -} - -variable "hcp" { - type = bool - description = "The KMS key is created for a HCP cluster" - default = false -} \ No newline at end of file diff --git a/tests/tf-manifests/rhcs/cluster-autoscaler/classic/main.tf b/tests/tf-manifests/rhcs/cluster-autoscaler/rosa-classic/main.tf similarity index 100% rename from tests/tf-manifests/rhcs/cluster-autoscaler/classic/main.tf rename to tests/tf-manifests/rhcs/cluster-autoscaler/rosa-classic/main.tf diff --git a/tests/tf-manifests/rhcs/cluster-autoscaler/classic/output.tf b/tests/tf-manifests/rhcs/cluster-autoscaler/rosa-classic/output.tf similarity index 100% rename from tests/tf-manifests/rhcs/cluster-autoscaler/classic/output.tf rename to tests/tf-manifests/rhcs/cluster-autoscaler/rosa-classic/output.tf diff --git a/tests/tf-manifests/rhcs/cluster-autoscaler/classic/variable.tf b/tests/tf-manifests/rhcs/cluster-autoscaler/rosa-classic/variable.tf similarity index 100% rename from tests/tf-manifests/rhcs/cluster-autoscaler/classic/variable.tf rename to tests/tf-manifests/rhcs/cluster-autoscaler/rosa-classic/variable.tf diff --git a/tests/tf-manifests/rhcs/cluster-autoscaler/hcp/main.tf b/tests/tf-manifests/rhcs/cluster-autoscaler/rosa-hcp/main.tf similarity index 100% rename from tests/tf-manifests/rhcs/cluster-autoscaler/hcp/main.tf rename to tests/tf-manifests/rhcs/cluster-autoscaler/rosa-hcp/main.tf diff --git a/tests/tf-manifests/rhcs/cluster-autoscaler/hcp/output.tf b/tests/tf-manifests/rhcs/cluster-autoscaler/rosa-hcp/output.tf similarity index 100% rename from tests/tf-manifests/rhcs/cluster-autoscaler/hcp/output.tf rename to tests/tf-manifests/rhcs/cluster-autoscaler/rosa-hcp/output.tf diff --git a/tests/tf-manifests/rhcs/cluster-autoscaler/hcp/variable.tf b/tests/tf-manifests/rhcs/cluster-autoscaler/rosa-hcp/variable.tf similarity index 100% rename from tests/tf-manifests/rhcs/cluster-autoscaler/hcp/variable.tf rename to tests/tf-manifests/rhcs/cluster-autoscaler/rosa-hcp/variable.tf diff --git a/tests/tf-manifests/rhcs/ingresses/classic/main.tf b/tests/tf-manifests/rhcs/ingresses/rosa-classic/main.tf similarity index 100% rename from tests/tf-manifests/rhcs/ingresses/classic/main.tf rename to tests/tf-manifests/rhcs/ingresses/rosa-classic/main.tf diff --git a/tests/tf-manifests/rhcs/ingresses/classic/output.tf b/tests/tf-manifests/rhcs/ingresses/rosa-classic/output.tf similarity index 100% rename from tests/tf-manifests/rhcs/ingresses/classic/output.tf rename to tests/tf-manifests/rhcs/ingresses/rosa-classic/output.tf diff --git a/tests/tf-manifests/rhcs/ingresses/classic/variables.tf b/tests/tf-manifests/rhcs/ingresses/rosa-classic/variables.tf similarity index 100% rename from tests/tf-manifests/rhcs/ingresses/classic/variables.tf rename to tests/tf-manifests/rhcs/ingresses/rosa-classic/variables.tf diff --git a/tests/tf-manifests/rhcs/ingresses/hcp/main.tf b/tests/tf-manifests/rhcs/ingresses/rosa-hcp/main.tf similarity index 100% rename from tests/tf-manifests/rhcs/ingresses/hcp/main.tf rename to tests/tf-manifests/rhcs/ingresses/rosa-hcp/main.tf diff --git a/tests/tf-manifests/rhcs/ingresses/hcp/output.tf b/tests/tf-manifests/rhcs/ingresses/rosa-hcp/output.tf similarity index 100% rename from tests/tf-manifests/rhcs/ingresses/hcp/output.tf rename to tests/tf-manifests/rhcs/ingresses/rosa-hcp/output.tf diff --git a/tests/tf-manifests/rhcs/ingresses/hcp/variables.tf b/tests/tf-manifests/rhcs/ingresses/rosa-hcp/variables.tf similarity index 100% rename from tests/tf-manifests/rhcs/ingresses/hcp/variables.tf rename to tests/tf-manifests/rhcs/ingresses/rosa-hcp/variables.tf diff --git a/tests/tf-manifests/rhcs/machine-pools/classic/main.tf b/tests/tf-manifests/rhcs/machine-pools/classic/main.tf deleted file mode 100644 index 735ce100..00000000 --- a/tests/tf-manifests/rhcs/machine-pools/classic/main.tf +++ /dev/null @@ -1,30 +0,0 @@ -terraform { - required_providers { - rhcs = { - version = ">= 1.1.0" - source = "terraform.local/local/rhcs" - } - } -} - -provider "rhcs" { -} - -resource "rhcs_machine_pool" "mps" { - count = var.mp_count - cluster = var.cluster - machine_type = var.machine_type - name = var.mp_count == 1 ? var.name : "${var.name}-${count.index}" - replicas = var.replicas - labels = var.labels - taints = var.taints - min_replicas = var.min_replicas - max_replicas = var.max_replicas - autoscaling_enabled = var.autoscaling_enabled - availability_zone = var.availability_zone - subnet_id = var.subnet_id - multi_availability_zone = var.multi_availability_zone - disk_size = var.disk_size - aws_additional_security_group_ids = var.additional_security_groups - aws_tags = var.tags -} diff --git a/tests/tf-manifests/rhcs/machine-pools/classic/output.tf b/tests/tf-manifests/rhcs/machine-pools/classic/output.tf deleted file mode 100644 index 80241edc..00000000 --- a/tests/tf-manifests/rhcs/machine-pools/classic/output.tf +++ /dev/null @@ -1,12 +0,0 @@ -output "machine_pools" { - value = [for mp in rhcs_machine_pool.mps : { - machine_pool_id : mp.id - name : mp.name - cluster_id : mp.cluster - replicas : mp.replicas - machine_type : mp.machine_type - autoscaling_enabled : mp.autoscaling_enabled - labels : mp.labels - taints : mp.taints - }] -} \ No newline at end of file diff --git a/tests/tf-manifests/rhcs/machine-pools/classic/variable.tf b/tests/tf-manifests/rhcs/machine-pools/classic/variable.tf deleted file mode 100644 index 3691710a..00000000 --- a/tests/tf-manifests/rhcs/machine-pools/classic/variable.tf +++ /dev/null @@ -1,76 +0,0 @@ -variable "mp_count" { - type = number - default = 1 -} - -variable "cluster" { - type = string -} -variable "machine_type" { - default = null - type = string -} -variable "name" { - type = string -} -variable "autoscaling_enabled" { - default = false - type = bool -} -variable "labels" { - default = null - type = map(string) -} -variable "max_replicas" { - type = number - default = null -} -variable "max_spot_price" { - type = number - default = null -} -variable "min_replicas" { - type = number - default = null -} -variable "replicas" { - type = number - default = null -} -variable "taints" { - default = null - type = list(object({ - key = string - value = string - schedule_type = string - })) -} -variable "use_spot_instances" { - type = bool - default = false -} - -variable "availability_zone" { - type = string - default = null -} -variable "subnet_id" { - type = string - default = null -} -variable "multi_availability_zone" { - type = bool - default = null -} -variable "disk_size" { - type = number - default = null -} -variable "additional_security_groups" { - type = list(string) - default = null -} -variable "tags" { - type = map(string) - default = null -} diff --git a/tests/tf-manifests/rhcs/default-machine-pool/main.tf b/tests/tf-manifests/rhcs/machine-pools/rosa-classic/main.tf similarity index 100% rename from tests/tf-manifests/rhcs/default-machine-pool/main.tf rename to tests/tf-manifests/rhcs/machine-pools/rosa-classic/main.tf diff --git a/tests/tf-manifests/rhcs/default-machine-pool/output.tf b/tests/tf-manifests/rhcs/machine-pools/rosa-classic/output.tf similarity index 100% rename from tests/tf-manifests/rhcs/default-machine-pool/output.tf rename to tests/tf-manifests/rhcs/machine-pools/rosa-classic/output.tf diff --git a/tests/tf-manifests/rhcs/default-machine-pool/variable.tf b/tests/tf-manifests/rhcs/machine-pools/rosa-classic/variable.tf similarity index 100% rename from tests/tf-manifests/rhcs/default-machine-pool/variable.tf rename to tests/tf-manifests/rhcs/machine-pools/rosa-classic/variable.tf diff --git a/tests/tf-manifests/rhcs/machine-pools/hcp/main.tf b/tests/tf-manifests/rhcs/machine-pools/rosa-hcp/main.tf similarity index 100% rename from tests/tf-manifests/rhcs/machine-pools/hcp/main.tf rename to tests/tf-manifests/rhcs/machine-pools/rosa-hcp/main.tf diff --git a/tests/tf-manifests/rhcs/machine-pools/hcp/output.tf b/tests/tf-manifests/rhcs/machine-pools/rosa-hcp/output.tf similarity index 100% rename from tests/tf-manifests/rhcs/machine-pools/hcp/output.tf rename to tests/tf-manifests/rhcs/machine-pools/rosa-hcp/output.tf diff --git a/tests/tf-manifests/rhcs/machine-pools/hcp/variable.tf b/tests/tf-manifests/rhcs/machine-pools/rosa-hcp/variable.tf similarity index 100% rename from tests/tf-manifests/rhcs/machine-pools/hcp/variable.tf rename to tests/tf-manifests/rhcs/machine-pools/rosa-hcp/variable.tf diff --git a/tests/ci/connection.go b/tests/utils/cms/connection.go similarity index 99% rename from tests/ci/connection.go rename to tests/utils/cms/connection.go index af6bc2fc..40da7996 100644 --- a/tests/ci/connection.go +++ b/tests/utils/cms/connection.go @@ -1,4 +1,4 @@ -package ci +package cms /* Copyright (c) 2018 Red Hat, Inc. diff --git a/tests/utils/constants/constants.go b/tests/utils/constants/constants.go index 4b23b229..d48c8777 100644 --- a/tests/utils/constants/constants.go +++ b/tests/utils/constants/constants.go @@ -3,7 +3,6 @@ package constants import ( "fmt" "os" - "path" cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" ) @@ -82,21 +81,6 @@ var ( DefaultAWSRegion = "us-east-2" ) -// Dirs of identity providers -var ( - HtpasswdDir = path.Join(IDPsDir, "htpasswd") - GitlabDir = path.Join(IDPsDir, "gitlab") - GithubDir = path.Join(IDPsDir, "github") - LdapDir = path.Join(IDPsDir, "ldap") - OpenidDir = path.Join(IDPsDir, "openid") - GoogleDir = path.Join(IDPsDir, "google") - MultiIDPDir = path.Join(IDPsDir, "multi-idp") -) - -func GrantTFstateFile(manifestDir string) string { - return path.Join(manifestDir, "terraform.tfstate") -} - // Machine pool taints effect const ( NoExecute = "NoExecute" @@ -153,3 +137,37 @@ func GetHCPClusterTypes() (types []ClusterType) { func (ct *ClusterType) String() string { return ct.Name } + +type IDPType string + +const ( + IDPHTPassword IDPType = "htpasswd" + IDPGitlab IDPType = "gitlab" + IDPGithub IDPType = "github" + IDPGoogle IDPType = "google" + IDPLDAP IDPType = "ldap" + IDPOpenID IDPType = "openid" + IDPMulti IDPType = "multi-idp" +) + +const ( + + // MaxExpiration in unit of hour + ClusterMaxExpiration = 168 + + // MaxNodeNumber means max node number per cluster/machinepool + ClusterMaxNodeNumber = 180 + + // MaxNameLength means cluster name will be trimed when request certificate + ClusterMaxNameLength = 15 + + ClusterMaxIngressNumber = 2 +) + +// version channel_groups +const ( + VersionFastChannel = "fast" + VersionStableChannel = "stable" + VersionNightlyChannel = "nightly" + VersionCandidateChannel = "candidate" +) diff --git a/tests/utils/constants/manifests.go b/tests/utils/constants/manifests.go deleted file mode 100644 index cf7501e3..00000000 --- a/tests/utils/constants/manifests.go +++ /dev/null @@ -1,115 +0,0 @@ -package constants - -import ( - "fmt" - "os" - "path" - "strings" -) - -func initManifestsDir() string { - if ManifestsDirENV != "" { - return 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" - RHCSProviderDir = "rhcs" - MachinePoolsDir = "machine-pools" - IngressDir = "ingresses" -) - -// Dirs of aws provider -var ( - AccountRolesClassicDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "account-roles", "rosa-classic") - AccountRolesHCPDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "account-roles", "rosa-hcp") - AddAccountRolesClassicDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "add-account-roles", "rosa-classic") - AddAccountRolesHCPDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "add-account-roles", "rosa-hcp") - OIDCProviderOperatorRolesClassicManifestDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "oidc-provider-operator-roles", "rosa-classic") - OIDCProviderOperatorRolesHCPManifestDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "oidc-provider-operator-roles", "rosa-hcp") - AWSVPCClassicDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "vpc", "rosa-classic") - AWSVPCHCPDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "vpc", "rosa-hcp") - AWSVPCTagDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "vpc-tags") - AWSSecurityGroupDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "security-groups") - ProxyDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "proxy") - KMSDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "kms") - KMSSecondDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "kms-second") - SharedVpcPolicyAndHostedZoneDir = path.Join(ManifestsConfigurationDir, AWSProviderDir, "shared-vpc-policy-and-hosted-zone") -) - -func GetAccountRoleDefaultManifestDir(clusterType ClusterType) string { - if clusterType.HCP { - return AccountRolesHCPDir - } else { - return AccountRolesClassicDir - } -} - -func GetAddAccountRoleDefaultManifestDir(clusterType ClusterType) string { - if clusterType.HCP { - return AddAccountRolesHCPDir - } else { - return AddAccountRolesClassicDir - } -} - -func GetOIDCProviderOperatorRolesDefaultManifestDir(clusterType ClusterType) string { - if clusterType.HCP { - return OIDCProviderOperatorRolesHCPManifestDir - } else { - return OIDCProviderOperatorRolesClassicManifestDir - } -} - -func GetAWSVPCDefaultManifestDir(clusterType ClusterType) string { - if clusterType.HCP { - return AWSVPCHCPDir - } else { - return AWSVPCClassicDir - } -} - -// Dirs of rhcs provider -var ( - ClusterDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "clusters") - ImportResourceDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "resource-import") - IDPsDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "idps") - ClassicMachinePoolDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, MachinePoolsDir, "classic") - HCPMachinePoolDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, MachinePoolsDir, "hcp") - DNSDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "dns") - ClassicIngressDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, IngressDir, "classic") - HCPIngressDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, IngressDir, "hcp") - RhcsInfoDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "rhcs-info") - DefaultMachinePoolDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "default-machine-pool") - KubeletConfigDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "kubelet-config") - ClassicClusterAutoscalerDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "cluster-autoscaler", "classic") - HCPClusterAutoscalerDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "cluster-autoscaler", "hcp") - TuningConfigDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "tuning-config") - ClusterWaiterDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "cluster-waiter") - TrustedIPsDir = path.Join(ManifestsConfigurationDir, RHCSProviderDir, "trusted-ips") -) - -func GetClusterManifestsDir(clusterType ClusterType) string { - return path.Join(ClusterDir, clusterType.String()) -} - -// Supports abs and relatives -func GrantClusterManifestDir(manifestDir string) string { - var targetDir string - if strings.Contains(manifestDir, ClusterDir) { - targetDir = manifestDir - } else { - targetDir = path.Join(ClusterDir, manifestDir) - } - return targetDir -} diff --git a/tests/utils/exec/account-roles.go b/tests/utils/exec/account-roles.go index c1f3b2f1..15eb3e9a 100644 --- a/tests/utils/exec/account-roles.go +++ b/tests/utils/exec/account-roles.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type AccountRolesArgs struct { @@ -34,13 +35,9 @@ type svcountRoleService struct { tfExecutor TerraformExecutor } -func NewAccountRoleService(manifestsDirs ...string) (AccountRoleService, error) { - manifestsDir := constants.AccountRolesClassicDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewAccountRoleService(tfWorkspace string, clusterType constants.ClusterType) (AccountRoleService, error) { svc := &svcountRoleService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetAWSAccountRolesManifestDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/cluster-autoscaler.go b/tests/utils/exec/cluster-autoscaler.go index ca04a4db..94455ffe 100644 --- a/tests/utils/exec/cluster-autoscaler.go +++ b/tests/utils/exec/cluster-autoscaler.go @@ -1,6 +1,9 @@ package exec -import "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" +import ( + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" +) type ClusterAutoscalerArgs struct { Cluster *string `hcl:"cluster_id"` @@ -74,13 +77,9 @@ type clusterAutoscalerService struct { tfExecutor TerraformExecutor } -func NewClusterAutoscalerService(manifestsDirs ...string) (ClusterAutoscalerService, error) { - manifestsDir := constants.ClassicClusterAutoscalerDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewClusterAutoscalerService(tfWorkspace string, clusterType constants.ClusterType) (ClusterAutoscalerService, error) { svc := &clusterAutoscalerService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetClusterAutoscalerManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/cluster-waiter.go b/tests/utils/exec/cluster-waiter.go index b7c62218..4456b0e2 100644 --- a/tests/utils/exec/cluster-waiter.go +++ b/tests/utils/exec/cluster-waiter.go @@ -1,6 +1,9 @@ package exec -import "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" +import ( + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" +) type ClusterWaiterArgs struct { Cluster *string `hcl:"cluster_id"` @@ -27,9 +30,9 @@ type clusterWaiterService struct { tfExecutor TerraformExecutor } -func NewClusterWaiterService() (ClusterWaiterService, error) { +func NewClusterWaiterService(tfWorkspace string, clusterType constants.ClusterType) (ClusterWaiterService, error) { svc := &clusterWaiterService{ - tfExecutor: NewTerraformExecutor(constants.ClusterWaiterDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetClusterWaiterManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/cluster.go b/tests/utils/exec/cluster.go index d40a4cd4..734ffda1 100644 --- a/tests/utils/exec/cluster.go +++ b/tests/utils/exec/cluster.go @@ -1,6 +1,9 @@ package exec -import "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" +import ( + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" +) type ClusterArgs struct { AccountRolePrefix *string `hcl:"account_role_prefix"` @@ -87,30 +90,6 @@ type ClusterOutput struct { UserTags map[string]string `json:"tags,omitempty"` } -// ****************************************************** -// RHCS test cases used -const ( - - // MaxExpiration in unit of hour - MaxExpiration = 168 - - // MaxNodeNumber means max node number per cluster/machinepool - MaxNodeNumber = 180 - - // MaxNameLength means cluster name will be trimed when request certificate - MaxNameLength = 15 - - MaxIngressNumber = 2 -) - -// version channel_groups -const ( - FastChannel = "fast" - StableChannel = "stable" - NightlyChannel = "nightly" - CandidateChannel = "candidate" -) - type ClusterService interface { Init() error Plan(args *ClusterArgs) (string, error) @@ -118,6 +97,8 @@ type ClusterService interface { Output() (*ClusterOutput, error) Destroy() (string, error) + GetStateResource(resourceType string, resoureName string) (interface{}, error) + ReadTFVars() (*ClusterArgs, error) WriteTFVars(args *ClusterArgs) error DeleteTFVars() error @@ -127,10 +108,9 @@ type clusterService struct { tfExecutor TerraformExecutor } -func NewClusterService(manifestDir string) (ClusterService, error) { - manifestsDir := constants.GrantClusterManifestDir(manifestDir) +func NewClusterService(tfWorkspace string, clusterType constants.ClusterType) (ClusterService, error) { svc := &clusterService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetClusterManifestsDir(clusterType)), } err := svc.Init() return svc, err @@ -162,6 +142,10 @@ func (svc *clusterService) Destroy() (string, error) { return svc.tfExecutor.RunTerraformDestroy() } +func (svc *clusterService) GetStateResource(resourceType string, resoureName string) (interface{}, error) { + return svc.tfExecutor.GetStateResource(resourceType, resoureName) +} + func (svc *clusterService) ReadTFVars() (*ClusterArgs, error) { args := &ClusterArgs{} err := svc.tfExecutor.ReadTerraformVars(args) diff --git a/tests/utils/exec/dns-domain.go b/tests/utils/exec/dns-domain.go index f4fb84c0..3065f0f8 100644 --- a/tests/utils/exec/dns-domain.go +++ b/tests/utils/exec/dns-domain.go @@ -1,6 +1,9 @@ package exec -import "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" +import ( + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" +) type DnsDomainArgs struct { ID *string `hcl:"id"` @@ -25,13 +28,9 @@ type dnsDomainService struct { tfExecutor TerraformExecutor } -func NewDnsDomainService(manifestsDirs ...string) (DnsDomainService, error) { - manifestsDir := constants.DNSDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewDnsDomainService(tfWorkspace string, clusterType constants.ClusterType) (DnsDomainService, error) { svc := &dnsDomainService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetDnsDomainManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/idps.go b/tests/utils/exec/idps.go index d0b2e766..d9d4d90c 100644 --- a/tests/utils/exec/idps.go +++ b/tests/utils/exec/idps.go @@ -1,6 +1,9 @@ package exec -import "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" +import ( + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" +) type IDPArgs struct { ClusterID *string `hcl:"cluster_id"` @@ -44,6 +47,8 @@ type IDPService interface { Output() (*IDPOutput, error) Destroy() (string, error) + GetStateResource(resourceType string, resoureName string) (interface{}, error) + ReadTFVars() (*IDPArgs, error) DeleteTFVars() error } @@ -52,13 +57,9 @@ type idpService struct { tfExecutor TerraformExecutor } -func NewIDPService(manifestsDirs ...string) (IDPService, error) { - manifestsDir := constants.IDPsDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewIDPService(tfWorkspace string, clusterType constants.ClusterType, idpType constants.IDPType) (IDPService, error) { svc := &idpService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetIDPManifestsDir(clusterType, idpType)), } err := svc.Init() return svc, err @@ -90,6 +91,10 @@ func (svc *idpService) Destroy() (string, error) { return svc.tfExecutor.RunTerraformDestroy() } +func (svc *idpService) GetStateResource(resourceType string, resoureName string) (interface{}, error) { + return svc.tfExecutor.GetStateResource(resourceType, resoureName) +} + func (svc *idpService) ReadTFVars() (*IDPArgs, error) { args := &IDPArgs{} err := svc.tfExecutor.ReadTerraformVars(args) diff --git a/tests/utils/exec/import.go b/tests/utils/exec/import.go index d35b04d6..90cd06fc 100644 --- a/tests/utils/exec/import.go +++ b/tests/utils/exec/import.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type ImportArgs struct { @@ -36,13 +37,9 @@ type importService struct { tfExecutor TerraformExecutor } -func NewImportService(manifestsDirs ...string) (ImportService, error) { - manifestsDir := constants.ImportResourceDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewImportService(tfWorkspace string, clusterType constants.ClusterType) (ImportService, error) { svc := &importService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetImportManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/ingress.go b/tests/utils/exec/ingress.go index fc051b43..eb95dafc 100644 --- a/tests/utils/exec/ingress.go +++ b/tests/utils/exec/ingress.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type IngressArgs struct { @@ -46,13 +47,9 @@ type ingressService struct { tfExecutor TerraformExecutor } -func NewIngressService(manifestsDirs ...string) (IngressService, error) { - manifestsDir := constants.ClassicIngressDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewIngressService(tfWorkspace string, clusterType constants.ClusterType) (IngressService, error) { svc := &ingressService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetIngressManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/kms.go b/tests/utils/exec/kms.go index f70d0e69..2895a7a0 100644 --- a/tests/utils/exec/kms.go +++ b/tests/utils/exec/kms.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type KMSArgs struct { @@ -34,13 +35,9 @@ type kmsService struct { tfExecutor TerraformExecutor } -func NewKMSService(manifestsDirs ...string) (KMSService, error) { - manifestsDir := constants.KMSDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewKMSService(tfWorkspace string, clusterType constants.ClusterType) (KMSService, error) { svc := &kmsService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetAWSKMSManifestDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/kubelet-config.go b/tests/utils/exec/kubelet-config.go index 82217828..7fe698dd 100644 --- a/tests/utils/exec/kubelet-config.go +++ b/tests/utils/exec/kubelet-config.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type KubeletConfigArgs struct { @@ -37,13 +38,9 @@ type kubeletConfigService struct { tfExecutor TerraformExecutor } -func NewKubeletConfigService(manifestsDirs ...string) (KubeletConfigService, error) { - manifestsDir := constants.KubeletConfigDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewKubeletConfigService(tfWorkspace string, clusterType constants.ClusterType) (KubeletConfigService, error) { svc := &kubeletConfigService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetKubeletConfigManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/machine-pools.go b/tests/utils/exec/machine-pools.go index c0be8500..867f5001 100644 --- a/tests/utils/exec/machine-pools.go +++ b/tests/utils/exec/machine-pools.go @@ -5,6 +5,7 @@ import ( cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" "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/helper" ) @@ -69,7 +70,8 @@ type MachinePoolService interface { Apply(args *MachinePoolArgs) (string, error) Output() (*MachinePoolsOutput, error) Destroy() (string, error) - + ShowState(resource string) (string, error) + RemoveState(resource string) (string, error) ReadTFVars() (*MachinePoolArgs, error) DeleteTFVars() error } @@ -78,13 +80,9 @@ type machinePoolService struct { tfExecutor TerraformExecutor } -func NewMachinePoolService(manifestsDirs ...string) (MachinePoolService, error) { - manifestsDir := constants.ClassicMachinePoolDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewMachinePoolService(tfWorkspace string, clusterType constants.ClusterType) (MachinePoolService, error) { svc := &machinePoolService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetMachinePoolsManifestsDir(clusterType)), } err := svc.Init() return svc, err @@ -116,6 +114,14 @@ func (svc *machinePoolService) Destroy() (string, error) { return svc.tfExecutor.RunTerraformDestroy() } +func (svc *machinePoolService) ShowState(resource string) (string, error) { + return svc.tfExecutor.RunTerraformState("show", resource) +} + +func (svc *machinePoolService) RemoveState(resource string) (string, error) { + return svc.tfExecutor.RunTerraformState("rm", resource) +} + func (svc *machinePoolService) ReadTFVars() (*MachinePoolArgs, error) { args := &MachinePoolArgs{} err := svc.tfExecutor.ReadTerraformVars(args) diff --git a/tests/utils/exec/manifests/manifests.go b/tests/utils/exec/manifests/manifests.go new file mode 100644 index 00000000..56ca38f1 --- /dev/null +++ b/tests/utils/exec/manifests/manifests.go @@ -0,0 +1,113 @@ +package manifests + +import ( + "fmt" + "os" + "path" + "strings" + + "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" + rhcsProviderDir = "rhcs" + idpsDir = "idps" +) + +// AWS dirs +func GetAWSAccountRolesManifestDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, awsProviderDir, "account-roles", clusterType.String()) +} + +func GetAWSKMSManifestDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, awsProviderDir, "kms") +} + +func GetAWSOIDCProviderOperatorRolesManifestDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, awsProviderDir, "oidc-provider-operator-roles", clusterType.String()) +} + +func GetAWSProxyManifestDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, awsProviderDir, "proxy") +} + +func GetAWSSecurityGroupManifestDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, awsProviderDir, "security-groups") +} + +func GetAWSSharedVPCPolicyAndHostedZoneManifestDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, awsProviderDir, "shared-vpc-policy-and-hosted-zone") +} + +func GetAWSVPCManifestDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, awsProviderDir, "vpc", clusterType.String()) +} + +func GetAWSVPCTagManifestDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, awsProviderDir, "vpc-tags") +} + +// RHCS provider dirs +func GetClusterManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "clusters", clusterType.String()) +} + +func GetClusterWaiterManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "cluster-waiter") +} + +func GetClusterAutoscalerManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "cluster-autoscaler", clusterType.String()) +} + +func GetDnsDomainManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "dns") +} + +func GetIDPManifestsDir(clusterType constants.ClusterType, idpType constants.IDPType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, idpsDir, string(idpType)) +} + +func GetIngressManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "ingresses", clusterType.String()) +} + +func GetImportManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "resource-import") +} + +func GetKubeletConfigManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "kubelet-config") +} + +func GetMachinePoolsManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "machine-pools", clusterType.String()) +} + +func GetRHCSInfoManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "rhcs-info") +} + +func GetTuningConfigManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "tuning-config") +} + +func GetTrustedIPsManifestsDir(clusterType constants.ClusterType) string { + return path.Join(ManifestsConfigurationDir, rhcsProviderDir, "trusted-ips") +} diff --git a/tests/utils/exec/manifests/state.go b/tests/utils/exec/manifests/state.go new file mode 100644 index 00000000..31151c59 --- /dev/null +++ b/tests/utils/exec/manifests/state.go @@ -0,0 +1,7 @@ +package manifests + +import "path" + +func GrantTFstateFile(manifestDir string) string { + return path.Join(manifestDir, "terraform.tfstate") +} diff --git a/tests/utils/exec/oidc-provider-operator-roles.go b/tests/utils/exec/oidc-provider-operator-roles.go index 5c4ff9c2..49fe6fa3 100644 --- a/tests/utils/exec/oidc-provider-operator-roles.go +++ b/tests/utils/exec/oidc-provider-operator-roles.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type OIDCProviderOperatorRolesArgs struct { @@ -34,13 +35,9 @@ type oidcProviderOperatorRolesService struct { tfExecutor TerraformExecutor } -func NewOIDCProviderOperatorRolesService(manifestsDirs ...string) (OIDCProviderOperatorRolesService, error) { - manifestsDir := constants.OIDCProviderOperatorRolesClassicManifestDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewOIDCProviderOperatorRolesService(tfWorkspace string, clusterType constants.ClusterType) (OIDCProviderOperatorRolesService, error) { svc := &oidcProviderOperatorRolesService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetAWSOIDCProviderOperatorRolesManifestDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/proxy.go b/tests/utils/exec/proxy.go index 24e7ecea..6ed04363 100644 --- a/tests/utils/exec/proxy.go +++ b/tests/utils/exec/proxy.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type ProxyArgs struct { @@ -47,13 +48,9 @@ type proxyService struct { tfExecutor TerraformExecutor } -func NewProxyService(manifestsDirs ...string) (ProxyService, error) { - manifestsDir := constants.ProxyDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewProxyService(tfWorkspace string, clusterType constants.ClusterType) (ProxyService, error) { svc := &proxyService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetAWSProxyManifestDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/rhcs-info.go b/tests/utils/exec/rhcs-info.go index 30f0a899..5b2ad552 100644 --- a/tests/utils/exec/rhcs-info.go +++ b/tests/utils/exec/rhcs-info.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type RhcsInfoArgs struct { @@ -19,13 +20,9 @@ type rhcsInfoService struct { tfExecutor TerraformExecutor } -func NewRhcsInfoService(manifestsDirs ...string) (RhcsInfoService, error) { - manifestsDir := constants.RhcsInfoDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewRhcsInfoService(tfWorkspace string, clusterType constants.ClusterType) (RhcsInfoService, error) { svc := &rhcsInfoService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetRHCSInfoManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/security-groups.go b/tests/utils/exec/security-groups.go index 632360ca..72e2fd4f 100644 --- a/tests/utils/exec/security-groups.go +++ b/tests/utils/exec/security-groups.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type SecurityGroupArgs struct { @@ -31,13 +32,9 @@ type securityGroupService struct { tfExecutor TerraformExecutor } -func NewSecurityGroupService(manifestsDirs ...string) (SecurityGroupService, error) { - manifestsDir := constants.AWSSecurityGroupDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewSecurityGroupService(tfWorkspace string, clusterType constants.ClusterType) (SecurityGroupService, error) { svc := &securityGroupService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetAWSSecurityGroupManifestDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/shared-vpc-policy-and-hosted-zone.go b/tests/utils/exec/shared-vpc-policy-and-hosted-zone.go index ae1febfe..de7a2388 100644 --- a/tests/utils/exec/shared-vpc-policy-and-hosted-zone.go +++ b/tests/utils/exec/shared-vpc-policy-and-hosted-zone.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type SharedVpcPolicyAndHostedZoneArgs struct { @@ -39,13 +40,9 @@ type sharedVpcPolicyAndHostedZoneService struct { tfExecutor TerraformExecutor } -func NewSharedVpcPolicyAndHostedZoneService(manifestsDirs ...string) (SharedVpcPolicyAndHostedZoneService, error) { - manifestsDir := constants.SharedVpcPolicyAndHostedZoneDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewSharedVpcPolicyAndHostedZoneService(tfWorkspace string, clusterType constants.ClusterType) (SharedVpcPolicyAndHostedZoneService, error) { svc := &sharedVpcPolicyAndHostedZoneService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetAWSSharedVPCPolicyAndHostedZoneManifestDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/tf-exec.go b/tests/utils/exec/tf-exec.go index 6e54c0a9..7cb6c0a9 100644 --- a/tests/utils/exec/tf-exec.go +++ b/tests/utils/exec/tf-exec.go @@ -28,6 +28,7 @@ type TerraformExecutor interface { RunTerraformOutput() (string, error) RunTerraformOutputIntoObject(obj any) error RunTerraformState(subcommand string, options ...string) (string, error) + GetStateResource(resourceType string, resoureName string) (interface{}, error) RunTerraformImport(importArgs ...string) (string, error) ReadTerraformVars(obj interface{}) error @@ -37,17 +38,19 @@ type TerraformExecutor interface { type terraformExecutorContext struct { manifestsDir string + tfWorkspace string } -func NewTerraformExecutor(manifestsDir string) TerraformExecutor { +func NewTerraformExecutor(tfWorkspace string, manifestsDir string) TerraformExecutor { return &terraformExecutorContext{ manifestsDir: manifestsDir, + tfWorkspace: tfWorkspace, } } // ************************ TF CMD*********************************** func (ctx *terraformExecutorContext) runTerraformCommand(tfCmd string, cmdFlags ...string) (string, error) { - Logger.Infof("Running terraform %s against the dir %s", tfCmd, ctx.manifestsDir) + Logger.Infof("Running terraform %s in workspace %s and against the dir %s", tfCmd, ctx.tfWorkspace, ctx.manifestsDir) cmd, flags := getTerraformCommand(tfCmd, cmdFlags...) Logger.Debugf("Running terraform command: %v", flags) return ctx.execCommand(cmd, flags) @@ -61,6 +64,9 @@ func getTerraformCommand(tfCmd string, cmdFlags ...string) (string, []string) { func (ctx *terraformExecutorContext) execCommand(cmd string, flags []string) (output string, err error) { finalCmd := exec.Command(cmd, flags...) + if ctx.tfWorkspace != "" { + finalCmd.Env = append(os.Environ(), fmt.Sprintf("TF_WORKSPACE=%s", ctx.tfWorkspace)) + } finalCmd.Dir = ctx.manifestsDir var stdoutput bytes.Buffer finalCmd.Stdout = &stdoutput @@ -234,12 +240,58 @@ func DeleteTFvarsFile(tfVarsFile string) error { } func (ctx *terraformExecutorContext) grantTFvarsFile() string { - // We don't name it `terraform.tfvars` as that one is load automatically - // See https://developer.hashicorp.com/terraform/language/values/variables#variable-definition-precedence - // And we don't want to load them when applying new values - return path.Join(ctx.manifestsDir, fmt.Sprintf(tfVarsFilenameTemplate, "e2e")) + return path.Join(ctx.getTFVarsWorkspaceFolder(), "terraform.tfvars") } func (ctx *terraformExecutorContext) grantTFvarsTempFile() string { - return path.Join(ctx.manifestsDir, fmt.Sprintf(tfVarsFilenameTemplate, "e2e.tmp")) + return path.Join(ctx.getTFVarsWorkspaceFolder(), "terraform.tmp.tfvars") +} + +func (ctx *terraformExecutorContext) getTFVarsWorkspaceFolder() string { + wk := "e2e" + if ctx.tfWorkspace != "" { + wk = ctx.tfWorkspace + } + path := path.Join(ctx.manifestsDir, "terraform.tfvars.d", wk) + err := os.MkdirAll(path, 0777) + if err != nil { + panic(err) + } + return path +} + +func (ctx *terraformExecutorContext) grantTFstateFile() string { + parentPath := path.Join(ctx.manifestsDir) + if ctx.tfWorkspace != "" { + parentPath = path.Join(ctx.manifestsDir, "terraform.tfstate.d", ctx.tfWorkspace) + } + return path.Join(parentPath, "terraform.tfstate") +} + +// Get the resoources state from the terraform.tfstate file by resource type and name +func (ctx *terraformExecutorContext) GetStateResource(resourceType string, resoureName string) (interface{}, error) { + // Check if there is a terraform.tfstate file in the manifest directory + stateFile := ctx.grantTFstateFile() + if _, err := os.Stat(stateFile); err == nil { + // Read the terraform.tfstate file + data, err := os.ReadFile(stateFile) + if err != nil { + return nil, fmt.Errorf("failed to readFile %s folder,%v", stateFile, err) + } + // Unmarshal the data from the terraform.tfstate file + var state map[string]interface{} + err = json.Unmarshal(data, &state) + if err != nil { + return nil, fmt.Errorf("failed to Unmarshal state %v", err) + } + //Find resource by resource type and resource name + for _, resource := range state["resources"].([]interface{}) { + if helper.DigString(resource, "type") == resourceType && helper.DigString(resource, "name") == resoureName && resource != nil { + return resource, err + } + } + + return nil, fmt.Errorf("no resource named %s of type %s is found", resoureName, resourceType) + } + return nil, fmt.Errorf("terraform.tfstate file doesn't exist in %s folder", ctx.manifestsDir) } diff --git a/tests/utils/exec/trusted-ips.go b/tests/utils/exec/trusted-ips.go index d2b83d5e..0e6d92bc 100644 --- a/tests/utils/exec/trusted-ips.go +++ b/tests/utils/exec/trusted-ips.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type TrustedIPsArgs struct { @@ -36,13 +37,9 @@ type trustedIPsService struct { tfExecutor TerraformExecutor } -func NewTrustedIPsService(manifestsDirs ...string) (TrustedIPsService, error) { - manifestsDir := constants.TrustedIPsDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewTrustedIPsService(tfWorkspace string, clusterType constants.ClusterType) (TrustedIPsService, error) { svc := &trustedIPsService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetTrustedIPsManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/tuning-configs.go b/tests/utils/exec/tuning-configs.go index a0428615..93414f4b 100644 --- a/tests/utils/exec/tuning-configs.go +++ b/tests/utils/exec/tuning-configs.go @@ -2,6 +2,7 @@ package exec import ( "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/helper" ) @@ -37,13 +38,9 @@ type tuningConfigService struct { tfExecutor TerraformExecutor } -func NewTuningConfigService(manifestsDirs ...string) (TuningConfigService, error) { - manifestsDir := constants.TuningConfigDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewTuningConfigService(tfWorkspace string, clusterType constants.ClusterType) (TuningConfigService, error) { svc := &tuningConfigService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetTuningConfigManifestsDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/vpc-tags.go b/tests/utils/exec/vpc-tags.go index 7f3b447a..98acbe62 100644 --- a/tests/utils/exec/vpc-tags.go +++ b/tests/utils/exec/vpc-tags.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type VPCTagArgs struct { @@ -29,13 +30,9 @@ type vpcTagService struct { tfExecutor TerraformExecutor } -func NewVPCTagService(manifestsDirs ...string) (VPCTagService, error) { - manifestsDir := constants.AWSVPCTagDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewVPCTagService(tfWorkspace string, clusterType constants.ClusterType) (VPCTagService, error) { svc := &vpcTagService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetAWSVPCTagManifestDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/exec/vpc.go b/tests/utils/exec/vpc.go index fab7cf20..221414e2 100644 --- a/tests/utils/exec/vpc.go +++ b/tests/utils/exec/vpc.go @@ -2,6 +2,7 @@ package exec import ( "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec/manifests" ) type VPCArgs struct { @@ -36,13 +37,9 @@ type vpcService struct { tfExecutor TerraformExecutor } -func NewVPCService(manifestsDirs ...string) (VPCService, error) { - manifestsDir := constants.ClassicClusterAutoscalerDir - if len(manifestsDirs) > 0 { - manifestsDir = manifestsDirs[0] - } +func NewVPCService(tfWorkspace string, clusterType constants.ClusterType) (VPCService, error) { svc := &vpcService{ - tfExecutor: NewTerraformExecutor(manifestsDir), + tfExecutor: NewTerraformExecutor(tfWorkspace, manifests.GetAWSVPCManifestDir(clusterType)), } err := svc.Init() return svc, err diff --git a/tests/utils/helper/tf_helper.go b/tests/utils/helper/tf_helper.go deleted file mode 100644 index 7fcff8bd..00000000 --- a/tests/utils/helper/tf_helper.go +++ /dev/null @@ -1,46 +0,0 @@ -package helper - -import ( - "encoding/json" - "fmt" - "os" - - con "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" -) - -// Get the resoources state from the terraform.tfstate file by resource type and name -func GetResource(manifestDir string, resourceType string, resoureName string) (interface{}, error) { - // Check if there is a terraform.tfstate file in the manifest directory - if _, err := os.Stat(manifestDir + "/terraform.tfstate"); err == nil { - // Read the terraform.tfstate file - data, err := os.ReadFile(manifestDir + "/terraform.tfstate") - if err != nil { - return nil, fmt.Errorf("failed to readFile %s folder,%v", manifestDir+"/terraform.tfstate", err) - } - // Unmarshal the data from the terraform.tfstate file - var state map[string]interface{} - err = json.Unmarshal(data, &state) - if err != nil { - return nil, fmt.Errorf("failed to Unmarshal state %v", err) - } - //Find resource by resource type and resource name - for _, resource := range state["resources"].([]interface{}) { - if DigString(resource, "type") == resourceType && DigString(resource, "name") == resoureName && resource != nil { - return resource, err - } - } - - return nil, fmt.Errorf("no resource named %s of type %s is found", resoureName, resourceType) - - } - return nil, fmt.Errorf("terraform.tfstate file doesn't exist in %s folder", manifestDir) -} - -// Check if the default machinepool imported by checking if there is terraform.tfstate in DefaultMachinePoolDir -func CheckDefaultMachinePoolImported() (imported bool, err error) { - _, err = GetResource(con.DefaultMachinePoolDir, "rhcs_machine_pool", "mp") - if err != nil { - return false, err - } - return true, nil -} diff --git a/tests/utils/helper/version.go b/tests/utils/helper/version.go new file mode 100644 index 00000000..fda27cde --- /dev/null +++ b/tests/utils/helper/version.go @@ -0,0 +1,13 @@ +package helper + +import "regexp" + +func GetMajorVersion(rawVersion string) string { + versionRegex := regexp.MustCompile(`^[0-9]+\.[0-9]+`) + vResults := versionRegex.FindAllStringSubmatch(rawVersion, 1) + vResult := "" + if len(vResults) != 0 { + vResult = vResults[0][0] + } + return vResult +} diff --git a/tests/utils/openshift/openshift.go b/tests/utils/openshift/openshift.go index 0c94acb1..11dce26c 100644 --- a/tests/utils/openshift/openshift.go +++ b/tests/utils/openshift/openshift.go @@ -8,10 +8,10 @@ import ( client "github.com/openshift-online/ocm-sdk-go" v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" - ci "github.com/terraform-redhat/terraform-provider-rhcs/tests/ci" - 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/constants" + "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/helper" + . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" ) @@ -49,7 +49,7 @@ func RetryCMDRun(cmd string, timeout time.Duration) (string, error) { var err error Logger.Infof("Retrying command %s in %d mins", cmd, timeout) for time.Now().Before(now.Add(timeout * time.Minute)) { - stdout, stderr, err = h.RunCMD(cmd) + stdout, stderr, err = helper.RunCMD(cmd) if err == nil { Logger.Debugf("Run command %s successffly", cmd) return stdout, nil @@ -93,7 +93,7 @@ func RestartMUOPods(connection *client.Connection, clusterID string) error { pods, err := console.GetPods(MUONamespace) for _, pod := range pods { cmd := fmt.Sprintf("oc delete pod/%s -n %s --kubeconfig %s", pod.Name, MUONamespace, console.KubePath) - _, _, err = h.RunCMD(cmd) + _, _, err = helper.RunCMD(cmd) if err != nil { return err } @@ -106,7 +106,7 @@ func RestartMUOPods(connection *client.Connection, clusterID string) error { func WaitForUpgradePolicyToState(connection *client.Connection, clusterID string, policyID string, state string, timeout int) error { fmt.Println("Going to wait upgrade to status ", state) startTime := time.Now() - resp, err := CMS.RetrieveUpgradePolicies(connection, clusterID, policyID) + resp, err := cms.RetrieveUpgradePolicies(connection, clusterID, policyID) if err != nil { return err } @@ -116,11 +116,11 @@ func WaitForUpgradePolicyToState(connection *client.Connection, clusterID string scheduleType := resp.Body().ScheduleType() for time.Now().Before(startTime.Add(time.Duration(timeout) * time.Minute)) { - stateResp, _ := CMS.GetUpgradePolicyState(connection, clusterID, policyID) + stateResp, _ := cms.GetUpgradePolicyState(connection, clusterID, policyID) switch state { - case CON.Completed: - if scheduleType == CON.ManualScheduleType { + case constants.Completed: + if scheduleType == constants.ManualScheduleType { if stateResp.Status() == http.StatusNotFound { return nil } else if resp.Status() != http.StatusOK { @@ -130,7 +130,7 @@ func WaitForUpgradePolicyToState(connection *client.Connection, clusterID string if stateResp.Status() != http.StatusOK { return fmt.Errorf(">>> Got response %s when retrieve the policy state: %s", resp.Error(), state) } - if stateResp.Body().Value() == CON.Pending { + if stateResp.Body().Value() == constants.Pending { return nil } } @@ -158,7 +158,7 @@ func WaitForUpgradePolicyToState(connection *client.Connection, clusterID string func WaitForControlPlaneUpgradePolicyToState(connection *client.Connection, clusterID string, policyID string, state v1.UpgradePolicyStateValue, timeout int) error { fmt.Println("Going to wait upgrade to status ", state) startTime := time.Now() - resp, err := CMS.RetrieveControlPlaneUpgradePolicy(connection, clusterID, policyID) + resp, err := cms.RetrieveControlPlaneUpgradePolicy(connection, clusterID, policyID) if err != nil { return err } @@ -168,11 +168,11 @@ func WaitForControlPlaneUpgradePolicyToState(connection *client.Connection, clus scheduleType := resp.Body().ScheduleType() for time.Now().Before(startTime.Add(time.Duration(timeout) * time.Minute)) { - resp, _ := CMS.RetrieveControlPlaneUpgradePolicy(connection, clusterID, policyID) + resp, _ := cms.RetrieveControlPlaneUpgradePolicy(connection, clusterID, policyID) switch state { case v1.UpgradePolicyStateValueCompleted: - if scheduleType == CON.ManualScheduleType { + if scheduleType == constants.ManualScheduleType { if resp.Status() == http.StatusNotFound { return nil } else if resp.Status() != http.StatusOK { @@ -207,39 +207,39 @@ func WaitForControlPlaneUpgradePolicyToState(connection *client.Connection, clus func WaitClassicClusterUpgradeFinished(connection *client.Connection, clusterID string) error { Logger.Infof("Get the automatic policy created for the cluster upgrade") - policyIDs, err := CMS.ListUpgradePolicies(ci.RHCSConnection, clusterID) + policyIDs, err := cms.ListUpgradePolicies(cms.RHCSConnection, clusterID) if err != nil { return err } policyID := policyIDs.Items().Get(0).ID() Logger.Infof("Wait the policy to be scheduled") - err = WaitForUpgradePolicyToState(ci.RHCSConnection, clusterID, policyID, CON.Scheduled, 4) + err = WaitForUpgradePolicyToState(cms.RHCSConnection, clusterID, policyID, constants.Scheduled, 4) if err != nil { - return fmt.Errorf("Policy %s not moved to state %s in 2 minutes with the error: %s", CON.Scheduled, policyID, err.Error()) + return fmt.Errorf("Policy %s not moved to state %s in 2 minutes with the error: %s", constants.Scheduled, policyID, err.Error()) } Logger.Infof("Restart the MUO operator pod to make the policy synced") - err = RestartMUOPods(ci.RHCSConnection, clusterID) + err = RestartMUOPods(cms.RHCSConnection, clusterID) if err != nil { return err } Logger.Infof("Watch for the upgrade Started in 1 hour") - err = WaitForUpgradePolicyToState(ci.RHCSConnection, clusterID, policyID, CON.Started, 60) + err = WaitForUpgradePolicyToState(cms.RHCSConnection, clusterID, policyID, constants.Started, 60) if err != nil { - return fmt.Errorf("Policy %s not moved to state %s in 1 hour with the error: %s", CON.Started, policyID, err.Error()) + return fmt.Errorf("Policy %s not moved to state %s in 1 hour with the error: %s", constants.Started, policyID, err.Error()) } Logger.Infof("Watch for the upgrade finished in 2 hours") - err = WaitForUpgradePolicyToState(ci.RHCSConnection, clusterID, policyID, CON.Completed, 2*60) + err = WaitForUpgradePolicyToState(cms.RHCSConnection, clusterID, policyID, constants.Completed, 2*60) if err != nil { - return fmt.Errorf("Policy %s not moved to state %s in 2 hour with the error: %s", CON.Completed, policyID, err.Error()) + return fmt.Errorf("Policy %s not moved to state %s in 2 hour with the error: %s", constants.Completed, policyID, err.Error()) } return nil } func WaitHCPClusterUpgradeFinished(connection *client.Connection, clusterID string) error { Logger.Infof("Get the automatic policy created for the cluster upgrade") - policyIDs, err := CMS.ListControlPlaneUpgradePolicies(ci.RHCSConnection, clusterID) + policyIDs, err := cms.ListControlPlaneUpgradePolicies(cms.RHCSConnection, clusterID) if err != nil { return err } @@ -247,18 +247,18 @@ func WaitHCPClusterUpgradeFinished(connection *client.Connection, clusterID stri Logger.Infof("Got policy ID %s", policyID) Logger.Infof("Wait the policy to be scheduled") - err = WaitForControlPlaneUpgradePolicyToState(ci.RHCSConnection, clusterID, policyID, v1.UpgradePolicyStateValueScheduled, 4) + err = WaitForControlPlaneUpgradePolicyToState(cms.RHCSConnection, clusterID, policyID, v1.UpgradePolicyStateValueScheduled, 4) if err != nil { return fmt.Errorf("Policy %s not moved to state %s in 2 minutes with the error: %s", v1.UpgradePolicyStateValueScheduled, policyID, err.Error()) } Logger.Infof("Watch for the upgrade Started in 1 hour") - err = WaitForControlPlaneUpgradePolicyToState(ci.RHCSConnection, clusterID, policyID, v1.UpgradePolicyStateValueStarted, 60) + err = WaitForControlPlaneUpgradePolicyToState(cms.RHCSConnection, clusterID, policyID, v1.UpgradePolicyStateValueStarted, 60) if err != nil { return fmt.Errorf("Policy %s not moved to state %s in 1 hour with the error: %s", v1.UpgradePolicyStateValueStarted, policyID, err.Error()) } Logger.Infof("Watch for the upgrade finished in 2 hours") - err = WaitForControlPlaneUpgradePolicyToState(ci.RHCSConnection, clusterID, policyID, v1.UpgradePolicyStateValueCompleted, 2*60) + err = WaitForControlPlaneUpgradePolicyToState(cms.RHCSConnection, clusterID, policyID, v1.UpgradePolicyStateValueCompleted, 2*60) if err != nil { return fmt.Errorf("Policy %s not moved to state %s in 2 hour with the error: %s", v1.UpgradePolicyStateValueCompleted, policyID, err.Error()) } @@ -267,11 +267,11 @@ func WaitHCPClusterUpgradeFinished(connection *client.Connection, clusterID stri // will return [map["NAME":"ip-10-0-130-210.us-east-2.compute.internal","STATUS":"Ready","ROLES":"worker"...]] func FigureStdout(stdout string, columns map[string][]interface{}) (result []map[string]interface{}, err error) { - items := h.DigArray(h.Parse([]byte(stdout)), "items") + items := helper.DigArray(helper.Parse([]byte(stdout)), "items") for _, item := range items { newMap := map[string]interface{}{} for key, pattern := range columns { - newMap[key] = h.Dig(item, pattern) + newMap[key] = helper.Dig(item, pattern) } result = append(result, newMap) } diff --git a/tests/ci/file.go b/tests/utils/profilehandler/file.go similarity index 56% rename from tests/ci/file.go rename to tests/utils/profilehandler/file.go index 17000266..d5a28310 100644 --- a/tests/ci/file.go +++ b/tests/utils/profilehandler/file.go @@ -1,19 +1,62 @@ -package ci +package profilehandler import ( "encoding/json" "fmt" + "os" + "slices" "sort" "strings" rosa "github.com/terraform-redhat/terraform-provider-rhcs/provider/clusterrosa/common" - CON "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/constants" - EXE "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/exec" + "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" + + . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" ) // The cfg will be used to define the testing environment -var cfg = CON.RHCS +var cfg = constants.RHCS + +func loadProfileYamlFile(profileName string) (*Profile, error) { + p, err := helper.GetProfile(profileName, GetYAMLProfilesDir()) + if err != nil { + return nil, err + } + Logger.Infof("Loaded cluster profile configuration from profile %s : %v", profileName, p.Cluster) + profile := Profile{ + Name: profileName, + } + err = helper.MapStructure(p.Cluster, &profile) + return &profile, err +} + +func LoadProfileYamlFileByENV() (profile *Profile, err error) { + profileEnv := os.Getenv(constants.RhcsClusterProfileENV) + if profileEnv == "" { + panic(fmt.Errorf("ENV Variable CLUSTER_PROFILE is empty, please make sure you set the env value")) + } + profile, err = loadProfileYamlFile(profileEnv) + if err != nil { + return + } + + // 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") + } + return +} func GetYAMLProfilesDir() string { return cfg.YAMLProfilesDir @@ -74,6 +117,33 @@ func convertToString(searchMap map[string]interface{}) (filter string) { return } +func getRandomProfile(clusterTypes ...constants.ClusterType) (profile *Profile, err error) { + if len(clusterTypes) > 0 { + Logger.Infof("Get random profile for cluster types: %v", clusterTypes) + } else { + Logger.Info("Get random profile from all profiles") + } + + profilesMap, err := helper.ParseProfiles(GetYAMLProfilesDir()) + if err != nil { + return + } + profilesNames := make([]string, 0, len(profilesMap)) + for k, v := range profilesMap { + clusterType := constants.FindClusterType(fmt.Sprintf("%v", v.Cluster["cluster_type"])) + if !v.NeedSpecificConfig { + if len(clusterTypes) <= 0 || slices.Contains(clusterTypes, clusterType) { + profilesNames = append(profilesNames, k) + } + } + } + Logger.Debugf("Got profile names %v", profilesNames) + profileName := profilesMap[profilesNames[helper.RandomInt(len(profilesNames))]].Name + profile, err = loadProfileYamlFile(profileName) + Logger.Debugf("Choose profile: %s", profile.Name) + return profile, err +} + // ConvertFilterToString will Convert a fileter struct to a string // if "like" in the value will be keeped // if no 'like' in value, the string will contains key=value @@ -85,8 +155,8 @@ func ConvertFilterToString(qs interface{}) (filter string) { } func TrimName(name string) string { - if len(name) >= EXE.MaxNameLength { - name = name[0:EXE.MaxNameLength] + if len(name) >= constants.ClusterMaxNameLength { + name = name[0:constants.ClusterMaxNameLength] } return name } @@ -94,7 +164,7 @@ func TrimName(name string) string { func TrimVersion(version string, groupChannel string) string { prefix := rosa.VersionPrefix suffix := "" - if groupChannel != EXE.StableChannel { + if groupChannel != constants.VersionStableChannel { suffix = "-" + groupChannel } trimedVersion := h.Rstrip(h.Lstrip(version, prefix), suffix) @@ -115,7 +185,7 @@ func ElementInArray(target string, str_array []string) bool { // If num 0 and itemkey id passed it will return the itemkey value with index 0 func GetElements(content map[string]interface{}, element string, num ...int) interface{} { var result []interface{} - keys := strings.Split(element, CON.DotConnector) + keys := strings.Split(element, constants.DotConnector) var keysInterface []interface{} for _, key := range keys { keysInterface = append(keysInterface, key) diff --git a/tests/utils/profilehandler/handler.go b/tests/utils/profilehandler/handler.go new file mode 100644 index 00000000..b2e9c05a --- /dev/null +++ b/tests/utils/profilehandler/handler.go @@ -0,0 +1,1192 @@ +package profilehandler + +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/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/log" +) + +type ProfileHandler interface { + Services() ProfileServices + Prepare() ProfilePrepare + Profile() ProfileSpec + + CreateRHCSClusterByProfile(token string) (string, error) + DestroyRHCSClusterResources(token string) error + GenerateClusterCreationArgs(token string) (*exec.ClusterArgs, error) + RetrieveClusterID() (string, error) + + // This will create a new profile handler with a different TF workspace (adding `-dup` suffix to current) + Duplicate() ProfileHandler + DuplicateRandom() ProfileHandler +} + +type ProfilePrepare interface { + PrepareVPC(multiZone bool, azIDs []string, name string, sharedVpcAWSSharedCredentialsFile string) (*exec.VPCOutput, error) + PrepareAdditionalSecurityGroups(vpcID string, sgNumbers int) ([]string, error) + PrepareAccountRoles(token string, accountRolePrefix string, accountRolesPath string, openshiftVersion string, channelGroup string, sharedVpcRoleArn string) (*exec.AccountRolesOutput, error) + PrepareOIDCProviderAndOperatorRoles(token string, oidcConfigType string, operatorRolePrefix string, accountRolePrefix string, accountRolesPath string) (*exec.OIDCProviderOperatorRolesOutput, error) + PrepareProxy(VPCID string, subnetPublicID string, keyPairID string) (*exec.ProxyOutput, error) + PrepareKMSKey(kmsName string, accountRolePrefix string, accountRolePath string) (string, error) + PrepareRoute53() (string, error) + PrepareSharedVpcPolicyAndHostedZone(sharedCredentialsFile string, clusterName string, dnsDomainID string, ingressOperatorRoleArn string, + installerRoleArn string, clusterAwsAccount string, vpcID string, subnets []string, domainPrefix string) (*exec.SharedVpcPolicyAndHostedZoneOutput, error) + PrepareVersion() string +} + +type ProfileServices interface { + GetAccountRolesService() (exec.AccountRoleService, error) + GetKMSService() (exec.KMSService, error) + GetOIDCProviderOperatorRolesService() (exec.OIDCProviderOperatorRolesService, error) + GetProxyService() (exec.ProxyService, error) + GetSecurityGroupService() (exec.SecurityGroupService, error) + GetSharedVPCPolicyAndHostedZoneService() (exec.SharedVpcPolicyAndHostedZoneService, error) + GetVPCService() (exec.VPCService, error) + GetVPCTagService() (exec.VPCTagService, error) + GetClusterService() (exec.ClusterService, error) + GetClusterAutoscalerService() (exec.ClusterAutoscalerService, error) + GetClusterWaiterService() (exec.ClusterWaiterService, error) + GetDnsDomainService() (exec.DnsDomainService, error) + GetIDPService(idpType constants.IDPType) (exec.IDPService, error) + GetIngressService() (exec.IngressService, error) + GetImportService() (exec.ImportService, error) + GetKubeletConfigService() (exec.KubeletConfigService, error) + GetMachinePoolsService() (exec.MachinePoolService, error) + GetRHCSInfoService() (exec.RhcsInfoService, error) + GetTrustedIPsService() (exec.TrustedIPsService, error) + GetTuningConfigService() (exec.TuningConfigService, error) +} + +type ProfileSpec interface { + GetClusterType() constants.ClusterType + GetRegion() string + GetName() string + GetChannelGroup() string + GetVersionPattern() string + GetMajorVersion() string + GetComputeMachineType() string + GetZones() string + GetEc2MetadataHttpTokens() string + GetUnifiedAccRolesPath() string + GetOIDCConfig() string + + GetAdditionalSGNumber() int + GetComputeReplicas() int + GetWorkerDiskSize() int + GetImdsv2() string + GetMachineCIDR() string + GetServiceCIDR() string + GetPodCIDR() string + GetHostPrefix() int + + IsHCP() bool + IsPrivateLink() bool + IsPrivate() bool + IsMultiAZ() bool + IsBYOVPC() bool + IsProxy() bool + IsEtcd() bool + IsDifferentEncryptionKeys() bool + IsAutoscale() bool + IsAdminEnabled() bool + IsFIPS() bool + IsLabeling() bool + IsTagging() bool + IsKMSKey() bool + IsFullResources() bool +} + +type profileContext struct { + profile *Profile + tfWorkspaceName string +} + +func NewProfileHandlerFromYamlFile() (handler ProfileHandler, err error) { + profile, err := LoadProfileYamlFileByENV() + if err != nil { + return + } + handler = newProfileHandler(profile, profile.Name) + return +} + +func NewRandomProfileHandler(clusterTypes ...constants.ClusterType) (handler ProfileHandler, err error) { + profile, err := getRandomProfile(clusterTypes...) + if err != nil { + return + } + handler = newProfileHandler(profile, helper.GenerateRandomName(profile.Name, 3)) + return +} + +func newProfileHandler(profile *Profile, tfWorkspaceName string) ProfileHandler { + if profile.Region == "" { + profile.Region = constants.DefaultAWSRegion + } + return &profileContext{ + profile: profile, + tfWorkspaceName: tfWorkspaceName, + } +} + +func (ctx *profileContext) Duplicate() ProfileHandler { + return newProfileHandler(ctx.profile, fmt.Sprintf("%s-dup", ctx.tfWorkspaceName)) +} + +func (ctx *profileContext) DuplicateRandom() ProfileHandler { + return newProfileHandler(ctx.profile, helper.GenerateRandomName(ctx.tfWorkspaceName, 3)) +} + +func (ctx *profileContext) Services() ProfileServices { + return ctx +} + +func (ctx *profileContext) Prepare() ProfilePrepare { + return ctx +} + +func (ctx *profileContext) Profile() ProfileSpec { + return ctx +} + +func (ctx *profileContext) GetName() string { + return ctx.profile.Name +} + +func (ctx *profileContext) GetRegion() string { + return ctx.profile.Region +} + +func (ctx *profileContext) GetChannelGroup() string { + return ctx.profile.ChannelGroup +} + +func (ctx *profileContext) GetVersionPattern() string { + return ctx.profile.VersionPattern +} + +func (ctx *profileContext) GetMajorVersion() string { + return ctx.profile.MajorVersion +} + +func (ctx *profileContext) GetComputeMachineType() string { + return ctx.profile.ComputeMachineType +} + +func (ctx *profileContext) GetZones() string { + return ctx.profile.Zones +} + +func (ctx *profileContext) GetEc2MetadataHttpTokens() string { + return ctx.profile.Ec2MetadataHttpTokens +} + +func (ctx *profileContext) GetUnifiedAccRolesPath() string { + return ctx.profile.UnifiedAccRolesPath +} + +func (ctx *profileContext) GetOIDCConfig() string { + return ctx.profile.OIDCConfig +} + +func (ctx *profileContext) GetAdditionalSGNumber() int { + return ctx.profile.AdditionalSGNumber +} + +func (ctx *profileContext) GetComputeReplicas() int { + return ctx.profile.ComputeReplicas +} + +func (ctx *profileContext) GetWorkerDiskSize() int { + return ctx.profile.WorkerDiskSize +} + +func (ctx *profileContext) GetClusterType() constants.ClusterType { + return constants.FindClusterType(ctx.profile.ClusterType) +} + +func (ctx *profileContext) GetTFWorkspace() string { + return ctx.tfWorkspaceName +} + +func (ctx *profileContext) IsHCP() bool { + return ctx.GetClusterType().HCP +} + +func (ctx *profileContext) IsPrivateLink() bool { + if ctx.GetClusterType().HCP { + return ctx.profile.Private + } else { + return ctx.profile.PrivateLink + } +} + +func (ctx *profileContext) IsPrivate() bool { + return ctx.profile.Private +} + +func (ctx *profileContext) IsMultiAZ() bool { + return ctx.profile.MultiAZ +} + +func (ctx *profileContext) IsBYOVPC() bool { + return ctx.profile.BYOVPC +} + +func (ctx *profileContext) IsProxy() bool { + return ctx.profile.Proxy +} + +func (ctx *profileContext) IsEtcd() bool { + return ctx.profile.Etcd +} + +func (ctx *profileContext) IsDifferentEncryptionKeys() bool { + return ctx.profile.DifferentEncryptionKeys +} + +func (ctx *profileContext) IsAutoscale() bool { + return ctx.profile.Autoscale +} + +func (ctx *profileContext) IsAdminEnabled() bool { + return ctx.profile.Autoscale +} + +func (ctx *profileContext) IsFIPS() bool { + return ctx.profile.FIPS +} + +func (ctx *profileContext) IsLabeling() bool { + return ctx.profile.Labeling +} + +func (ctx *profileContext) IsTagging() bool { + return ctx.profile.Tagging +} + +func (ctx *profileContext) IsKMSKey() bool { + return ctx.profile.KMSKey +} + +func (ctx *profileContext) IsFullResources() bool { + return ctx.profile.FullResources +} + +func (ctx *profileContext) GetImdsv2() string { + return ctx.profile.Ec2MetadataHttpTokens +} + +func (ctx *profileContext) GetMachineCIDR() string { + return ctx.profile.MachineCIDR +} + +func (ctx *profileContext) GetServiceCIDR() string { + return ctx.profile.ServiceCIDR +} + +func (ctx *profileContext) GetPodCIDR() string { + return ctx.profile.PodCIDR +} + +func (ctx *profileContext) GetHostPrefix() int { + return ctx.profile.HostPrefix +} + +func (ctx *profileContext) PrepareVPC(multiZone bool, azIDs []string, name string, sharedVpcAWSSharedCredentialsFile string) (*exec.VPCOutput, error) { + region := ctx.profile.Region + vpcService, err := ctx.Services().GetVPCService() + if err != nil { + return nil, err + } + vpcArgs := &exec.VPCArgs{ + AWSRegion: helper.StringPointer(region), + VPCCIDR: helper.StringPointer(constants.DefaultVPCCIDR), + } + + if len(azIDs) != 0 { + turnedZoneIDs := []string{} + for _, zone := range azIDs { + if strings.Contains(zone, region) { + turnedZoneIDs = append(turnedZoneIDs, zone) + } else { + turnedZoneIDs = append(turnedZoneIDs, region+zone) + } + } + vpcArgs.AvailabilityZones = helper.StringSlicePointer(turnedZoneIDs) + } else { + azCount := 1 + if multiZone { + azCount = 3 + } + vpcArgs.AvailabilityZonesCount = helper.IntPointer(azCount) + } + if name != "" { + vpcArgs.NamePrefix = helper.StringPointer(name) + } + + if sharedVpcAWSSharedCredentialsFile != "" { + vpcArgs.AWSSharedCredentialsFiles = helper.StringSlicePointer([]string{sharedVpcAWSSharedCredentialsFile}) + } + + _, err = vpcService.Apply(vpcArgs) + if err != nil { + vpcService.Destroy() + return nil, err + } + output, err := vpcService.Output() + if err != nil { + vpcService.Destroy() + return nil, err + } + return output, err +} + +func (ctx *profileContext) PrepareAdditionalSecurityGroups(vpcID string, sgNumbers int) ([]string, error) { + sgService, err := ctx.Services().GetSecurityGroupService() + if err != nil { + return nil, err + } + sgArgs := &exec.SecurityGroupArgs{ + AWSRegion: helper.StringPointer(ctx.profile.Region), + VPCID: helper.StringPointer(vpcID), + SGNumber: helper.IntPointer(sgNumbers), + NamePrefix: helper.StringPointer("rhcs-ci"), + } + _, err = sgService.Apply(sgArgs) + if err != nil { + sgService.Destroy() + return nil, err + } + output, err := sgService.Output() + if err != nil { + sgService.Destroy() + return nil, err + } + return output.SGIDs, err +} + +func (ctx *profileContext) PrepareAccountRoles(token string, accountRolePrefix string, accountRolesPath string, openshiftVersion string, channelGroup string, sharedVpcRoleArn string) ( + *exec.AccountRolesOutput, error) { + accService, err := ctx.Services().GetAccountRolesService() + if err != nil { + return nil, err + } + args := &exec.AccountRolesArgs{ + AccountRolePrefix: helper.StringPointer(accountRolePrefix), + OpenshiftVersion: helper.StringPointer(openshiftVersion), + UnifiedAccRolesPath: helper.StringPointer(accountRolesPath), + } + + if sharedVpcRoleArn != "" { + args.SharedVpcRoleArn = helper.StringPointer(sharedVpcRoleArn) + } + + _, err = accService.Apply(args) + if err != nil { + accService.Destroy() + return nil, err + } + return accService.Output() +} + +func (ctx *profileContext) PrepareOIDCProviderAndOperatorRoles(token string, oidcConfigType string, operatorRolePrefix string, accountRolePrefix string, accountRolesPath string) ( + *exec.OIDCProviderOperatorRolesOutput, error) { + oidcOpService, err := ctx.Services().GetOIDCProviderOperatorRolesService() + if err != nil { + return nil, err + } + args := &exec.OIDCProviderOperatorRolesArgs{ + AccountRolePrefix: helper.StringPointer(accountRolePrefix), + OperatorRolePrefix: helper.StringPointer(operatorRolePrefix), + OIDCConfig: helper.StringPointer(oidcConfigType), + UnifiedAccRolesPath: helper.StringPointer(accountRolesPath), + } + _, err = oidcOpService.Apply(args) + if err != nil { + oidcOpService.Destroy() + return nil, err + } + return oidcOpService.Output() +} + +func (ctx *profileContext) PrepareProxy(VPCID string, subnetPublicID string, keyPairID string) (*exec.ProxyOutput, error) { + if VPCID == "" { + return nil, fmt.Errorf("vpc ID is empty. Cannot prepare proxy") + } + proxyService, err := ctx.Services().GetProxyService() + if err != nil { + return nil, err + } + proxyArgs := &exec.ProxyArgs{ + ProxyCount: helper.IntPointer(1), + Region: helper.StringPointer(ctx.profile.Region), + VPCID: helper.StringPointer(VPCID), + PublicSubnetID: helper.StringPointer(subnetPublicID), + TrustBundleFilePath: helper.StringPointer(path.Join(constants.RHCS.RhcsOutputDir, "ca.cert")), + KeyPairID: helper.StringPointer(keyPairID), + } + + _, err = proxyService.Apply(proxyArgs) + if err != nil { + proxyService.Destroy() + return nil, err + } + proxyOutput, err := proxyService.Output() + if err != nil { + proxyService.Destroy() + return nil, err + } + + return proxyOutput.Proxies[0], err +} + +func (ctx *profileContext) PrepareKMSKey(kmsName string, accountRolePrefix string, accountRolePath string) (string, error) { + kmsService, err := ctx.Services().GetKMSService() + if err != nil { + return "", err + } + kmsArgs := &exec.KMSArgs{ + KMSName: helper.StringPointer(kmsName), + AWSRegion: helper.StringPointer(ctx.profile.Region), + AccountRolePrefix: helper.StringPointer(accountRolePrefix), + AccountRolePath: helper.StringPointer(accountRolePath), + TagKey: helper.StringPointer("Purpose"), + TagValue: helper.StringPointer("RHCS automation test"), + TagDescription: helper.StringPointer("BYOK Test Key for API automation"), + HCP: helper.BoolPointer(ctx.GetClusterType().HCP), + } + + _, err = kmsService.Apply(kmsArgs) + if err != nil { + kmsService.Destroy() + return "", err + } + kmsOutput, err := kmsService.Output() + if err != nil { + kmsService.Destroy() + return "", err + } + return kmsOutput.KeyARN, err +} + +func (ctx *profileContext) PrepareRoute53() (string, error) { + dnsDomainService, err := ctx.Services().GetDnsDomainService() + if err != nil { + return "", err + } + a := &exec.DnsDomainArgs{} + + _, err = dnsDomainService.Apply(a) + if err != nil { + dnsDomainService.Destroy() + return "", err + } + output, err := dnsDomainService.Output() + if err != nil { + dnsDomainService.Destroy() + return "", err + } + return output.DnsDomainId, err +} + +func (ctx *profileContext) PrepareSharedVpcPolicyAndHostedZone(sharedCredentialsFile string, clusterName string, dnsDomainID string, ingressOperatorRoleArn string, + installerRoleArn string, clusterAwsAccount string, vpcID string, subnets []string, domainPrefix string) (*exec.SharedVpcPolicyAndHostedZoneOutput, error) { + + sharedVPCService, err := ctx.Services().GetSharedVPCPolicyAndHostedZoneService() + if err != nil { + return nil, err + } + + hostedZoneArgs := &exec.SharedVpcPolicyAndHostedZoneArgs{ + SharedVpcAWSSharedCredentialsFiles: helper.StringSlicePointer([]string{sharedCredentialsFile}), + Region: helper.StringPointer(ctx.profile.Region), + ClusterName: helper.StringPointer(clusterName), + DnsDomainId: helper.StringPointer(dnsDomainID), + IngressOperatorRoleArn: helper.StringPointer(ingressOperatorRoleArn), + InstallerRoleArn: helper.StringPointer(installerRoleArn), + ClusterAWSAccount: helper.StringPointer(clusterAwsAccount), + VpcId: helper.StringPointer(vpcID), + Subnets: helper.StringSlicePointer(subnets), + } + if domainPrefix != "" { + hostedZoneArgs.DomainPrefix = helper.StringPointer(domainPrefix) + } + + _, err = sharedVPCService.Apply(hostedZoneArgs) + if err != nil { + sharedVPCService.Destroy() + return nil, err + } + output, err := sharedVPCService.Output() + if err != nil { + sharedVPCService.Destroy() + return nil, err + } + return output, err +} + +// PrepareVersion supports below types +// version with a openshift version like 4.13.12 +// version with latest +// verion with x-1, it means the version will choose one with x-1 version which can be used for x stream upgrade +// version with y-1, it means the version will choose one with y-1 version which can be used for y stream upgrade +func (ctx *profileContext) PrepareVersion() string { + version := ctx.profile.Version + versionPattern := ctx.profile.VersionPattern + channelGroup := ctx.profile.ChannelGroup + versionRegex := regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+\-*[\s\S]*$`) + if version != "" { + if versionRegex.MatchString(version) { + return version + } + versionPattern = version // Version has precedence over version pattern + } + // Check that the version is matching openshift version regexp + if versionRegex.MatchString(versionPattern) { + return versionPattern + } + var vResult string + switch versionPattern { + case "", "latest": + versions := cms.EnabledVersions(cms.RHCSConnection, channelGroup, ctx.profile.MajorVersion, true) + versions = cms.SortVersions(versions) + vResult = versions[len(versions)-1].RawID + case "y-1": + versions, _ := cms.GetVersionsWithUpgrades(cms.RHCSConnection, channelGroup, constants.Y, true, false, 1) + vResult = versions[len(versions)-1].RawID + case "z-1": + versions, _ := cms.GetVersionsWithUpgrades(cms.RHCSConnection, channelGroup, constants.Z, true, false, 1) + vResult = versions[len(versions)-1].RawID + case "eol": + vResult = "" + } + Logger.Infof("Cluster OCP latest version is set to %s", vResult) + return vResult +} + +func (ctx *profileContext) GenerateClusterCreationArgs(token string) (clusterArgs *exec.ClusterArgs, err error) { + // For Shared VPC + var clusterAwsAccount string + var installerRoleArn string + var ingressRoleArn string + + version := ctx.PrepareVersion() + + clusterArgs = &exec.ClusterArgs{ + OpenshiftVersion: helper.StringPointer(version), + } + + // Init cluster's args by profile's attributes + + clusterArgs.Fips = helper.BoolPointer(ctx.profile.FIPS) + clusterArgs.MultiAZ = helper.BoolPointer(ctx.profile.MultiAZ) + + if ctx.profile.NetWorkingSet { + clusterArgs.MachineCIDR = helper.StringPointer(constants.DefaultVPCCIDR) + } + + if ctx.profile.Autoscale { + clusterArgs.Autoscaling = &exec.Autoscaling{ + AutoscalingEnabled: helper.BoolPointer(true), + MinReplicas: helper.IntPointer(3), + MaxReplicas: helper.IntPointer(6), + } + } + + if constants.RHCS.ComputeMachineType != "" { + clusterArgs.ComputeMachineType = helper.StringPointer(constants.RHCS.ComputeMachineType) + } else if ctx.profile.ComputeMachineType != "" { + clusterArgs.ComputeMachineType = helper.StringPointer(ctx.profile.ComputeMachineType) + } + + if ctx.profile.ComputeReplicas > 0 { + clusterArgs.Replicas = helper.IntPointer(ctx.profile.ComputeReplicas) + } + + if ctx.profile.ChannelGroup != "" { + clusterArgs.ChannelGroup = helper.StringPointer(ctx.profile.ChannelGroup) + } + + if ctx.profile.Ec2MetadataHttpTokens != "" { + clusterArgs.Ec2MetadataHttpTokens = helper.StringPointer(ctx.profile.Ec2MetadataHttpTokens) + } + + if ctx.profile.Labeling { + clusterArgs.DefaultMPLabels = helper.StringMapPointer(constants.DefaultMPLabels) + } + + if ctx.profile.Tagging { + clusterArgs.Tags = helper.StringMapPointer(constants.Tags) + } + + if ctx.profile.AdminEnabled { + userName := constants.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) + if err != nil { + Logger.Error("Error happens when try to record the admin password") + return + } + Logger.Info("Admin password is written to the output directory") + + } + + if ctx.profile.AuditLogForward { + // ToDo + } + + var clusterName string + if constants.RHCS.RHCSClusterName != "" { + clusterName = constants.RHCS.RHCSClusterName + } else if ctx.profile.ClusterName != "" { + clusterName = ctx.profile.ClusterName + } else { + // Generate random chars later cluster name with profile name + name := helper.GenerateClusterName(ctx.profile.Name) + clusterName = name + } + clusterArgs.ClusterName = helper.StringPointer(clusterName) + + // There are some problem for cluster created with name length + // longer than 15 chars with auto generated domain prefix + if ctx.profile.DomainPrefix == "" && ctx.profile.SharedVpc && len(clusterName) > 15 { + ctx.profile.DomainPrefix = helper.GenerateRandomName("shared-vpc", 4) + } + + clusterArgs.ClusterName = &clusterName + err = os.WriteFile(cfg.ClusterNameFile, []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) + // short and re-generate the clusterName when it is longer than 15 chars + if ctx.profile.DomainPrefix != "" { + clusterArgs.DomainPrefix = &ctx.profile.DomainPrefix + } + if ctx.profile.Region != "" { + clusterArgs.AWSRegion = &ctx.profile.Region + } else { + clusterArgs.AWSRegion = &constants.DefaultAWSRegion + } + + if ctx.profile.STS { + majorVersion := helper.GetMajorVersion(version) + var accountRolesOutput *exec.AccountRolesOutput + var oidcOutput *exec.OIDCProviderOperatorRolesOutput + + sharedVPCRoleArn := "" + if ctx.profile.SharedVpc { + // FIXME: + // To create Shared-VPC compatible policies, we need to pass a role arn to create_account_roles module. + // But we got an chicken-egg prolems here: + // * The Shared-VPC compatible policie requries installer role + // * The install role (account roles) require Shared-VPC ARN. + // Use hardcode as a temporary solution. + sharedVPCRoleArn = fmt.Sprintf("arn:aws:iam::641733028092:role/%s-shared-vpc-role", clusterName) + } + accountRolesOutput, err = ctx.PrepareAccountRoles(token, clusterName, ctx.profile.UnifiedAccRolesPath, majorVersion, ctx.profile.ChannelGroup, sharedVPCRoleArn) + if err != nil { + return + } + clusterArgs.AccountRolePrefix = helper.StringPointer(accountRolesOutput.AccountRolePrefix) + clusterArgs.UnifiedAccRolesPath = helper.StringPointer(ctx.profile.UnifiedAccRolesPath) + Logger.Infof("Created account roles with prefix %s", accountRolesOutput.AccountRolePrefix) + + Logger.Infof("Sleep for 10 sec to let aws account role async creation finished") + time.Sleep(10 * time.Second) + + oidcOutput, err = ctx.PrepareOIDCProviderAndOperatorRoles(token, ctx.profile.OIDCConfig, clusterName, accountRolesOutput.AccountRolePrefix, ctx.profile.UnifiedAccRolesPath) + if err != nil { + return + } + clusterArgs.OIDCConfigID = &oidcOutput.OIDCConfigID + clusterArgs.OperatorRolePrefix = &oidcOutput.OperatorRolePrefix + + clusterAwsAccount = accountRolesOutput.AWSAccountId + installerRoleArn = accountRolesOutput.InstallerRoleArn + ingressRoleArn = oidcOutput.IngressOperatorRoleArn + } + + if ctx.profile.BYOVPC { + var zones []string + var vpcOutput *exec.VPCOutput + var sgIDs []string + + // 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"), ",") + clusterArgs.AWSAvailabilityZones = &azs + clusterArgs.AWSSubnetIDs = &subnetIDs + } else { + if ctx.profile.Zones != "" { + zones = strings.Split(ctx.profile.Zones, ",") + } + + 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 = constants.SharedVpcAWSSharedCredentialsFileENV + } + vpcOutput, err = ctx.PrepareVPC(ctx.profile.MultiAZ, zones, clusterName, sharedVPCAWSSharedCredentialsFile) + if err != nil { + return + } + + if vpcOutput.PrivateSubnets == nil { + err = fmt.Errorf("error when creating the vpc, check the previous log. The created resources had been destroyed") + return + } + if ctx.profile.Private { + clusterArgs.Private = helper.BoolPointer(ctx.profile.Private) + clusterArgs.PrivateLink = helper.BoolPointer(ctx.profile.PrivateLink) + if ctx.IsPrivateLink() { + clusterArgs.AWSSubnetIDs = &vpcOutput.PrivateSubnets + } + } else { + subnetIDs := vpcOutput.PrivateSubnets + subnetIDs = append(subnetIDs, vpcOutput.PublicSubnets...) + clusterArgs.AWSSubnetIDs = &subnetIDs + } + + if ctx.profile.SharedVpc { + // Base domain + var baseDnsDomain string + baseDnsDomain, err = ctx.PrepareRoute53() + if err != nil { + return + } + + // Resources for Shared-VPC + var sharedVpcPolicyAndHostedZoneOutput *exec.SharedVpcPolicyAndHostedZoneOutput + sharedVpcPolicyAndHostedZoneOutput, err = ctx.PrepareSharedVpcPolicyAndHostedZone( + constants.SharedVpcAWSSharedCredentialsFileENV, + clusterName, + baseDnsDomain, + ingressRoleArn, + installerRoleArn, + clusterAwsAccount, + vpcOutput.VPCID, + *clusterArgs.AWSSubnetIDs, + ctx.profile.DomainPrefix) + if err != nil { + return + } + + clusterArgs.BaseDnsDomain = helper.StringPointer(baseDnsDomain) + privateHostedZone := exec.PrivateHostedZone{ + ID: sharedVpcPolicyAndHostedZoneOutput.HostedZoneId, + RoleArn: sharedVpcPolicyAndHostedZoneOutput.SharedRole, + } + clusterArgs.PrivateHostedZone = &privateHostedZone + /* + The AZ us-east-1a for VPC-account might not have the same location as us-east-1a for Cluster-account. + For AZs which will be used in cluster configuration, the values should be the ones in Cluster-account. + */ + clusterArgs.AWSAvailabilityZones = &sharedVpcPolicyAndHostedZoneOutput.AvailabilityZones + } else { + clusterArgs.AWSAvailabilityZones = &vpcOutput.AvailabilityZones + } + + clusterArgs.MachineCIDR = helper.StringPointer(vpcOutput.VPCCIDR) + if ctx.profile.AdditionalSGNumber != 0 { + // Prepare profile.AdditionalSGNumber+5 security groups for negative testing + sgIDs, err = ctx.PrepareAdditionalSecurityGroups(vpcOutput.VPCID, ctx.profile.AdditionalSGNumber+5) + if err != nil { + return + } + clusterArgs.AdditionalComputeSecurityGroups = helper.StringSlicePointer(sgIDs[0:ctx.profile.AdditionalSGNumber]) + clusterArgs.AdditionalInfraSecurityGroups = helper.StringSlicePointer(sgIDs[0:ctx.profile.AdditionalSGNumber]) + clusterArgs.AdditionalControlPlaneSecurityGroups = helper.StringSlicePointer(sgIDs[0:ctx.profile.AdditionalSGNumber]) + } + + // in case Proxy is enabled + if ctx.profile.Proxy { + var proxyOutput *exec.ProxyOutput + proxyOutput, err = ctx.PrepareProxy(vpcOutput.VPCID, vpcOutput.PublicSubnets[0], clusterName) + if err != nil { + return + } + proxy := exec.Proxy{ + AdditionalTrustBundle: &proxyOutput.AdditionalTrustBundle, + HTTPSProxy: &proxyOutput.HttpsProxy, + HTTPProxy: &proxyOutput.HttpProxy, + NoProxy: &proxyOutput.NoProxy, + } + clusterArgs.Proxy = &proxy + } + } + } + + // Prepare KMS key if needed + if ctx.profile.Etcd || ctx.profile.KMSKey { + var kmskey string + kmskey, err = ctx.PrepareKMSKey(*clusterArgs.ClusterName, *clusterArgs.AccountRolePrefix, ctx.profile.UnifiedAccRolesPath) + if err != nil { + return + } + + if ctx.profile.Etcd { + clusterArgs.Etcd = &ctx.profile.Etcd + clusterArgs.EtcdKmsKeyARN = helper.StringPointer(kmskey) + } + if ctx.profile.KMSKey { + clusterArgs.KmsKeyARN = &kmskey + if ctx.Profile().IsHCP() { + if ctx.profile.DifferentEncryptionKeys { + kmsName := fmt.Sprintf("%s-2", *clusterArgs.ClusterName) + var etcdKMSKeyArn string + etcdKMSKeyArn, err = ctx.Duplicate().Prepare(). + PrepareKMSKey(kmsName, *clusterArgs.AccountRolePrefix, ctx.profile.UnifiedAccRolesPath) + if err != nil { + return + } + clusterArgs.EtcdKmsKeyARN = helper.StringPointer(etcdKMSKeyArn) + } + } + + } + } + + if ctx.profile.MachineCIDR != "" { + clusterArgs.MachineCIDR = helper.StringPointer(ctx.profile.MachineCIDR) + } + if ctx.profile.ServiceCIDR != "" { + clusterArgs.ServiceCIDR = helper.StringPointer(ctx.profile.ServiceCIDR) + } + if ctx.profile.PodCIDR != "" { + clusterArgs.PodCIDR = helper.StringPointer(ctx.profile.PodCIDR) + } + if ctx.profile.HostPrefix > 0 { + clusterArgs.HostPrefix = helper.IntPointer(ctx.profile.HostPrefix) + } + + if ctx.profile.WorkerDiskSize != 0 { + clusterArgs.WorkerDiskSize = helper.IntPointer(ctx.profile.WorkerDiskSize) + } + clusterArgs.UnifiedAccRolesPath = helper.StringPointer(ctx.profile.UnifiedAccRolesPath) + clusterArgs.CustomProperties = helper.StringMapPointer(constants.CustomProperties) // id:72450 + + if ctx.profile.FullResources { + clusterArgs.FullResources = helper.BoolPointer(true) + } + if ctx.profile.DontWaitForCluster { + clusterArgs.WaitForCluster = helper.BoolPointer(false) + } + + return clusterArgs, err +} + +func (ctx *profileContext) CreateRHCSClusterByProfile(token string) (string, error) { + creationArgs, err := ctx.GenerateClusterCreationArgs(token) + if err != nil { + defer ctx.DestroyRHCSClusterResources(token) + return "", err + } + clusterService, err := ctx.Services().GetClusterService() + if err != nil { + defer ctx.DestroyRHCSClusterResources(token) + return "", err + } + _, err = clusterService.Apply(creationArgs) + if err != nil { + clusterService.WriteTFVars(creationArgs) + defer ctx.DestroyRHCSClusterResources(token) + return "", err + } + clusterOutput, err := clusterService.Output() + if err != nil { + clusterService.WriteTFVars(creationArgs) + defer ctx.DestroyRHCSClusterResources(token) + return "", err + } + clusterID := clusterOutput.ClusterID + return clusterID, 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") + return nil + } + + // Destroy cluster + var errs []error + clusterService, err := ctx.GetClusterService() + if err != nil { + errs = append(errs, err) + } else { + _, err = clusterService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + // Get the cluster name from backend to double check cluster deleted + clusterName, _ := helper.ReadFile(cfg.ClusterNameFile) + Logger.Infof("Double checking with the cluster name %s", clusterName) + if clusterName != "" { + parameter := map[string]interface{}{ + "search": fmt.Sprintf("name is '%s'", clusterName), + } + resp, err := cms.ListClusters(cms.RHCSConnection, parameter) + if err != nil { + errs = append(errs, err) + } else { + if resp.Size() != 0 { + Logger.Infof("Got the matched cluster with name %s, deleting via connection directly", + clusterName) + _, err = cms.DeleteCluster(cms.RHCSConnection, resp.Items().Get(0).ID()) + if err != nil { + errs = append(errs, err) + } else { + err = cms.WaitClusterDeleted(cms.RHCSConnection, resp.Items().Get(0).ID()) + if err != nil { + errs = append(errs, err) + } + } + + } + } + } + + // Destroy VPC + if ctx.profile.BYOVPC { + if ctx.profile.Proxy { + proxyService, err := ctx.GetProxyService() + if err != nil { + errs = append(errs, err) + } else { + _, err = proxyService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + } + if ctx.profile.AdditionalSGNumber != 0 { + sgService, err := ctx.GetSecurityGroupService() + if err != nil { + errs = append(errs, err) + } else { + _, err = sgService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + } + + if ctx.profile.SharedVpc { + sharedVpcPolicyAndHostedZoneService, err := ctx.GetSharedVPCPolicyAndHostedZoneService() + if err != nil { + errs = append(errs, err) + } else { + _, err = sharedVpcPolicyAndHostedZoneService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + + // DNS domain + dnsDomainService, err := ctx.GetDnsDomainService() + if err != nil { + errs = append(errs, err) + } else { + _, err = dnsDomainService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + } + + vpcService, _ := ctx.GetVPCService() + if err != nil { + errs = append(errs, err) + } else { + _, err = vpcService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + } + if ctx.profile.STS { + // Destroy oidc and operator roles + oidcOpService, err := ctx.GetOIDCProviderOperatorRolesService() + if err != nil { + errs = append(errs, err) + } else { + _, err = oidcOpService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + + // Destroy Account roles + accService, err := ctx.GetAccountRolesService() + if err != nil { + errs = append(errs, err) + } else { + _, err = accService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + + } + if ctx.profile.KMSKey || ctx.profile.Etcd { + //Destroy KMS Key + kmsService, err := ctx.GetKMSService() + if err != nil { + errs = append(errs, err) + } else { + _, err = kmsService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + + if ctx.profile.DifferentEncryptionKeys { + kmsService, err = ctx.Duplicate().Services().GetKMSService() + if err != nil { + errs = append(errs, err) + } else { + _, err = kmsService.Destroy() + if err != nil { + errs = append(errs, err) + } + } + } + } + if len(errs) > 0 { + return errors.Join(errs...) + } + return nil +} + +// 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 + } + clusterOutput, err := clusterService.Output() + clusterID := clusterOutput.ClusterID + return clusterID, err +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Services Interface for easy retrieval of TF exec services from a profile + +func (ctx *profileContext) GetAccountRolesService() (exec.AccountRoleService, error) { + return exec.NewAccountRoleService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetKMSService() (exec.KMSService, error) { + return exec.NewKMSService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetOIDCProviderOperatorRolesService() (exec.OIDCProviderOperatorRolesService, error) { + return exec.NewOIDCProviderOperatorRolesService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetProxyService() (exec.ProxyService, error) { + return exec.NewProxyService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetSecurityGroupService() (exec.SecurityGroupService, error) { + return exec.NewSecurityGroupService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetSharedVPCPolicyAndHostedZoneService() (exec.SharedVpcPolicyAndHostedZoneService, error) { + return exec.NewSharedVpcPolicyAndHostedZoneService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetVPCService() (exec.VPCService, error) { + return exec.NewVPCService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetVPCTagService() (exec.VPCTagService, error) { + return exec.NewVPCTagService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +// RHCS provider dirs +func (ctx *profileContext) GetClusterService() (exec.ClusterService, error) { + return exec.NewClusterService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetClusterAutoscalerService() (exec.ClusterAutoscalerService, error) { + return exec.NewClusterAutoscalerService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetClusterWaiterService() (exec.ClusterWaiterService, error) { + return exec.NewClusterWaiterService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetDnsDomainService() (exec.DnsDomainService, error) { + return exec.NewDnsDomainService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetIDPService(idpType constants.IDPType) (exec.IDPService, error) { + return exec.NewIDPService(ctx.GetTFWorkspace(), ctx.GetClusterType(), idpType) +} + +func (ctx *profileContext) GetIngressService() (exec.IngressService, error) { + return exec.NewIngressService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetImportService() (exec.ImportService, error) { + return exec.NewImportService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetKubeletConfigService() (exec.KubeletConfigService, error) { + return exec.NewKubeletConfigService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetMachinePoolsService() (exec.MachinePoolService, error) { + return exec.NewMachinePoolService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetRHCSInfoService() (exec.RhcsInfoService, error) { + return exec.NewRhcsInfoService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetTrustedIPsService() (exec.TrustedIPsService, error) { + return exec.NewTrustedIPsService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} + +func (ctx *profileContext) GetTuningConfigService() (exec.TuningConfigService, error) { + return exec.NewTuningConfigService(ctx.GetTFWorkspace(), ctx.GetClusterType()) +} diff --git a/tests/utils/profilehandler/profile.go b/tests/utils/profilehandler/profile.go new file mode 100644 index 00000000..3420ef30 --- /dev/null +++ b/tests/utils/profilehandler/profile.go @@ -0,0 +1,52 @@ +package profilehandler + +type Profile struct { + Name string `ini:"name,omitempty" json:"name,omitempty"` + ClusterName string `ini:"cluster_name,omitempty" json:"cluster_name,omitempty"` + DomainPrefix string `ini:"domain_prefix,omitempty" json:"domain_prefix,omitempty"` + ClusterType string `ini:"cluster_type,omitempty" json:"cluster_type,omitempty"` + ProductID string `ini:"product_id,omitempty" json:"product_id,omitempty"` + MajorVersion string `ini:"major_version,omitempty" json:"major_version,omitempty"` + Version string `ini:"version,omitempty" json:"version,omitempty"` //Specific OCP version to be specified + VersionPattern string `ini:"version_pattern,omitempty" json:"version_pattern,omitempty"` //Version supports indicated version started with openshift-v or major-1 (y-1) or minor-1 (z-1) + ChannelGroup string `ini:"channel_group,omitempty" json:"channel_group,omitempty"` + CloudProvider string `ini:"cloud_provider,omitempty" json:"cloud_provider,omitempty"` + Region string `ini:"region,omitempty" json:"region,omitempty"` + InstanceType string `ini:"instance_type,omitempty" json:"instance_type,omitempty"` + Zones string `ini:"zones,omitempty" json:"zones,omitempty"` // zones should be like a,b,c,d + StorageLB bool `ini:"storage_lb,omitempty" json:"storage_lb,omitempty"` // the unit is GIB, don't support unit set + Tagging bool `ini:"tagging,omitempty" json:"tagging,omitempty"` + Labeling bool `ini:"labeling,omitempty" json:"labeling,omitempty"` + Etcd bool `ini:"etcd_encryption,omitempty" json:"etcd_encryption,omitempty"` + FIPS bool `ini:"fips,omitempty" json:"fips,omitempty"` + CCS bool `ini:"ccs,omitempty" json:"ccs,omitempty"` + STS bool `ini:"sts,omitempty" json:"sts,omitempty"` + Autoscale bool `ini:"autoscaling_enabled,omitempty" json:"autoscaling_enabled,omitempty"` + MultiAZ bool `ini:"multi_az,omitempty" json:"multi_az,omitempty"` + BYOVPC bool `ini:"byovpc,omitempty" json:"byovpc,omitempty"` + PrivateLink bool `ini:"private_link,omitempty" json:"private_link,omitempty"` + Private bool `ini:"private,omitempty" json:"private,omitempty"` + BYOK bool `ini:"byok,omitempty" json:"byok,omitempty"` + KMSKey bool `ini:"kms_key_arn,omitempty" json:"kms_key_arn,omitempty"` + DifferentEncryptionKeys bool `ini:"different_encryption_keys,omitempty" json:"different_encryption_keys,omitempty"` + NetWorkingSet bool `ini:"networking_set,omitempty" json:"networking_set,omitempty"` + Proxy bool `ini:"proxy,omitempty" json:"proxy,omitempty"` + OIDCConfig string `ini:"oidc_config,omitempty" json:"oidc_config,omitempty"` + ProvisionShard string `ini:"provisionShard,omitempty" json:"provisionShard,omitempty"` + Ec2MetadataHttpTokens string `ini:"ec2_metadata_http_tokens,omitempty" json:"ec2_metadata_http_tokens,omitempty"` + ComputeReplicas int `ini:"compute_replicas,omitempty" json:"compute_replicas,omitempty"` + ComputeMachineType string `ini:"compute_machine_type,omitempty" json:"compute_machine_type,omitempty"` + AuditLogForward bool `ini:"auditlog_forward,omitempty" json:"auditlog_forward,omitempty"` + AdminEnabled bool `ini:"admin_enabled,omitempty" json:"admin_enabled,omitempty"` + ManagedPolicies bool `ini:"managed_policies,omitempty" json:"managed_policies,omitempty"` + WorkerDiskSize int `ini:"worker_disk_size,omitempty" json:"worker_disk_size,omitempty"` + AdditionalSGNumber int `ini:"additional_sg_number,omitempty" json:"additional_sg_number,omitempty"` + UnifiedAccRolesPath string `ini:"unified_acc_role_path,omitempty" json:"unified_acc_role_path,omitempty"` + SharedVpc bool `ini:"shared_vpc,omitempty" json:"shared_vpc,omitempty"` + MachineCIDR string `ini:"machine_cidr,omitempty" json:"machine_cidr,omitempty"` + ServiceCIDR string `ini:"service_cidr,omitempty" json:"service_cidr,omitempty"` + PodCIDR string `ini:"pod_cidr,omitempty" json:"pod_cidr,omitempty"` + HostPrefix int `ini:"host_prefix,omitempty" json:"host_prefix,omitempty"` + FullResources bool `ini:"full_resources,omitempty" json:"full_resources,omitempty"` + DontWaitForCluster bool `ini:"no_wait_cluster,omitempty" json:"no_wait_cluster,omitempty"` +}