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