blob: 9a5ff3641239fdefb0f4281fd0f9f453e599b419 [file] [log] [blame]
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03001package com.mirantis.system_qa
2
3
4def run_cmd(cmd, returnStdout=false) {
5 def common = new com.mirantis.mk.Common()
6 common.printMsg("Run shell command:\n" + cmd, "blue")
7 def VENV_PATH='/home/jenkins/fuel-devops30'
8 script = """\
9 set +x;
10 echo 'activate python virtualenv ${VENV_PATH}';
11 . ${VENV_PATH}/bin/activate;
12 bash -c 'set -ex; set -ex; ${cmd.stripIndent()}'
13 """
14 return sh(script: script, returnStdout: returnStdout)
15}
16
17def run_cmd_stdout(cmd) {
18 return run_cmd(cmd, true)
19}
20
21
22def prepare_working_dir() {
23 println "Clean the working directory ${env.WORKSPACE}"
24 deleteDir()
25
26 //// do not fail if environment doesn't exists
27 // println "Remove environment ${ENV_NAME}"
28 // run_cmd("""\
29 // dos.py erase ${ENV_NAME} || true
30 // """)
31 // println "Remove config drive ISO"
32 // run_cmd("""\
33 // rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
34 // """)
35
36 run_cmd("""\
37 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
38 if [ -n "$TCP_QA_REFS" ]; then
39 set -e
40 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
41 fi
42 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
43 """)
44}
45
46def swarm_bootstrap_salt_cluster_devops() {
47 def common = new com.mirantis.mk.Common()
48 def parameters = [
49 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
50 string(name: 'PARENT_WORKSPACE', value: pwd()),
51 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
52 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
53 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
54 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
55 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
56 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
57 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
58 string(name: 'PIPELINE_LIBRARY_REF', value: "${PIPELINE_LIBRARY_REF}"),
59 string(name: 'MK_PIPELINES_REF', value: "${MK_PIPELINES_REF}"),
60 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${COOKIECUTTER_TEMPLATE_COMMIT}"),
61 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${SALT_MODELS_SYSTEM_COMMIT}"),
62 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
63 ]
64 common.printMsg("Start building job 'swarm-bootstrap-salt-cluster-devops' with parameters:", "purple")
65 common.prettyPrint(parameters)
66 build job: 'swarm-bootstrap-salt-cluster-devops',
67 parameters: parameters
68}
69
70def swarm_deploy_cicd(String stack_to_install='core,cicd') {
71 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
72 def common = new com.mirantis.mk.Common()
73 def parameters = [
74 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
75 string(name: 'PARENT_WORKSPACE', value: pwd()),
76 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
77 string(name: 'STACK_INSTALL', value: stack_to_install),
78 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
79 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
80 ]
81 common.printMsg("Start building job 'swarm-deploy-cicd' with parameters:", "purple")
82 common.prettyPrint(parameters)
83 build job: 'swarm-deploy-cicd',
84 parameters: parameters
85}
86
87def swarm_deploy_platform(String stack_to_install) {
88 // Run openstack_deploy job on CICD Jenkins for specified stacks
89 def common = new com.mirantis.mk.Common()
90 def parameters = [
91 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
92 string(name: 'PARENT_WORKSPACE', value: pwd()),
93 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
94 string(name: 'STACK_INSTALL', value: stack_to_install),
95 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
96 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
97 ]
98 common.printMsg("Start building job 'swarm-deploy-platform' with parameters:", "purple")
99 common.prettyPrint(parameters)
100 build job: 'swarm-deploy-platform',
101 parameters: parameters
102}
103
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300104def swarm_run_pytest(String passed_steps) {
105 // Run pytest tests
106 def common = new com.mirantis.mk.Common()
107 def parameters = [
108 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
109 string(name: 'PASSED_STEPS', value: passed_steps),
110 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
111 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
112 string(name: 'PARENT_WORKSPACE', value: pwd()),
113 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
114 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
115 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
116 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
117 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
118 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
119 ]
120 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
121 common.prettyPrint(parameters)
122 build job: 'swarm-run-pytest',
123 parameters: parameters
124}
125
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300126def generate_cookied_model() {
127 def common = new com.mirantis.mk.Common()
128 // do not fail if environment doesn't exists
129 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
130 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
131 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
132 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
133 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
134 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
135 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
136 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
137
138 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
139 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
140
141 def parameters = [
142 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
143 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
144 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
145 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
146 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
147 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
148 string(name: 'TCP_QA_REVIEW', value: "${TCP_QA_REFS}"),
149 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
150 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
151 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
152 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
153 ]
154 common.printMsg("Start building job 'swarm-cookied-model-generator' with parameters:", "purple")
155 common.prettyPrint(parameters)
156 build job: 'swarm-cookied-model-generator',
157 parameters: parameters
158}
159
160def generate_configdrive_iso() {
161 def common = new com.mirantis.mk.Common()
162 def SALT_MASTER_IP=run_cmd_stdout("""\
163 export ENV_NAME=${ENV_NAME}
164 . ./tcp_tests/utils/env_salt
165 echo \$SALT_MASTER_IP
166 """).trim().split().last()
167 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
168 def parameters = [
169 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
170 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
171 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
172 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
173 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
174 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
175 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
176 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
177 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
178 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
179 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
180 string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"),
181 string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"),
182 string(name: 'PIPELINE_LIBRARY_REF', value: "${PIPELINE_LIBRARY_REF}"),
183 string(name: 'MK_PIPELINES_REF', value: "${MK_PIPELINES_REF}"),
184 ]
185 common.printMsg("Start building job 'create-cfg-config-drive' with parameters:", "purple")
186 common.prettyPrint(parameters)
187 build job: 'create-cfg-config-drive',
188 parameters: parameters
189}
190
191def run_job_on_day01_node(stack_to_install, timeout=1800) {
192 // stack_to_install="core,cicd"
193 def stack = "${stack_to_install}"
194 run_cmd("""\
195 export ENV_NAME=${ENV_NAME}
196 . ./tcp_tests/utils/env_salt
197 . ./tcp_tests/utils/env_jenkins_day01
198 export JENKINS_BUILD_TIMEOUT=${timeout}
199 JOB_PARAMETERS=\"{
200 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
201 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
202 }\"
203 JOB_PREFIX="[ {job_name}/{build_number}:${stack} {time} ] "
204 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
205 """)
206}
207
208def run_job_on_cicd_nodes(stack_to_install, timeout=1800) {
209 // stack_to_install="k8s,calico,stacklight"
210 def stack = "${stack_to_install}"
211 run_cmd("""\
212 export ENV_NAME=${ENV_NAME}
213 . ./tcp_tests/utils/env_salt
214 . ./tcp_tests/utils/env_jenkins_cicd
215 export JENKINS_BUILD_TIMEOUT=${timeout}
216 JOB_PARAMETERS=\"{
217 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
218 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
219 }\"
220 JOB_PREFIX="[ {job_name}/{build_number}:${stack} {time} ] "
221 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
222 sleep 60 # Wait for IO calm down on cluster nodes
223 """)
224}
225
226def sanity_check_component(stack) {
227 // Run sanity check for the component ${stack}.
228 // Result will be stored in JUnit XML file deploy_${stack}.xml
229 run_cmd("""\
230 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
231 """)
232}
233
234def devops_snapshot(stack) {
235 // Make the snapshot with name "${stack}_deployed"
236 // for all VMs in the environment.
237 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
238 // then make a copy for the created snapshot to allow the system
239 // tests to revert this snapshot along with the metadata from the INI file.
240 run_cmd("""\
241 dos.py suspend ${ENV_NAME}
242 dos.py snapshot ${ENV_NAME} ${stack}_deployed
243 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300244 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300245 dos.py time-sync ${ENV_NAME} || dos.py time-sync ${ENV_NAME} # sometimes, timesync may fail. Need to update it in fuel-devops.
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300246 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
247 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
248 fi
249 """)
250}
251
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300252def get_steps_list(steps) {
253 // Make a list from comma separated string
254 return steps.split(',').collect { it.split(':')[0] }
255}
256
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300257def report_deploy_result(deploy_expected_stacks) {
258}
259
260def report_test_result() {
261}