Skip to content

Commit

Permalink
OSSM-1514: Expand Disconnected test cases (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
unsortedhashsets authored Nov 6, 2024
1 parent 8a13bf3 commit 56258fc
Show file tree
Hide file tree
Showing 26 changed files with 144 additions and 136 deletions.
2 changes: 1 addition & 1 deletion pkg/tests/non-dependant/bug_multiple_smcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestSMCPMultiple(t *testing.T) {
NewTest(t).Id("T36").Groups(Full, ARM).Run(func(t TestHelper) {
NewTest(t).Id("T36").Groups(Full, ARM, Disconnected).Run(func(t TestHelper) {
t.Log("This test verifies whether the operator only reconciles one SMCP when two exist in a namespace")
t.Log("See https://issues.redhat.com/browse/OSSM-2419")

Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/non-dependant/olm_webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestOlmWebhookCreation(t *testing.T) {
NewTest(t).Groups(Full, ARM).Run(func(t TestHelper) {
NewTest(t).Groups(Full, ARM, Disconnected).Run(func(t TestHelper) {
t.Log("This test verifies that OLM creates all validating/mutating webhooks")
t.Log("See https://issues.redhat.com/browse/OSSM-6762")
if env.GetOperatorVersion().LessThan(version.OPERATOR_2_6_0) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/ossm/bug_istiopods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestIstiodPodFailsAfterRestarts(t *testing.T) {
}

func TestControllerFailsToUpdatePod(t *testing.T) {
NewTest(t).Groups(Full, Disconnected, ARM).Run(func(t TestHelper) {
NewTest(t).Groups(Full, ARM).Run(func(t TestHelper) {
t.Log("Verify that the controller does not fails to update the pod when the member controller couldn't add the member-of label")
t.Log("References: \n- https://issues.redhat.com/browse/OSSM-2169\n- https://issues.redhat.com/browse/OSSM-2420")

Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/ossm/bug_rolebinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type namespaceResources struct {
}

func TestMissingRoleBinding(t *testing.T) {
NewTest(t).Groups(Full, ARM).Run(func(t TestHelper) {
NewTest(t).Groups(Full, ARM, Disconnected).Run(func(t TestHelper) {
t.Log("Verify that role and role binding is detected with SMMR namespace with gateway")
t.Log("Reference: https://issues.redhat.com/browse/OSSM-2143")

Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/ossm/discovery_selectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func TestDiscoverySelectors(t *testing.T) {
NewTest(t).Groups(Full, ARM).Run(func(t TestHelper) {
NewTest(t).Groups(Full, ARM, Disconnected).Run(func(t TestHelper) {
t.Log("This test checks if discoverySelectors are being honored")
t.Log("See https://issues.redhat.com/browse/OSSM-3802")
t.Log("Test case is based on https://istio.io/latest/blog/2021/discovery-selectors/")
Expand Down
79 changes: 41 additions & 38 deletions pkg/tests/ossm/ior_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sort"
"strings"
"testing"
"time"

"gopkg.in/yaml.v2"

Expand All @@ -32,8 +33,9 @@ import (
"github.com/maistra/maistra-test-tool/pkg/util/pod"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
"github.com/maistra/maistra-test-tool/pkg/util/shell"
"github.com/maistra/maistra-test-tool/pkg/util/test"
"github.com/maistra/maistra-test-tool/pkg/util/version"

. "github.com/maistra/maistra-test-tool/pkg/util/test"
)

type RouteMetadata struct {
Expand All @@ -54,7 +56,7 @@ const (

// TestIOR tests IOR error regarding routes recreated: https://issues.redhat.com/browse/OSSM-1974. IOR will be deprecated on 2.4 and willl be removed on 3.0
func TestIOR(t *testing.T) {
test.NewTest(t).Groups(test.Full, test.ARM).Run(func(t test.TestHelper) {
NewTest(t).Groups(Full, ARM, Disconnected).Run(func(t TestHelper) {
t.Log("This test verifies the behavior of IOR.")

meshNamespace := env.GetDefaultMeshNamespace()
Expand All @@ -67,19 +69,19 @@ func TestIOR(t *testing.T) {
host := "www.test.ocp"
gatewayName := "gw"

createSimpleGateway := func(t test.TestHelper) {
createSimpleGateway := func(t TestHelper) {
t.Logf("Creating Gateway for %s host", host)
oc.ApplyString(t, "", generateGateway(gatewayName, meshNamespace, host))
}

deleteSimpleGateway := func(t test.TestHelper) {
deleteSimpleGateway := func(t TestHelper) {
t.Logf("Deleting Gateway for %s host", host)
oc.DeleteFromString(t, "", generateGateway(gatewayName, meshNamespace, host))
}

checkSimpleGateway := func(t test.TestHelper) {
checkSimpleGateway := func(t TestHelper) {
t.Logf("Checking whether a Route is generated for %s", host)
retry.UntilSuccess(t, func(t test.TestHelper) {
retry.UntilSuccess(t, func(t TestHelper) {
routes := getRoutes(t, meshNamespace)
if len(routes) != 1 {
t.Fatalf("Expect a single route set for %s host, but got %s instead", host, len(routes))
Expand All @@ -98,7 +100,7 @@ func TestIOR(t *testing.T) {

DeployControlPlane(t)

t.NewSubTest("check IOR off by default from v2.5").Run(func(t test.TestHelper) {
t.NewSubTest("check IOR off by default from v2.5").Run(func(t TestHelper) {
if env.GetSMCPVersion().LessThan(version.SMCP_2_5) {
t.Skip("Skipping until 2.5")
} else {
Expand All @@ -110,7 +112,7 @@ func TestIOR(t *testing.T) {
}
})

t.NewSubTest("check IOR basic functionalities").Run(func(t test.TestHelper) {
t.NewSubTest("check IOR basic functionalities").Run(func(t TestHelper) {
t.Cleanup(func() {
if env.GetSMCPVersion().GreaterThanOrEqual(version.SMCP_2_5) {
removeIORCustomSetting(t, meshNamespace, meshName)
Expand All @@ -128,7 +130,7 @@ func TestIOR(t *testing.T) {
checkSimpleGateway(t)
})

t.NewSubTest("check routes aren't deleted during v2.3 to v2.4 upgrade").Run(func(t test.TestHelper) {
t.NewSubTest("check routes aren't deleted during v2.3 to v2.4 upgrade").Run(func(t TestHelper) {
if env.GetSMCPVersion().LessThan(version.SMCP_2_4) {
t.Skip("This test only applies for v2.3 to v2.4 upgrade")
}
Expand Down Expand Up @@ -169,7 +171,7 @@ func TestIOR(t *testing.T) {
}
})

t.NewSubTest("check IOR does not delete routes after deleting Istio pod").Run(func(t test.TestHelper) {
t.NewSubTest("check IOR does not delete routes after deleting Istio pod").Run(func(t TestHelper) {
total := 3
nsNames := []string{}
gateways := []string{}
Expand Down Expand Up @@ -210,7 +212,7 @@ func TestIOR(t *testing.T) {
oc.ApplyString(t, meshNamespace, AppendDefaultSMMR(nsNames...))
oc.WaitSMMRReady(t, meshNamespace)

retry.UntilSuccess(t, func(t test.TestHelper) {
retry.UntilSuccess(t, func(t TestHelper) {
routes := getRoutes(t, meshNamespace)
if len(routes) != total {
t.Fatalf("Expect to find %d Routes but found %d instead", total, len(routes))
Expand Down Expand Up @@ -240,7 +242,7 @@ func TestIOR(t *testing.T) {
})

before := buildManagedRouteYamlDocument(t, meshNamespace)
detectRouteChanges := func(t test.TestHelper) {
detectRouteChanges := func(t TestHelper) {
after := buildManagedRouteYamlDocument(t, meshNamespace)
if err := util.Compare(
[]byte(before),
Expand All @@ -267,7 +269,7 @@ func TestIOR(t *testing.T) {
detectRouteChanges(t)
})

t.NewSubTest("Check argocd.argoproj.io labels from Gateways to Routes except argocd.argoproj.io/instance").Run(func(t test.TestHelper) {
t.NewSubTest("Check argocd.argoproj.io labels from Gateways to Routes except argocd.argoproj.io/instance").Run(func(t TestHelper) {
if env.GetArch() == "arm64" && env.GetSMCPVersion().LessThan(version.SMCP_2_5) {
t.Skip("2.4 is not supported in arm, from 2.5 GA in arm")
}
Expand Down Expand Up @@ -297,17 +299,17 @@ metadata:
`)

t.LogStep("Check the argocd.argoproj.io/secret label was copied to the Route")
retry.UntilSuccess(t, func(t test.TestHelper) {
retry.UntilSuccess(t, func(t TestHelper) {
if oc.ResourceByLabelExists(t, "istio-system", "route", "argocd.argoproj.io/secret-type=cluster") {
t.LogSuccess("argocd.argoproj.io/secret-type=cluster label was copied to the Route")
} else {
t.Fatalf("argocd.argoproj.io/secret-type=cluster label was not copied to the Route")
t.Errorf("argocd.argoproj.io/secret-type=cluster label was not copied to the Route")
}
})

t.LogStep("Check the argocd.argoproj.io/instance label was not copied to the Route")
if oc.ResourceByLabelExists(t, "istio-system", "route", "argocd.argoproj.io/instance=app") {
t.Fatalf("argocd.argoproj.io/instance=app label was copied to the Route")
t.Errorf("argocd.argoproj.io/instance=app label was copied to the Route")
} else {
t.LogSuccess("argocd.argoproj.io/instance=app label was not copied to the Route")
}
Expand All @@ -319,7 +321,7 @@ metadata:
checkAnnotationCopiedToRoute(t, meshNamespace, "argocd.argoproj.io/instance", "app", gatewayName)
})

t.NewSubTest("Check Headless service in istio namespace does not break IOR").Run(func(t test.TestHelper) {
t.NewSubTest("Check Headless service in istio namespace does not break IOR").Run(func(t TestHelper) {
if env.GetSMCPVersion().LessThan(version.SMCP_2_5) {
t.Skip("Issue fixed from SMCP 2.5")
}
Expand Down Expand Up @@ -351,21 +353,22 @@ spec:
testAttempts := 5
t.LogStepf("Try to delete istiod pod and check the bookinfo route few times (%d)", testAttempts)
for i := 0; i < testAttempts; i++ {
shell.Execute(t,
fmt.Sprintf(`
oc delete pod -l app=istiod -n %[1]s;
oc rollout status deployment -l app=istiod -n %[1]s;
sleep 5;
oc get route -l maistra.io/gateway-name=bookinfo-gateway -n %[1]s -o jsonpath='{.items[].spec.to.name}'`, meshNamespace),
assert.OutputContains("istio-ingressgateway",
fmt.Sprintf("%d: Headless service in istio namespace did not broke IOR", i+1),
fmt.Sprintf("%d: Headless service in istio namespace broke IOR", i+1)))
oc.DeletePod(t, pod.MatchingSelector("app=istiod", meshNamespace))
oc.WaitPodReady(t, pod.MatchingSelector("app=istiod", meshNamespace))
retry.UntilSuccessWithOptions(t, retry.Options().MaxAttempts(10).DelayBetweenAttempts(2*time.Second), func(t TestHelper) {
shell.Execute(t,
fmt.Sprintf(`oc get route -n %s -l 'maistra.io/gateway-name=bookinfo-gateway' -o jsonpath='{.items[*].spec.to.name}'`, meshNamespace),
assert.OutputContains(
"istio-ingressgateway",
fmt.Sprintf("%d: Headless service in istio namespace did not broke IOR", i+1),
fmt.Sprintf("%d: Headless service in istio namespace broke IOR", i+1)))
})
}
})
})
}

func addAdditionalIngressGateway(t test.TestHelper, meshName, meshNamespace, gatewayName string) {
func addAdditionalIngressGateway(t TestHelper, meshName, meshNamespace, gatewayName string) {
oc.Patch(t, meshNamespace,
"smcp", meshName,
"merge", fmt.Sprintf(`
Expand All @@ -382,7 +385,7 @@ func addAdditionalIngressGateway(t test.TestHelper, meshName, meshNamespace, gat
oc.WaitSMCPReady(t, meshNamespace, meshName)
}

func getRoutes(t test.TestHelper, ns string) []Route {
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)
var routes []Route
err := json.Unmarshal([]byte(res), &routes)
Expand All @@ -393,11 +396,11 @@ func getRoutes(t test.TestHelper, ns string) []Route {
return routes
}

func getRouteNames(t test.TestHelper, ns string) []string {
func getRouteNames(t TestHelper, ns string) []string {
return oc.GetAllResoucesNamesByLabel(t, ns, "route", "maistra.io/generated-by=ior")
}

func buildManagedRouteYamlDocument(t test.TestHelper, ns string) string {
func buildManagedRouteYamlDocument(t TestHelper, ns string) string {
names := getRouteNames(t, ns)
sort.Strings(names)

Expand All @@ -422,40 +425,40 @@ func buildManagedRouteYamlDocument(t test.TestHelper, ns string) string {
return doc
}

func setupDefaultSMCP(t test.TestHelper, ns string) {
func setupDefaultSMCP(t TestHelper, ns string) {
InstallSMCP(t, ns)
oc.WaitSMCPReady(t, ns, env.GetDefaultSMCPName())
}

func setupV23SMCP(t test.TestHelper, ns, name string) {
func setupV23SMCP(t TestHelper, ns, name string) {
InstallSMCPVersion(t, ns, version.SMCP_2_3)
oc.WaitSMCPReady(t, ns, name)

oc.ApplyString(t, ns, GetSMMRTemplate())
oc.WaitSMMRReady(t, ns)
}

func updateToV24SMCP(t test.TestHelper, ns, name string) {
func updateToV24SMCP(t TestHelper, ns, name string) {
oc.Patch(t, ns,
"smcp", name,
"json", `[{"op": "add", "path": "/spec/version", "value": "v2.4"}]`)
oc.WaitSMCPReady(t, ns, name)
}

func getIORSetting(t test.TestHelper, ns, name string) string {
func getIORSetting(t TestHelper, ns, name string) string {
return shell.Executef(t,
`oc -n %s get smcp/%s -o jsonpath='{.status.appliedValues.istio.gateways.istio-ingressgateway.ior_enabled}'`,
ns, name)
}

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

func removeIORCustomSetting(t test.TestHelper, ns, name string) {
func removeIORCustomSetting(t TestHelper, ns, name string) {
oc.Patch(t,
ns, "smcp", name, "json",
`[{"op": "remove", "path": "/spec/gateways"}]`,
Expand Down Expand Up @@ -484,8 +487,8 @@ spec:
)
}

func checkAnnotationCopiedToRoute(t test.TestHelper, meshNamespace, annotationKey, annotationValue, expectedOutput string) {
retry.UntilSuccess(t, func(t test.TestHelper) {
func checkAnnotationCopiedToRoute(t TestHelper, meshNamespace, annotationKey, annotationValue, expectedOutput string) {
retry.UntilSuccess(t, func(t TestHelper) {
shell.Execute(t,
fmt.Sprintf(`oc get route -n %s -o json | jq -r '.items[] | select(.metadata.annotations["%s"] == "%s") | .metadata.name'`, meshNamespace, annotationKey, annotationValue),
assert.OutputContains(expectedOutput,
Expand Down
Loading

0 comments on commit 56258fc

Please sign in to comment.