X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Ftestcase_common.sh;h=66cbd96bbe079304a4ace330922b2a8b198dbf94;hb=72951a9e46961aa98d20b4674cc091039917a494;hp=41135afb891a482bd794bd68bc256343fde2599e;hpb=674793d94f09873d24edd85f9eb2da2582d21673;p=nonrtric.git diff --git a/test/common/testcase_common.sh b/test/common/testcase_common.sh index 41135afb..66cbd96b 100755 --- a/test/common/testcase_common.sh +++ b/test/common/testcase_common.sh @@ -672,6 +672,37 @@ if [ $? -ne 0 ] || [ -z tmp ]; then echo -e $RED"kubectl is required to run the test environment in kubernetes mode, pls install"$ERED exit 1 fi +else + if [ $RUNMODE == "KUBE" ]; then + res=$(kubectl cluster-info 2>&1) + if [ $? -ne 0 ]; then + echo -e "$BOLD$RED############################################# $ERED$EBOLD" + echo -e $BOLD$RED"Command 'kubectl cluster-info' returned error $ERED$EBOLD" + echo -e "$BOLD$RED############################################# $ERED$EBOLD" + echo " " + echo "kubectl response:" + echo $res + echo " " + echo "This script may have been started with user with no permission to run kubectl" + echo "Try running with 'sudo' or set 'KUBECONFIG'" + echo "Do either 1, 2 or 3 " + echo " " + echo "1" + echo "Run with sudo" + echo -e $BOLD"sudo "$EBOLD + echo " " + echo "2" + echo "Export KUBECONFIG and pass env to sudo - (replace user)" + echo -e $BOLD"export KUBECONFIG='/home//.kube/config'"$EBOLD + echo -e $BOLD"sudo -E "$EBOLD + echo " " + echo "3" + echo "Set KUBECONFIG inline (replace user)" + echo -e $BOLD"sudo KUBECONFIG='/home//.kube/config' "$EBOLD + + exit 1 + fi + fi fi echo -e $BOLD"Checking configured image setting for this test case"$EBOLD @@ -1619,6 +1650,23 @@ __clean_containers() { ### Functions for kube management ################################### +# Get resource type for scaling +# args: +__kube_get_resource_type() { + kubectl get deployment $1 -n $2 1> /dev/null 2> ./tmp/kubeerr + if [ $? -eq 0 ]; then + echo "deployment" + return 0 + fi + kubectl get sts $1 -n $2 1> /dev/null 2> ./tmp/kubeerr + if [ $? -eq 0 ]; then + echo "sts" + return 0 + fi + echo "unknown-resource-type" + return 1 +} + # Scale a kube resource to a specific count # args: # (Not for test scripts) @@ -1973,7 +2021,7 @@ __kube_clean_pvc() { envsubst < $input_yaml > $output_yaml - kubectl delete -f $output_yaml #> /dev/null 2>&1 # Delete the previous terminated pod - if existing + kubectl delete -f $output_yaml 1> /dev/null 2> /dev/null # Delete the previous terminated pod - if existing __kube_create_instance pod pvc-cleaner $input_yaml $output_yaml if [ $? -ne 0 ]; then @@ -2150,13 +2198,6 @@ __start_container() { appcount=$1 shift - os_version=$(uname -a 2> /dev/null | awk '{print tolower($0)}' | grep "microsoft") - if [[ "$os_version" == *"microsoft"* ]]; then - echo -e $YELLOW" Workaround for Linux on Win - delay container start, 1 sec, to make sure files mounted in the container are available on disk - WLS problem"$EYELLOW - sleep 1 - fi - - if [ "$compose_args" == "NODOCKERARGS" ]; then docker-compose -f $compose_file up -d &> .dockererr if [ $? -ne 0 ]; then