blob: c5df0adbcf7a159e13148f40fb89a9fe9a777f1a [file] [log] [blame]
Petr Lomakin47fee0a2017-08-01 10:46:05 -07001package com.mirantis.mcp
2
3/**
4 *
5 * Tests providing functions
6 *
7 */
8
9/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -060010 * Run docker container with basic (keystone) parameters
Petr Lomakin47fee0a2017-08-01 10:46:05 -070011 *
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -060012 * @param target Host to run container
13 * @param dockerImageLink Docker image link. May be custom or default rally image
Petr Lomakin47fee0a2017-08-01 10:46:05 -070014 */
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -060015def runBasicContainer(master, target, dockerImageLink="rallyforge/rally"){
Petr Lomakin47fee0a2017-08-01 10:46:05 -070016 def salt = new com.mirantis.mk.Salt()
17 def common = new com.mirantis.mk.Common()
Sam Stoelinga28bdb722017-09-25 18:29:59 -070018 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
19 def keystone = _pillar['return'][0].values()[0]
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -060020 if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) {
21 salt.cmdRun(master, target, "docker rm -f cvp")
22 }
23 salt.cmdRun(master, target, "docker run -tid --net=host --name=cvp " +
24 "-u root -e OS_USERNAME=${keystone.admin_name} " +
Petr Lomakin47fee0a2017-08-01 10:46:05 -070025 "-e OS_PASSWORD=${keystone.admin_password} -e OS_TENANT_NAME=${keystone.admin_tenant} " +
26 "-e OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0 " +
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -060027 "-e OS_REGION_NAME=${keystone.region} -e OS_ENDPOINT_TYPE=admin ${dockerImageLink} /bin/bash")
Petr Lomakin47fee0a2017-08-01 10:46:05 -070028}
29
30/**
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070031 * Get file content (encoded). The content encoded by Base64.
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070032 *
33 * @param target Compound target (should target only one host)
34 * @param file File path to read
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070035 * @return The encoded content of the file
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070036 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070037def getFileContentEncoded(master, target, file) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070038 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070039 def file_content = ''
40 def cmd = "base64 -w0 ${file} > ${file}_encoded; " +
41 "split -b 1MB -d ${file}_encoded ${file}__; " +
42 "rm ${file}_encoded"
43 salt.cmdRun(master, target, cmd, false, null, false)
44 def filename = file.tokenize('/').last()
45 def folder = file - filename
46 def parts = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*"])
47 for ( part in parts['return'][0].values()[0]) {
48 def _result = salt.cmdRun(master, target, "cat ${part}", false, null, false)
49 file_content = file_content + _result['return'][0].values()[0].replaceAll('Salt command execution success','')
50 }
51 salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*", "delete"])
52 return file_content
53}
54
55/**
56 * Copy files from remote to local directory. The content of files will be
57 * decoded by Base64.
58 *
59 * @param target Compound target (should target only one host)
60 * @param folder The path to remote folder.
61 * @param output_dir The path to local folder.
62 */
63def addFiles(master, target, folder, output_dir) {
64 def salt = new com.mirantis.mk.Salt()
65 def _result = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f"])
66 def files = _result['return'][0].values()[0]
67 for (file in files) {
68 def file_content = getFileContentEncoded(master, target, "${file}")
69 def fileName = file.tokenize('/').last()
70 writeFile file: "${output_dir}${fileName}_encoded", text: file_content
71 def cmd = "base64 -d ${output_dir}${fileName}_encoded > ${output_dir}${fileName}; " +
72 "rm ${output_dir}${fileName}_encoded"
73 sh(script: cmd)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070074 }
75}
76
77/**
78 * Get reclass value
79 *
80 * @param target The host for which the values will be provided
81 * @param filter Parameters divided by dots
82 * @return The pillar data
83 */
84def getReclassValue(master, target, filter) {
85 def common = new com.mirantis.mk.Common()
86 def salt = new com.mirantis.mk.Salt()
87 def items = filter.tokenize('.')
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070088 def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -p ${target}", false, null, false)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070089 _result = common.parseJSON(_result['return'][0].values()[0])
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070090 for (int k = 0; k < items.size(); k++) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070091 if ( _result ) {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070092 _result = _result["${items[k]}"]
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070093 }
94 }
95 return _result
96}
97
98/**
99 * Create list of nodes in JSON format.
100 *
101 * @param filter The Salt's matcher
102 * @return JSON list of nodes
103 */
104def getNodeList(master, filter = null) {
105 def salt = new com.mirantis.mk.Salt()
106 def common = new com.mirantis.mk.Common()
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700107 def nodes = []
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700108 def filtered_list = null
109 def controllers = salt.getMinions(master, 'I@nova:controller')
110 def hw_nodes = salt.getMinions(master, 'G@virtual:physical')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700111 if ( filter ) {
112 filtered_list = salt.getMinions(master, filter)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700113 }
114 def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -t", false, null, false)
115 def reclass_top = common.parseJSON(_result['return'][0].values()[0])
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700116 def nodesList = reclass_top['base'].keySet()
117 for (int i = 0; i < nodesList.size(); i++) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700118 if ( filtered_list ) {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700119 if ( ! filtered_list.contains(nodesList[i]) ) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700120 continue
121 }
122 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700123 def ip = getReclassValue(master, nodesList[i], '_param.linux_single_interface.address')
124 def network_data = [ip: ip, name: 'management']
125 def roles = [nodesList[i].tokenize('.')[0]]
126 if ( controllers.contains(nodesList[i]) ) {
127 roles.add('controller')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700128 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700129 if ( hw_nodes.contains(nodesList[i]) ) {
130 roles.add('hw_node')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700131 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700132 nodes.add([id: i+1, ip: ip, roles: roles, network_data: [network_data]])
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700133 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700134 return common.prettify(nodes)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700135}
136
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500137/**
138 * Execute mcp sanity tests
139 *
140 * @param salt_url Salt master url
141 * @param salt_credentials Salt credentials
142 * @param test_set Test set for mcp sanity framework
143 * @param output_dir Directory for results
144 */
145def runSanityTests(salt_url, salt_credentials, test_set, output_dir) {
146 def common = new com.mirantis.mk.Common()
147 creds = common.getCredentials(salt_credentials)
148 username = creds.username
149 password = creds.password
150 def script = ". ${env.WORKSPACE}/venv/bin/activate; pytest --junitxml ${output_dir}cvp_sanity.xml -sv ${env.WORKSPACE}/cvp-sanity-checks/cvp_checks/tests/${test_set}"
151 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
152 def statusCode = sh script:script, returnStatus:true
153 }
154}
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700155
156/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700157 * Execute tempest tests
158 *
159 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700160 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700161 * @param pattern If not false, will run only tests matched the pattern
162 * @param output_dir Directory for results
163 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700164def runTempestTests(master, target, dockerImageLink, output_dir, pattern = "false") {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700165 def salt = new com.mirantis.mk.Salt()
166 def output_file = 'docker-tempest.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700167 def results = '/root/qa_results'
168 def dest_folder = '/home/rally/qa_results'
169 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
170 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
171 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
172 def keystone = _pillar['return'][0].values()[0]
173 def env_vars = ['tempest_version=15.0.0',
174 "OS_USERNAME=${keystone.admin_name}",
175 "OS_PASSWORD=${keystone.admin_password}",
176 "OS_TENANT_NAME=${keystone.admin_tenant}",
177 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
178 "OS_REGION_NAME=${keystone.region}",
179 'OS_ENDPOINT_TYPE=admin'].join(' -e ')
180 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; '
181 if (pattern == 'false') {
182 cmd += 'rally verify start --pattern set=full --detailed; '
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700183 }
184 else {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700185 cmd += "rally verify start --pattern set=${pattern} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700186 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700187 cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " +
188 "rally verify report --type html --to ${dest_folder}/report-tempest.html"
189 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
190 "-v ${results}:${dest_folder} ${dockerImageLink} " +
191 "/bin/bash -c \"${cmd}\" > ${results}/${output_file}")
192 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700193}
194
195/**
196 * Execute rally tests
197 *
198 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700199 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700200 * @param pattern If not false, will run only tests matched the pattern
201 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700202 * @param ext_variables The list of external variables
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700203 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700204def runRallyTests(master, target, dockerImageLink, output_dir, ext_variables = []) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700205 def salt = new com.mirantis.mk.Salt()
206 def output_file = 'docker-rally.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700207 def results = '/root/qa_results'
208 def dest_folder = '/home/rally/qa_results'
209 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
210 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
211 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
212 def keystone = _pillar['return'][0].values()[0]
213 def env_vars = ( ['tempest_version=15.0.0',
214 "OS_USERNAME=${keystone.admin_name}",
215 "OS_PASSWORD=${keystone.admin_password}",
216 "OS_TENANT_NAME=${keystone.admin_tenant}",
217 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
218 "OS_REGION_NAME=${keystone.region}",
219 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
220 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
221 'rally task start combined_scenario.yaml ' +
222 "--task-args-file /opt/devops-qa-tools/rally-scenarios/task_arguments.yaml; " +
223 "rally task export --type junit-xml --to ${dest_folder}/report-rally.xml; " +
224 "rally task report --out ${dest_folder}/report-rally.html"
225 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
226 "-v ${results}:${dest_folder} ${dockerImageLink} " +
227 "/bin/bash -c \"${cmd}\" > ${results}/${output_file}")
228 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700229}
230
231/**
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700232 * Generate test report
233 *
234 * @param target Host to run script from
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700235 * @param dockerImageLink Docker image link
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700236 * @param output_dir Directory for results
237 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700238def generateTestReport(master, target, dockerImageLink, output_dir) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700239 def report_file = 'jenkins_test_report.html'
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700240 def salt = new com.mirantis.mk.Salt()
241 def common = new com.mirantis.mk.Common()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700242 def results = '/root/qa_results'
243 def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results'
244 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
245 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
246 def reports = ['report-tempest.json',
247 'report-rally.xml',
248 'report-k8s-e2e-tests.txt',
249 'report-ha.json',
250 'report-spt.txt']
251 for ( report in reports ) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700252 if ( fileExists("${output_dir}${report}") ) {
253 common.infoMsg("Copying ${report} to docker container")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700254 def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " +
255 "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " +
256 "rm ${output_dir}${report}_encoded; " +
257 "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true)
258 for ( item in items.tokenize() ) {
259 def content = sh(script: "cat ${output_dir}${item}", returnStdout: true)
260 salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false)
261 sh(script: "rm ${output_dir}${item}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700262 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700263 salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " +
264 "rm ${results}/${report}_encoded", false, null, false)
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700265 }
266 }
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700267
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700268 def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " +
269 "cp ${report_file} ${dest_folder}/${report_file}"
270 salt.cmdRun(master, target, "docker run -i --rm --net=host " +
271 "-v ${results}:${dest_folder} ${dockerImageLink} " +
272 "/bin/bash -c \"${cmd}\"")
273 def report_content = salt.getFileContent(master, target, "${results}/${report_file}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700274 writeFile file: "${output_dir}${report_file}", text: report_content
275}
276
277/**
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700278 * Execute SPT tests
279 *
280 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700281 * @param dockerImageLink Docker image link
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700282 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700283 * @param ext_variables The list of external variables
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700284 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700285def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = []) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700286 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700287 def results = '/root/qa_results'
288 def dest_folder = '/home/rally/qa_results'
289 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
290 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
291 def nodes = getNodeList(master)
292 def nodes_hw = getNodeList(master, 'G@virtual:physical')
293 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
294 def keystone = _pillar['return'][0].values()[0]
295 def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
296 def env_vars = ( ['tempest_version=15.0.0',
297 "OS_USERNAME=${keystone.admin_name}",
298 "OS_PASSWORD=${keystone.admin_password}",
299 "OS_TENANT_NAME=${keystone.admin_tenant}",
300 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
301 "OS_REGION_NAME=${keystone.region}",
302 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
303 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes])
304 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw])
305 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
306 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' +
307 "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " +
308 'sudo chmod 600 /root/.ssh/id_rsa; ' +
309 "sudo timmy -c simplified-performance-testing/config.yaml " +
310 "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " +
311 "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " +
312 "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " +
313 "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz"
314 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
315 "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " +
316 "\"${cmd}\" > ${results}/docker-spt.log")
317 addFiles(master, target, results, output_dir)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700318}
319
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700320/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600321 * Configure docker container
322 *
323 * @param target Host to run container
324 * @param proxy Proxy for accessing github and pip
325 * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc.
326 * @param tempest_repo Url to tempest for cloning. Can be github or internal gerrit. If not specified, tempest will not be configured.
327 * @param tempest_endpoint_type internalURL or adminURL or publicURL
328 * @param tempest_version Version of tempest to use
329 */
330def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo,
331 tempest_endpoint_type="internalURL", tempest_version="15.0.0",
332 configure_script="/home/rally/testing-stuff/configure.sh", ext_variables = []) {
333 def salt = new com.mirantis.mk.Salt()
334 if (testing_tools_repo != "" ) {
335 salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo}")
336 }
337 salt.cmdRun(master, target, "docker exec -e tempest_version=${tempest_version} -e PROXY=${proxy} " +
338 " -e TEMPEST_ENDPOINT=${tempest_repo} -e TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type} " +
339 ext_variables.join(' -e ') +
340 " cvp bash -c ${configure_script}")
341}
342
343/**
344 * Run Tempest
345 *
346 * @param target Host to run container
347 * @param test_pattern Test pattern to run
348 * @param skip_list Path to skip-list
349 * @param output_dir Directory on target host for storing results (containers is not a good place)
350 */
351def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") {
352 def salt = new com.mirantis.mk.Salt()
353 def xml_file = "${output_filename}.xml"
354 def log_file = "${output_filename}.log"
355 skip_list_cmd = ''
356 if (skip_list != '') {
357 skip_list_cmd = "--skip-list ${skip_list}"
358 }
359 salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} " +
360 "--detailed > ${log_file}", false)
361 salt.cmdRun(master, target, "cat ${log_file}")
362 salt.cmdRun(master, target, "docker exec cvp rally verify report --type junit-xml --to /home/rally/${xml_file}")
363 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
364 return salt.cmdRun(master, target, "docker exec cvp rally verify list | tail -n 2 | grep -v '+' | awk '{print \$16}'")['return'][0].values()[0].split()[0]
365}
366
367/**
368 * Run Rally
369 *
370 * @param target Host to run container
371 * @param test_pattern Test pattern to run
372 * @param scenarios_path Path to Rally scenarios
373 * @param output_dir Directory on target host for storing results (containers is not a good place)
374 */
375def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally") {
376 def salt = new com.mirantis.mk.Salt()
377 def xml_file = "${output_filename}.xml"
378 def log_file = "${output_filename}.log"
379 def html_file = "${output_filename}.html"
380 salt.cmdRun(master, target, "docker exec cvp rally task start ${scenarios_path} > ${log_file}", false)
381 salt.cmdRun(master, target, "cat ${log_file}")
382 salt.cmdRun(master, target, "docker exec cvp rally task report --out ${html_file}")
383 salt.cmdRun(master, target, "docker exec cvp rally task export --type junit-xml --to ${xml_file}")
384 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
385 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
386}
387
388
389/**
390 * Shutdown node
391 *
392 * @param target Host to run command
393 * @param mode How to shutdown node
394 * @param retries # of retries to make to check node status
395 */
396def shutdown_vm_node(master, target, mode, retries=200) {
397 def salt = new com.mirantis.mk.Salt()
398 def common = new com.mirantis.mk.Common()
399 if (mode == 'reboot') {
400 try {
401 def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3)
402 } catch (Exception e) {
403 common.warningMsg('Timeout from minion: node must be rebooting now')
404 }
405 common.warningMsg("Checking that minion is down")
406 status = "True"
407 for (i = 0; i < retries; i++) {
408 status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1)
409 if (status != "True") {
410 break
411 }
412 }
413 if (status == "True") {
414 throw new Exception("Tired to wait for minion ${target} to stop responding")
415 }
416 }
417 if (mode == 'hard_shutdown' || mode == 'soft_shutdown') {
418 kvm = locate_node_on_kvm(master, target)
419 if (mode == 'soft_shutdown') {
420 salt.cmdRun(master, target, "shutdown -h 0")
421 }
422 if (mode == 'hard_shutdown') {
423 salt.cmdRun(master, kvm, "virsh destroy ${target}")
424 }
425 common.warningMsg("Checking that vm on kvm is in power off state")
426 status = 'running'
427 for (i = 0; i < retries; i++) {
428 status = check_vm_status(master, target, kvm)
429 echo "Current status - ${status}"
430 if (status != 'running') {
431 break
432 }
433 sleep (1)
434 }
435 if (status == 'running') {
436 throw new Exception("Tired to wait for node ${target} to shutdown")
437 }
438 }
439}
440
441
442/**
443 * Locate kvm where target host is located
444 *
445 * @param target Host to check
446 */
447def locate_node_on_kvm(master, target) {
448 def salt = new com.mirantis.mk.Salt()
449 def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
450 for (item in list.keySet()) {
451 if (list[item]) {
452 return item
453 }
454 }
455}
456
457/**
458 * Check target host status
459 *
460 * @param target Host to check
461 * @param kvm KVM node where target host is located
462 */
463def check_vm_status(master, target, kvm) {
464 def salt = new com.mirantis.mk.Salt()
465 def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
466 for (item in list.keySet()) {
467 if (list[item]) {
468 return list[item].split()[2]
469 }
470 }
471}
472
473/**
474 * Find vip on nodes
475 *
476 * @param target Pattern, e.g. ctl*
477 */
478def get_vip_node(master, target) {
479 def salt = new com.mirantis.mk.Salt()
480 def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep global | grep -v brd"])['return'][0]
481 for (item in list.keySet()) {
482 if (list[item]) {
483 return item
484 }
485 }
486}
487
488/**
489 * Find vip on nodes
490 *
491 * @param target Host with cvp container
492 */
493def openstack_cleanup(master, target, script_path="/home/rally/testing-stuff/clean.sh") {
494 def salt = new com.mirantis.mk.Salt()
495 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec cvp bash -c ${script_path}"])
496}
497
498
499/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700500 * Cleanup
501 *
502 * @param target Host to run commands
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700503 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700504def runCleanup(master, target) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700505 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov321405a2017-08-16 16:38:51 -0700506 if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) {
507 salt.cmdRun(master, target, "docker rm -f qa_tools")
508 }
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600509 if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) {
510 salt.cmdRun(master, target, "docker rm -f cvp")
511 }
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700512}
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500513/**
514 * Prepare venv for any python project
515 * Note: <repo_name>\/requirements.txt content will be used
516 * for this venv
517 *
518 * @param repo_url Repository url to clone
519 * @param proxy Proxy address to use
520 */
521def prepareVenv(repo_url, proxy) {
522 def python = new com.mirantis.mk.Python()
523 repo_name = "${repo_url}".tokenize("/").last()
524 sh "rm -rf ${repo_name}"
525 withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
526 sh "git clone ${repo_url}"
527 python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true)
528 }
529}
530
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700531/** Install docker if needed
532 *
533 * @param target Target node to install docker pkg
534 */
535def installDocker(master, target) {
536 def salt = new com.mirantis.mk.Salt()
537 if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) {
538 salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
539 }
540}