+################ Test engine functions ################
+
+# Create the image var used during the test
+# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
+# <image-tag-suffix> is present only for images with staging, snapshot,release tags
+__PA_imagesetup() {
+ __check_and_create_image_var PA "POLICY_AGENT_IMAGE" "POLICY_AGENT_IMAGE_BASE" "POLICY_AGENT_IMAGE_TAG" $1 "$POLICY_AGENT_DISPLAY_NAME"
+}
+
+# Pull image from remote repo or use locally built image
+# arg: <pull-policy-override> <pull-policy-original>
+# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
+# <pull-policy-original> Shall be used for images that does not allow overriding
+# Both var may contain: 'remote', 'remote-remove' or 'local'
+__PA_imagepull() {
+ __check_and_pull_image $1 "$POLICY_AGENT_DISPLAY_NAME" $POLICY_AGENT_APP_NAME POLICY_AGENT_IMAGE
+}
+
+# Build image (only for simulator or interfaces stubs owned by the test environment)
+# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
+# <image-tag-suffix> is present only for images with staging, snapshot,release tags
+__PA_imagebuild() {
+ echo -e $RED" Image for app PA shall never be built"$ERED
+}
+
+# Generate a string for each included image using the app display name and a docker images format string
+# If a custom image repo is used then also the source image from the local repo is listed
+# arg: <docker-images-format-string> <file-to-append>
+__PA_image_data() {
+ echo -e "$POLICY_AGENT_DISPLAY_NAME\t$(docker images --format $1 $POLICY_AGENT_IMAGE)" >> $2
+ if [ ! -z "$POLICY_AGENT_IMAGE_SOURCE" ]; then
+ echo -e "-- source image --\t$(docker images --format $1 $POLICY_AGENT_IMAGE_SOURCE)" >> $2
+ fi
+}
+
+# Scale kubernetes resources to zero
+# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
+# This function is called for apps fully managed by the test script
+__PA_kube_scale_zero() {
+ __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
+}
+
+# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
+# This function is called for prestarted apps not managed by the test script.
+__PA_kube_scale_zero_and_wait() {
+ __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app "$KUBE_NONRTRIC_NAMESPACE"-policymanagementservice
+}
+
+# Delete all kube resouces for the app
+# This function is called for apps managed by the test script.
+__PA_kube_delete_all() {
+ __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest PA
+}
+
+# Store docker logs
+# This function is called for apps managed by the test script.
+# args: <log-dir> <file-prexix>
+__PA_store_docker_logs() {
+ if [ $RUNMODE == "KUBE" ]; then
+ kubectl logs -l "autotest=PA" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_policy-agent.log 2>&1
+ else
+ docker logs $POLICY_AGENT_APP_NAME > $1$2_policy-agent.log 2>&1
+ fi
+}
+
+# Initial setup of protocol, host and ports
+# This function is called for apps managed by the test script.
+# args: -
+__PA_initial_setup() {
+ use_agent_rest_http
+}
+
+#######################################################
+
+###########################
+### Policy Agents functions
+###########################
+
+# Set http as the protocol to use for all communication to the Policy Agent
+# args: -
+# (Function for test scripts)
+use_agent_rest_http() {
+ __agent_set_protocoll "http" $POLICY_AGENT_INTERNAL_PORT $POLICY_AGENT_EXTERNAL_PORT
+}
+
+# Set https as the protocol to use for all communication to the Policy Agent
+# args: -
+# (Function for test scripts)
+use_agent_rest_https() {
+ __agent_set_protocoll "https" $POLICY_AGENT_INTERNAL_SECURE_PORT $POLICY_AGENT_EXTERNAL_SECURE_PORT
+}
+
+# All calls to the agent will be directed to the agent dmaap interface over http from now on
+# args: -
+# (Function for test scripts)
+use_agent_dmaap_http() {
+ echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
+ echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
+ PA_ADAPTER_TYPE="MR-HTTP"
+ echo ""
+}
+
+# All calls to the agent will be directed to the agent dmaap interface over https from now on
+# args: -
+# (Function for test scripts)
+use_agent_dmaap_https() {
+ echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME dmaap protocol setting"$EBOLD
+ echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
+ echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
+ PA_ADAPTER_TYPE="MR-HTTPS"
+ echo ""
+}
+
+# Setup paths to svc/container for internal and external access
+# args: <protocol> <internal-port> <external-port>
+__agent_set_protocoll() {
+ echo -e $BOLD"$POLICY_AGENT_DISPLAY_NAME protocol setting"$EBOLD
+ echo -e " Using $BOLD http $EBOLD towards $POLICY_AGENT_DISPLAY_NAME"
+
+ ## Access to Dmaap adapter
+
+ PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME":"$2 # docker access, container->container and script->container via proxy
+ if [ $RUNMODE == "KUBE" ]; then
+ PA_SERVICE_PATH=$1"://"$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
+ fi
+
+ # PA_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
+ PA_ADAPTER_TYPE="REST"
+ PA_ADAPTER=$PA_SERVICE_PATH
+
+ echo ""
+}
+
+# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
+AGENT_RETRY_CODES=""
+
+#Save first worker node the pod is started on
+__PA_WORKER_NODE=""
+
+# Export env vars for config files, docker compose and kube resources
+# args: PROXY|NOPROXY
+__export_agent_vars() {
+
+ export POLICY_AGENT_APP_NAME
+ export POLICY_AGENT_APP_NAME_ALIAS
+ export POLICY_AGENT_DISPLAY_NAME
+
+ export KUBE_NONRTRIC_NAMESPACE
+ export POLICY_AGENT_IMAGE
+ export POLICY_AGENT_INTERNAL_PORT
+ export POLICY_AGENT_INTERNAL_SECURE_PORT
+ export POLICY_AGENT_EXTERNAL_PORT
+ export POLICY_AGENT_EXTERNAL_SECURE_PORT
+ export POLICY_AGENT_CONFIG_MOUNT_PATH
+ export POLICY_AGENT_DATA_MOUNT_PATH
+ export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
+ export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
+ export POLICY_AGENT_PKG_NAME
+ export CONSUL_HOST
+ export CONSUL_INTERNAL_PORT
+ export CONFIG_BINDING_SERVICE
+ export POLICY_AGENT_CONFIG_KEY
+ export DOCKER_SIM_NWNAME
+ export POLICY_AGENT_HOST_MNT_DIR
+ export POLICY_AGENT_CONFIG_FILE
+
+ export POLICY_AGENT_DATA_PV_NAME=$POLICY_AGENT_APP_NAME"-pv"
+ export POLICY_AGENT_DATA_PVC_NAME=$POLICY_AGENT_APP_NAME"-pvc"
+ ##Create a unique path for the pv each time to prevent a previous volume to be reused
+ export POLICY_AGENT_PV_PATH="padata-"$(date +%s)
+ export POLICY_AGENT_CONTAINER_MNT_DIR
+
+ if [ $1 == "PROXY" ]; then
+ export AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
+ export AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
+ if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
+ echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
+ else
+ echo " Configured with http proxy"