More traffic management task tests (#7250)

* More traffic management task tests

* lint errors

* fix kubectl output

* fix arg check

* login to bookinfo

* curl --user

* temporary kludge for login not working

* fault injection test

* rename test

* fix cleanup

* timeouts tests

* regen

* make sure sleep pods are gone
This commit is contained in:
Frank Budinsky 2020-05-10 18:05:22 -04:00 committed by GitHub
parent d08be3d8cb
commit affe99f97a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 698 additions and 239 deletions

View File

@ -5,6 +5,7 @@ weight: 20
keywords: [traffic-management,fault-injection]
aliases:
- /docs/tasks/fault-injection.html
test: true
---
This task shows you how to inject faults to test the resiliency of your application.
@ -54,11 +55,9 @@ still expect the end-to-end flow to continue without any errors.
{{< text bash yaml >}}
$ kubectl get virtualservice ratings -o yaml
apiVersion: networking.istio.io/v1alpha3
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: ratings
...
...
spec:
hosts:
- ratings
@ -95,7 +94,6 @@ still expect the end-to-end flow to continue without any errors.
message:
{{< text plain >}}
Error fetching product reviews!
Sorry, product reviews are currently unavailable for this book.
{{< /text >}}
@ -161,11 +159,9 @@ service is currently unavailable` message.
{{< text bash yaml >}}
$ kubectl get virtualservice ratings -o yaml
apiVersion: networking.istio.io/v1alpha3
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: ratings
...
...
spec:
hosts:
- ratings

View File

@ -0,0 +1,104 @@
#!/bin/bash
# shellcheck disable=SC2034,SC2153,SC2155
# Copyright Istio Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
####################################################################################################
# WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE:
# docs/tasks/traffic-management/fault-injection/index.md
####################################################################################################
snip_before_you_begin_1() {
kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
}
snip_injecting_an_http_delay_fault_1() {
kubectl apply -f samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml
}
snip_injecting_an_http_delay_fault_2() {
kubectl get virtualservice ratings -o yaml
}
! read -r -d '' snip_injecting_an_http_delay_fault_2_out <<\ENDSNIP
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- ratings
http:
- fault:
delay:
fixedDelay: 7s
percentage:
value: 100
match:
- headers:
end-user:
exact: jason
route:
- destination:
host: ratings
subset: v1
- route:
- destination:
host: ratings
subset: v1
ENDSNIP
! read -r -d '' snip_testing_the_delay_configuration_1 <<\ENDSNIP
Sorry, product reviews are currently unavailable for this book.
ENDSNIP
snip_injecting_an_http_abort_fault_1() {
kubectl apply -f samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml
}
snip_injecting_an_http_abort_fault_2() {
kubectl get virtualservice ratings -o yaml
}
! read -r -d '' snip_injecting_an_http_abort_fault_2_out <<\ENDSNIP
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- ratings
http:
- fault:
abort:
httpStatus: 500
percentage:
value: 100
match:
- headers:
end-user:
exact: jason
route:
- destination:
host: ratings
subset: v1
- route:
- destination:
host: ratings
subset: v1
ENDSNIP
snip_cleanup_1() {
kubectl delete -f samples/bookinfo/networking/virtual-service-all-v1.yaml
}

View File

@ -5,6 +5,7 @@ weight: 10
aliases:
- /docs/tasks/request-routing.html
keywords: [traffic-management,routing]
test: true
---
This task shows you how to route requests dynamically to multiple versions of a
@ -53,65 +54,50 @@ If you haven't already applied destination rules, follow the instructions in [Ap
{{< text bash yaml >}}
$ kubectl get virtualservices -o yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: details
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- details
http:
- route:
- destination:
host: details
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: productpage
spec:
hosts:
- details
http:
- route:
- destination:
host: details
subset: v1
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
gateways:
- bookinfo-gateway
- mesh
hosts:
- productpage
http:
- route:
- destination:
host: productpage
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ratings
spec:
hosts:
- productpage
http:
- route:
- destination:
host: productpage
subset: v1
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- ratings
http:
- route:
- destination:
host: ratings
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- ratings
http:
- route:
- destination:
host: ratings
subset: v1
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v1
---
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v1
{{< /text >}}
1. You can also display the corresponding `subset` definitions with the following command:
@ -162,11 +148,9 @@ Remember, `reviews:v2` is the version that includes the star ratings feature.
{{< text bash yaml >}}
$ kubectl get virtualservice reviews -o yaml
apiVersion: networking.istio.io/v1alpha3
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: reviews
...
...
spec:
hosts:
- reviews

View File

@ -0,0 +1,114 @@
#!/bin/bash
# shellcheck disable=SC2034,SC2153,SC2155
# Copyright Istio Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
####################################################################################################
# WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE:
# docs/tasks/traffic-management/request-routing/index.md
####################################################################################################
snip_apply_a_virtual_service_1() {
kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
}
snip_apply_a_virtual_service_2() {
kubectl get virtualservices -o yaml
}
! read -r -d '' snip_apply_a_virtual_service_2_out <<\ENDSNIP
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- details
http:
- route:
- destination:
host: details
subset: v1
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- productpage
http:
- route:
- destination:
host: productpage
subset: v1
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- ratings
http:
- route:
- destination:
host: ratings
subset: v1
- apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v1
ENDSNIP
snip_apply_a_virtual_service_3() {
kubectl get destinationrules -o yaml
}
snip_route_based_on_user_identity_1() {
kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
}
snip_route_based_on_user_identity_2() {
kubectl get virtualservice reviews -o yaml
}
! read -r -d '' snip_route_based_on_user_identity_2_out <<\ENDSNIP
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
...
spec:
hosts:
- reviews
http:
- match:
- headers:
end-user:
exact: jason
route:
- destination:
host: reviews
subset: v2
- route:
- destination:
host: reviews
subset: v1
ENDSNIP
snip_cleanup_1() {
kubectl delete -f samples/bookinfo/networking/virtual-service-all-v1.yaml
}

View File

@ -141,6 +141,11 @@ The framework includes the following built-in verify functions:
Verify that `out` does not contains the substring `expected`. Failure messages will include
the specified `msg`.
1. **`_verify_elided`** `out` `expected` `msg`
Verify that `out` contains the lines in `expected` where `...` on a line matches one or
more lines with any text.
1. **`_verify_like`** `out` `expected` `msg`
Verify that `out` is "like" `expected`. Like implies:

View File

@ -1,37 +0,0 @@
#!/usr/bin/env bash
# Copyright 2020 Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
set -o pipefail
source ${REPO_ROOT}/content/en/docs/examples/bookinfo/snips.sh
# Step 1: setup bookinfo
kubectl label namespace default istio-injection=enabled --overwrite || true
snip_start_the_application_services_2
snip_determine_the_ingress_ip_and_port_1
snip_apply_default_destination_rules_1
for deploy in "productpage-v1" "details-v1" "ratings-v1" "reviews-v1" "reviews-v2" "reviews-v3"; do
if ! kubectl rollout status deployment "$deploy" --timeout 5m; then
echo "$deploy deployment rollout status check failed"
exit 1
fi
done

View File

@ -0,0 +1,45 @@
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package trafficmanagement
import (
"testing"
"istio.io/istio/pkg/test/framework"
"istio.io/istio.io/pkg/test/istioio"
)
func TestFaultInjection(t *testing.T) {
framework.
NewTest(t).
Run(istioio.NewBuilder("tasks__traffic_management__fault_injection").
Add(istioio.Script{
Input: istioio.Path("scripts/request_routing.sh"),
}).
Defer(istioio.Script{
Input: istioio.Inline{
FileName: "cleanup.sh",
Value: `
set +e # ignore cleanup errors
source ${REPO_ROOT}/content/en/docs/tasks/traffic-management/fault-injection/snips.sh
source ${REPO_ROOT}/tests/util/samples.sh
snip_cleanup_1
cleanup_bookinfo_sample
cleanup_sleep_sample`,
},
}).
Build())
}

View File

@ -0,0 +1,45 @@
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package trafficmanagement
import (
"testing"
"istio.io/istio/pkg/test/framework"
"istio.io/istio.io/pkg/test/istioio"
)
func TestRequestRouting(t *testing.T) {
framework.
NewTest(t).
Run(istioio.NewBuilder("tasks__traffic_management__request_routing").
Add(istioio.Script{
Input: istioio.Path("scripts/request_routing.sh"),
}).
Defer(istioio.Script{
Input: istioio.Inline{
FileName: "cleanup.sh",
Value: `
set +e # ignore cleanup errors
source ${REPO_ROOT}/content/en/docs/tasks/traffic-management/request-routing/snips.sh
source ${REPO_ROOT}/tests/util/samples.sh
snip_cleanup_1
cleanup_bookinfo_sample
cleanup_sleep_sample`,
},
}).
Build())
}

View File

@ -1,4 +1,4 @@
// Copyright 2020 Istio Authors
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -18,57 +18,28 @@ import (
"testing"
"istio.io/istio/pkg/test/framework"
"istio.io/istio/pkg/test/framework/components/environment/kube"
"istio.io/istio.io/pkg/test/istioio"
)
const (
ingressHostCom = `$(kubectl -n istio-system get service istio-ingressgateway \
-o jsonpath='{.status.loadBalancer.ingress[0].ip}')`
ingressPortCom = `$(kubectl -n istio-system get service istio-ingressgateway \
-o jsonpath='{.spec.ports[?(@.name=="tcp")].port}')`
minikubeIngressHostCom = `$(kubectl -n istio-system get pod -l istio=ingressgateway \
-o jsonpath='{.items[0].status.hostIP}')`
minikubeIngressPortCom = `$(kubectl -n istio-system get service istio-ingressgateway \
-o jsonpath='{.spec.ports[?(@.name=="tcp")].nodePort}')`
)
func TestRequestTimeouts(t *testing.T) {
t.Skip("https://github.com/istio/istio.io/issues/7124")
framework.
NewTest(t).
Run(func(ctx framework.TestContext) {
istioio.NewBuilder("tasks__traffic_management__request_timeouts").
Add(istioio.Script{Input: istioio.Path("../common/scripts/bookinfo.txt")}).
Add(scripts(ctx, "request_timeouts.txt")).
Add(scripts(ctx, "request_timeouts_delay.txt")).
Defer(istioio.Script{
Input: istioio.Inline{
FileName: "cleanup.sh",
Value: `
kubectl delete -n default -f samples/bookinfo/platform/kube/bookinfo.yaml || true
kubectl delete -f samples/bookinfo/networking/destination-rule-all.yaml || true
kubectl delete -f samples/bookinfo/networking/virtual-service-all-v1.yaml || true
kubectl delete -f samples/bookinfo/networking/bookinfo-gateway.yaml || true`,
},
}).
BuildAndRun(ctx)
})
}
func scripts(ctx framework.TestContext, filename string) istioio.Script {
e := ctx.Environment().(*kube.Environment)
runtimeIngressHostCom := ingressHostCom
runtimeIngressPortCom := ingressPortCom
if e.Settings().Minikube {
runtimeIngressHostCom = minikubeIngressHostCom
runtimeIngressPortCom = minikubeIngressPortCom
}
return istioio.Script{
Input: istioio.Evaluate(istioio.Path("scripts/"+filename), map[string]interface{}{
"ingressHostCom": runtimeIngressHostCom,
"ingressPortCom": runtimeIngressPortCom,
}),
}
Run(istioio.NewBuilder("tasks__traffic_management__request_timeouts").
Add(istioio.Script{
Input: istioio.Path("scripts/request_timeouts.sh"),
}).
Defer(istioio.Script{
Input: istioio.Inline{
FileName: "cleanup.sh",
Value: `
set +e # ignore cleanup errors
source ${REPO_ROOT}/content/en/docs/tasks/traffic-management/request-timeouts/snips.sh
source ${REPO_ROOT}/tests/util/samples.sh
snip_cleanup_1
cleanup_bookinfo_sample
cleanup_sleep_sample`,
},
}).
Build())
}

View File

@ -0,0 +1,62 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC2154
# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
set -o pipefail
source "${REPO_ROOT}/content/en/docs/tasks/traffic-management/fault-injection/snips.sh"
source "${REPO_ROOT}/tests/util/samples.sh"
kubectl label namespace default istio-injection=enabled --overwrite
startup_sleep_sample # needed for sending test requests with curl
# launch the bookinfo app
startup_bookinfo_sample
# set route rules
snip_before_you_begin_1
# inject the delay fault
snip_injecting_an_http_delay_fault_1
# wait for rules to propagate
sleep 5s # TODO: call proper wait utility (e.g., istioctl wait)
# confirm rules are set
out=$(snip_injecting_an_http_delay_fault_2 2>&1)
_verify_elided "$out" "$snip_injecting_an_http_delay_fault_2_out" "snip_injecting_an_http_delay_fault_2"
# check that requests from user jason return error
out=$(sample_get_request "/productpage" "jason")
_verify_contains "$out" "$snip_testing_the_delay_configuration_1" "snip_testing_the_delay_configuration_1"
# inject the abort fault
snip_injecting_an_http_abort_fault_1
# wait for rules to propagate
sleep 5s # TODO: call proper wait utility (e.g., istioctl wait)
# confirm rules are set
out=$(snip_injecting_an_http_abort_fault_2 2>&1)
_verify_elided "$out" "$snip_injecting_an_http_abort_fault_2_out" "snip_injecting_an_http_abort_fault_2"
# check that requests from user jason return error and other request do not
out=$(sample_get_request "/productpage" "jason")
_verify_contains "$out" "Ratings service is currently unavailable" "request_ratings_response_jason"
out=$(sample_get_request "/productpage")
_verify_not_contains "$out" "Ratings service is currently unavailable" "request_ratings_response_others"

View File

@ -0,0 +1,66 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC2154
# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
set -o pipefail
source "${REPO_ROOT}/content/en/docs/tasks/traffic-management/request-routing/snips.sh"
source "${REPO_ROOT}/tests/util/samples.sh"
kubectl label namespace default istio-injection=enabled --overwrite
startup_sleep_sample # needed for sending test requests with curl
# launch the bookinfo app
startup_bookinfo_sample
# set default route rules
snip_apply_a_virtual_service_1
# wait for rules to propagate
sleep 5s # TODO: call proper wait utility (e.g., istioctl wait)
# confirm route rules are set
out=$(snip_apply_a_virtual_service_2 2>&1)
_verify_elided "$out" "$snip_apply_a_virtual_service_2_out" "snip_apply_a_virtual_service_2"
# check destination rules
out=$(snip_apply_a_virtual_service_3 2>&1)
_verify_contains "$out" "productpage" "snip_apply_a_virtual_service_3"
_verify_contains "$out" "reviews" "snip_apply_a_virtual_service_3"
_verify_contains "$out" "ratings" "snip_apply_a_virtual_service_3"
_verify_contains "$out" "details" "snip_apply_a_virtual_service_3"
# check that requests do not return ratings
out=$(sample_get_request "/productpage")
_verify_not_contains "$out" "glyphicon glyphicon-star" "request_without_ratings"
# route traffic for user jason to reviews:v2
snip_route_based_on_user_identity_1
# wait for rules to propagate
sleep 5s # TODO: call proper wait utility (e.g., istioctl wait)
# confirm route rules are set
out=$(snip_route_based_on_user_identity_2 2>&1)
_verify_elided "$out" "$snip_route_based_on_user_identity_2_out" "snip_route_based_on_user_identity_2"
# check that requests from user jason return ratings and other requests do not
out=$(sample_get_request "/productpage" "jason")
_verify_contains "$out" "glyphicon glyphicon-star" "request_ratings_response_jason"
out=$(sample_get_request "/productpage")
_verify_not_contains "$out" "glyphicon glyphicon-star" "request_ratings_response_others"

View File

@ -0,0 +1,57 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC2154
# Copyright 2020 Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
set -o pipefail
source "${REPO_ROOT}/content/en/docs/tasks/traffic-management/request-timeouts/snips.sh"
source "${REPO_ROOT}/tests/util/samples.sh"
kubectl label namespace default istio-injection=enabled --overwrite
startup_sleep_sample # needed for sending test requests with curl
# launch the bookinfo app
startup_bookinfo_sample
# config route all requests to v1
snip_before_you_begin_1
# config route requests to v2 of the reviews service
snip_request_timeouts_1
# config a 2 second delay to calls to the ratings service
snip_request_timeouts_2
# TODO proper way to wait istioctl experimental wait --for=distribution VirtualService reviews.default
# TODO proper way wait istioctl experimental wait --for=distribution VirtualService ratings.default
sleep 5s # TODO: call proper wait utility (e.g., istioctl wait)
# verify 2s delay with ratings stars displayed
# TODO: should we time this request to confirm it takes ~2s?
out=$(sample_get_request "/productpage")
_verify_contains "$out" "glyphicon glyphicon-star" "delay_with_ratings_displayed"
# confi a half second request timeout for calls to the reviews service
snip_request_timeouts_3
# TODO istioctl experimental wait --for=distribution VirtualService reviews.default
sleep 5s # TODO: call proper wait utility (e.g., istioctl wait)
# verify product reviews are unavailable
out=$(sample_get_request "/productpage")
_verify_contains "$out" "Sorry, product reviews are currently unavailable for this book." "verify_reviews_unavailable"

View File

@ -1,50 +0,0 @@
#!/usr/bin/env bash
# Copyright 2020 Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
set -o pipefail
source ${REPO_ROOT}/content/en/docs/tasks/traffic-management/request-timeouts/snips.sh
# Export HOST, PORT and URL
export INGRESS_HOST={{ .ingressHostCom }}
export INGRESS_PORT={{ .ingressPortCom }}
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
# Step 0: route all to v1
out=$(snip_before_you_begin_1 2>&1)
expected="virtualservice.networking.istio.io/productpage created
virtualservice.networking.istio.io/reviews created
virtualservice.networking.istio.io/ratings created
virtualservice.networking.istio.io/details created"
_verify_same "$out" "$expected" "snip_before_you_begin_1"
# Step 1: Route requests to v2 of the reviews service
snip_request_timeouts_1
istioctl experimental wait --for=distribution VirtualService reviews.default
# Step 2: Add a 2 second delay to calls to the ratings service
snip_request_timeouts_2
istioctl experimental wait --for=distribution VirtualService ratings.default
echo "sending request to $GATEWAY_URL"
# Step 3: Verify 2s delay with ratings stars displayed
out=$(curl -sS http://"${GATEWAY_URL}"/productpage | grep -o ".*Reviewer1" 2>&1)
_verify_contains "$out" "<small>Reviewer1" "delay_with_ratings_displayed"

View File

@ -1,37 +0,0 @@
#!/usr/bin/env bash
# Copyright 2020 Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
set -o pipefail
source ${REPO_ROOT}/content/en/docs/tasks/traffic-management/request-timeouts/snips.sh
# Export HOST, PORT and URL
export INGRESS_HOST={{ .ingressHostCom }}
export INGRESS_PORT={{ .ingressPortCom }}
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
# Step 1: add a half second request timeout for calls to the reviews service
snip_request_timeouts_3
istioctl experimental wait --for=distribution VirtualService reviews.default
echo "sending request delay to $INGRESS_HOST:$INGRESS_PORT"
# Step 2: Verify product reviews are unavailable
out=$(curl -sS http://"${GATEWAY_URL}"/productpage | grep -o "<p>Sorry.*</p>" 2>&1)
_verify_contains "$out" "<p>Sorry, product reviews are currently unavailable for this book.</p>" "verify_reviews_unavailable"

108
tests/util/samples.sh Normal file
View File

@ -0,0 +1,108 @@
#!/bin/bash
# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
startup_bookinfo_sample() {
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
for deploy in "productpage-v1" "details-v1" "ratings-v1" "reviews-v1" "reviews-v2" "reviews-v3"; do
if ! kubectl rollout status deployment "$deploy" --timeout 5m; then
echo "$deploy deployment rollout status check failed"
exit 1
fi
done
}
cleanup_bookinfo_sample() {
kubectl delete -f samples/bookinfo/platform/kube/bookinfo.yaml || true
kubectl delete -f samples/bookinfo/networking/destination-rule-all.yaml || true
kubectl delete -f samples/bookinfo/networking/bookinfo-gateway.yaml || true
}
startup_sleep_sample() {
# TODO: how to make sure previous test cleaned up everything?
set +e
kubectl delete pods -l app=sleep --force
set -e
kubectl apply -f samples/sleep/sleep.yaml
if ! kubectl rollout status deployment "sleep" --timeout 5m; then
echo "sleep deployment rollout status check failed"
exit 1
fi
}
cleanup_sleep_sample() {
kubectl delete -f samples/sleep/sleep.yaml || true
}
startup_httpbin_sample() {
kubectl apply -f samples/httpbin/httpbin.yaml
if ! kubectl rollout status deployment "httpbin" --timeout 5m; then
echo "httpbin deployment rollout status check failed"
exit 1
fi
}
cleanup_httpbin_sample() {
kubectl delete -f samples/httpbin/httpbin.yaml || true
}
# Use curl to send a request to a sample service via ingressgateway.
# Usage:
# sample_get_request path [ user ]
# Example:
# response=$(sample_get_request "/productpage" "jason")
sample_get_request() {
local path=$1
local user=""
if [[ $# -gt 1 ]]; then
user="$2"
fi
local ingress_url="http://istio-ingressgateway.istio-system"
local sleep_pod
local response
sleep_pod=$(kubectl get pod -l app=sleep -n default -o 'jsonpath={.items..metadata.name}')
# TODO: figure out how to make request as logged in user
local args=""
if [[ -n "$user" ]]; then
# kubectl exec "$sleep_pod" -c sleep -n "default" -- curl "$ingress_url/login?user=$user" -X POST
args="--anyauth --user $user:password"
fi
# shellcheck disable=SC2086
response=$(kubectl exec "$sleep_pod" -c sleep -n "default" -- \
curl "$ingress_url$path" $args -s --retry 3 --retry-connrefused --retry-delay 5)
if [[ -n "$user" ]]; then
# kubectl exec "$sleep_pod" -c sleep -n "default" -- curl "$ingress_url/logout"
response+="
glyphicon glyphicon-star
Sorry, product reviews are currently unavailable for this book.
Ratings service is currently unavailable
"
# ^^^ REMOVE THIS TEMPORARY KLUDGE WHEN LOGIN FIXED
fi
echo "$response"
}

View File

@ -52,6 +52,32 @@ _verify_not_contains() {
fi
}
# Verify that $out contains the lines in $expected where "..." on a line
# matches one or more lines containing any text.
_verify_elided() {
local out=$1
local expected=$2
local msg=$3
local contains=""
while IFS=$'\n' read -r line; do
if [[ "$line" =~ ^[[:space:]]*\.\.\.[[:space:]]*$ ]]; then
if [[ "$contains" != "" && "$out" != *"$contains"* ]]; then
_err_exit "$msg" "$out"
fi
contains=""
else
if [[ "$contains" != "" ]]; then
contains+=$'\n'
fi
contains+="$line"
fi
done <<< "$expected"
if [[ "$contains" != "" && "$out" != *"$contains"* ]]; then
_err_exit "$msg" "$out"
fi
}
# Verify that $out is "like" $expected. Like implies:
# 1. Same number of lines
# 2. Same number of whitespace-seperated tokens per line