adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # ============LICENSE_START==================================================== |
| 3 | # Copyright (C) 2022 Nordix Foundation. |
| 4 | # ============================================================================= |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # SPDX-License-Identifier: Apache-2.0 |
| 18 | # ============LICENSE_END====================================================== |
| 19 | # shellcheck disable=SC2039 |
| 20 | # shellcheck disable=SC2086 |
| 21 | # shellcheck disable=SC2012 |
| 22 | echo "Start of test $(date +%F-%T)" |
| 23 | |
| 24 | export POLICY_HOME=/opt/app/policy |
| 25 | export SQL_USER=policy_user |
| 26 | export SQL_PASSWORD=policy_user |
| 27 | export SQL_HOST=mariadb |
| 28 | export MYSQL_ROOT_PASSWORD=secret |
| 29 | export SCHEMA=policyadmin |
| 30 | export SCRIPT_DIRECTORY=sql |
| 31 | |
| 32 | # Test variables |
| 33 | TOTAL_COUNT=0 |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 34 | H_UPGRADE_COUNT=$(ls /home/policy/sql/0800/upgrade/*.sql | wc -l) |
| 35 | H_DOWNGRADE_COUNT=$(ls /home/policy/sql/0800/downgrade/*.sql | wc -l) |
| 36 | TOTAL_SQLS_UPGRADE=$H_UPGRADE_COUNT |
| 37 | TOTAL_SQLS_DOWNGRADE=$H_DOWNGRADE_COUNT |
| 38 | |
| 39 | I_UPGRADE_COUNT=$(ls /home/policy/sql/0900/upgrade/*.sql | wc -l) |
| 40 | I_DOWNGRADE_COUNT=$(ls /home/policy/sql/0900/downgrade/*.sql | wc -l) |
| 41 | TOTAL_SQLS_UPGRADE=$(($TOTAL_SQLS_UPGRADE+$I_UPGRADE_COUNT)) |
| 42 | TOTAL_SQLS_DOWNGRADE=$(($TOTAL_SQLS_DOWNGRADE+$I_DOWNGRADE_COUNT)) |
| 43 | |
| 44 | J_UPGRADE_COUNT=$(ls /home/policy/sql/1000/upgrade/*.sql | wc -l) |
| 45 | J_DOWNGRADE_COUNT=$(ls /home/policy/sql/1000/downgrade/*.sql | wc -l) |
| 46 | TOTAL_SQLS_UPGRADE=$(($TOTAL_SQLS_UPGRADE+$J_UPGRADE_COUNT)) |
| 47 | TOTAL_SQLS_DOWNGRADE=$(($TOTAL_SQLS_DOWNGRADE+$J_DOWNGRADE_COUNT)) |
| 48 | |
| 49 | K_UPGRADE_COUNT=$(ls /home/policy/sql/1100/upgrade/*.sql | wc -l) |
| 50 | K_DOWNGRADE_COUNT=$(ls /home/policy/sql/1100/downgrade/*.sql | wc -l) |
| 51 | TOTAL_SQLS_UPGRADE=$(($TOTAL_SQLS_UPGRADE+$K_UPGRADE_COUNT)) |
| 52 | TOTAL_SQLS_DOWNGRADE=$(($TOTAL_SQLS_DOWNGRADE+$K_DOWNGRADE_COUNT)) |
| 53 | |
| 54 | L_UPGRADE_COUNT=$(ls /home/policy/sql/1200/upgrade/*.sql | wc -l) |
| 55 | L_DOWNGRADE_COUNT=$(ls /home/policy/sql/1200/downgrade/*.sql | wc -l) |
| 56 | TOTAL_SQLS_UPGRADE=$(($TOTAL_SQLS_UPGRADE+$L_UPGRADE_COUNT)) |
| 57 | TOTAL_SQLS_DOWNGRADE=$(($TOTAL_SQLS_DOWNGRADE+$L_DOWNGRADE_COUNT)) |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 58 | |
adheli.tavares | 9fb99a6 | 2023-11-08 15:52:05 +0000 | [diff] [blame^] | 59 | M_UPGRADE_COUNT=$(ls /home/policy/sql/1300/upgrade/*.sql | wc -l) |
| 60 | M_DOWNGRADE_COUNT=$(ls /home/policy/sql/1300/downgrade/*.sql | wc -l) |
| 61 | TOTAL_SQLS_UPGRADE=$(($TOTAL_SQLS_UPGRADE+$M_UPGRADE_COUNT)) |
| 62 | TOTAL_SQLS_DOWNGRADE=$(($TOTAL_SQLS_DOWNGRADE+$M_DOWNGRADE_COUNT)) |
| 63 | |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 64 | NEW_SQL_EXECUTIONS=0 |
| 65 | START_VERSION="" |
| 66 | PREVIOUS_SQL_EXECUTIONS=0 |
| 67 | END_VERSION="" |
| 68 | RECENT_SQL_EXECUTIONS=0 |
| 69 | END_STATUS=0 |
| 70 | TEST_STATUS="FAIL" |
| 71 | TEST_MSG="" |
| 72 | TESTS=0 |
| 73 | PASSED=0 |
| 74 | FAILED=0 |
| 75 | |
| 76 | # SQL statements |
| 77 | PDPSTATISTICS="CREATE TABLE IF NOT EXISTS pdpstatistics (" |
| 78 | PDPSTATISTICS=${PDPSTATISTICS}"PDPGROUPNAME VARCHAR(120) NULL, " |
| 79 | PDPSTATISTICS=${PDPSTATISTICS}"PDPSUBGROUPNAME VARCHAR(120) NULL, " |
| 80 | PDPSTATISTICS=${PDPSTATISTICS}"POLICYDEPLOYCOUNT BIGINT DEFAULT NULL NULL, " |
| 81 | PDPSTATISTICS=${PDPSTATISTICS}"POLICYDEPLOYFAILCOUNT BIGINT DEFAULT NULL NULL, " |
| 82 | PDPSTATISTICS=${PDPSTATISTICS}"POLICYDEPLOYSUCCESSCOUNT BIGINT DEFAULT NULL NULL, " |
| 83 | PDPSTATISTICS=${PDPSTATISTICS}"POLICYEXECUTEDCOUNT BIGINT DEFAULT NULL NULL, " |
| 84 | PDPSTATISTICS=${PDPSTATISTICS}"POLICYEXECUTEDFAILCOUNT BIGINT DEFAULT NULL NULL, " |
| 85 | PDPSTATISTICS=${PDPSTATISTICS}"POLICYEXECUTEDSUCCESSCOUNT BIGINT DEFAULT NULL NULL, " |
| 86 | PDPSTATISTICS2=${PDPSTATISTICS}"POLICYUNDEPLOYCOUNT BIGINT DEFAULT NULL NULL, " |
| 87 | PDPSTATISTICS2=${PDPSTATISTICS2}"POLICYUNDEPLOYFAILCOUNT BIGINT DEFAULT NULL NULL, " |
| 88 | PDPSTATISTICS2=${PDPSTATISTICS2}"POLICYUNDEPLOYSUCCESSCOUNT BIGINT DEFAULT NULL NULL, " |
| 89 | PDPSTATISTICS=${PDPSTATISTICS}"timeStamp datetime NOT NULL, " |
| 90 | PDPSTATISTICS2=${PDPSTATISTICS2}"timeStamp datetime DEFAULT NULL NULL, " |
| 91 | PDPSTATISTICS2=${PDPSTATISTICS2}"ID BIGINT NOT NULL, " |
| 92 | PDPSTATISTICS=${PDPSTATISTICS}"name VARCHAR(120) NOT NULL, " |
| 93 | PDPSTATISTICS2=${PDPSTATISTICS2}"name VARCHAR(120) NOT NULL, " |
| 94 | PDPSTATISTICS=${PDPSTATISTICS}"version VARCHAR(20) NOT NULL," |
| 95 | PDPSTATISTICS2=${PDPSTATISTICS2}"version VARCHAR(20) NOT NULL," |
| 96 | PDPSTATISTICS=${PDPSTATISTICS}"CONSTRAINT PK_PDPSTATISTICS PRIMARY KEY (timeStamp, name, version));" |
| 97 | PDPSTATISTICS2=${PDPSTATISTICS2}"CONSTRAINT PK_PDPSTATISTICS PRIMARY KEY (ID, name, version));" |
| 98 | |
| 99 | IDX_TSIDX1="CREATE INDEX IDX_TSIDX1 ON pdpstatistics(timeStamp, name, version);" |
| 100 | INSERT="INSERT INTO pdpstatistics(PDPGROUPNAME,PDPSUBGROUPNAME,POLICYDEPLOYCOUNT,POLICYDEPLOYFAILCOUNT,POLICYDEPLOYSUCCESSCOUNT," |
| 101 | INSERT1="${INSERT}""POLICYEXECUTEDCOUNT,POLICYEXECUTEDFAILCOUNT,POLICYEXECUTEDSUCCESSCOUNT,timeStamp,name,version)" |
| 102 | INSERT2="${INSERT}""POLICYEXECUTEDCOUNT,POLICYEXECUTEDFAILCOUNT,POLICYEXECUTEDSUCCESSCOUNT,POLICYUNDEPLOYCOUNT," |
| 103 | INSERT2="${INSERT2}""POLICYUNDEPLOYFAILCOUNT,POLICYUNDEPLOYSUCCESSCOUNT,timeStamp,ID,name,version)" |
| 104 | SQL1="${INSERT1}"" values('groupname', 'subgroup',1,1,1,1,1,1,now(),'test1', '1.0')" |
| 105 | SQL2="${INSERT1}"" values('groupname', 'subgroup',1,1,1,1,1,1,now(),'test1', '1.0')" |
| 106 | SQL3="${INSERT2}"" values('groupname', 'subgroup',1,1,1,1,1,1,1,1,1,now(),3,'test1', '1.0')" |
| 107 | SQL4="${INSERT2}"" values('groupname', 'subgroup',1,1,1,1,1,1,1,1,1,now(),4,'test1', '1.0')" |
| 108 | SQL5="${INSERT1}"" values('groupname', 'subgroup',1,1,1,1,1,1,now(),'test2', '1.0')" |
| 109 | SQL6="${INSERT1}"" values('groupname', 'subgroup',1,1,1,1,1,1,now(),'test2', '1.0')" |
| 110 | |
| 111 | run_sql() { |
| 112 | local user="${1}" password="${2}" schema="${3}" sql="${4}" |
| 113 | MYSQL="mysql -u${user} -p${password} -h ${SQL_HOST} ${schema}" |
| 114 | ${MYSQL} --execute "${sql}" |
| 115 | return $? |
| 116 | } |
| 117 | |
| 118 | start_test() { |
| 119 | echo "" |
| 120 | echo "############################################################################################################" |
| 121 | echo "" |
| 122 | let TESTS=$TESTS+1 |
| 123 | reportStatus=$(/opt/app/policy/bin/db-migrator -s ${SQL_DB} -o report | tail -2) |
| 124 | echo "Starting test $TESTS" |
| 125 | echo "$reportStatus" |
| 126 | START_VERSION=$(echo $reportStatus | cut -f13 -d' ') |
| 127 | PREVIOUS_SQL_EXECUTIONS=$(echo $reportStatus | cut -f1 -d' ') |
| 128 | |
| 129 | if [ "${START_VERSION}" == "" ]; then |
| 130 | START_VERSION="0" |
| 131 | PREVIOUS_SQL_EXECUTIONS=0 |
| 132 | fi |
| 133 | } |
| 134 | |
| 135 | end_test() { |
| 136 | reportStatus=$(/opt/app/policy/bin/db-migrator -s ${SQL_DB} -o report | tail -2) |
| 137 | echo "Ending test $TESTS" |
| 138 | echo "$reportStatus" |
| 139 | END_VERSION=$(echo $reportStatus | cut -f13 -d' ') |
| 140 | RECENT_SQL_EXECUTIONS=$(echo $reportStatus | cut -f1 -d' ') |
| 141 | END_STATUS=$(echo $reportStatus | cut -f7 -d' ') |
| 142 | } |
| 143 | |
| 144 | check_results() { |
| 145 | local status="${1}" operation="${2}" startVer="${3}" endVer="${4}" newRecords="${5}" filesRan="${6}" |
| 146 | |
| 147 | echo "" |
| 148 | echo "Test summary: status:$status, operation:$operation, from:$startVer, to:$endVer, new executions:$newRecords, sqlFiles:$filesRan" |
| 149 | # Convert to number |
| 150 | startVer=$(echo ${startVer} | awk '{$0=int($0)}1') |
| 151 | endVer=$(echo ${endVer} | awk '{$0=int($0)}1') |
| 152 | |
| 153 | if [ ${startVer} -eq ${endVer} ] && [ $newRecords -eq $filesRan ] && [ $newRecords -eq 0 ]; then |
| 154 | TEST_MSG="No ${operation} required" |
| 155 | TEST_STATUS="PASS" |
| 156 | let PASSED=$PASSED+1 |
| 157 | elif [ $status -eq 1 ] && [ "${operation}" == "upgrade" ] && [ ${startVer} -le ${endVer} ] && [ $newRecords -eq $filesRan ]; then |
| 158 | TEST_MSG="Successful ${operation}" |
| 159 | TEST_STATUS="PASS" |
| 160 | let PASSED=$PASSED+1 |
| 161 | elif [ $status -eq 1 ] && [ "${operation}" == "downgrade" ] && [ ${startVer} -ge ${endVer} ] && [ $newRecords -eq $filesRan ]; then |
| 162 | TEST_MSG="Successful ${operation}" |
| 163 | TEST_STATUS="PASS" |
| 164 | let PASSED=$PASSED+1 |
| 165 | else |
| 166 | TEST_MSG="Errors occurred during ${operation}" |
| 167 | TEST_STATUS="FAIL" |
| 168 | let FAILED=$FAILED+1 |
| 169 | fi |
| 170 | echo "" |
| 171 | echo "*** Test $TESTS: $TEST_STATUS , $TEST_MSG, current version: $END_VERSION ***" |
| 172 | echo "" |
| 173 | } |
| 174 | |
| 175 | # Test 1 - Upgrade to Istanbul |
| 176 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 177 | start_test |
| 178 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade -t 0900 |
| 179 | end_test |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 180 | let TOTAL_COUNT=$H_UPGRADE_COUNT+$I_UPGRADE_COUNT |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 181 | check_results $END_STATUS 'upgrade' "${START_VERSION}" "${END_VERSION}" $RECENT_SQL_EXECUTIONS $TOTAL_COUNT |
| 182 | |
| 183 | sleep 5 |
| 184 | |
| 185 | # Test 2 - downgrade to 0800 |
| 186 | start_test |
| 187 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
| 188 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0900 -t 0800 |
| 189 | end_test |
| 190 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 191 | check_results $END_STATUS 'downgrade' "${START_VERSION}" "${END_VERSION}" $NEW_SQL_EXECUTIONS $I_UPGRADE_COUNT |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 192 | |
| 193 | sleep 5 |
| 194 | |
| 195 | # Test 3 - upgrade to 0900 |
| 196 | start_test |
| 197 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 198 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade -f 0800 -t 0900 |
| 199 | end_test |
| 200 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 201 | check_results $END_STATUS 'upgrade' "${START_VERSION}" "${END_VERSION}" $NEW_SQL_EXECUTIONS $I_UPGRADE_COUNT |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 202 | |
| 203 | sleep 5 |
| 204 | |
| 205 | # Test4 - run upgrade on db where tables already exist and migration schema is empty |
| 206 | start_test |
| 207 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
| 208 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0900 -t 0800 |
| 209 | run_sql "root" "${MYSQL_ROOT_PASSWORD}" "${SCHEMA}" "DROP DATABASE IF EXISTS migration;" |
| 210 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 211 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade -t 0900 |
| 212 | end_test |
| 213 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 214 | check_results $END_STATUS 'upgrade' "0800" "${END_VERSION}" $NEW_SQL_EXECUTIONS $I_UPGRADE_COUNT |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 215 | |
| 216 | sleep 5 |
| 217 | |
| 218 | # Test5 - upgrade after failed downgrade |
| 219 | start_test |
| 220 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
| 221 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "DROP table pdpstatistics;" |
| 222 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0900 -t 0800 |
| 223 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${PDPSTATISTICS2}" |
| 224 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${IDX_TSIDX1}" |
| 225 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 226 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade -f 0800 -t 0900 |
| 227 | end_test |
| 228 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
| 229 | # (files run before error * 2) + 1 to run the file again |
| 230 | let TOTAL_COUNT=11 |
| 231 | check_results $END_STATUS 'upgrade' "0800" "0900" $NEW_SQL_EXECUTIONS $TOTAL_COUNT |
| 232 | |
| 233 | sleep 5 |
| 234 | |
| 235 | # Test6 - Downgrade after failed downgrade |
| 236 | start_test |
| 237 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
| 238 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "DROP table pdpstatistics;" |
| 239 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0900 -t 0800 |
| 240 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${PDPSTATISTICS2}" |
| 241 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${IDX_TSIDX1}" |
| 242 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0900 -t 0800 |
| 243 | end_test |
| 244 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
| 245 | # +1 to run the file again |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 246 | let TOTAL_COUNT=$I_UPGRADE_COUNT+1 |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 247 | check_results $END_STATUS 'downgrade' "${START_VERSION}" "${END_VERSION}" $NEW_SQL_EXECUTIONS $TOTAL_COUNT |
| 248 | |
| 249 | sleep 5 |
| 250 | |
| 251 | # Test7 - downgrade after failed upgrade |
| 252 | start_test |
| 253 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 254 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "DROP table pdpstatistics;" |
| 255 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade -f 0800 -t 0900 |
| 256 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${PDPSTATISTICS}" |
| 257 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
| 258 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0900 -t 0800 |
| 259 | end_test |
| 260 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
| 261 | # (files run before error * 2) + 1 to run the file again |
| 262 | let TOTAL_COUNT=3 |
| 263 | check_results $END_STATUS 'downgrade' "${START_VERSION}" "${END_VERSION}" $NEW_SQL_EXECUTIONS $TOTAL_COUNT |
| 264 | |
| 265 | sleep 5 |
| 266 | |
| 267 | # Test 8 - Upgrade after failed upgrade |
| 268 | start_test |
| 269 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 270 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "DROP table pdpstatistics;" |
| 271 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade -f 0800 -t 0900 |
| 272 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${PDPSTATISTICS}" |
| 273 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade -t 0900 |
| 274 | end_test |
| 275 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
| 276 | # +1 to run the file again |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 277 | let TOTAL_COUNT=$I_UPGRADE_COUNT+1 |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 278 | check_results $END_STATUS 'upgrade' "${START_VERSION}" "${END_VERSION}" $NEW_SQL_EXECUTIONS $TOTAL_COUNT |
| 279 | |
| 280 | sleep 5 |
| 281 | |
| 282 | # Test 9 - Upgrade when pdpstatistics contains data |
| 283 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
| 284 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0900 -t 0800 |
| 285 | start_test |
| 286 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${SQL1}" |
| 287 | sleep 1 |
| 288 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${SQL2}" |
| 289 | sleep 1 |
| 290 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 291 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade -f 0800 -t 0900 |
| 292 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${SQL3}" |
| 293 | sleep 1 |
| 294 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${SQL4}" |
| 295 | end_test |
| 296 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
| 297 | # +1 to run the file again |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 298 | let TOTAL_COUNT=$I_UPGRADE_COUNT |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 299 | check_results $END_STATUS 'upgrade' "${START_VERSION}" "${END_VERSION}" $NEW_SQL_EXECUTIONS $TOTAL_COUNT |
| 300 | |
| 301 | sleep 5 |
| 302 | |
| 303 | # Test 10 - downgrade to 0800 with records in pdpstatistics |
| 304 | start_test |
| 305 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
| 306 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0900 -t 0800 |
| 307 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${SQL5}" |
| 308 | sleep 1 |
| 309 | run_sql "${SQL_USER}" "${SQL_PASSWORD}" "${SCHEMA}" "${SQL6}" |
| 310 | end_test |
| 311 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 312 | check_results $END_STATUS 'downgrade' "${START_VERSION}" "${END_VERSION}" $NEW_SQL_EXECUTIONS $I_UPGRADE_COUNT |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 313 | |
| 314 | sleep 5 |
| 315 | |
| 316 | # Test 11 - downgrade from 0800 |
| 317 | start_test |
| 318 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
| 319 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 0800 |
| 320 | end_test |
| 321 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 322 | check_results $END_STATUS 'downgrade' "${START_VERSION}" "${END_VERSION}" $NEW_SQL_EXECUTIONS $H_DOWNGRADE_COUNT |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 323 | |
| 324 | sleep 5 |
| 325 | |
| 326 | # Test 12 - Full upgrade |
| 327 | start_test |
| 328 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 329 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade |
| 330 | end_test |
| 331 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 332 | check_results $END_STATUS 'upgrade' "0" "${END_VERSION}" $NEW_SQL_EXECUTIONS $TOTAL_SQLS_UPGRADE |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 333 | |
| 334 | sleep 5 |
| 335 | |
| 336 | # Test 13 - Full downgrade |
| 337 | start_test |
| 338 | /opt/app/policy/bin/prepare_downgrade.sh ${SQL_DB} |
adheli.tavares | 9fb99a6 | 2023-11-08 15:52:05 +0000 | [diff] [blame^] | 339 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o downgrade -f 1300 -t 0 |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 340 | end_test |
| 341 | let NEW_SQL_EXECUTIONS=$RECENT_SQL_EXECUTIONS-$PREVIOUS_SQL_EXECUTIONS |
adheli.tavares | 864b623 | 2023-02-08 09:24:26 +0000 | [diff] [blame] | 342 | check_results $END_STATUS 'downgrade' "${START_VERSION}" "0" $NEW_SQL_EXECUTIONS $TOTAL_SQLS_DOWNGRADE |
| 343 | |
| 344 | # Install database |
| 345 | /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB} |
| 346 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade |
| 347 | /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o report |
adheli.tavares | 7a58ae1 | 2022-03-28 12:29:01 +0100 | [diff] [blame] | 348 | |
| 349 | echo |
| 350 | echo "-----------------------------------------------------------------------" |
| 351 | echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED" |
| 352 | echo "-----------------------------------------------------------------------" |
| 353 | |
| 354 | echo "End of test $(date +%F-%T)" |
| 355 | |
| 356 | nc -lk -p 6824 |
| 357 | |
| 358 | exit 0 |