Fix mirroring test (#7399)

* Fix mirroring test

* fix typo

* fixes

* export vars

* lint
This commit is contained in:
Frank Budinsky 2020-05-26 15:57:19 -04:00 committed by GitHub
parent f27566cc16
commit 77d3dc6bf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 29 deletions

View File

@ -198,13 +198,13 @@ log entries for `v1` and none for `v2`:
{{< text bash >}} {{< text bash >}}
$ export V1_POD=$(kubectl get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name}) $ export V1_POD=$(kubectl get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name})
$ kubectl logs -f "$V1_POD" -c httpbin $ kubectl logs "$V1_POD" -c httpbin
127.0.0.1 - - [07/Mar/2018:19:02:43 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" 127.0.0.1 - - [07/Mar/2018:19:02:43 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0"
{{< /text >}} {{< /text >}}
{{< text bash >}} {{< text bash >}}
$ export V2_POD=$(kubectl get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name}) $ export V2_POD=$(kubectl get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name})
$ kubectl logs -f "$V2_POD" -c httpbin $ kubectl logs "$V2_POD" -c httpbin
<none> <none>
{{< /text >}} {{< /text >}}
@ -255,13 +255,13 @@ log entries for `v1` and none for `v2`:
created in `v2` are the mirrored requests that are actually going to `v1`. created in `v2` are the mirrored requests that are actually going to `v1`.
{{< text bash >}} {{< text bash >}}
$ kubectl logs -f "$V1_POD" -c httpbin $ kubectl logs "$V1_POD" -c httpbin
127.0.0.1 - - [07/Mar/2018:19:02:43 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" 127.0.0.1 - - [07/Mar/2018:19:02:43 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0"
127.0.0.1 - - [07/Mar/2018:19:26:44 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" 127.0.0.1 - - [07/Mar/2018:19:26:44 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0"
{{< /text >}} {{< /text >}}
{{< text bash >}} {{< text bash >}}
$ kubectl logs -f "$V2_POD" -c httpbin $ kubectl logs "$V2_POD" -c httpbin
127.0.0.1 - - [07/Mar/2018:19:26:44 +0000] "GET /headers HTTP/1.1" 200 361 "-" "curl/7.35.0" 127.0.0.1 - - [07/Mar/2018:19:26:44 +0000] "GET /headers HTTP/1.1" 200 361 "-" "curl/7.35.0"
{{< /text >}} {{< /text >}}

View File

@ -174,7 +174,7 @@ ENDSNIP
snip_creating_a_default_routing_policy_3() { snip_creating_a_default_routing_policy_3() {
export V1_POD=$(kubectl get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name}) export V1_POD=$(kubectl get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name})
kubectl logs -f "$V1_POD" -c httpbin kubectl logs "$V1_POD" -c httpbin
} }
! read -r -d '' snip_creating_a_default_routing_policy_3_out <<\ENDSNIP ! read -r -d '' snip_creating_a_default_routing_policy_3_out <<\ENDSNIP
@ -183,7 +183,7 @@ ENDSNIP
snip_creating_a_default_routing_policy_4() { snip_creating_a_default_routing_policy_4() {
export V2_POD=$(kubectl get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name}) export V2_POD=$(kubectl get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name})
kubectl logs -f "$V2_POD" -c httpbin kubectl logs "$V2_POD" -c httpbin
} }
! read -r -d '' snip_creating_a_default_routing_policy_4_out <<\ENDSNIP ! read -r -d '' snip_creating_a_default_routing_policy_4_out <<\ENDSNIP
@ -217,7 +217,7 @@ kubectl exec "${SLEEP_POD}" -c sleep -- curl -s http://httpbin:8000/headers
} }
snip_mirroring_traffic_to_v2_3() { snip_mirroring_traffic_to_v2_3() {
kubectl logs -f "$V1_POD" -c httpbin kubectl logs "$V1_POD" -c httpbin
} }
! read -r -d '' snip_mirroring_traffic_to_v2_3_out <<\ENDSNIP ! read -r -d '' snip_mirroring_traffic_to_v2_3_out <<\ENDSNIP
@ -226,7 +226,7 @@ kubectl logs -f "$V1_POD" -c httpbin
ENDSNIP ENDSNIP
snip_mirroring_traffic_to_v2_4() { snip_mirroring_traffic_to_v2_4() {
kubectl logs -f "$V2_POD" -c httpbin kubectl logs "$V2_POD" -c httpbin
} }
! read -r -d '' snip_mirroring_traffic_to_v2_4_out <<\ENDSNIP ! read -r -d '' snip_mirroring_traffic_to_v2_4_out <<\ENDSNIP

View File

@ -52,7 +52,7 @@ To write an `istio.io` test, follow these steps:
1. Create Go boilderplate that will invoke your test bash script using the following pattern: 1. Create Go boilderplate that will invoke your test bash script using the following pattern:
```golang ```golang
package <your test package> package <your-test-package>
import ( import (
"testing" "testing"
@ -62,19 +62,19 @@ To write an `istio.io` test, follow these steps:
"istio.io/istio.io/pkg/test/istioio" "istio.io/istio.io/pkg/test/istioio"
) )
func Test<your test>(t *testing.T) { func Test<your-test>(t *testing.T) {
framework. framework.
NewTest(t). NewTest(t).
Run(istioio.NewBuilder("<your test name"). Run(istioio.NewBuilder("<your-test-name>").
Add(istioio.Script{ Add(istioio.Script{
Input: istioio.Path("scripts/<your bash script>.sh"), Input: istioio.Path("scripts/<your-bash-script>.sh"),
}). }).
Defer(istioio.Script{ Defer(istioio.Script{
Input: istioio.Inline{ Input: istioio.Inline{
FileName: "cleanup.sh", FileName: "cleanup.sh",
Value: ` Value: `
set +e # ignore cleanup errors set +e # ignore cleanup errors
source ${REPO_ROOT}/content/en/docs/<your snips dir>/snips.sh source ${REPO_ROOT}/content/en/docs/<your-snips-dir>/snips.sh
<your cleanup steps>`, <your cleanup steps>`,
}, },
}). }).
@ -164,7 +164,7 @@ The framework includes the following built-in verify functions:
This function is useful for comparing the output of commands that include some run-specific This function is useful for comparing the output of commands that include some run-specific
values in the output (e.g., `kubectl get pods`), or when whitespace in the output may be different. values in the output (e.g., `kubectl get pods`), or when whitespace in the output may be different.
Everery `verify_` function has a corresponding `_run_and_verify_` function that Every `verify_` function has a corresponding `_run_and_verify_` function that
first runs a function and then compares the result to the expected output. first runs a function and then compares the result to the expected output.
The specified function will be retried 5 times, with exponential backoff, before failing: The specified function will be retried 5 times, with exponential backoff, before failing:

View File

@ -45,6 +45,7 @@ test.kube.%: init | $(JUNIT_REPORT)
PATH=${PATH}:${ISTIO_OUT} $(GO) test -p 1 ${T} ./tests/$(subst .,/,$*)/... -timeout 30m \ PATH=${PATH}:${ISTIO_OUT} $(GO) test -p 1 ${T} ./tests/$(subst .,/,$*)/... -timeout 30m \
--istio.test.select -postsubmit,-flaky \ --istio.test.select -postsubmit,-flaky \
--istio.test.env kube \ --istio.test.env kube \
--log_output_level=script:debug \
${_INTEGRATION_TEST_FLAGS} \ ${_INTEGRATION_TEST_FLAGS} \
2>&1 | tee >($(JUNIT_REPORT) > $(JUNIT_OUT)) 2>&1 | tee >($(JUNIT_REPORT) > $(JUNIT_OUT))

View File

@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# shellcheck disable=SC2155
set -e set -e
set -u set -u
set -o pipefail set -o pipefail
@ -33,32 +35,39 @@ snip_before_you_begin_3
snip_before_you_begin_4 snip_before_you_begin_4
# wait for deployments # wait for deployments
#sample_wait_for_deployment default httpbin-v1 sample_wait_for_deployment default httpbin-v1
#sample_wait_for_deployment default httpbin-v2 sample_wait_for_deployment default httpbin-v2
#sample_wait_for_deployment default sleep sample_wait_for_deployment default sleep
snip_creating_a_default_routing_policy_1 snip_creating_a_default_routing_policy_1
# wait for virtual service # wait for virtual service
#istioctl experimental wait --for=distribution VirtualService httpbin.default #istioctl experimental wait --for=distribution VirtualService httpbin.default
#sleep 5s sleep 5s
kubectl get all --all-namespaces _run_and_verify_contains snip_creating_a_default_routing_policy_2 "headers"
#_run_and_verify_contains snip_creating_a_default_routing_policy_2 "headers" _run_and_verify_contains snip_creating_a_default_routing_policy_3 "GET /headers HTTP/1.1"
#_run_and_verify_contains snip_creating_a_default_routing_policy_3 "GET /headers HTTP/1.1"
# No point in retrying for "not contains". TODO: some kind of _verify_worked_and_not_contains function
#_run_and_verify_not_contains snip_creating_a_default_routing_policy_4 "GET /headers HTTP/1.1" #_run_and_verify_not_contains snip_creating_a_default_routing_policy_4 "GET /headers HTTP/1.1"
out=$(snip_creating_a_default_routing_policy_4 2>&1)
_verify_not_contains "$out" "GET /headers HTTP/1.1" "snip_creating_a_default_routing_policy_4"
#snip_mirroring_traffic_to_v2_1 snip_mirroring_traffic_to_v2_1
# wait for virtual service # wait for virtual service
#istioctl experimental wait --for=distribution VirtualService httpbin.default #istioctl experimental wait --for=distribution VirtualService httpbin.default
#sleep 5s sleep 5s
#snip_mirroring_traffic_to_v2_2 # Set environment variables. TODO: why didn't the exports from snip_creating_a_default_routing_policy_2/3/4 take?
export SLEEP_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
export V1_POD=$(kubectl get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name})
export V2_POD=$(kubectl get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name})
#_run_and_verify_contains snip_mirroring_traffic_to_v2_3 "GET /headers HTTP/1.1" snip_mirroring_traffic_to_v2_2
#_run_and_verify_contains snip_mirroring_traffic_to_v2_3 "GET /headers HTTP/1.1" # TODO: This should check for 2 lines with the GET request
_run_and_verify_contains snip_mirroring_traffic_to_v2_3 "GET /headers HTTP/1.1"
_run_and_verify_contains snip_mirroring_traffic_to_v2_3 "GET /headers HTTP/1.1"

View File

@ -40,7 +40,6 @@ __cmp_contains() {
local expected=$2 local expected=$2
if [[ "$out" != *"$expected"* ]]; then if [[ "$out" != *"$expected"* ]]; then
echo "false"
return 1 return 1
fi fi
@ -212,10 +211,13 @@ __verify_with_retry() {
# Run the command. # Run the command.
out=$($func 2>&1) out=$($func 2>&1)
$cmp_func "$out" "$expected"
local retval="$?"
# Restore the "errexit" state. # Restore the "errexit" state.
eval "$errexit_state" eval "$errexit_state"
if $cmp_func "$out" "$expected"; then if [[ "$retval" -eq 0 ]]; then
return return
fi fi