Skip to content

Commit

Permalink
OCM-9364 | test: automate id:36293,57102,64078
Browse files Browse the repository at this point in the history
  • Loading branch information
aaraj7 committed Jul 5, 2024
1 parent 0dc8b7b commit b56158a
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 11 deletions.
47 changes: 39 additions & 8 deletions tests/e2e/test_rosacli_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,16 @@ var _ = Describe("Classic cluster creation validation",
defer GinkgoRecover()

var (
rosaClient *rosacli.Client
profilesMap map[string]*profilehandler.Profile
profile *profilehandler.Profile
rosaClient *rosacli.Client
profilesMap map[string]*profilehandler.Profile
profile *profilehandler.Profile
clusterService rosacli.ClusterService
)

BeforeEach(func() {
// Init the client
rosaClient = rosacli.NewClient()
clusterService = rosaClient.Cluster
// Get a random profile
profilesMap = profilehandler.ParseProfilesByFile(path.Join(ciConfig.Test.YAMLProfilesDir, "rosa-classic.yaml"))
profilesNames := make([]string, 0, len(profilesMap))
Expand Down Expand Up @@ -560,7 +562,6 @@ var _ = Describe("Classic cluster creation validation",
It("to validate to create the sts cluster with invalid tag - [id:56440]",
labels.Medium, labels.Runtime.Day1Negative,
func() {
clusterService := rosaClient.Cluster
clusterName := "ocp-56440"

By("Create cluster with invalid tag key")
Expand Down Expand Up @@ -625,7 +626,6 @@ var _ = Describe("Classic cluster creation validation",
func() {
minSize := 128
maxSize := 16384
clusterService := rosaClient.Cluster
clusterName := "ocp-66372"
client := rosacli.NewClient()

Expand Down Expand Up @@ -683,7 +683,6 @@ var _ = Describe("Classic cluster creation validation",
It("to validate to create cluster with availability zones - [id:52692]",
labels.Medium, labels.Runtime.Day1Negative,
func() {
clusterService := rosaClient.Cluster
clusterName := "ocp-52692"

By("Create cluster with the zone not available in the region")
Expand Down Expand Up @@ -828,7 +827,6 @@ var _ = Describe("Classic cluster creation validation",
It("to validate to create the cluster with version not in the channel group - [id:74399]",
labels.Medium, labels.Runtime.Day1Negative,
func() {
clusterService := rosaClient.Cluster
clusterName := "ocp-74399"

By("Create cluster with version not in channel group")
Expand All @@ -844,7 +842,6 @@ var _ = Describe("Classic cluster creation validation",
It("to validate to create the cluster with setting 'fips' flag but '--etcd-encryption=false' - [id:74436]",
labels.Medium, labels.Runtime.Day1Negative,
func() {
clusterService := rosaClient.Cluster
clusterName := "ocp-74436"

By("Create cluster with fips flag but '--etcd-encryption=false")
Expand Down Expand Up @@ -1159,6 +1156,40 @@ var _ = Describe("HCP cluster creation negative testing",
"External authentication is only supported in version '4.15.9' or greater, current cluster version is '%s'",
foundVersion))
})

It("to validate '--ec2-metadata-http-tokens' flag during creating cluster - [id:64078]",
labels.Medium,
labels.Runtime.Day1Negative,
func() {
clusterName := "ocp-64078"

By("Create classic cluster with invalid httpTokens")
errorOutput, err := clusterService.CreateDryRun(
clusterName, "--ec2-metadata-http-tokens=invalid",
)
Expect(err).NotTo(BeNil())
Expect(errorOutput.String()).
To(
ContainSubstring(
"ERR: Expected a valid http tokens value : " +
"ec2-metadata-http-tokens value should be one of 'required', 'optional'"))

By("Craete HCP cluster with httpTokens=Required")
replacingFlags := map[string]string{
"-c": clusterName,
"--cluster-name": clusterName,
"--domain-prefix": clusterName,
}

rosalCommand.ReplaceFlagValue(replacingFlags)
rosalCommand.AddFlags("--dry-run", "--ec2-metadata-http-tokens=required", "-y")
out, err := rosaClient.Runner.RunCMD(strings.Split(rosalCommand.GetFullCommand(), " "))
Expect(err).NotTo(BeNil())
Expect(out.String()).
To(
ContainSubstring(
"ERR: 'ec2-metadata-http-tokens' is not available for Hosted Control Plane clusters"))
})
})

var _ = Describe("Create cluster with availability zones testing",
Expand Down
141 changes: 138 additions & 3 deletions tests/e2e/test_rosacli_machine_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,76 @@ var _ = Describe("Create machinepool",

})

It("can create/list/delete machinepool - [id:36293]",
labels.Critical,
labels.Runtime.Day2,
func() {
By("Check help info for create machinepool")
_, err := machinePoolService.RetrieveHelpForCreate()
Expect(err).ToNot(HaveOccurred())

labels_1 := "m5.xlarge/test=aaa"
taints := "Key1=value1:NoExecute,test1=value2:NoSchedule"
labels_2 := "aaa=bbb"
maxReplicas := "6"
minReplicas := "3"

reqFlags := map[string][]string{
"default": {"--replicas", "0"},
"advanced": {"--replicas", "3", "--labels", labels_1,
"--taints", taints, "--instance-type", "m5.2xlarge"},
"auto_scaling": {"--enable-autoscaling", "--max-replicas", maxReplicas,
"--min-replicas", minReplicas, "--labels", labels_2},
}

By("List the default machinepool of the cluster")
resp, err := machinePoolService.ListAndReflectMachinePools(clusterID)
Expect(err).ToNot(HaveOccurred())

for key, flags := range reqFlags {
By("Create machinepools to the cluster")
mpID := common.GenerateRandomName("mp-36293", 2)
output, err := machinePoolService.CreateMachinePool(clusterID, mpID, flags...)
Expect(err).ToNot(HaveOccurred())
textData := rosaClient.Parser.TextData.Input(output).Parse().Tip()
Expect(textData).
To(
ContainSubstring(
"Machine pool '%s' created successfully on cluster '%s'",
mpID,
clusterID))

By("List the machinepools of the cluster")
out, err := machinePoolService.ListAndReflectMachinePools(clusterID)
Expect(out.Machinepool(mpID).AvalaiblityZones).To(Equal(resp.MachinePools[0].AvalaiblityZones))
Expect(err).ToNot(HaveOccurred())
if key == "default" {
Expect(out.Machinepool(mpID).Replicas).To(Equal("0"))
Expect(out.Machinepool(mpID).InstanceType).To(Equal("m5.xlarge"))
}

if key == "advanced" {
Expect(out.Machinepool(mpID).Replicas).To(Equal("3"))
Expect(out.Machinepool(mpID).InstanceType).To(Equal("m5.2xlarge"))
Expect(out.Machinepool(mpID).AutoScaling).To(Equal("No"))
Expect(out.Machinepool(mpID).Labels).To(
Equal(strings.Join(common.ParseCommaSeparatedStrings(labels_1), ", ")))
Expect(out.Machinepool(mpID).Taints).To(
Equal(strings.Join(common.ParseCommaSeparatedStrings(taints), ", ")))
}

if key == "auto_scaling" {
Expect(out.Machinepool(mpID).AutoScaling).To(Equal("Yes"))
Expect(out.Machinepool(mpID).Replicas).
To(
Equal(fmt.Sprintf("%s-%s", minReplicas, maxReplicas)))
Expect(out.Machinepool(mpID).InstanceType).To(Equal("m5.xlarge"))
Expect(out.Machinepool(mpID).Labels).To(
Equal(strings.Join(common.ParseCommaSeparatedStrings(labels_2), ", ")))
}
}
})

It("can create machinepool with volume size set - [id:66872]",
labels.Runtime.Day2,
labels.Critical,
Expand All @@ -66,15 +136,21 @@ var _ = Describe("Create machinepool",
machineType := "r5.xlarge"

By("Create a machinepool with the disk size")
_, err := machinePoolService.CreateMachinePool(clusterID, mpID,
output, err := machinePoolService.CreateMachinePool(clusterID, mpID,
"--replicas", "0",
"--disk-size", "200GB",
"--instance-type", machineType,
)
Expect(err).ToNot(HaveOccurred())
textData := rosaClient.Parser.TextData.Input(output).Parse().Tip()
Expect(textData).
Should(ContainSubstring(
"Machine pool '%s' created successfully on cluster '%s'",
mpID,
clusterID))

By("Check the machinepool list")
output, err := machinePoolService.ListMachinePool(clusterID)
output, err = machinePoolService.ListMachinePool(clusterID)
Expect(err).ToNot(HaveOccurred())

mplist, err := machinePoolService.ReflectMachinePoolList(output)
Expand All @@ -96,13 +172,19 @@ var _ = Describe("Create machinepool",
mpID = "mp-66872-2"
expectedDiskSize = "512 GiB" // it is 0.5TiB
machineType = "m5.2xlarge"
_, err = machinePoolService.CreateMachinePool(clusterID, mpID,
output, err = machinePoolService.CreateMachinePool(clusterID, mpID,
"--replicas", "0",
"--disk-size", "0.5TiB",
"--instance-type", machineType,
)

Expect(err).ToNot(HaveOccurred())
textData = rosaClient.Parser.TextData.Input(output).Parse().Tip()
Expect(textData).
Should(ContainSubstring(
"Machine pool '%s' created successfully on cluster '%s'",
mpID,
clusterID))

By("Check the machinepool list")
output, err = machinePoolService.ListMachinePool(clusterID)
Expand Down Expand Up @@ -752,6 +834,59 @@ var _ = Describe("Edit machinepool",
Expect(mp.Taints).To(Equal(strings.Join(common.ParseCommaSeparatedStrings(taints), ", ")))
})

It("can edit the default machinepool labels and taints - [id:57102]",
labels.High,
labels.Runtime.Day2,
func() {
By("List the machinepools of the cluster")
mpList, err := rosaClient.MachinePool.ListAndReflectMachinePools(clusterID)
Expect(err).ToNot(HaveOccurred())
workerPool := mpList.Machinepool(con.DefaultClassicWorkerPool)
Expect(workerPool).ToNot(BeNil())

labels_1 := "m5.xlarge/test=aaa"
taints_1 := "Key1=:NoExecute"
labels_2 := "aaa="
taints_2 := "Key2=Value1:NoExecute"

reqFlags := map[string][]string{
"empty_taint_value": {"--labels", labels_1, "--taints", taints_1},
"empty_label_value": {"--labels", labels_2, "--taints", taints_2},
"empty_label_and_taint": {"--labels", "", "--taints", ""},
}

for key, flags := range reqFlags {
By("Edit machinepools to the cluster")
_, err := machinePoolService.EditMachinePool(clusterID, con.DefaultClassicWorkerPool, flags...)
Expect(err).ToNot(HaveOccurred())

By("List the machinepools of the cluster")
out, err := machinePoolService.ListAndReflectMachinePools(clusterID)
Expect(err).ToNot(HaveOccurred())

if key == "empty_taint_value" {
Expect(out.Machinepool(con.DefaultClassicWorkerPool).Labels).To(
Equal(strings.Join(common.ParseCommaSeparatedStrings(labels_1), ", ")))
Expect(out.Machinepool(con.DefaultClassicWorkerPool).Taints).To(
Equal(strings.Join(common.ParseCommaSeparatedStrings(taints_1), ", ")))
}

if key == "empty_label_value" {
Expect(out.Machinepool(con.DefaultClassicWorkerPool).Labels).To(
Equal(strings.Join(common.ParseCommaSeparatedStrings(labels_2), ", ")))
Expect(out.Machinepool(con.DefaultClassicWorkerPool).Taints).To(
Equal(strings.Join(common.ParseCommaSeparatedStrings(taints_2), ", ")))
}

if key == "empty_label_and_taint" {
Expect(out.Machinepool(con.DefaultClassicWorkerPool).Labels).To(
Equal(""))
Expect(out.Machinepool(con.DefaultClassicWorkerPool).Taints).To(
Equal(""))
}
}
})

It("can list/edit/delete the default worker pool - [id:66750]", labels.Runtime.Destructive, labels.High,
func() {
By("List the machinepools of the cluster")
Expand Down

0 comments on commit b56158a

Please sign in to comment.