From f6d42293220d3450c7ed842d78905d6fca7f1543 Mon Sep 17 00:00:00 2001 From: Praneeth Bajjuri Date: Tue, 14 May 2024 09:31:39 -0500 Subject: [PATCH] update_ns_package (#686) Co-authored-by: Praneeth Bajjuri --- .../tasks/traffic/circuit_breaking_test.go | 19 +++++++------- .../egress/egress_wildcard_hosts_test.go | 20 +++++++------- .../tasks/traffic/fault_injection_test.go | 14 +++++----- .../tasks/traffic/ingress/gatewayapi_test.go | 26 +++++++++---------- .../traffic/ingress/ingress_gateways_test.go | 11 ++++---- .../ingress_without_tls_termination_test.go | 13 +++++----- .../traffic/ingress/secure_gateways_test.go | 18 ++++++------- .../tasks/traffic/request_routing_test.go | 10 +++---- .../tasks/traffic/request_timeouts_test.go | 10 +++---- .../tasks/traffic/traffic_mirroring_test.go | 26 +++++++++---------- .../tasks/traffic/traffic_shifting_test.go | 12 ++++----- .../traffic/traffic_tcp_shifting_test.go | 18 ++++++------- 12 files changed, 99 insertions(+), 98 deletions(-) diff --git a/pkg/tests/tasks/traffic/circuit_breaking_test.go b/pkg/tests/tasks/traffic/circuit_breaking_test.go index d318545f..831fcbaa 100644 --- a/pkg/tests/tasks/traffic/circuit_breaking_test.go +++ b/pkg/tests/tasks/traffic/circuit_breaking_test.go @@ -25,10 +25,12 @@ import ( "github.com/maistra/maistra-test-tool/pkg/app" "github.com/maistra/maistra-test-tool/pkg/tests/ossm" "github.com/maistra/maistra-test-tool/pkg/util/check/assert" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "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/test" + . "github.com/maistra/maistra-test-tool/pkg/util/test" ) @@ -36,24 +38,23 @@ func TestCircuitBreaking(t *testing.T) { NewTest(t).Id("T6").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { t.Log("This test checks whether the circuit breaker functions correctly. Check documentation: https://istio.io/latest/docs/tasks/traffic-management/circuit-breaking/") - ns := "bookinfo" t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) }) ossm.DeployControlPlane(t) t.LogStep("Install httpbin and fortio") - app.InstallAndWaitReady(t, app.Httpbin(ns), app.Fortio(ns)) + app.InstallAndWaitReady(t, app.Httpbin(ns.Bookinfo), app.Fortio(ns.Bookinfo)) t.LogStep("Configure circuit breaker destination rule") - oc.ApplyString(t, ns, httpbinCircuitBreaker) + oc.ApplyString(t, ns.Bookinfo, httpbinCircuitBreaker) t.LogStep("Verify connection with curl: expect 200 OK") retry.UntilSuccess(t, func(t test.TestHelper) { - httpbinIP := oc.GetServiceClusterIP(t, ns, "httpbin") + httpbinIP := oc.GetServiceClusterIP(t, ns.Bookinfo, "httpbin") oc.Exec(t, - pod.MatchingSelector("app=fortio", ns), + pod.MatchingSelector("app=fortio", ns.Bookinfo), "fortio", fmt.Sprintf(`/usr/bin/fortio curl -quiet -resolve %s http://httpbin:8000/get`, httpbinIP), assert.OutputContains("200", @@ -66,9 +67,9 @@ func TestCircuitBreaking(t *testing.T) { t.LogStep("Trip the circuit breaker by sending 50 requests to httpbin with 2 connections") t.Log("We expect request with response code 503") retry.UntilSuccess(t, func(t test.TestHelper) { - httpbinIP := oc.GetServiceClusterIP(t, ns, "httpbin") + httpbinIP := oc.GetServiceClusterIP(t, ns.Bookinfo, "httpbin") msg := oc.Exec(t, - pod.MatchingSelector("app=fortio", ns), + pod.MatchingSelector("app=fortio", ns.Bookinfo), "fortio", fmt.Sprintf("/usr/bin/fortio load -c %d -qps 0 -n %d -loglevel Warning -resolve %s http://httpbin:8000/get", connection, reqCount, httpbinIP)) @@ -85,7 +86,7 @@ func TestCircuitBreaking(t *testing.T) { t.LogStep("Validate the circuit breaker is tripped by checking the istio-proxy log") t.Log("Verify istio-proxy pilot-agent stats, expected upstream_rq_pending_overflow value to be more than zero") oc.Exec(t, - pod.MatchingSelector("app=fortio", ns), + pod.MatchingSelector("app=fortio", ns.Bookinfo), "istio-proxy", "pilot-agent request GET stats | grep httpbin | grep pending", assertProxyContainsUpstreamRqPendingOverflow) diff --git a/pkg/tests/tasks/traffic/egress/egress_wildcard_hosts_test.go b/pkg/tests/tasks/traffic/egress/egress_wildcard_hosts_test.go index a4ed90d3..b984316f 100644 --- a/pkg/tests/tasks/traffic/egress/egress_wildcard_hosts_test.go +++ b/pkg/tests/tasks/traffic/egress/egress_wildcard_hosts_test.go @@ -20,7 +20,9 @@ import ( "github.com/maistra/maistra-test-tool/pkg/app" "github.com/maistra/maistra-test-tool/pkg/tests/ossm" "github.com/maistra/maistra-test-tool/pkg/util/check/assert" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" + . "github.com/maistra/maistra-test-tool/pkg/util/test" ) @@ -28,34 +30,32 @@ func TestEgressWildcard(t *testing.T) { NewTest(t).Id("T16").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { t.Log("This test checks if the wildcard in the ServiceEntry and Gateway works as expected for Egress traffic.") - ns := "bookinfo" - ossm.DeployControlPlane(t) t.LogStep("Install the sleep pod") - app.InstallAndWaitReady(t, app.Sleep(ns)) + app.InstallAndWaitReady(t, app.Sleep(ns.Bookinfo)) t.Cleanup(func() { - app.Uninstall(t, app.Sleep(ns)) + app.Uninstall(t, app.Sleep(ns.Bookinfo)) }) t.NewSubTest("ServiceEntry").Run(func(t TestHelper) { t.LogStep("Configure ServiceEntry with wildcard host *.wikipedia.org") - oc.ApplyString(t, ns, EgressWildcardServiceEntry) + oc.ApplyString(t, ns.Bookinfo, EgressWildcardServiceEntry) t.Cleanup(func() { - oc.DeleteFromString(t, ns, EgressWildcardServiceEntry) + oc.DeleteFromString(t, ns.Bookinfo, EgressWildcardServiceEntry) }) - assertExternalRequestSuccess(t, ns) + assertExternalRequestSuccess(t, ns.Bookinfo) }) t.NewSubTest("Gateway").Run(func(t TestHelper) { t.LogStep("Configure egress Gateway with wildcard host *.wikipedia.org") - oc.ApplyTemplate(t, ns, EgressWildcardGatewayTemplate, smcp) + oc.ApplyTemplate(t, ns.Bookinfo, EgressWildcardGatewayTemplate, smcp) t.Cleanup(func() { - oc.DeleteFromTemplate(t, ns, EgressWildcardGatewayTemplate, smcp) + oc.DeleteFromTemplate(t, ns.Bookinfo, EgressWildcardGatewayTemplate, smcp) }) - assertExternalRequestSuccess(t, ns) + assertExternalRequestSuccess(t, ns.Bookinfo) }) }) } diff --git a/pkg/tests/tasks/traffic/fault_injection_test.go b/pkg/tests/tasks/traffic/fault_injection_test.go index b6bb08ef..500be82e 100644 --- a/pkg/tests/tasks/traffic/fault_injection_test.go +++ b/pkg/tests/tasks/traffic/fault_injection_test.go @@ -25,6 +25,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/check/assert" "github.com/maistra/maistra-test-tool/pkg/util/curl" "github.com/maistra/maistra-test-tool/pkg/util/env" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/retry" . "github.com/maistra/maistra-test-tool/pkg/util/test" @@ -40,25 +41,24 @@ var ( func TestFaultInjection(t *testing.T) { NewTest(t).Id("T2").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { - ns := "bookinfo" t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-test-user-v2-rating-unavailable.html`) }) ossm.DeployControlPlane(t) t.LogStep("Install Bookinfo") - app.InstallAndWaitReady(t, app.Bookinfo(ns)) + app.InstallAndWaitReady(t, app.Bookinfo(ns.Bookinfo)) testUserCookieJar := app.BookinfoLogin(t, meshNamespace) - oc.ApplyString(t, ns, app.BookinfoVirtualServicesAllV1) - oc.ApplyString(t, ns, app.BookinfoVirtualServiceReviewsV2) + oc.ApplyString(t, ns.Bookinfo, app.BookinfoVirtualServicesAllV1) + oc.ApplyString(t, ns.Bookinfo, app.BookinfoVirtualServiceReviewsV2) t.NewSubTest("ratings-fault-delay").Run(func(t TestHelper) { - oc.ApplyString(t, ns, ratingsVirtualServiceWithFixedDelay) + oc.ApplyString(t, ns.Bookinfo, ratingsVirtualServiceWithFixedDelay) t.LogStep("check if productpage shows 'error fetching product reviews' due to delay injection") retry.UntilSuccess(t, func(t TestHelper) { @@ -75,7 +75,7 @@ func TestFaultInjection(t *testing.T) { }) t.NewSubTest("ratings-fault-abort").Run(func(t TestHelper) { - oc.ApplyString(t, ns, ratingsVirtualServiceWithHttpStatus500) + oc.ApplyString(t, ns.Bookinfo, ratingsVirtualServiceWithHttpStatus500) expectedResponseFile := TestreviewV2(t, "productpage-test-user-v2-rating-unavailable.html") diff --git a/pkg/tests/tasks/traffic/ingress/gatewayapi_test.go b/pkg/tests/tasks/traffic/ingress/gatewayapi_test.go index 979fb1fc..9c2caecb 100644 --- a/pkg/tests/tasks/traffic/ingress/gatewayapi_test.go +++ b/pkg/tests/tasks/traffic/ingress/gatewayapi_test.go @@ -9,6 +9,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/check/assert" "github.com/maistra/maistra-test-tool/pkg/util/env" "github.com/maistra/maistra-test-tool/pkg/util/gatewayapi" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/pod" "github.com/maistra/maistra-test-tool/pkg/util/retry" @@ -23,7 +24,6 @@ func TestGatewayApi(t *testing.T) { if env.GetSMCPVersion().LessThan(version.SMCP_2_3) { t.Skip("TestGatewayApi was added in v2.3") } - ns := "foo" smcpName := env.GetDefaultSMCPName() @@ -33,17 +33,17 @@ func TestGatewayApi(t *testing.T) { shell.Executef(t, "kubectl get crd gateways.gateway.networking.k8s.io &> /dev/null && echo 'Gateway API CRDs already installed' || kubectl apply -k github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=%s", gatewayapi.GetSupportedVersion(env.GetSMCPVersion())) - oc.CreateNamespace(t, ns) + oc.CreateNamespace(t, ns.Foo) t.NewSubTest("Deploy the Kubernetes Gateway API").Run(func(t test.TestHelper) { t.Cleanup(func() { oc.RecreateNamespace(t, meshNamespace) - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Foo) }) t.LogStep("Install httpbin") - app.InstallAndWaitReady(t, app.Httpbin(ns)) + app.InstallAndWaitReady(t, app.Httpbin(ns.Foo)) t.LogStep("Deploy the Gateway SMCP") @@ -79,13 +79,13 @@ func TestGatewayApi(t *testing.T) { } t.LogStep("Deploy the Gateway API configuration including a single exposed route (i.e., /get)") - oc.ApplyTemplate(t, ns, gatewayAndRouteYAML, map[string]string{"GatewayClassName": "istio"}) + oc.ApplyTemplate(t, ns.Foo, gatewayAndRouteYAML, map[string]string{"GatewayClassName": "istio"}) t.Cleanup(func() { - oc.DeleteFromTemplate(t, ns, gatewayAndRouteYAML, map[string]string{"GatewayClassName": "istio"}) + oc.DeleteFromTemplate(t, ns.Foo, gatewayAndRouteYAML, map[string]string{"GatewayClassName": "istio"}) }) t.LogStep("Wait for Gateway to be ready") - oc.WaitCondition(t, ns, "Gateway", "gateway", gatewayapi.GetWaitingCondition(env.GetSMCPVersion())) + oc.WaitCondition(t, ns.Foo, "Gateway", "gateway", gatewayapi.GetWaitingCondition(env.GetSMCPVersion())) t.LogStep("Verfiy the GatewayApi access the httpbin service using curl") retry.UntilSuccess(t, func(t TestHelper) { @@ -106,11 +106,11 @@ func TestGatewayApi(t *testing.T) { t.Cleanup(func() { oc.RecreateNamespace(t, meshNamespace) - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Foo) }) t.LogStep("Install httpbin") - app.InstallAndWaitReady(t, app.Httpbin(ns)) + app.InstallAndWaitReady(t, app.Httpbin(ns.Foo)) t.LogStep("Deploy SMCP with the profile") oc.ApplyTemplate(t, @@ -121,17 +121,17 @@ func TestGatewayApi(t *testing.T) { t.LogStep("delete default SMMR and create custom SMMR") oc.DeleteFromString(t, meshNamespace, defaultSMMR) - oc.ApplyTemplate(t, meshNamespace, createSMMR, map[string]string{"Member": ns}) + oc.ApplyTemplate(t, meshNamespace, createSMMR, map[string]string{"Member": ns.Foo}) oc.WaitSMMRReady(t, meshNamespace) t.LogStep("Deploy the Gateway API configuration including a single exposed route (i.e., /get)") - oc.ApplyTemplate(t, ns, gatewayAndRouteYAML, map[string]string{"GatewayClassName": "ocp"}) + oc.ApplyTemplate(t, ns.Foo, gatewayAndRouteYAML, map[string]string{"GatewayClassName": "ocp"}) t.Cleanup(func() { - oc.DeleteFromTemplate(t, ns, gatewayAndRouteYAML, map[string]string{"GatewayClassName": "ocp"}) + oc.DeleteFromTemplate(t, ns.Foo, gatewayAndRouteYAML, map[string]string{"GatewayClassName": "ocp"}) }) t.LogStep("Wait for Gateway to be ready") - oc.WaitCondition(t, ns, "Gateway", "gateway", gatewayapi.GetWaitingCondition(env.GetSMCPVersion())) + oc.WaitCondition(t, ns.Foo, "Gateway", "gateway", gatewayapi.GetWaitingCondition(env.GetSMCPVersion())) t.LogStep("Verify the Gateway-Controller Profile access the httpbin service using curl") retry.UntilSuccess(t, func(t TestHelper) { diff --git a/pkg/tests/tasks/traffic/ingress/ingress_gateways_test.go b/pkg/tests/tasks/traffic/ingress/ingress_gateways_test.go index 5595456f..06cc8234 100644 --- a/pkg/tests/tasks/traffic/ingress/ingress_gateways_test.go +++ b/pkg/tests/tasks/traffic/ingress/ingress_gateways_test.go @@ -25,6 +25,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/curl" "github.com/maistra/maistra-test-tool/pkg/util/env" "github.com/maistra/maistra-test-tool/pkg/util/istio" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/request" "github.com/maistra/maistra-test-tool/pkg/util/retry" @@ -34,21 +35,21 @@ import ( func TestIngressGateways(t *testing.T) { NewTest(t).Id("T8").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { - ns := "bookinfo" + t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) }) ossm.DeployControlPlane(t) t.LogStep("Install httpbin") - app.InstallAndWaitReady(t, app.Httpbin(ns)) + app.InstallAndWaitReady(t, app.Httpbin(ns.Bookinfo)) gatewayHTTP := istio.GetIngressGatewayHost(t, meshNamespace) t.NewSubTest("TrafficManagement_ingress_status_200_test").Run(func(t TestHelper) { t.LogStep("Create httpbin Gateway and VirtualService with host set to httpbin.example.com") - oc.ApplyString(t, ns, httpbinGateway1) + oc.ApplyString(t, ns.Bookinfo, httpbinGateway1) if env.GetSMCPVersion().GreaterThanOrEqual(version.SMCP_2_5) { createRoute(t, meshNamespace, "httpbin.example.com", "http2", "istio-ingressgateway") @@ -65,7 +66,7 @@ func TestIngressGateways(t *testing.T) { t.NewSubTest("TrafficManagement_ingress_headers_test").Run(func(t TestHelper) { t.LogStep("Create httpbin Gateway and VirtualService with host set to *") - oc.ApplyString(t, ns, httpbinGateway2) + oc.ApplyString(t, ns.Bookinfo, httpbinGateway2) t.LogStep("Check if httpbin service is reachable through istio-ingressgateway") retry.UntilSuccess(t, func(t TestHelper) { diff --git a/pkg/tests/tasks/traffic/ingress/ingress_without_tls_termination_test.go b/pkg/tests/tasks/traffic/ingress/ingress_without_tls_termination_test.go index b4c3086b..6d0b5770 100644 --- a/pkg/tests/tasks/traffic/ingress/ingress_without_tls_termination_test.go +++ b/pkg/tests/tasks/traffic/ingress/ingress_without_tls_termination_test.go @@ -23,6 +23,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/curl" "github.com/maistra/maistra-test-tool/pkg/util/env" "github.com/maistra/maistra-test-tool/pkg/util/istio" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/pod" "github.com/maistra/maistra-test-tool/pkg/util/request" @@ -36,22 +37,20 @@ func TestIngressWithoutTlsTermination(t *testing.T) { t.Log("This test validates configuring an Gateway with TLS PassThrough") t.Log("Doc reference: https://istio.io/v1.14/docs/tasks/traffic-management/ingress/ingress-sni-passthrough/") - ns := "bookinfo" - t.Cleanup(func() { - oc.DeleteFromString(t, ns, nginxIngressGateway) - app.Uninstall(t, app.Nginx(ns)) + oc.DeleteFromString(t, ns.Bookinfo, nginxIngressGateway) + app.Uninstall(t, app.Nginx(ns.Bookinfo)) }) ossm.DeployControlPlane(t) t.LogStep("Create NGINX Deployment") - app.InstallAndWaitReady(t, app.Nginx(ns)) + app.InstallAndWaitReady(t, app.Nginx(ns.Bookinfo)) t.LogStep("Verify NGINX server is running by connecting to it via loopback") retry.UntilSuccess(t, func(t test.TestHelper) { oc.Exec(t, - pod.MatchingSelector("run=my-nginx", ns), + pod.MatchingSelector("run=my-nginx", ns.Bookinfo), "istio-proxy", "curl -sS -v -k --resolve nginx.example.com:8443:127.0.0.1 https://nginx.example.com:8443", assert.OutputContains( @@ -61,7 +60,7 @@ func TestIngressWithoutTlsTermination(t *testing.T) { }) t.LogStep("Configure Gateway resource with TLS passthrough for host nginx.example.com") - oc.ApplyString(t, ns, nginxIngressGateway) + oc.ApplyString(t, ns.Bookinfo, nginxIngressGateway) if env.GetSMCPVersion().GreaterThanOrEqual(version.SMCP_2_5) { createRouteWithTLS(t, meshNamespace, "nginx.example.com", "https", "istio-ingressgateway", "passthrough") diff --git a/pkg/tests/tasks/traffic/ingress/secure_gateways_test.go b/pkg/tests/tasks/traffic/ingress/secure_gateways_test.go index 46ece2ce..33203538 100644 --- a/pkg/tests/tasks/traffic/ingress/secure_gateways_test.go +++ b/pkg/tests/tasks/traffic/ingress/secure_gateways_test.go @@ -25,6 +25,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/curl" "github.com/maistra/maistra-test-tool/pkg/util/env" "github.com/maistra/maistra-test-tool/pkg/util/istio" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/request" "github.com/maistra/maistra-test-tool/pkg/util/retry" @@ -48,7 +49,6 @@ var ( func TestSecureGateways(t *testing.T) { NewTest(t).Id("T9").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { - ns := "bookinfo" t.Log("This test verifies secure gateways.") t.Log("Doc reference: https://istio.io/latest/docs/tasks/traffic-management/ingress/secure-ingress/") @@ -56,15 +56,15 @@ func TestSecureGateways(t *testing.T) { t.Cleanup(func() { oc.DeleteSecret(t, meshNamespace, "httpbin-credential") oc.DeleteSecret(t, meshNamespace, "helloworld-credential") - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) }) ossm.DeployControlPlane(t) t.LogStep("Install httpbin") - app.InstallAndWaitReady(t, app.Httpbin(ns)) - oc.ApplyTemplate(t, ns, helloWorldTemplate, nil) - oc.WaitDeploymentRolloutComplete(t, ns, "helloworld-v1") + app.InstallAndWaitReady(t, app.Httpbin(ns.Bookinfo)) + oc.ApplyTemplate(t, ns.Bookinfo, helloWorldTemplate, nil) + oc.WaitDeploymentRolloutComplete(t, ns.Bookinfo, "helloworld-v1") t.LogStep("Create TLS secrets") oc.CreateTLSSecret(t, meshNamespace, "httpbin-credential", httpbinSampleServerCertKey, httpbinSampleServerCert) @@ -77,7 +77,7 @@ func TestSecureGateways(t *testing.T) { t.NewSubTest("tls_single_host").Run(func(t TestHelper) { t.LogStep("Configure a TLS ingress gateway for a single host") - oc.ApplyString(t, ns, httpbinTLSGatewayHTTPS) + oc.ApplyString(t, ns.Bookinfo, httpbinTLSGatewayHTTPS) if env.GetSMCPVersion().GreaterThanOrEqual(version.SMCP_2_5) { createRouteWithTLS(t, meshNamespace, "httpbin.example.com", "https", "istio-ingressgateway", "passthrough") @@ -95,7 +95,7 @@ func TestSecureGateways(t *testing.T) { t.NewSubTest("tls_multiple_hosts").Run(func(t TestHelper) { t.LogStep("configure Gateway with multiple TLS hosts") - oc.ApplyString(t, ns, gatewayMultipleHosts) + oc.ApplyString(t, ns.Bookinfo, gatewayMultipleHosts) if env.GetSMCPVersion().GreaterThanOrEqual(version.SMCP_2_5) { createRouteWithTLS(t, meshNamespace, "helloworld-v1.example.com", "https", "istio-ingressgateway", "passthrough") @@ -125,7 +125,7 @@ func TestSecureGateways(t *testing.T) { "tls.key="+httpbinSampleServerCertKey, "tls.crt="+httpbinSampleServerCert, "ca.crt="+httpbinSampleCACert) - oc.ApplyString(t, ns, gatewayHttpbinMTLSYaml) + oc.ApplyString(t, ns.Bookinfo, gatewayHttpbinMTLSYaml) if env.GetSMCPVersion().GreaterThanOrEqual(version.SMCP_2_5) { createRouteWithTLS(t, meshNamespace, "httpbin.example.com", "https", "istio-ingressgateway", "passthrough") @@ -169,7 +169,7 @@ func TestSecureGateways(t *testing.T) { "tls.crt="+httpbinSampleServerCert, "ca.crt="+httpbinSampleCACert, "ca.crl="+httpbinSampleCACrl) - oc.ApplyString(t, ns, gatewayHttpbinMTLSYaml) + oc.ApplyString(t, ns.Bookinfo, gatewayHttpbinMTLSYaml) createRouteWithTLS(t, meshNamespace, "httpbin.example.com", "https", "istio-ingressgateway", "passthrough") t.LogStep("check if SSL handshake fails when no client certificate is given") diff --git a/pkg/tests/tasks/traffic/request_routing_test.go b/pkg/tests/tasks/traffic/request_routing_test.go index ae798259..f01be2d3 100644 --- a/pkg/tests/tasks/traffic/request_routing_test.go +++ b/pkg/tests/tasks/traffic/request_routing_test.go @@ -23,6 +23,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/check/require" "github.com/maistra/maistra-test-tool/pkg/util/curl" "github.com/maistra/maistra-test-tool/pkg/util/env" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/retry" . "github.com/maistra/maistra-test-tool/pkg/util/test" @@ -30,10 +31,9 @@ import ( func TestRequestRouting(t *testing.T) { NewTest(t).Id("T1").Groups(Smoke, Full, InterOp, ARM).Run(func(t TestHelper) { - ns := "bookinfo" t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-test-user-v2.html`) os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-normal-user-v1.html`) }) @@ -41,13 +41,13 @@ func TestRequestRouting(t *testing.T) { ossm.DeployControlPlane(t) t.LogStep("Install Bookinfo") - app.InstallAndWaitReady(t, app.Bookinfo(ns)) + app.InstallAndWaitReady(t, app.Bookinfo(ns.Bookinfo)) productpageURL := app.BookinfoProductPageURL(t, meshNamespace) testUserCookieJar := app.BookinfoLogin(t, meshNamespace) t.NewSubTest("not-logged-in").Run(func(t TestHelper) { - oc.ApplyString(t, ns, app.BookinfoVirtualServicesAllV1) + oc.ApplyString(t, ns.Bookinfo, app.BookinfoVirtualServicesAllV1) expectedResponseFile := TestreviewV1(t, "productpage-normal-user-v1.html") @@ -66,7 +66,7 @@ func TestRequestRouting(t *testing.T) { }) t.NewSubTest("logged-in").Run(func(t TestHelper) { - oc.ApplyString(t, ns, app.BookinfoVirtualServiceReviewsV2) + oc.ApplyString(t, ns.Bookinfo, app.BookinfoVirtualServiceReviewsV2) expectedResponseFile2 := TestreviewV2(t, "productpage-test-user-v2.html") diff --git a/pkg/tests/tasks/traffic/request_timeouts_test.go b/pkg/tests/tasks/traffic/request_timeouts_test.go index 41c1bb99..42d13e3f 100644 --- a/pkg/tests/tasks/traffic/request_timeouts_test.go +++ b/pkg/tests/tasks/traffic/request_timeouts_test.go @@ -25,6 +25,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/check/require" "github.com/maistra/maistra-test-tool/pkg/util/curl" "github.com/maistra/maistra-test-tool/pkg/util/env" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/retry" . "github.com/maistra/maistra-test-tool/pkg/util/test" @@ -35,21 +36,20 @@ var reviewTimeout string func TestRequestTimeouts(t *testing.T) { NewTest(t).Id("T5").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { - ns := "bookinfo" t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-normal-user-v1.html`) }) ossm.DeployControlPlane(t) t.LogStep("Install Bookinfo") - app.InstallAndWaitReady(t, app.Bookinfo(ns)) + app.InstallAndWaitReady(t, app.Bookinfo(ns.Bookinfo)) productpageURL := app.BookinfoProductPageURL(t, meshNamespace) - oc.ApplyString(t, ns, app.BookinfoVirtualServicesAllV1) + oc.ApplyString(t, ns.Bookinfo, app.BookinfoVirtualServicesAllV1) t.LogStep("make sure there is no timeout before applying delay and timeout in VirtualServices") @@ -66,7 +66,7 @@ func TestRequestTimeouts(t *testing.T) { }) t.LogStep("apply delay and timeout in VirtualServices") - oc.ApplyString(t, ns, reviewTimeout) + oc.ApplyString(t, ns.Bookinfo, reviewTimeout) t.LogStep("check if productpage shows 'error fetching product reviews' due to delay and timeout injection") retry.UntilSuccess(t, func(t TestHelper) { diff --git a/pkg/tests/tasks/traffic/traffic_mirroring_test.go b/pkg/tests/tasks/traffic/traffic_mirroring_test.go index cc9693cb..5340492a 100644 --- a/pkg/tests/tasks/traffic/traffic_mirroring_test.go +++ b/pkg/tests/tasks/traffic/traffic_mirroring_test.go @@ -21,6 +21,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/tests/ossm" . "github.com/maistra/maistra-test-tool/pkg/util" "github.com/maistra/maistra-test-tool/pkg/util/check/assert" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/pod" "github.com/maistra/maistra-test-tool/pkg/util/retry" @@ -29,34 +30,33 @@ import ( func TestMirroring(t *testing.T) { NewTest(t).Id("T7").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { - ns := "bookinfo" t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) }) ossm.DeployControlPlane(t) t.LogStep("Install httpbin-v1, httpbin-v2, and sleep") app.InstallAndWaitReady(t, - app.HttpbinV1(ns), - app.HttpbinV2(ns), - app.Sleep(ns)) + app.HttpbinV1(ns.Bookinfo), + app.HttpbinV2(ns.Bookinfo), + app.Sleep(ns.Bookinfo)) t.NewSubTest("no mirroring").Run(func(t TestHelper) { - oc.ApplyString(t, ns, httpbinAllv1) + oc.ApplyString(t, ns.Bookinfo, httpbinAllv1) t.LogStep("sending HTTP request from sleep to httpbin-v1, not expecting mirroring to v2") retry.UntilSuccess(t, func(t TestHelper) { nonce := NewNonce() oc.Exec(t, - pod.MatchingSelector("app=sleep", ns), + pod.MatchingSelector("app=sleep", ns.Bookinfo), "sleep", "curl -sS http://httpbin:8000/headers?nonce="+nonce) oc.Logs(t, - pod.MatchingSelector("app=httpbin,version=v1", ns), + pod.MatchingSelector("app=httpbin,version=v1", ns.Bookinfo), "httpbin", assert.OutputContains( "GET /headers?nonce="+nonce, @@ -64,7 +64,7 @@ func TestMirroring(t *testing.T) { "request not received by httpbin-v1")) oc.Logs(t, - pod.MatchingSelector("app=httpbin,version=v2", ns), + pod.MatchingSelector("app=httpbin,version=v2", ns.Bookinfo), "httpbin", assert.OutputDoesNotContain( "GET /headers?nonce="+nonce, @@ -74,19 +74,19 @@ func TestMirroring(t *testing.T) { }) t.NewSubTest("mirroring to httpbin-v2").Run(func(t TestHelper) { - oc.ApplyString(t, ns, httpbinMirrorv2) + oc.ApplyString(t, ns.Bookinfo, httpbinMirrorv2) t.LogStep("sending HTTP request from sleep to httpbin-v1, expecting mirroring to v2") retry.UntilSuccess(t, func(t TestHelper) { nonce := NewNonce() oc.Exec(t, - pod.MatchingSelector("app=sleep", ns), + pod.MatchingSelector("app=sleep", ns.Bookinfo), "sleep", "curl -sS http://httpbin:8000/headers?nonce="+nonce) oc.Logs(t, - pod.MatchingSelector("app=httpbin,version=v1", ns), + pod.MatchingSelector("app=httpbin,version=v1", ns.Bookinfo), "httpbin", assert.OutputContains( "GET /headers?nonce="+nonce, @@ -94,7 +94,7 @@ func TestMirroring(t *testing.T) { "request not received by httpbin-v1")) oc.Logs(t, - pod.MatchingSelector("app=httpbin,version=v2", ns), + pod.MatchingSelector("app=httpbin,version=v2", ns.Bookinfo), "httpbin", assert.OutputContains( "GET /headers?nonce="+nonce, diff --git a/pkg/tests/tasks/traffic/traffic_shifting_test.go b/pkg/tests/tasks/traffic/traffic_shifting_test.go index f39b5196..b6f6a5d2 100644 --- a/pkg/tests/tasks/traffic/traffic_shifting_test.go +++ b/pkg/tests/tasks/traffic/traffic_shifting_test.go @@ -27,6 +27,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/check/require" "github.com/maistra/maistra-test-tool/pkg/util/curl" "github.com/maistra/maistra-test-tool/pkg/util/env" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/retry" . "github.com/maistra/maistra-test-tool/pkg/util/test" @@ -34,10 +35,9 @@ import ( func TestTrafficShifting(t *testing.T) { NewTest(t).Id("T3").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { - ns := "bookinfo" t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-normal-user-v3.html`) os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-normal-user-v1.html`) }) @@ -45,17 +45,17 @@ func TestTrafficShifting(t *testing.T) { ossm.DeployControlPlane(t) t.LogStep("Install Bookinfo") - app.InstallAndWaitReady(t, app.Bookinfo(ns)) + app.InstallAndWaitReady(t, app.Bookinfo(ns.Bookinfo)) productpageURL := app.BookinfoProductPageURL(t, meshNamespace) - oc.ApplyString(t, ns, app.BookinfoVirtualServicesAllV1) + oc.ApplyString(t, ns.Bookinfo, app.BookinfoVirtualServicesAllV1) expectedResponseFile := TestreviewV1(t, "productpage-normal-user-v1.html") expectedResponseFile3 := TestreviewV3(t, "productpage-normal-user-v3.html") t.NewSubTest("50 percent to v3").Run(func(t TestHelper) { t.LogStep("configure VirtualService to split traffic 50% to v1 and 50% to v3") - oc.ApplyString(t, ns, splitReviews5050BetweenV1andV3) + oc.ApplyString(t, ns.Bookinfo, splitReviews5050BetweenV1andV3) t.LogStep("Make 100 requests and check if v1 and v3 get 50% of requests each (tolerance: 20%)") @@ -70,7 +70,7 @@ func TestTrafficShifting(t *testing.T) { t.NewSubTest("100 percent to v3").Run(func(t TestHelper) { t.LogStep("configure VirtualService to send all traffic to v3") - oc.ApplyString(t, ns, allReviewsToV3) + oc.ApplyString(t, ns.Bookinfo, allReviewsToV3) t.LogStep("Make 100 requests and check if all of them go to v3 (tolerance: 0%)") retry.UntilSuccess(t, func(t TestHelper) { diff --git a/pkg/tests/tasks/traffic/traffic_tcp_shifting_test.go b/pkg/tests/tasks/traffic/traffic_tcp_shifting_test.go index 045b0435..10408276 100644 --- a/pkg/tests/tasks/traffic/traffic_tcp_shifting_test.go +++ b/pkg/tests/tasks/traffic/traffic_tcp_shifting_test.go @@ -23,6 +23,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/app" "github.com/maistra/maistra-test-tool/pkg/tests/ossm" "github.com/maistra/maistra-test-tool/pkg/util" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/pod" "github.com/maistra/maistra-test-tool/pkg/util/retry" @@ -32,10 +33,9 @@ import ( // TestTcpTrafficShifting validates TCP traffic shifting feature. func TestTcpTrafficShifting(t *testing.T) { test.NewTest(t).Id("T4").Groups(test.Full, test.InterOp, test.ARM).Run(func(t test.TestHelper) { - ns := "foo" t.Cleanup(func() { - app.Uninstall(t, app.Sleep(ns), app.EchoV1(ns), app.EchoV2(ns)) + app.Uninstall(t, app.Sleep(ns.Foo), app.EchoV1(ns.Foo), app.EchoV2(ns.Foo)) }) t.Log("This test validates traffic shifting for TCP traffic.") @@ -44,20 +44,20 @@ func TestTcpTrafficShifting(t *testing.T) { ossm.DeployControlPlane(t) t.LogStep("Install sleep, echoV1 and echoV2") - app.InstallAndWaitReady(t, app.Sleep(ns), app.EchoV1(ns), app.EchoV2(ns)) + app.InstallAndWaitReady(t, app.Sleep(ns.Foo), app.EchoV1(ns.Foo), app.EchoV2(ns.Foo)) t.NewSubTest("tcp shift 100 percent to v1").Run(func(t test.TestHelper) { t.Cleanup(func() { - oc.DeleteFromString(t, ns, EchoAllv1Yaml) + oc.DeleteFromString(t, ns.Foo, EchoAllv1Yaml) }) t.LogStep("Shifting all TCP traffic to v1") - oc.ApplyString(t, ns, EchoAllv1Yaml) + oc.ApplyString(t, ns.Foo, EchoAllv1Yaml) t.LogStep("make 20 requests and checking if all of them go to v1 (tolerance: 0%)") retry.UntilSuccess(t, func(t test.TestHelper) { tolerance := 0.0 - checkTcpTrafficRatio(t, ns, "tcp-echo", "9000", 20, tolerance, map[string]float64{ + checkTcpTrafficRatio(t, ns.Foo, "tcp-echo", "9000", 20, tolerance, map[string]float64{ "one": 1.0, "two": 0.0, }) @@ -66,16 +66,16 @@ func TestTcpTrafficShifting(t *testing.T) { t.NewSubTest("tcp shift 20 percent to v2").Run(func(t test.TestHelper) { t.Cleanup(func() { - oc.DeleteFromString(t, ns, Echo20v2Yaml) + oc.DeleteFromString(t, ns.Foo, Echo20v2Yaml) }) t.LogStep("Shifting 20 percent TCP traffic to v2") - oc.ApplyString(t, ns, Echo20v2Yaml) + oc.ApplyString(t, ns.Foo, Echo20v2Yaml) t.LogStep("make 100 requests and checking if 20 percent of them go to v2 (tolerance: 10%)") retry.UntilSuccess(t, func(t test.TestHelper) { tolerance := 0.10 - checkTcpTrafficRatio(t, ns, "tcp-echo", "9000", 100, tolerance, map[string]float64{ + checkTcpTrafficRatio(t, ns.Foo, "tcp-echo", "9000", 100, tolerance, map[string]float64{ "one": 0.8, "two": 0.2, })