X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fecs_api_functions.sh;h=cf5f580f462e31b3606c09b6c1901ad2d64b3146;hb=674793d94f09873d24edd85f9eb2da2582d21673;hp=525ac8b501c8d60eee8ad4b17adeb83d29843532;hpb=483ee33ac3de88385c0eeb3f1ecf3a1bb760db54;p=nonrtric.git diff --git a/test/common/ecs_api_functions.sh b/test/common/ecs_api_functions.sh index 525ac8b5..cf5f580f 100644 --- a/test/common/ecs_api_functions.sh +++ b/test/common/ecs_api_functions.sh @@ -96,6 +96,9 @@ ECS_ADAPTER=$ECS_PATH # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes ECS_RETRY_CODES="" +#Save first worker node the pod is started on +__ECS_WORKER_NODE="" + ########################### ### ECS functions ########################### @@ -205,6 +208,7 @@ start_ecs() { export ECS_CONTAINER_MNT_DIR export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv" + export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc" #Create a unique path for the pv each time to prevent a previous volume to be reused export ECS_PV_PATH="ecsdata-"$(date +%s) @@ -251,6 +255,19 @@ start_ecs() { __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml fi + # Tie the ECS to a worker node so that ECS will always be scheduled to the same worker node if the ECS pod is restarted + # A PVC of type hostPath is mounted to ECS, for persistent storage, so the ECS must always be on the node which mounted the volume + + # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host + if [ $retcode_i -eq 0 ]; then + __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}') + if [ -z "$__ECS_WORKER_NODE" ]; then + echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW + fi + else + echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW + fi + echo " Retrieving host and ports for service..." ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE) ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http") @@ -337,20 +354,88 @@ start_ecs() { return 0 } -# Restart ECS +# Stop the ecs +# args: - # args: - # (Function for test scripts) -restart_ecs() { - echo -e $BOLD"Re-starting ECS"$EBOLD - docker restart $ECS_APP_NAME &> ./tmp/.dockererr - if [ $? -ne 0 ]; then - __print_err "Could not restart $ECS_APP_NAME" $@ - cat ./tmp/.dockererr - ((RES_CONF_FAIL++)) - return 1 +stop_ecs() { + echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD + + if [ $RUNMODE == "KUBE" ]; then + + __check_prestarted_image "ECS" + if [ $? -eq 0 ]; then + echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW + __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0 + return 0 + fi + + __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS + echo " Deleting the replica set - a new will be started when the app is started" + tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS") + if [ $? -ne 0 ]; then + echo -e $RED" Could not delete replica set "$RED + ((RES_CONF_FAIL++)) + return 1 + fi + else + docker stop $ECS_APP_NAME &> ./tmp/.dockererr + if [ $? -ne 0 ]; then + __print_err "Could not stop $ECS_APP_NAME" $@ + cat ./tmp/.dockererr + ((RES_CONF_FAIL++)) + return 1 + fi fi + echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD + echo "" + return 0 +} + +# Start a previously stopped ecs +# args: - +# (Function for test scripts) +start_stopped_ecs() { + echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD + + if [ $RUNMODE == "KUBE" ]; then + __check_prestarted_image "ECS" + if [ $? -eq 0 ]; then + echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW + __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 + __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL + return 0 + fi + + # Tie the PMS to the same worker node it was initially started on + # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume + if [ -z "$__ECS_WORKER_NODE" ]; then + echo -e $RED" No initial worker node found for pod "$RED + ((RES_CONF_FAIL++)) + return 1 + else + echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ECS_WORKER_NODE to deployment for $ECS_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD + echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD + tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}') + if [ $? -ne 0 ]; then + echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW + fi + __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1 + fi + else + docker start $ECS_APP_NAME &> ./tmp/.dockererr + if [ $? -ne 0 ]; then + __print_err "Could not start (the stopped) $ECS_APP_NAME" $@ + cat ./tmp/.dockererr + ((RES_CONF_FAIL++)) + return 1 + fi + fi __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL + if [ $? -ne 0 ]; then + return 1 + fi echo "" return 0 } @@ -1686,6 +1771,25 @@ ecs_api_admin_reset() { fi done + __log_test_pass + return 0 +} + +########################################## +#### Reset jobs and producers #### +########################################## + + +# Admin reset to remove all data in ecs; jobs, producers etc +# NOTE - only works in kubernetes and the pod should not be running +# args: - +# (Function for test scripts) + +ecs_kube_pvc_reset() { + __log_test_start $@ + + __kube_clean_pvc $ECS_APP_NAME nonrtric enrichmentservice-pvc /var/enrichment-coordinator-service/database + __log_test_pass return 0 } \ No newline at end of file