blob: 8774552f9ecefde44af28b13f395c7fa204b9011 [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
56eval $(ssh-agent)
57ssh-add ${COOKIECUTTER_TEMPLATES_REPOSITORY_KEY_PATH}
58
59# Create remote repository
60ssh jenkins@${REMOTE_JENKINS} "
61 if [[ ! -d /home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git ]]; then
62 mkdir -p /home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git;
63 cd /home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git;
64 git init --bare;
65 cp hooks/post-update.sample hooks/post-update;
66 fi"
67
68cd ./model
69
70# Prepare the repository in the ./model
71git init
72git remote add integration ssh://jenkins@${REMOTE_JENKINS}/home/jenkins/salt-models/${LAB_CONTEXT_NAME}.git
73git pull integration ${REPOSITORY_SUITE} || true
74git checkout -b ${REPOSITORY_SUITE}
75git rm -rf . || true # remove previous content from the working dir
76
77# unpack new model into ./model dir
78tar -xzf ../${MODEL_FILENAME} -C ./
79# Add reclass-system submodule
80git submodule add https://gerrit.mcp.mirantis.com/salt-models/reclass-system classes/system/
81cd classes/system
82git checkout ${SALT_MODELS_SYSTEM_COMMIT}
83cd ../..
84
85# The directory "classes/service" is created at bootstrap time
86# and cannot be commited to the repository automatically.
87# It is not needed in the repo because contains only symlinks.
88cat << EOF > ./.gitignore
89classes/service
90EOF
91
92# create a commit with new model (if any change exists)
93git add -A
94git commit -m "${LAB_CONTEXT_NAME}@${REPOSITORY_SUITE} generated at $(date +%Y-%m-%d/%H-%M)
95
96REPOSITORY_SUITE=${REPOSITORY_SUITE}
97SALT_MODELS_SYSTEM_COMMIT=${SALT_MODELS_SYSTEM_COMMIT}
98COOKIECUTTER_TEMPLATE_COMMIT=${COOKIECUTTER_TEMPLATE_COMMIT}
99"
100
101# Push new commit to the ${REMOTE_JENKINS} repository
102git push integration ${REPOSITORY_SUITE}
103
104echo "######################################################################################################################"
105echo "#"
106echo "# Clone the model into the tests: git clone http://${REMOTE_JENKINS}:8098/${LAB_CONTEXT_NAME}.git -b ${REPOSITORY_SUITE}"
107echo "#"
108echo "######################################################################################################################"
109