Skip to content

Commit

Permalink
Stability improvements for IOR tests (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkralik3 authored Nov 7, 2024
1 parent 56258fc commit 977dac3
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions pkg/tests/ossm/ior_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ func TestIOR(t *testing.T) {
t.NewSubTest("check IOR basic functionalities").Run(func(t TestHelper) {
t.Cleanup(func() {
if env.GetSMCPVersion().GreaterThanOrEqual(version.SMCP_2_5) {
deleteSimpleGateway(t)
removeIORCustomSetting(t, meshNamespace, meshName)
deleteAllRoutes(t, meshNamespace)
}
deleteSimpleGateway(t)
})

t.LogStep("Ensure the IOR enabled")
Expand All @@ -135,7 +136,7 @@ func TestIOR(t *testing.T) {
t.Skip("This test only applies for v2.3 to v2.4 upgrade")
}
if env.GetArch() == "arm64" {
t.Skip("2.3 & 2.4 is not supported in arm, from 2.5 GA in arm")
t.Skip("2.3 & 2.4 is not supported in arm (arm is supported from ossm 2.5+)")
}

t.Cleanup(func() {
Expand Down Expand Up @@ -277,8 +278,9 @@ func TestIOR(t *testing.T) {
t.Log("Reference: https://issues.redhat.com/browse/OSSM-6295")

t.Cleanup(func() {
removeIORCustomSetting(t, meshNamespace, meshName)
deleteSimpleGateway(t)
removeIORCustomSetting(t, meshNamespace, meshName)
deleteAllRoutes(t, meshNamespace)
})

t.LogStep("Ensure the IOR enabled")
Expand Down Expand Up @@ -386,18 +388,31 @@ func addAdditionalIngressGateway(t TestHelper, meshName, meshNamespace, gatewayN
}

func getRoutes(t TestHelper, ns string) []Route {
res := shell.Executef(t, "oc -n %s get --selector 'maistra.io/generated-by=ior' --output 'jsonpath={.items}' route", ns)
res := shell.Executef(t, "oc -n %s get --selector 'maistra.io/generated-by=ior' --output 'jsonpath={.items}' route --ignore-not-found", ns)
var routes []Route
err := json.Unmarshal([]byte(res), &routes)
if err != nil {
t.Fatalf("Error parsing data %s: %v", res, err)
if res != "" {
err := json.Unmarshal([]byte(res), &routes)
if err != nil {
t.Fatalf("Error parsing data %s: %v", res, err)
}
}

return routes
}

func getRouteNames(t TestHelper, ns string) []string {
return oc.GetAllResoucesNamesByLabel(t, ns, "route", "maistra.io/generated-by=ior")
routes := getRoutes(t, ns)
var names []string
for _, route := range routes {
names = append(names, route.Metadata.Name)
}
return names
}

// Sometimes, the IOR routes are not deleted after the Gateway is deleted. Do it explicitly
func deleteAllRoutes(t TestHelper, ns string) {
for _, name := range getRouteNames(t, ns) {
oc.DeleteResource(t, ns, "Route", name)
}
}

func buildManagedRouteYamlDocument(t TestHelper, ns string) string {
Expand Down Expand Up @@ -452,17 +467,21 @@ func getIORSetting(t TestHelper, ns, name string) string {
}

func enableIOR(t TestHelper, ns, name string) {
t.Log("Enabling IOR")
oc.Patch(t,
ns, "smcp", name, "json",
`[{"op": "add", "path": "/spec/gateways", "value": {"openshiftRoute": {"enabled": true}}}]`,
)
oc.WaitSMCPReady(t, meshNamespace, DefaultSMCP().Name)
}

func removeIORCustomSetting(t TestHelper, ns, name string) {
t.Log("Disabling IOR")
oc.Patch(t,
ns, "smcp", name, "json",
`[{"op": "remove", "path": "/spec/gateways"}]`,
)
oc.WaitSMCPReady(t, meshNamespace, DefaultSMCP().Name)
}

func generateGateway(name, ns, host string) string {
Expand Down

0 comments on commit 977dac3

Please sign in to comment.