blob: bd998b0ffc1a52b680a68f274f9f73aefee6e2d1 [file] [log] [blame]
Anna Arhipova77178482023-06-14 11:46:42 +02001#!/bin/bash
Anna Arhipovad2ced492022-09-28 10:02:56 +02002# export REMOTE_JENKINS='172.19.112.216'
Anna Arhipova77178482023-06-14 11:46:42 +02003set -eo pipefail;
Anna Arhipovad2ced492022-09-28 10:02:56 +02004export REMOTE_JENKINS='sre-ci.scc.mirantis.net'
5
6if [ ! -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
14fi
15
16
17if [ -n "$TCP_QA_REVIEW" ]; then
18 git fetch https://gerrit.mcp.mirantis.com/mcp/tcp-qa $TCP_QA_REVIEW && git checkout FETCH_HEAD
19fi
20
21. ${VENV_PATH}/bin/activate
22
23if [ "$ERASE_EXISTING_ENVIRONMENT" = "true" ]; then
24 dos.py erase $ENV_NAME || true
25fi
26
27cd tcp_tests
28
29sed -i 's/%LOGIN%/rHm22xBV9K/' templates/${LAB_CONTEXT_NAME}/salt-context-cookiecutter*
30sed -i 's/%PASS%/az9Gq7Wq4jRic29YWP/' templates/${LAB_CONTEXT_NAME}/salt-context-cookiecutter*
31
32rm -f ./*.tar.gz
33
34#MODEL_FILENAME=model_${CLUSTER_NAME}_${BUILD_NUMBER}.tar.gz
35MODEL_FILENAME=model_${ENV_NAME}.tar.gz
36if [[ -f $MODEL_FILENAME ]]; then
37 rm $MODEL_FILENAME
38fi
39
40####################
41# Generate the model
42git config user.name "tester"
43git config user.email "tester@example.com"
44
45py.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
52rm -rf ./model
53mkdir -p ./model
54
55eval $(ssh-agent)
56ssh-add ${COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH}
57
58# Create remote repository
59ssh 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
67cd ./model
68
69# Prepare the repository in the ./model
70git init
71git remote add integration ssh://jenkins@${REMOTE_JENKINS}/home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git
72git pull integration ${REPOSITORY_SUITE} || true
73git checkout -b ${REPOSITORY_SUITE}
74git rm -rf . || true # remove previous content from the working dir
75
76# unpack new model into ./model dir
77tar -xzf ../${MODEL_FILENAME} -C ./
78# Add reclass-system submodule
79git submodule add https://gerrit.mcp.mirantis.com/salt-models/reclass-system classes/system/
80cd classes/system
81git checkout ${SALT_MODELS_SYSTEM_COMMIT}
82cd ../..
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.
87cat << EOF > ./.gitignore
88classes/service
89EOF
90
91# create a commit with new model (if any change exists)
92git add -A
93git commit -m "${LAB_CONTEXT_NAME}@${REPOSITORY_SUITE} generated at $(date +%Y-%m-%d/%H-%M)
94
95REPOSITORY_SUITE=${REPOSITORY_SUITE}
96SALT_MODELS_SYSTEM_COMMIT=${SALT_MODELS_SYSTEM_COMMIT}
97COOKIECUTTER_TEMPLATE_COMMIT=${COOKIECUTTER_TEMPLATE_COMMIT}
98"
99
100# Push new commit to the ${REMOTE_JENKINS} repository
101git push integration ${REPOSITORY_SUITE}
102
103echo "######################################################################################################################"
104echo "#"
105echo "# Clone the model into the tests: git clone http://${REMOTE_JENKINS}:8098/${LAB_CONTEXT_NAME}.git -b ${REPOSITORY_SUITE}"
106echo "#"
107echo "######################################################################################################################"
108