3 # ============LICENSE_START===============================================
4 # Copyright (C) 2021 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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
20 # This is a script that contains function to handle helm on localhost
23 ################ Test engine functions ################
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 __LOCALHELM_imagesetup() {
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 __LOCALHELM_imagepull() {
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 __LOCALHELM_imagebuild() {
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 __LOCALHELM_image_data() {
55 # Scale kubernetes resources to zero
56 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
57 # This function is called for apps fully managed by the test script
58 __LOCALHELM_kube_scale_zero() {
62 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
63 # This function is called for prestarted apps not managed by the test script.
64 __LOCALHELM_kube_scale_zero_and_wait() {
68 # Delete all kube resouces for the app
69 # This function is called for apps managed by the test script.
70 __LOCALHELM_kube_delete_all() {
75 # This function is called for apps managed by the test script.
76 # args: <log-dir> <file-prexix>
77 __LOCALHELM_store_docker_logs() {
81 # Initial setup of protocol, host and ports
82 # This function is called for apps managed by the test script.
84 __LOCALHELM_initial_setup() {
88 # Set app short-name, app name and namespace for logging runtime statistics of kubernets pods or docker containers
89 # For docker, the namespace shall be excluded
90 # This function is called for apps managed by the test script as well as for prestarted apps.
92 __LOCALHELM_statisics_setup() {
96 # Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
98 __LOCALHELM_test_requirements() {
100 if [ $? -ne 0 ]; then
101 echo $RED" Helm3 is required for running this test. Pls install helm3"
104 tmp_version=$(helm version | grep 'v3')
105 if [ -z "$tmp_version" ]; then
106 echo $RED" Helm3 is required for running this test. Pls install helm3"
111 #######################################################
114 # Create a dummy helmchart
116 localhelm_create_test_chart() {
118 if [ $# -ne 1 ]; then
119 __print_err "<path-to-chart-dir>" $@
122 if [[ "$1" == *"/"* ]]; then
123 echo -e $RED"Chart name cannot contain '/'"
124 __log_conf_fail_general
127 helm create $TESTENV_TEMP_FILES/$1 | indent1
128 if [ $? -ne 0 ]; then
129 __log_conf_fail_general
136 # Package a created helmchart
138 localhelm_package_test_chart() {
140 if [ $# -ne 1 ]; then
141 __print_err "<path-to-chart-dir>" $@
144 if [[ "$1" == *"/"* ]]; then
145 echo -e $RED"Chart name cannot contain '/'"
146 __log_conf_fail_general
149 helm package -d $TESTENV_TEMP_FILES $TESTENV_TEMP_FILES/$1 | indent1
150 if [ $? -ne 0 ]; then
151 __log_conf_fail_general
158 # Check if a release is installed
159 # arg: INSTALLED|NOTINSTALLED <release-name> <name-space>
160 localhelm_installed_chart_release() {
162 if [ $# -ne 3 ]; then
163 __print_err "INSTALLED|NOTINSTALLED <release-name> <name-space>" $@
166 if [ $1 != "INSTALLED" ] && [ $1 != "NOTINSTALLED" ]; then
167 __print_err "INSTALLED|NOTINSTALLED <release-name> <name-space>" $@
171 filter="helm ls -n $3 --filter ^$2"
173 if [ $? -ne 0 ]; then
174 __log_test_fail_general "Failed to list helm releases"
177 if [ $1 == "INSTALLED" ]; then
178 if [ "$res" != $2 ]; then
179 echo -e "$RED Release $2 does not exists $ERED"
180 __log_test_fail_general
183 elif [ $1 == "NOTINSTALLED" ]; then
184 if [ "$res" == $2 ]; then
185 __log_test_fail_general "Release $2 exists"
189 echo " Currently installed releases in namespace $3"
190 helm ls -n $3 | indent2