blob: 9132fd62819207cee9c89c9679d73b35bac97af3 [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
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800163 * @param confRepository Git repository with configuration files for Tempest
164 * @param confBranch Git branch which will be used during the checkout
165 * @param repository Git repository with Tempest
166 * @param version Version of Tempest (tag, branch or commit)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700167 */
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800168def runTempestTests(master, target, dockerImageLink, output_dir, confRepository, confBranch, repository, version, pattern = "false") {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700169 def salt = new com.mirantis.mk.Salt()
170 def output_file = 'docker-tempest.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700171 def results = '/root/qa_results'
172 def dest_folder = '/home/rally/qa_results'
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800173 def skip_list = '--skip-list /opt/devops-qa-tools/deployment/skip_contrail.list'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700174 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
175 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
176 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
177 def keystone = _pillar['return'][0].values()[0]
178 def env_vars = ['tempest_version=15.0.0',
179 "OS_USERNAME=${keystone.admin_name}",
180 "OS_PASSWORD=${keystone.admin_password}",
181 "OS_TENANT_NAME=${keystone.admin_tenant}",
182 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
183 "OS_REGION_NAME=${keystone.region}",
184 'OS_ENDPOINT_TYPE=admin'].join(' -e ')
185 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; '
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800186 if (confRepository != '' ) {
187 cmd = "git clone -b ${confBranch ?: 'master'} ${confRepository} test_config; " +
188 'rally deployment create --fromenv --name=tempest; rally deployment config; ' +
189 'rally verify create-verifier --name tempest_verifier --type tempest ' +
190 "--source ${repository ?: '/tmp/tempest/'} --version ${version: '15.0.0'}; " +
191 'rally verify configure-verifier --extend test_config/tempest/tempest.conf --show; '
192 skip_list = '--skip-list test_config/tempest/skip-list.yaml'
193 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700194 if (pattern == 'false') {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800195 cmd += "rally verify start --pattern set=full ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700196 }
197 else {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800198 cmd += "rally verify start --pattern set=${pattern} ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700199 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700200 cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " +
201 "rally verify report --type html --to ${dest_folder}/report-tempest.html"
202 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400203 "-v ${results}:${dest_folder} --entrypoint /bin/bash ${dockerImageLink} " +
204 "-c \"${cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700205 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700206}
207
208/**
209 * Execute rally tests
210 *
211 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700212 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700213 * @param output_dir Directory for results
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800214 * @param repository Git repository with files for Rally
215 * @param branch Git branch which will be used during the checkout
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700216 * @param ext_variables The list of external variables
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700217 */
Sergey Galkinea53f922017-11-29 19:11:54 +0400218def runRallyTests(master, target, dockerImageLink, output_dir, repository, branch, scenarios, tasks_args_file, ext_variables = []) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700219 def salt = new com.mirantis.mk.Salt()
220 def output_file = 'docker-rally.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700221 def results = '/root/qa_results'
222 def dest_folder = '/home/rally/qa_results'
223 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
224 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
225 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
226 def keystone = _pillar['return'][0].values()[0]
227 def env_vars = ( ['tempest_version=15.0.0',
228 "OS_USERNAME=${keystone.admin_name}",
229 "OS_PASSWORD=${keystone.admin_password}",
230 "OS_TENANT_NAME=${keystone.admin_tenant}",
231 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
232 "OS_REGION_NAME=${keystone.region}",
233 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
234 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
235 'rally task start combined_scenario.yaml ' +
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800236 '--task-args-file /opt/devops-qa-tools/rally-scenarios/task_arguments.yaml; '
237 if (repository != '' ) {
238 cmd = "git clone -b ${branch ?: 'master'} ${repository} test_config; " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400239 'rally deployment create --fromenv --name=existing; ' +
Sergey Galkinea53f922017-11-29 19:11:54 +0400240 'rally deployment config; '
241 if (scenarios == '') {
242 cmd += 'rally task start test_config/rally/scenario.yaml '
243 } else {
244 cmd += "rally task start ${scenarios} "
245 }
246 switch(tasks_args_file) {
247 case 'none':
248 cmd += '; '
249 break
250 case '':
251 cmd += '--task-args-file test_config/rally/task_arguments.yaml; '
252 break
253 default:
254 cmd += "--task-args-file ${tasks_args_file}; "
255 break
256 }
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800257 }
258 cmd += "rally task export --type junit-xml --to ${dest_folder}/report-rally.xml; " +
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700259 "rally task report --out ${dest_folder}/report-rally.html"
260 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400261 "-v ${results}:${dest_folder} --entrypoint /bin/bash ${dockerImageLink} " +
262 "-c \"${cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700263 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700264}
265
266/**
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700267 * Generate test report
268 *
269 * @param target Host to run script from
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700270 * @param dockerImageLink Docker image link
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700271 * @param output_dir Directory for results
272 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700273def generateTestReport(master, target, dockerImageLink, output_dir) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700274 def report_file = 'jenkins_test_report.html'
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700275 def salt = new com.mirantis.mk.Salt()
276 def common = new com.mirantis.mk.Common()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700277 def results = '/root/qa_results'
278 def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results'
279 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
280 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
281 def reports = ['report-tempest.json',
282 'report-rally.xml',
283 'report-k8s-e2e-tests.txt',
284 'report-ha.json',
285 'report-spt.txt']
286 for ( report in reports ) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700287 if ( fileExists("${output_dir}${report}") ) {
288 common.infoMsg("Copying ${report} to docker container")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700289 def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " +
290 "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " +
291 "rm ${output_dir}${report}_encoded; " +
292 "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true)
293 for ( item in items.tokenize() ) {
294 def content = sh(script: "cat ${output_dir}${item}", returnStdout: true)
295 salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false)
296 sh(script: "rm ${output_dir}${item}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700297 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700298 salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " +
299 "rm ${results}/${report}_encoded", false, null, false)
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700300 }
301 }
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700302
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700303 def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " +
304 "cp ${report_file} ${dest_folder}/${report_file}"
305 salt.cmdRun(master, target, "docker run -i --rm --net=host " +
306 "-v ${results}:${dest_folder} ${dockerImageLink} " +
307 "/bin/bash -c \"${cmd}\"")
308 def report_content = salt.getFileContent(master, target, "${results}/${report_file}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700309 writeFile file: "${output_dir}${report_file}", text: report_content
310}
311
312/**
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700313 * Execute SPT tests
314 *
315 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700316 * @param dockerImageLink Docker image link
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700317 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700318 * @param ext_variables The list of external variables
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700319 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700320def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = []) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700321 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700322 def results = '/root/qa_results'
323 def dest_folder = '/home/rally/qa_results'
324 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
325 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
326 def nodes = getNodeList(master)
327 def nodes_hw = getNodeList(master, 'G@virtual:physical')
328 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
329 def keystone = _pillar['return'][0].values()[0]
330 def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
331 def env_vars = ( ['tempest_version=15.0.0',
332 "OS_USERNAME=${keystone.admin_name}",
333 "OS_PASSWORD=${keystone.admin_password}",
334 "OS_TENANT_NAME=${keystone.admin_tenant}",
335 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
336 "OS_REGION_NAME=${keystone.region}",
337 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
338 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes])
339 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw])
340 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
341 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' +
342 "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " +
343 'sudo chmod 600 /root/.ssh/id_rsa; ' +
344 "sudo timmy -c simplified-performance-testing/config.yaml " +
345 "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " +
346 "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " +
347 "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " +
348 "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz"
349 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
350 "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " +
351 "\"${cmd}\" > ${results}/docker-spt.log")
352 addFiles(master, target, results, output_dir)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700353}
354
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700355/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600356 * Configure docker container
357 *
358 * @param target Host to run container
359 * @param proxy Proxy for accessing github and pip
360 * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc.
361 * @param tempest_repo Url to tempest for cloning. Can be github or internal gerrit. If not specified, tempest will not be configured.
362 * @param tempest_endpoint_type internalURL or adminURL or publicURL
363 * @param tempest_version Version of tempest to use
364 */
365def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo,
366 tempest_endpoint_type="internalURL", tempest_version="15.0.0",
367 configure_script="/home/rally/testing-stuff/configure.sh", ext_variables = []) {
368 def salt = new com.mirantis.mk.Salt()
369 if (testing_tools_repo != "" ) {
370 salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo}")
371 }
372 salt.cmdRun(master, target, "docker exec -e tempest_version=${tempest_version} -e PROXY=${proxy} " +
373 " -e TEMPEST_ENDPOINT=${tempest_repo} -e TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type} " +
374 ext_variables.join(' -e ') +
375 " cvp bash -c ${configure_script}")
376}
377
378/**
379 * Run Tempest
380 *
381 * @param target Host to run container
382 * @param test_pattern Test pattern to run
383 * @param skip_list Path to skip-list
384 * @param output_dir Directory on target host for storing results (containers is not a good place)
385 */
386def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") {
387 def salt = new com.mirantis.mk.Salt()
388 def xml_file = "${output_filename}.xml"
389 def log_file = "${output_filename}.log"
390 skip_list_cmd = ''
391 if (skip_list != '') {
392 skip_list_cmd = "--skip-list ${skip_list}"
393 }
394 salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} " +
395 "--detailed > ${log_file}", false)
396 salt.cmdRun(master, target, "cat ${log_file}")
397 salt.cmdRun(master, target, "docker exec cvp rally verify report --type junit-xml --to /home/rally/${xml_file}")
398 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
399 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]
400}
401
402/**
403 * Run Rally
404 *
405 * @param target Host to run container
406 * @param test_pattern Test pattern to run
407 * @param scenarios_path Path to Rally scenarios
408 * @param output_dir Directory on target host for storing results (containers is not a good place)
409 */
410def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally") {
411 def salt = new com.mirantis.mk.Salt()
412 def xml_file = "${output_filename}.xml"
413 def log_file = "${output_filename}.log"
414 def html_file = "${output_filename}.html"
415 salt.cmdRun(master, target, "docker exec cvp rally task start ${scenarios_path} > ${log_file}", false)
416 salt.cmdRun(master, target, "cat ${log_file}")
417 salt.cmdRun(master, target, "docker exec cvp rally task report --out ${html_file}")
418 salt.cmdRun(master, target, "docker exec cvp rally task export --type junit-xml --to ${xml_file}")
419 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
420 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
421}
422
423
424/**
425 * Shutdown node
426 *
427 * @param target Host to run command
428 * @param mode How to shutdown node
429 * @param retries # of retries to make to check node status
430 */
431def shutdown_vm_node(master, target, mode, retries=200) {
432 def salt = new com.mirantis.mk.Salt()
433 def common = new com.mirantis.mk.Common()
434 if (mode == 'reboot') {
435 try {
436 def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3)
437 } catch (Exception e) {
438 common.warningMsg('Timeout from minion: node must be rebooting now')
439 }
440 common.warningMsg("Checking that minion is down")
441 status = "True"
442 for (i = 0; i < retries; i++) {
443 status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1)
444 if (status != "True") {
445 break
446 }
447 }
448 if (status == "True") {
449 throw new Exception("Tired to wait for minion ${target} to stop responding")
450 }
451 }
452 if (mode == 'hard_shutdown' || mode == 'soft_shutdown') {
453 kvm = locate_node_on_kvm(master, target)
454 if (mode == 'soft_shutdown') {
455 salt.cmdRun(master, target, "shutdown -h 0")
456 }
457 if (mode == 'hard_shutdown') {
458 salt.cmdRun(master, kvm, "virsh destroy ${target}")
459 }
460 common.warningMsg("Checking that vm on kvm is in power off state")
461 status = 'running'
462 for (i = 0; i < retries; i++) {
463 status = check_vm_status(master, target, kvm)
464 echo "Current status - ${status}"
465 if (status != 'running') {
466 break
467 }
468 sleep (1)
469 }
470 if (status == 'running') {
471 throw new Exception("Tired to wait for node ${target} to shutdown")
472 }
473 }
474}
475
476
477/**
478 * Locate kvm where target host is located
479 *
480 * @param target Host to check
481 */
482def locate_node_on_kvm(master, target) {
483 def salt = new com.mirantis.mk.Salt()
484 def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
485 for (item in list.keySet()) {
486 if (list[item]) {
487 return item
488 }
489 }
490}
491
492/**
493 * Check target host status
494 *
495 * @param target Host to check
496 * @param kvm KVM node where target host is located
497 */
498def check_vm_status(master, target, kvm) {
499 def salt = new com.mirantis.mk.Salt()
500 def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
501 for (item in list.keySet()) {
502 if (list[item]) {
503 return list[item].split()[2]
504 }
505 }
506}
507
508/**
509 * Find vip on nodes
510 *
511 * @param target Pattern, e.g. ctl*
512 */
513def get_vip_node(master, target) {
514 def salt = new com.mirantis.mk.Salt()
515 def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep global | grep -v brd"])['return'][0]
516 for (item in list.keySet()) {
517 if (list[item]) {
518 return item
519 }
520 }
521}
522
523/**
524 * Find vip on nodes
525 *
526 * @param target Host with cvp container
527 */
528def openstack_cleanup(master, target, script_path="/home/rally/testing-stuff/clean.sh") {
529 def salt = new com.mirantis.mk.Salt()
530 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec cvp bash -c ${script_path}"])
531}
532
533
534/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700535 * Cleanup
536 *
537 * @param target Host to run commands
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700538 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700539def runCleanup(master, target) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700540 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov321405a2017-08-16 16:38:51 -0700541 if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) {
542 salt.cmdRun(master, target, "docker rm -f qa_tools")
543 }
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600544 if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) {
545 salt.cmdRun(master, target, "docker rm -f cvp")
546 }
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700547}
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500548/**
549 * Prepare venv for any python project
550 * Note: <repo_name>\/requirements.txt content will be used
551 * for this venv
552 *
553 * @param repo_url Repository url to clone
554 * @param proxy Proxy address to use
555 */
556def prepareVenv(repo_url, proxy) {
557 def python = new com.mirantis.mk.Python()
558 repo_name = "${repo_url}".tokenize("/").last()
559 sh "rm -rf ${repo_name}"
560 withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
561 sh "git clone ${repo_url}"
562 python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true)
563 }
564}
565
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700566/** Install docker if needed
567 *
568 * @param target Target node to install docker pkg
569 */
570def installDocker(master, target) {
571 def salt = new com.mirantis.mk.Salt()
572 if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) {
573 salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
574 }
575}