blob: af2b2dcf5bfd556f3c01bc4d5e4c06cc0bb08fa6 [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
104def generate_cookied_model() {
105 def common = new com.mirantis.mk.Common()
106 // do not fail if environment doesn't exists
107 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
108 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
109 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
110 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
111 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
112 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
113 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
114 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
115
116 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
117 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
118
119 def parameters = [
120 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
121 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
122 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
123 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
124 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
125 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
126 string(name: 'TCP_QA_REVIEW', value: "${TCP_QA_REFS}"),
127 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
128 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
129 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
130 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
131 ]
132 common.printMsg("Start building job 'swarm-cookied-model-generator' with parameters:", "purple")
133 common.prettyPrint(parameters)
134 build job: 'swarm-cookied-model-generator',
135 parameters: parameters
136}
137
138def generate_configdrive_iso() {
139 def common = new com.mirantis.mk.Common()
140 def SALT_MASTER_IP=run_cmd_stdout("""\
141 export ENV_NAME=${ENV_NAME}
142 . ./tcp_tests/utils/env_salt
143 echo \$SALT_MASTER_IP
144 """).trim().split().last()
145 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
146 def parameters = [
147 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
148 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
149 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
150 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
151 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
152 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
153 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
154 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
155 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
156 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
157 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
158 string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"),
159 string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"),
160 string(name: 'PIPELINE_LIBRARY_REF', value: "${PIPELINE_LIBRARY_REF}"),
161 string(name: 'MK_PIPELINES_REF', value: "${MK_PIPELINES_REF}"),
162 ]
163 common.printMsg("Start building job 'create-cfg-config-drive' with parameters:", "purple")
164 common.prettyPrint(parameters)
165 build job: 'create-cfg-config-drive',
166 parameters: parameters
167}
168
169def run_job_on_day01_node(stack_to_install, timeout=1800) {
170 // stack_to_install="core,cicd"
171 def stack = "${stack_to_install}"
172 run_cmd("""\
173 export ENV_NAME=${ENV_NAME}
174 . ./tcp_tests/utils/env_salt
175 . ./tcp_tests/utils/env_jenkins_day01
176 export JENKINS_BUILD_TIMEOUT=${timeout}
177 JOB_PARAMETERS=\"{
178 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
179 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
180 }\"
181 JOB_PREFIX="[ {job_name}/{build_number}:${stack} {time} ] "
182 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
183 """)
184}
185
186def run_job_on_cicd_nodes(stack_to_install, timeout=1800) {
187 // stack_to_install="k8s,calico,stacklight"
188 def stack = "${stack_to_install}"
189 run_cmd("""\
190 export ENV_NAME=${ENV_NAME}
191 . ./tcp_tests/utils/env_salt
192 . ./tcp_tests/utils/env_jenkins_cicd
193 export JENKINS_BUILD_TIMEOUT=${timeout}
194 JOB_PARAMETERS=\"{
195 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
196 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
197 }\"
198 JOB_PREFIX="[ {job_name}/{build_number}:${stack} {time} ] "
199 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
200 sleep 60 # Wait for IO calm down on cluster nodes
201 """)
202}
203
204def sanity_check_component(stack) {
205 // Run sanity check for the component ${stack}.
206 // Result will be stored in JUnit XML file deploy_${stack}.xml
207 run_cmd("""\
208 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
209 """)
210}
211
212def devops_snapshot(stack) {
213 // Make the snapshot with name "${stack}_deployed"
214 // for all VMs in the environment.
215 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
216 // then make a copy for the created snapshot to allow the system
217 // tests to revert this snapshot along with the metadata from the INI file.
218 run_cmd("""\
219 dos.py suspend ${ENV_NAME}
220 dos.py snapshot ${ENV_NAME} ${stack}_deployed
221 dos.py resume ${ENV_NAME}
222 dos.py time-sync ${ENV_NAME}
223 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
224 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
225 fi
226 """)
227}
228
229def report_deploy_result(deploy_expected_stacks) {
230}
231
232def report_test_result() {
233}