Anna Arhipova | 7717848 | 2023-06-14 11:46:42 +0200 | [diff] [blame^] | 1 | #!/bin/bash |
Anna Arhipova | d2ced49 | 2022-09-28 10:02:56 +0200 | [diff] [blame] | 2 | # export REMOTE_JENKINS='172.19.112.216' |
Anna Arhipova | 7717848 | 2023-06-14 11:46:42 +0200 | [diff] [blame^] | 3 | set -eo pipefail; |
Anna Arhipova | d2ced49 | 2022-09-28 10:02:56 +0200 | [diff] [blame] | 4 | export REMOTE_JENKINS='sre-ci.scc.mirantis.net' |
| 5 | |
| 6 | if [ ! -n "$LAB_CONTEXT_NAME" ]; then |
| 7 | echo 'LAB_CONTEXT_NAME is not set! |
| 8 | This name will be used: |
| 9 | - to find the template file tcp_tests/templates/cookied-model-generator/salt_${LAB_CONTEXT_NAME}.yaml |
| 10 | - to set the salt model cluster name |
| 11 | - to make DOMAIN_NAME=${LAB_CONTEXT_NAME}.local |
| 12 | '; |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | |
| 17 | if [ -n "$TCP_QA_REVIEW" ]; then |
| 18 | git fetch https://gerrit.mcp.mirantis.com/mcp/tcp-qa $TCP_QA_REVIEW && git checkout FETCH_HEAD |
| 19 | fi |
| 20 | |
| 21 | . ${VENV_PATH}/bin/activate |
| 22 | |
| 23 | if [ "$ERASE_EXISTING_ENVIRONMENT" = "true" ]; then |
| 24 | dos.py erase $ENV_NAME || true |
| 25 | fi |
| 26 | |
| 27 | cd tcp_tests |
| 28 | |
| 29 | sed -i 's/%LOGIN%/rHm22xBV9K/' templates/${LAB_CONTEXT_NAME}/salt-context-cookiecutter* |
| 30 | sed -i 's/%PASS%/az9Gq7Wq4jRic29YWP/' templates/${LAB_CONTEXT_NAME}/salt-context-cookiecutter* |
| 31 | |
| 32 | rm -f ./*.tar.gz |
| 33 | |
| 34 | #MODEL_FILENAME=model_${CLUSTER_NAME}_${BUILD_NUMBER}.tar.gz |
| 35 | MODEL_FILENAME=model_${ENV_NAME}.tar.gz |
| 36 | if [[ -f $MODEL_FILENAME ]]; then |
| 37 | rm $MODEL_FILENAME |
| 38 | fi |
| 39 | |
| 40 | #################### |
| 41 | # Generate the model |
| 42 | git config user.name "tester" |
| 43 | git config user.email "tester@example.com" |
| 44 | |
| 45 | py.test --junit-xml=deploy_generate_model.xml -k ${TEST_GROUP} |
| 46 | |
| 47 | |
| 48 | ######################################################## |
| 49 | # Upload the generated model to the repository on cz8133 |
| 50 | |
| 51 | # Create a directory where the created model will be unpacked |
| 52 | rm -rf ./model |
| 53 | mkdir -p ./model |
| 54 | |
| 55 | eval $(ssh-agent) |
| 56 | ssh-add ${COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH} |
| 57 | |
| 58 | # Create remote repository |
| 59 | ssh jenkins@${REMOTE_JENKINS} " |
| 60 | if [[ ! -d /home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git ]]; then |
| 61 | mkdir -p /home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git; |
| 62 | cd /home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git; |
| 63 | git init --bare; |
| 64 | cp hooks/post-update.sample hooks/post-update; |
| 65 | fi" |
| 66 | |
| 67 | cd ./model |
| 68 | |
| 69 | # Prepare the repository in the ./model |
| 70 | git init |
| 71 | git remote add integration ssh://jenkins@${REMOTE_JENKINS}/home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git |
| 72 | git pull integration ${REPOSITORY_SUITE} || true |
| 73 | git checkout -b ${REPOSITORY_SUITE} |
| 74 | git rm -rf . || true # remove previous content from the working dir |
| 75 | |
| 76 | # unpack new model into ./model dir |
| 77 | tar -xzf ../${MODEL_FILENAME} -C ./ |
| 78 | # Add reclass-system submodule |
| 79 | git submodule add https://gerrit.mcp.mirantis.com/salt-models/reclass-system classes/system/ |
| 80 | cd classes/system |
| 81 | git checkout ${SALT_MODELS_SYSTEM_COMMIT} |
| 82 | cd ../.. |
| 83 | |
| 84 | # The directory "classes/service" is created at bootstrap time |
| 85 | # and cannot be commited to the repository automatically. |
| 86 | # It is not needed in the repo because contains only symlinks. |
| 87 | cat << EOF > ./.gitignore |
| 88 | classes/service |
| 89 | EOF |
| 90 | |
| 91 | # create a commit with new model (if any change exists) |
| 92 | git add -A |
| 93 | git commit -m "${LAB_CONTEXT_NAME}@${REPOSITORY_SUITE} generated at $(date +%Y-%m-%d/%H-%M) |
| 94 | |
| 95 | REPOSITORY_SUITE=${REPOSITORY_SUITE} |
| 96 | SALT_MODELS_SYSTEM_COMMIT=${SALT_MODELS_SYSTEM_COMMIT} |
| 97 | COOKIECUTTER_TEMPLATE_COMMIT=${COOKIECUTTER_TEMPLATE_COMMIT} |
| 98 | " |
| 99 | |
| 100 | # Push new commit to the ${REMOTE_JENKINS} repository |
| 101 | git push integration ${REPOSITORY_SUITE} |
| 102 | |
| 103 | echo "######################################################################################################################" |
| 104 | echo "#" |
| 105 | echo "# Clone the model into the tests: git clone http://${REMOTE_JENKINS}:8098/${LAB_CONTEXT_NAME}.git -b ${REPOSITORY_SUITE}" |
| 106 | echo "#" |
| 107 | echo "######################################################################################################################" |
| 108 | |