Skip to content

Commit c91562d

Browse files
committed
OCM-13513 | test: fix ids: 64620,43070,57408,77140
1 parent cca9ff5 commit c91562d

File tree

5 files changed

+79
-64
lines changed

5 files changed

+79
-64
lines changed

tests/e2e/test_rosacli_account_roles.go

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ var _ = Describe("Edit account roles", labels.Feature.AccountRoles, func() {
147147
Expect(textData).To(ContainSubstring("Creating classic account roles"))
148148
Expect(textData).ToNot(ContainSubstring("Creating hosted CP account roles"))
149149
Expect(textData).To(ContainSubstring("Created role"))
150-
Expect(textData).ToNot(ContainSubstring("Attached trust policy to role"))
150+
Expect(textData).To(ContainSubstring("Attached trust policy to role"))
151151

152152
By("List account-roles and check the result are expected")
153153
accountRoleList, _, err := ocmResourceService.ListAccountRole()
@@ -508,6 +508,7 @@ var _ = Describe("Edit account roles", labels.Feature.AccountRoles, func() {
508508
var (
509509
rolePrefixAuto = helper.GenerateRandomName("ar57408a", 2)
510510
rolePrefixManual = helper.GenerateRandomName("ar57408m", 2)
511+
testAWSAccountID string
511512
roleVersion string
512513
path = "/fd/sd/"
513514
policiesArn []string
@@ -578,6 +579,10 @@ var _ = Describe("Edit account roles", labels.Feature.AccountRoles, func() {
578579
})
579580
helper.AssertWaitPollNoErr(err, "Network verification result are not ready after 200")
580581

582+
By("Get the AWS Account Id from policy arn")
583+
arnParts := strings.Split(policiesArn[0], ":")
584+
testAWSAccountID = arnParts[4]
585+
581586
By("Prepare verson for testing")
582587
versionService := rosaClient.Version
583588
versionList, err := versionService.ListAndReflectVersions(rosacli.VersionChannelGroupStable, true)
@@ -607,6 +612,9 @@ var _ = Describe("Edit account roles", labels.Feature.AccountRoles, func() {
607612
commands := helper.ExtractCommandsToCreateAWSResources(output)
608613

609614
for _, command := range commands {
615+
command = strings.ReplaceAll(
616+
command, "arn:aws:iam::765374464689:",
617+
fmt.Sprintf("arn:aws:iam::%s:", testAWSAccountID))
610618
_, err := rosaClient.Runner.RunCMD(strings.Split(command, " "))
611619
Expect(err).To(BeNil())
612620
}
@@ -633,32 +641,36 @@ var _ = Describe("Edit account roles", labels.Feature.AccountRoles, func() {
633641
Expect(err).To(BeNil())
634642
}
635643

636-
By("Create classic account-roles with managed policies in auto mode")
637-
output, err = ocmResourceService.CreateAccountRole("--mode", "auto",
638-
"--prefix", rolePrefixAuto,
639-
"--path", path,
640-
"--permissions-boundary", permissionsBoundaryArn,
641-
"--version", roleVersion,
642-
"--managed-policies",
643-
"-y")
644-
Expect(err).To(BeNil())
645-
Expect(output.String()).To(ContainSubstring("Created role"))
646-
647-
By("List the account roles created in auto mode")
648-
accountRoleList, _, err = ocmResourceService.ListAccountRole()
649-
Expect(err).To(BeNil())
650-
accountRoles = accountRoleList.AccountRoles(rolePrefixAuto)
651-
Expect(len(accountRoles)).To(Equal(4))
652-
for _, ar := range accountRoles {
653-
Expect(ar.AWSManaged).To(Equal("Yes"))
654-
}
655-
656-
By("Delete the account-roles in auto mode")
657-
output, err = ocmResourceService.DeleteAccountRole("--mode", "auto",
658-
"--prefix", rolePrefixAuto,
659-
"-y")
660-
Expect(err).To(BeNil())
661-
Expect(output.String()).To(ContainSubstring("Successfully deleted"))
644+
// commented out the auto mode test as the aws account in the managed policies
645+
// is the dev aws account which will lead failure.
646+
// Move this back when the managed policies are supported
647+
// officially for classic account-roles
648+
// By("Create classic account-roles with managed policies in auto mode")
649+
// output, err = ocmResourceService.CreateAccountRole("--mode", "auto",
650+
// "--prefix", rolePrefixAuto,
651+
// "--path", path,
652+
// "--permissions-boundary", permissionsBoundaryArn,
653+
// "--version", roleVersion,
654+
// "--managed-policies",
655+
// "-y")
656+
// Expect(err).To(BeNil())
657+
// Expect(output.String()).To(ContainSubstring("Created role"))
658+
659+
// By("List the account roles created in auto mode")
660+
// accountRoleList, _, err = ocmResourceService.ListAccountRole()
661+
// Expect(err).To(BeNil())
662+
// accountRoles = accountRoleList.AccountRoles(rolePrefixAuto)
663+
// Expect(len(accountRoles)).To(Equal(4))
664+
// for _, ar := range accountRoles {
665+
// Expect(ar.AWSManaged).To(Equal("Yes"))
666+
// }
667+
668+
// By("Delete the account-roles in auto mode")
669+
// output, err = ocmResourceService.DeleteAccountRole("--mode", "auto",
670+
// "--prefix", rolePrefixAuto,
671+
// "-y")
672+
// Expect(err).To(BeNil())
673+
// Expect(output.String()).To(ContainSubstring("Successfully deleted"))
662674
})
663675

664676
It("Validation for account-role creation by user - [id:43067]",

tests/e2e/test_rosacli_network_resources.go

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"path/filepath"
78
"time"
89

910
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
@@ -91,7 +92,10 @@ var _ = Describe("Network Resources",
9192
Expect(err).ToNot(HaveOccurred())
9293

9394
By("Get current working directory as template dir path")
94-
templateDirPath, err := helper.GetCurrentWorkingDir()
95+
templateDir := filepath.Dir(templatePath)
96+
97+
templateDirPath := filepath.Dir(templateDir)
98+
templateDirName := filepath.Base(templateDir)
9599
Expect(err).ToNot(HaveOccurred())
96100

97101
By("Create network resources without passing template name and parameter")
@@ -109,13 +113,13 @@ var _ = Describe("Network Resources",
109113
Expect(resp).To(And(
110114
ContainSubstring("Name not provided, using default name %s", defaultName),
111115
ContainSubstring("No template name provided in the command. Defaulting to rosa-quickstart-default-vpc"),
112-
ContainSubstring("Region not provided, using default region %s", region)))
116+
ContainSubstring("Region not provided, using default region")))
113117

114118
By("Create network resources by passing template name and all parameters")
115119
stackName_1 := helper.GenerateRandomName("ocp-77140", 2)
116120
paramNameFlag := fmt.Sprintf("--param=Name=%s", stackName_1)
117121
paramRegionFlag := fmt.Sprintf("--param=Region=%s", region)
118-
output, err = networkResourcesService.CreateNetworkResources(false, "single-vpc",
122+
output, err = networkResourcesService.CreateNetworkResources(false, templateDirName,
119123
paramNameFlag,
120124
paramRegionFlag,
121125
"--template-dir", templateDirPath,
@@ -140,15 +144,8 @@ var _ = Describe("Network Resources",
140144

141145
By("Create network using manual mode")
142146
stackName_2 := helper.GenerateRandomName("ocp-77140", 2)
143-
manualModeOutput := fmt.Sprintf("aws cloudformation create-stack --stack-name %s "+
144-
"--template-body file://%s"+
145-
" --param ParameterKey=AvailabilityZoneCount,ParameterValue=3 "+
146-
"ParameterKey=Name,ParameterValue=%s "+
147-
"ParameterKey=Region,ParameterValue=%s "+
148-
"--tags Key=Key1,Value=Value1 Key=Key2,Value=Value2 --region %s",
149-
stackName_2, templateContent, stackName_2, region, region)
150147
paramNameFlag = fmt.Sprintf("--param=Name=%s", stackName_2)
151-
output, err = networkResourcesService.CreateNetworkResources(false, "single-vpc",
148+
output, err = networkResourcesService.CreateNetworkResources(false, templateDirName,
152149
paramNameFlag,
153150
paramRegionFlag,
154151
"--template-dir", templateDirPath,
@@ -165,37 +162,28 @@ var _ = Describe("Network Resources",
165162
Expect(err).ToNot(HaveOccurred())
166163
resp = rosaClient.Parser.TextData.Input(output).Parse().Output()
167164
Expect(resp).To(
168-
ContainSubstring(manualModeOutput))
165+
ContainSubstring("aws cloudformation create-stack --stack-name"))
169166

170167
By("Try to create network by setting OCM_TEMPLATE_DIR env variable")
168+
err = os.Setenv("OCM_TEMPLATE_DIR", templateDirPath)
169+
Expect(err).ToNot(HaveOccurred())
171170
stackName_3 := helper.GenerateRandomName("ocp-77140", 2)
172171
paramNameFlag = fmt.Sprintf("--param=Name=%s", stackName_3)
173-
output, err = networkResourcesService.CreateNetworkResources(true, "single-vpc",
172+
output, err = networkResourcesService.CreateNetworkResources(false, templateDirName,
174173
paramNameFlag,
175174
paramRegionFlag)
176-
defer func() {
177-
params := cloudformation.DeleteStackInput{
178-
StackName: &stackName_3,
179-
}
180-
_, err = awsClient.StackFormationClient.DeleteStack(context.TODO(), &params)
181-
Expect(err).ToNot(HaveOccurred())
182-
Eventually(func() string {
183-
describeParam := cloudformation.DescribeStacksInput{
184-
StackName: &stackName_3,
185-
}
186-
res, _ := awsClient.StackFormationClient.DescribeStacks(context.TODO(), &describeParam)
187-
return string(res.Stacks[0].StackStatus)
188-
}, time.Minute*2).Should(ContainSubstring("DELETE_IN_PROGRESS"))
189-
}()
190-
Expect(err).ToNot(HaveOccurred())
191-
resp = rosaClient.Parser.TextData.Input(output).Parse().Output()
192-
Expect(resp).To(
193-
ContainSubstring("msg=\"Stack %s created\"", stackName_3))
175+
176+
Expect(err).To(HaveOccurred())
177+
178+
Expect(output.String()).To(
179+
ContainSubstring("when using a custom template please use `--template-dir` to specify the template directory"))
194180

195181
By("Try to override 'OCM_TEMPLATE_DIR' env variable using --template-dir flag")
182+
err = os.Setenv("OCM_TEMPLATE_DIR", "/fake/dir")
183+
Expect(err).ToNot(HaveOccurred())
196184
stackName_4 := helper.GenerateRandomName("ocp-77140", 2)
197185
paramNameFlag = fmt.Sprintf("--param=Name=%s", stackName_4)
198-
output, err = networkResourcesService.CreateNetworkResources(true, "single-vpc",
186+
output, err = networkResourcesService.CreateNetworkResources(false, templateDirName,
199187
paramNameFlag,
200188
paramRegionFlag,
201189
"--template-dir", templateDirPath)

tests/e2e/test_rosacli_oidc_config.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package e2e
33
import (
44
"fmt"
55
"os"
6+
"regexp"
67
"strings"
78
"time"
89

@@ -285,8 +286,17 @@ var _ = Describe("Register ummanaged oidc config testing",
285286
secretArn = helper.ParseSecretArnFromOutput(stdout.String())
286287
continue
287288
}
288-
if strings.Contains(command, "aws iam create-open-id-connect-provider") {
289-
issuerUrl = helper.ParseIssuerURLFromCommand(command)
289+
if strings.Contains(command, "aws s3api create-bucket") {
290+
commandArgs = helper.ParseCommandToArgs(command)
291+
stdout, err := rosaClient.Runner.RunCMD(commandArgs)
292+
Expect(err).To(BeNil())
293+
re := regexp.MustCompile(`"Location":\s*"(http://[^"]+)"`)
294+
matches := re.FindStringSubmatch(stdout.String())
295+
if len(matches) > 1 {
296+
issuerUrl = strings.Replace(matches[1], "http://", "https://", 1)
297+
}
298+
Expect(issuerUrl).ToNot(BeEmpty(), "issuerUrl is empty which will block coming steps.")
299+
continue
290300
}
291301
_, err := rosaClient.Runner.RunCMD(strings.Split(command, " "))
292302
Expect(err).To(BeNil())

tests/utils/helper/file.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package helper
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"os"
67
"path/filepath"
78
"strings"
@@ -31,15 +32,16 @@ func GetCurrentWorkingDir() (string, error) {
3132
}
3233

3334
func CreateTemplateDirForNetworkResources(templateName string, fileContent string) (string, error) {
34-
err := os.Mkdir(templateName, 0744)
35+
// err := os.Mkdir(templateName, 0744)
36+
dirpath, err := os.MkdirTemp("", fmt.Sprintf("%s-*", templateName))
3537
if err != nil {
3638
return "", err
3739
}
38-
exPath, err := GetCurrentWorkingDir()
40+
// exPath, err := GetCurrentWorkingDir()
3941
if err != nil {
4042
return "", err
4143
}
42-
dirpath := filepath.Join(exPath + "/" + templateName)
44+
// dirpath := filepath.Join(exPath + "/" + templateName)
4345
outputPath := filepath.Join(dirpath, "cloudformation.yaml")
4446

4547
f, err := os.Create(outputPath)

tests/utils/helper/oidc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func ExtractCommandsFromOIDCRegister(bf bytes.Buffer) []string {
7171
command = spaceRegex.ReplaceAllString(command, " ")
7272
// remove '' in the value
7373
command = strings.ReplaceAll(command, "'", "")
74+
if strings.Contains(command, " INFO") {
75+
command = strings.Split(command, " INFO")[0]
76+
}
7477
newCommands = append(newCommands, command)
7578

7679
}

0 commit comments

Comments
 (0)