Updated test env documentation
[nonrtric.git] / test / common / authsidecar_api_functions.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 #  ========================================================================
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License.
17 #  ============LICENSE_END=================================================
18 #
19
20 # This is a script that contains container/service management functions
21 # for AUTHSIDECAR
22
23 ################ Test engine functions ################
24
25 # Create the image var used during the test
26 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
27 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
28 __AUTHSIDECAR_imagesetup() {
29         __check_and_create_image_var AUTHSIDECAR "AUTHSIDECAR_IMAGE" "AUTHSIDECAR_IMAGE_BASE" "AUTHSIDECAR_IMAGE_TAG" $1 "$AUTHSIDECAR_DISPLAY_NAME" ""
30 }
31
32 # Pull image from remote repo or use locally built image
33 # arg: <pull-policy-override> <pull-policy-original>
34 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
35 # <pull-policy-original> Shall be used for images that does not allow overriding
36 # Both var may contain: 'remote', 'remote-remove' or 'local'
37 __AUTHSIDECAR_imagepull() {
38         __check_and_pull_image $1 "$AUTHSIDECAR_DISPLAY_NAME" $AUTHSIDECAR_APP_NAME AUTHSIDECAR_IMAGE
39 }
40
41 # Build image (only for simulator or interfaces stubs owned by the test environment)
42 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
43 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
44 __AUTHSIDECAR_imagebuild() {
45         echo -e $RED"Image for app AUTHSIDECAR shall never be built"$ERED
46 }
47
48 # Generate a string for each included image using the app display name and a docker images format string
49 # If a custom image repo is used then also the source image from the local repo is listed
50 # arg: <docker-images-format-string> <file-to-append>
51 __AUTHSIDECAR_image_data() {
52         echo -e "$AUTHSIDECAR_DISPLAY_NAME\t$(docker images --format $1 $AUTHSIDECAR_IMAGE)" >>   $2
53         if [ ! -z "$AUTHSIDECAR_IMAGE_SOURCE" ]; then
54                 echo -e "-- source image --\t$(docker images --format $1 $AUTHSIDECAR_IMAGE_SOURCE)" >>   $2
55         fi
56 }
57
58 # Scale kubernetes resources to zero
59 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
60 # This function is called for apps fully managed by the test script
61 __AUTHSIDECAR_kube_scale_zero() {
62         :
63 }
64
65 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
66 # This function is called for pre-started apps not managed by the test script.
67 __AUTHSIDECAR_kube_scale_zero_and_wait() {
68         :
69 }
70
71 # Delete all kube resources for the app
72 # This function is called for apps managed by the test script.
73 __AUTHSIDECAR_kube_delete_all() {
74         :
75 }
76
77 # Store docker logs
78 # This function is called for apps managed by the test script.
79 # args: <log-dir> <file-prefix>
80 __AUTHSIDECAR_store_docker_logs() {
81         if [ $RUNMODE == "KUBE" ]; then
82                 kubectl $KUBECONF  logs -l "autotest=AUTHSIDECAR" -A --tail=-1 > $1$2_authsidecar.log 2>&1
83         fi
84 }
85
86 # Initial setup of protocol, host and ports
87 # This function is called for apps managed by the test script.
88 # args: -
89 __AUTHSIDECAR_initial_setup() {
90         :
91 }
92
93 # Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
94 # For docker, the namespace shall be excluded
95 # This function is called for apps managed by the test script as well as for pre-started apps.
96 # args: -
97 __AUTHSIDECAR_statistics_setup() {
98         echo ""
99 }
100
101 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
102 # args: -
103 __AUTHSIDECAR_test_requirements() {
104         :
105 }
106
107 #######################################################
108
109 # This app is intended as a sidecar container - no specific test functions