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
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 container/service management function
21 # and test functions for Control Panel
23 ## Access to control panel
24 # Host name may be changed if app started by kube
25 # Direct access from script
27 CP_HOST_NAME=$LOCALHOST_NAME
28 CP_PATH=$CP_HTTPX"://"$CP_HOST_NAME":"$CONTROL_PANEL_EXTERNAL_PORT
30 ###########################
31 ### Control Panel functions
32 ###########################
34 # Set http as the protocol to use for all communication to the Control Panel
36 # (Function for test scripts)
37 use_control_panel_http() {
38 echo -e $BOLD"Control Panel, CP, protocol setting"$EBOLD
39 echo -e " Using $BOLD http $EBOLD towards CP"
41 CP_PATH=$CP_HTTPX"://"$CP_HOST_NAME":"$CONTROL_PANEL_EXTERNAL_PORT
45 # Set https as the protocol to use for all communication to the Control Panel
47 # (Function for test scripts)
48 use_control_panel_https() {
49 echo -e $BOLD"Control Panel, CP, protocol setting"$EBOLD
50 echo -e " Using $BOLD https $EBOLD towards CP"
52 CP_PATH=$CP_HTTPX"://"$CP_HOST_NAME":"$CONTROL_PANEL_EXTERNAL_SECURE_PORT
56 # Start the Control Panel container
58 # (Function for test scripts)
59 start_control_panel() {
61 echo -e $BOLD"Starting $CONTROL_PANEL_DISPLAY_NAME"$EBOLD
63 if [ $RUNMODE == "KUBE" ]; then
65 # Check if app shall be fully managed by the test script
66 __check_included_image "CP"
69 # Check if app shall only be used by the testscipt
70 __check_prestarted_image "CP"
73 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
74 echo -e $RED"The $CONTROL_PANEL_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
75 echo -e $RED"The $CONTROL_PANEL_APP_NAME will not be started"$ERED
78 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
79 echo -e $RED"The $CONTROL_PANEL_APP_NAME app is included both as managed and prestarted in this test script"$ERED
80 echo -e $RED"The $CONTROL_PANEL_APP_NAME will not be started"$ERED
84 # Check if app shall be used - not managed - by the test script
85 __check_prestarted_image "CP"
87 echo -e " Using existing $CONTROL_PANEL_APP_NAME deployment and service"
88 echo " Setting CP replicas=1"
89 __kube_scale deployment $CONTROL_PANEL_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
92 if [ $retcode_i -eq 0 ]; then
94 echo -e " Creating $CP_APP_NAME app and expose service"
96 #Export all vars needed for service and deployment
97 export CONTROL_PANEL_APP_NAME
98 export KUBE_NONRTRIC_NAMESPACE
99 export CONTROL_PANEL_IMAGE
100 export CONTROL_PANEL_INTERNAL_PORT
101 export CONTROL_PANEL_INTERNAL_SECURE_PORT
102 export CONTROL_PANEL_EXTERNAL_PORT
103 export CONTROL_PANEL_EXTERNAL_SECURE_PORT
104 export CONTROL_PANEL_CONFIG_MOUNT_PATH
105 export CONTROL_PANEL_CONFIG_FILE
106 export CP_CONFIG_CONFIGMAP_NAME=$CONTROL_PANEL_APP_NAME"-config"
108 export POLICY_AGENT_EXTERNAL_SECURE_PORT
109 export ECS_EXTERNAL_SECURE_PORT
110 export POLICY_AGENT_DOMAIN_NAME=$POLICY_AGENT_APP_NAME.$KUBE_NONRTRIC_NAMESPACE
111 export ECS_DOMAIN_NAME=$ECS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE
113 #Check if nonrtric namespace exists, if not create it
114 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
116 # Create config map for config
117 datafile=$PWD/tmp/$CONTROL_PANEL_CONFIG_FILE
118 #Add config to properties file
119 envsubst < $1 > $datafile
120 output_yaml=$PWD/tmp/cp_cfc.yaml
121 __kube_create_configmap $CP_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest CP $datafile $output_yaml
124 input_yaml=$SIM_GROUP"/"$CONTROL_PANEL_COMPOSE_DIR"/"svc.yaml
125 output_yaml=$PWD/tmp/cp_svc.yaml
126 __kube_create_instance service $CONTROL_PANEL_APP_NAME $input_yaml $output_yaml
129 input_yaml=$SIM_GROUP"/"$CONTROL_PANEL_COMPOSE_DIR"/"app.yaml
130 output_yaml=$PWD/tmp/cp_app.yaml
131 __kube_create_instance app $CONTROL_PANEL_APP_NAME $input_yaml $output_yaml
135 echo " Retrieving host and ports for service..."
136 CP_HOST_NAME=$(__kube_get_service_host $CONTROL_PANEL_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
138 CONTROL_PANEL_EXTERNAL_PORT=$(__kube_get_service_port $CONTROL_PANEL_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
139 CONTROL_PANEL_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $CONTROL_PANEL_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
141 echo " Host IP, http port, https port: $CP_HOST_NAME $CONTROL_PANEL_EXTERNAL_PORT $CONTROL_PANEL_EXTERNAL_SECURE_PORT"
142 if [ $CP_HTTPX == "http" ]; then
143 CP_PATH=$CP_HTTPX"://"$CP_HOST_NAME":"$CONTROL_PANEL_EXTERNAL_PORT
145 CP_PATH=$CP_HTTPX"://"$CP_HOST_NAME":"$CONTROL_PANEL_EXTERNAL_SECURE_PORT
148 __check_service_start $CONTROL_PANEL_APP_NAME $CP_PATH$CONTROL_PANEL_ALIVE_URL
150 # Check if docker app shall be fully managed by the test script
151 __check_included_image 'CP'
152 if [ $? -eq 1 ]; then
153 echo -e $RED"The Control Panel app is not included in this test script"$ERED
154 echo -e $RED"The Control Panel will not be started"$ERED
158 # Export needed vars for docker compose
159 export CONTROL_PANEL_APP_NAME
160 export CONTROL_PANEL_INTERNAL_PORT
161 export CONTROL_PANEL_EXTERNAL_PORT
162 export CONTROL_PANEL_INTERNAL_SECURE_PORT
163 export CONTROL_PANEL_EXTERNAL_SECURE_PORT
164 export DOCKER_SIM_NWNAME
166 __start_container $CONTROL_PANEL_COMPOSE_DIR NODOCKERARGS 1 $CONTROL_PANEL_APP_NAME
168 __check_service_start $CONTROL_PANEL_APP_NAME $CP_PATH$CONTROL_PANEL_ALIVE_URL