From 08d774342ce007a682a9e63ba6570ec28611af94 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Mon, 16 Oct 2023 09:46:48 +0000 Subject: [PATCH] test: enable cloudprovider_azure metrics print --- hack/verify-examples.sh | 6 +++--- test/e2e/dynamic_provisioning_test.go | 9 +++++---- test/e2e/suite_test.go | 25 ++++++++++++++++--------- test/utils/azurefile_log.sh | 20 ++++++++++++++++---- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/hack/verify-examples.sh b/hack/verify-examples.sh index 8d66d4ae05..ce9dddd7ff 100755 --- a/hack/verify-examples.sh +++ b/hack/verify-examples.sh @@ -30,9 +30,9 @@ rollout_and_wait() { APPNAME=$(kubectl apply -f $1 | grep -E "^(:?daemonset|deployment|statefulset|pod)" | awk '{printf $1}') if [[ -n $(expr "${APPNAME}" : "\(daemonset\|deployment\|statefulset\)" || true) ]]; then - kubectl rollout status $APPNAME --watch --timeout=5m + kubectl rollout status $APPNAME --watch --timeout=10m else - kubectl wait "${APPNAME}" --for condition=ready --timeout=5m + kubectl wait "${APPNAME}" --for condition=ready --timeout=10m fi } @@ -63,4 +63,4 @@ for EXAMPLE in "${EXAMPLES[@]}"; do rollout_and_wait $EXAMPLE done -echo "deployment examples running completed." \ No newline at end of file +echo "deployment examples running completed." diff --git a/test/e2e/dynamic_provisioning_test.go b/test/e2e/dynamic_provisioning_test.go index b7d3593cb8..e533a1d610 100644 --- a/test/e2e/dynamic_provisioning_test.go +++ b/test/e2e/dynamic_provisioning_test.go @@ -1316,10 +1316,11 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() { // print azure file driver logs before driver restart azurefileLog := testCmd{ - command: "bash", - args: []string{"test/utils/azurefile_log.sh"}, - startLog: "===================azurefile log (before restart)===================", - endLog: "====================================================================", + command: "bash", + args: []string{"test/utils/azurefile_log.sh"}, + startLog: "===================azurefile log (before restart)===================", + endLog: "====================================================================", + ignoreError: true, } execTestCmd([]testCmd{azurefileLog}) diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index a806496202..759fcc92e4 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -66,10 +66,11 @@ var ( ) type testCmd struct { - command string - args []string - startLog string - endLog string + command string + args []string + startLog string + endLog string + ignoreError bool } var _ = ginkgo.BeforeSuite(func() { @@ -181,10 +182,11 @@ var _ = ginkgo.AfterSuite(func() { execTestCmd([]testCmd{createExampleDeployment}) azurefileLog := testCmd{ - command: "bash", - args: []string{"test/utils/azurefile_log.sh"}, - startLog: "===================azurefile log===================", - endLog: "===================================================", + command: "bash", + args: []string{"test/utils/azurefile_log.sh"}, + startLog: "===================azurefile log===================", + endLog: "===================================================", + ignoreError: true, } e2eTeardown := testCmd{ command: "make", @@ -231,7 +233,12 @@ func execTestCmd(cmds []testCmd) { cmdSh.Stdout = os.Stdout cmdSh.Stderr = os.Stderr err = cmdSh.Run() - gomega.Expect(err).NotTo(gomega.HaveOccurred()) + if err != nil { + log.Println(err) + if !cmd.ignoreError { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + } + } log.Println(cmd.endLog) } } diff --git a/test/utils/azurefile_log.sh b/test/utils/azurefile_log.sh index 7197ee069e..94b3f0a3b7 100755 --- a/test/utils/azurefile_log.sh +++ b/test/utils/azurefile_log.sh @@ -23,6 +23,13 @@ if [[ "$#" -gt 0 ]]; then DRIVER=$1 fi +cleanup() { + echo "hit unexpected error during log print, exit 0" + exit 0 +} + +trap cleanup ERR + echo "print out all nodes status ..." kubectl get nodes -o wide echo "======================================================================================" @@ -63,7 +70,12 @@ kubectl get pods -n${NS} -l${LABEL} \ | awk 'NR>1 {print $1}' \ | xargs -I {} bash -c "echo 'dumping logs for ${NS}/{}/${DRIVER}' && kubectl logs {} -c${CONTAINER} -n${NS}" -#echo "print out cloudprovider_azure metrics ..." -#echo "======================================================================================" -#ip=`kubectl get svc csi-${DRIVER}-controller -n kube-system | awk '{print $4}'` -#curl http://$ip:29614/metrics +echo "======================================================================================" +ip=`kubectl get svc csi-${DRIVER}-controller -n kube-system | awk '{print $4}'` +if echo "$ip" | grep -q "\."; then + echo "print out cloudprovider_azure metrics ..." + curl http://$ip:29614/metrics +else + echo "csi-$DRIVER-controller service ip is empty" + kubectl get svc csi-$DRIVER-controller -n kube-system +fi