rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START==================================================== |
| 4 | # Copyright (C) 2022-2023 Nordix Foundation. |
| 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 | # |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ============LICENSE_END====================================================== |
| 20 | |
| 21 | # This script spins up kubernetes cluster in Microk8s for deploying policy helm charts. |
| 22 | # Runs CSITs in kubernetes. |
| 23 | |
| 24 | if [ -z "${WORKSPACE}" ]; then |
| 25 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 26 | export WORKSPACE |
| 27 | fi |
| 28 | |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 29 | export GERRIT_BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${WORKSPACE}"/.gitreview) |
| 30 | |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 31 | CSIT_SCRIPT="scripts/run-test.sh" |
| 32 | ROBOT_DOCKER_IMAGE="policy-csit-robot" |
| 33 | POLICY_CLAMP_ROBOT="policy-clamp-test.robot" |
waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 34 | POLICY_API_ROBOT="api-test.robot api-slas.robot" |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 35 | POLICY_PAP_ROBOT="pap-test.robot pap-slas.robot" |
waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 36 | POLICY_APEX_PDP_ROBOT="apex-pdp-test.robot apex-slas.robot" |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 37 | POLICY_XACML_PDP_ROBOT="xacml-pdp-test.robot" |
| 38 | POLICY_DROOLS_PDP_ROBOT="drools-pdp-test.robot" |
| 39 | POLICY_DISTRIBUTION_ROBOT="distribution-test.robot" |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 40 | |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 41 | POLICY_API_CONTAINER="policy-api" |
| 42 | POLICY_PAP_CONTAINER="policy-pap" |
| 43 | POLICY_CLAMP_CONTAINER="policy-clamp-runtime-acm" |
| 44 | POLICY_APEX_CONTAINER="policy-apex-pdp" |
| 45 | POLICY_DROOLS_CONTAINER="policy-drools-pdp" |
| 46 | POLICY_XACML_CONTAINER="policy-xacml-pdp" |
| 47 | POLICY_DISTRIBUTION_CONTAINER="policy-distribution" |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 48 | POLICY_K8S_PPNT_CONTAINER="policy-clamp-ac-k8s-ppnt" |
| 49 | POLICY_HTTP_PPNT_CONTAINER="policy-clamp-ac-http-ppnt" |
| 50 | POLICY_PF_PPNT_CONTAINER="policy-clamp-ac-pf-ppnt" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 51 | SET_VALUES="" |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 52 | |
| 53 | DISTRIBUTION_CSAR=${WORKSPACE}/csit/resources/tests/data/csar |
| 54 | DIST_TEMP_FOLDER=/tmp/distribution |
| 55 | |
| 56 | export PROJECT="" |
| 57 | export ROBOT_FILE="" |
| 58 | export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives |
| 59 | export READINESS_CONTAINERS=() |
| 60 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 61 | function spin_microk8s_cluster() { |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 62 | echo "Verify if Microk8s cluster is running.." |
| 63 | microk8s version |
| 64 | exitcode="${?}" |
| 65 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 66 | if [ "$exitcode" -ne 0 ]; then |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 67 | echo "Microk8s cluster not available, Spinning up the cluster.." |
| 68 | sudo snap install microk8s --classic --channel=1.25/stable |
| 69 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 70 | if [ "${?}" -ne 0 ]; then |
| 71 | echo "Failed to install kubernetes cluster. Aborting.." |
| 72 | return 1 |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 73 | fi |
| 74 | echo "Microk8s cluster installed successfully" |
| 75 | sudo usermod -a -G microk8s $USER |
| 76 | echo "Enabling DNS and helm3 plugins" |
| 77 | sudo microk8s.enable dns helm3 hostpath-storage |
| 78 | echo "Creating configuration file for Microk8s" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 79 | sudo mkdir -p $HOME/.kube |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 80 | sudo chown -R $USER:$USER $HOME/.kube |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 81 | sudo microk8s kubectl config view --raw >$HOME/.kube/config |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 82 | sudo chmod 600 $HOME/.kube/config |
| 83 | echo "K8s installation completed" |
| 84 | echo "----------------------------------------" |
| 85 | else |
| 86 | echo "K8s cluster is already running" |
| 87 | echo "----------------------------------------" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 88 | return 0 |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 89 | fi |
| 90 | |
| 91 | } |
| 92 | |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 93 | function uninstall_policy() { |
| 94 | echo "Removing the policy helm deployment" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 95 | sudo microk8s helm uninstall csit-policy |
| 96 | sudo microk8s helm uninstall prometheus |
| 97 | sudo microk8s helm uninstall csit-robot |
| 98 | rm -rf ${WORKSPACE}/helm/policy/Chart.lock |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 99 | sudo rm -rf /dockerdata-nfs/mariadb-galera/ |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 100 | echo "Policy deployment deleted" |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 101 | echo "Clean up docker" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 102 | docker image prune -f |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 103 | } |
| 104 | |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 105 | function teardown_cluster() { |
| 106 | echo "Removing k8s cluster and k8s configuration file" |
| 107 | sudo snap remove microk8s;rm -rf $HOME/.kube/config |
| 108 | echo "MicroK8s Cluster removed" |
| 109 | } |
| 110 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 111 | function build_robot_image() { |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 112 | echo "Build docker image for robot framework" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 113 | cd ${WORKSPACE}/csit/resources || exit |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 114 | clone_models |
| 115 | if [ "${PROJECT}" == "distribution" ] || [ "${PROJECT}" == "policy-distribution" ]; then |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 116 | copy_csar_file |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 117 | fi |
| 118 | echo "Build robot framework docker image" |
| 119 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 120 | docker build . --file Dockerfile \ |
| 121 | --build-arg CSIT_SCRIPT="$CSIT_SCRIPT" \ |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 122 | --build-arg ROBOT_FILE="$ROBOT_FILE" \ |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 123 | --tag "${ROBOT_DOCKER_IMAGE}" --no-cache |
| 124 | echo "---------------------------------------------" |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 125 | } |
| 126 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 127 | function start_csit() { |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 128 | build_robot_image |
| 129 | if [ "${?}" -eq 0 ]; then |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 130 | echo "Importing robot image into microk8s registry" |
| 131 | docker save -o policy-csit-robot.tar ${ROBOT_DOCKER_IMAGE}:latest |
| 132 | sudo microk8s ctr image import policy-csit-robot.tar |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 133 | rm -rf ${WORKSPACE}/csit/resources/policy-csit-robot.tar |
| 134 | rm -rf ${WORKSPACE}/csit/resources/tests/models/ |
| 135 | echo "---------------------------------------------" |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 136 | if [ $PROJECT == "clamp" ] || [ $PROJECT == "policy-clamp" ]; then |
| 137 | POD_READY_STATUS="0/1" |
| 138 | while [[ ${POD_READY_STATUS} != "1/1" ]]; do |
| 139 | echo "Waiting for chartmuseum pod to come up..." |
| 140 | sleep 5 |
| 141 | POD_READY_STATUS=$(microk8s kubectl get pods | grep -e "policy-chartmuseum" | awk '{print $2}') |
| 142 | done |
| 143 | push_acelement_chart |
| 144 | fi |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 145 | echo "Installing Robot framework pod for running CSIT" |
| 146 | cd ${WORKSPACE}/helm |
| 147 | mkdir -p ${ROBOT_LOG_DIR} |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 148 | sudo microk8s helm install csit-robot robot --set robot="$ROBOT_FILE" --set "readiness={${READINESS_CONTAINERS[*]}}" --set robotLogDir=$ROBOT_LOG_DIR |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 149 | print_robot_log |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 150 | teardown_cluster |
| 151 | fi |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 152 | } |
| 153 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 154 | function print_robot_log() { |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 155 | count_pods=0 |
| 156 | while [[ ${count_pods} -eq 0 ]]; do |
| 157 | echo "Waiting for pods to come up..." |
| 158 | sleep 5 |
| 159 | count_pods=$(sudo microk8s kubectl get pods --output name | wc -l) |
| 160 | done |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 161 | sudo microk8s kubectl get po |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 162 | robotpod=$(sudo microk8s kubectl get po | grep policy-csit) |
| 163 | podName=$(echo "$robotpod" | awk '{print $1}') |
| 164 | echo "The robot tests will begin once the policy components {${READINESS_CONTAINERS[*]}} are up and running..." |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 165 | sudo microk8s kubectl wait --for=jsonpath='{.status.phase}'=Running --timeout=10m pod/"$podName" |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 166 | sudo microk8s kubectl logs -f "$podName" |
| 167 | echo "Please check the logs of policy-csit-robot pod for the test execution results" |
| 168 | } |
| 169 | |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 170 | |
| 171 | function clone_models () { |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 172 | # download models examples |
| 173 | git clone -b "${GERRIT_BRANCH}" --single-branch https://github.com/onap/policy-models.git "${WORKSPACE}"/csit/resources/tests/models |
| 174 | |
| 175 | # create a couple of variations of the policy definitions |
| 176 | sed -e 's!Measurement_vGMUX!ADifferentValue!' \ |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 177 | tests/models/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.json \ |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 178 | >tests/models/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.v1_2.json |
| 179 | |
| 180 | sed -e 's!"version": "1.0.0"!"version": "2.0.0"!' \ |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 181 | -e 's!"policy-version": 1!"policy-version": 2!' \ |
| 182 | tests/models/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.json \ |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 183 | >tests/models/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.v2.json |
| 184 | } |
| 185 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 186 | function copy_csar_file() { |
| 187 | zip -F ${DISTRIBUTION_CSAR}/sample_csar_with_apex_policy.csar \ |
| 188 | --out ${DISTRIBUTION_CSAR}/csar_temp.csar -q |
| 189 | # Remake temp directory |
| 190 | sudo rm -rf "${DIST_TEMP_FOLDER}" |
| 191 | sudo mkdir "${DIST_TEMP_FOLDER}" |
| 192 | sudo cp ${DISTRIBUTION_CSAR}/csar_temp.csar ${DISTRIBUTION_CSAR}/temp.csar |
| 193 | sudo mv ${DISTRIBUTION_CSAR}/temp.csar ${DIST_TEMP_FOLDER}/sample_csar_with_apex_policy.csar |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 194 | } |
| 195 | |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 196 | |
| 197 | function set_project_config() { |
| 198 | echo "Setting project configuration for: $PROJECT" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 199 | case $PROJECT in |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 200 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 201 | clamp | policy-clamp) |
| 202 | export ROBOT_FILE=$POLICY_CLAMP_ROBOT |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 203 | export READINESS_CONTAINERS=($POLICY_CLAMP_CONTAINER,$POLICY_APEX_CONTAINER,$POLICY_PF_PPNT_CONTAINER,$POLICY_K8S_PPNT_CONTAINER, |
| 204 | $POLICY_HTTP_PPNT_CONTAINER) |
| 205 | export SET_VALUES="--set $POLICY_CLAMP_CONTAINER.enabled=true --set $POLICY_APEX_CONTAINER.enabled=true |
| 206 | --set $POLICY_PF_PPNT_CONTAINER.enabled=true --set $POLICY_K8S_PPNT_CONTAINER.enabled=true --set $POLICY_HTTP_PPNT_CONTAINER.enabled=true" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 207 | ;; |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 208 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 209 | api | policy-api) |
| 210 | export ROBOT_FILE=$POLICY_API_ROBOT |
| 211 | export READINESS_CONTAINERS=($POLICY_API_CONTAINER) |
| 212 | ;; |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 213 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 214 | pap | policy-pap) |
| 215 | export ROBOT_FILE=$POLICY_PAP_ROBOT |
| 216 | export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_PAP_CONTAINER,$POLICY_API_CONTAINER,$POLICY_DROOLS_CONTAINER, |
| 217 | $POLICY_XACML_CONTAINER) |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 218 | export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true --set $POLICY_DROOLS_CONTAINER.enabled=true --set $POLICY_XACML_CONTAINER.enabled=true" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 219 | ;; |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 220 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 221 | apex-pdp | policy-apex-pdp) |
| 222 | export ROBOT_FILE=$POLICY_APEX_PDP_ROBOT |
| 223 | export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER) |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 224 | export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 225 | ;; |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 226 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 227 | xacml-pdp | policy-xacml-pdp) |
| 228 | export ROBOT_FILE=($POLICY_XACML_PDP_ROBOT) |
| 229 | export READINESS_CONTAINERS=($POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER,$POLICY_XACML_CONTAINER) |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 230 | export SET_VALUES="--set $POLICY_XACML_CONTAINER.enabled=true" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 231 | ;; |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 232 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 233 | drools-pdp | policy-drools-pdp) |
| 234 | export ROBOT_FILE=($POLICY_DROOLS_PDP_ROBOT) |
| 235 | export READINESS_CONTAINERS=($POLICY_DROOLS_CONTAINER) |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 236 | export SET_VALUES="--set $POLICY_DROOLS_CONTAINER.enabled=true" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 237 | ;; |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 238 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 239 | distribution | policy-distribution) |
| 240 | export ROBOT_FILE=($POLICY_DISTRIBUTION_ROBOT) |
| 241 | export READINESS_CONTAINERS=($POLICY_APEX_CONTAINER,$POLICY_API_CONTAINER,$POLICY_PAP_CONTAINER, |
| 242 | $POLICY_DISTRIBUTION_CONTAINER) |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 243 | export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true --set $POLICY_DISTRIBUTION_CONTAINER.enabled=true" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 244 | ;; |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 245 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 246 | *) |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 247 | echo "Unknown project supplied. Enabling all policy charts for the deployment" |
| 248 | export SET_VALUES="--set $POLICY_APEX_CONTAINER.enabled=true --set $POLICY_XACML_CONTAINER.enabled=true |
| 249 | --set $POLICY_DISTRIBUTION_CONTAINER.enabled=true --set $POLICY_POLICY_DROOLS_CONTAINER.enabled=true |
| 250 | --set $POLICY_CLAMP_CONTAINER.enabled=true --set $POLICY_PF_PPNT_CONTAINER.enabled=true |
| 251 | --set $POLICY_K8S_PPNT_CONTAINER.enabled=true --set $POLICY_HTTP_PPNT_CONTAINER.enabled=true" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 252 | ;; |
| 253 | esac |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 254 | |
| 255 | } |
| 256 | |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 257 | function install_chartmuseum () { |
| 258 | echo "Installing Chartmuseum helm repository..." |
| 259 | sudo microk8s helm repo add chartmuseum-git https://chartmuseum.github.io/charts |
| 260 | sudo microk8s helm repo update |
| 261 | sudo microk8s helm install policy-chartmuseum chartmuseum-git/chartmuseum --set env.open.DISABLE_API=false --set service.type=NodePort --set service.nodePort=30208 |
| 262 | sudo microk8s helm plugin install https://github.com/chartmuseum/helm-push |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 263 | } |
| 264 | |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 265 | function push_acelement_chart() { |
| 266 | echo "Pushing acelement chart to the chartmuseum repo..." |
| 267 | sudo microk8s helm repo add policy-chartmuseum http://localhost:30208 |
| 268 | |
| 269 | # download clamp repo |
| 270 | git clone -b "${GERRIT_BRANCH}" --single-branch https://github.com/onap/policy-clamp.git "${WORKSPACE}"/csit/resources/tests/clamp |
| 271 | ACELEMENT_CHART=${WORKSPACE}/csit/resources/tests/clamp/examples/src/main/resources/clamp/acm/acelement-helm/acelement |
| 272 | sudo microk8s helm cm-push $ACELEMENT_CHART policy-chartmuseum |
| 273 | sudo microk8s helm repo update |
| 274 | echo "-------------------------------------------" |
| 275 | } |
| 276 | |
| 277 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 278 | OPERATION="$1" |
| 279 | PROJECT="$2" |
| 280 | |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 281 | if [ $OPERATION == "install" ]; then |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 282 | spin_microk8s_cluster |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 283 | if [ "${?}" -eq 0 ]; then |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 284 | set_project_config |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 285 | echo "Installing policy helm charts in the default namespace" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 286 | cd ${WORKSPACE}/helm || exit |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 287 | sudo microk8s helm dependency build policy |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 288 | sudo microk8s helm install csit-policy policy ${SET_VALUES} |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 289 | sudo microk8s helm install prometheus prometheus |
| 290 | echo "Policy chart installation completed" |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 291 | echo "-------------------------------------------" |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 292 | fi |
| 293 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 294 | if [ "$PROJECT" ]; then |
| 295 | export $PROJECT |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 296 | export ROBOT_LOG_DIR=${WORKSPACE}/csit/archives/${PROJECT} |
| 297 | get_robot_file |
| 298 | echo "CSIT will be invoked from $ROBOT_FILE" |
| 299 | echo "Readiness containers: ${READINESS_CONTAINERS[*]}" |
| 300 | echo "-------------------------------------------" |
| 301 | start_csit |
| 302 | else |
| 303 | echo "No project supplied for running CSIT" |
| 304 | fi |
| 305 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 306 | elif [ $OPERATION == "uninstall" ]; then |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 307 | uninstall_policy |
| 308 | |
| 309 | elif [ $OPERATION == "clean" ]; then |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 310 | teardown_cluster |
| 311 | else |
rameshiyer27 | e909866 | 2023-04-03 00:57:58 +0100 | [diff] [blame] | 312 | echo "Invalid arguments provided. Usage: $0 [option..] {install {project} | uninstall} | {clean}" |
rameshiyer27 | 181e6c5 | 2023-03-30 10:50:18 +0100 | [diff] [blame] | 313 | fi |