blob: 085def4e019fb4a6276498b39f70d32158d01a0a [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
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600143 * @param env_vars Additional environment variables for cvp-sanity-checks
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500144 * @param output_dir Directory for results
145 */
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600146def runSanityTests(salt_url, salt_credentials, test_set="", output_dir="validation_artifacts/", env_vars="") {
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500147 def common = new com.mirantis.mk.Common()
Oleksii Zhurba0a7b0702017-11-10 16:02:16 -0600148 def creds = common.getCredentials(salt_credentials)
149 def username = creds.username
150 def password = creds.password
151 def settings = ""
152 if ( env_vars != "" ) {
153 for (var in env_vars.tokenize(";")) {
154 settings += "export ${var}; "
155 }
156 }
157 def script = ". ${env.WORKSPACE}/venv/bin/activate; ${settings}" +
158 "pytest --junitxml ${output_dir}cvp_sanity.xml -sv ${env.WORKSPACE}/cvp-sanity-checks/cvp_checks/tests/${test_set}"
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500159 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
160 def statusCode = sh script:script, returnStatus:true
161 }
162}
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700163
164/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700165 * Execute tempest tests
166 *
167 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700168 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700169 * @param pattern If not false, will run only tests matched the pattern
170 * @param output_dir Directory for results
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800171 * @param confRepository Git repository with configuration files for Tempest
172 * @param confBranch Git branch which will be used during the checkout
173 * @param repository Git repository with Tempest
174 * @param version Version of Tempest (tag, branch or commit)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700175 */
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800176def runTempestTests(master, target, dockerImageLink, output_dir, confRepository, confBranch, repository, version, pattern = "false") {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700177 def salt = new com.mirantis.mk.Salt()
178 def output_file = 'docker-tempest.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700179 def results = '/root/qa_results'
180 def dest_folder = '/home/rally/qa_results'
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800181 def skip_list = '--skip-list /opt/devops-qa-tools/deployment/skip_contrail.list'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700182 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
183 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
184 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
185 def keystone = _pillar['return'][0].values()[0]
186 def env_vars = ['tempest_version=15.0.0',
187 "OS_USERNAME=${keystone.admin_name}",
188 "OS_PASSWORD=${keystone.admin_password}",
189 "OS_TENANT_NAME=${keystone.admin_tenant}",
190 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
191 "OS_REGION_NAME=${keystone.region}",
192 'OS_ENDPOINT_TYPE=admin'].join(' -e ')
193 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; '
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800194 if (confRepository != '' ) {
195 cmd = "git clone -b ${confBranch ?: 'master'} ${confRepository} test_config; " +
196 'rally deployment create --fromenv --name=tempest; rally deployment config; ' +
197 'rally verify create-verifier --name tempest_verifier --type tempest ' +
198 "--source ${repository ?: '/tmp/tempest/'} --version ${version: '15.0.0'}; " +
199 'rally verify configure-verifier --extend test_config/tempest/tempest.conf --show; '
200 skip_list = '--skip-list test_config/tempest/skip-list.yaml'
201 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700202 if (pattern == 'false') {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800203 cmd += "rally verify start --pattern set=full ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700204 }
205 else {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800206 cmd += "rally verify start --pattern set=${pattern} ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700207 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700208 cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " +
209 "rally verify report --type html --to ${dest_folder}/report-tempest.html"
210 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400211 "-v ${results}:${dest_folder} --entrypoint /bin/bash ${dockerImageLink} " +
212 "-c \"${cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700213 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700214}
215
216/**
217 * Execute rally tests
218 *
219 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700220 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700221 * @param output_dir Directory for results
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800222 * @param repository Git repository with files for Rally
223 * @param branch Git branch which will be used during the checkout
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700224 * @param ext_variables The list of external variables
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700225 */
Sergey Galkinea53f922017-11-29 19:11:54 +0400226def runRallyTests(master, target, dockerImageLink, output_dir, repository, branch, scenarios, tasks_args_file, ext_variables = []) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700227 def salt = new com.mirantis.mk.Salt()
228 def output_file = 'docker-rally.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700229 def results = '/root/qa_results'
230 def dest_folder = '/home/rally/qa_results'
231 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
232 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
233 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
234 def keystone = _pillar['return'][0].values()[0]
235 def env_vars = ( ['tempest_version=15.0.0',
236 "OS_USERNAME=${keystone.admin_name}",
237 "OS_PASSWORD=${keystone.admin_password}",
238 "OS_TENANT_NAME=${keystone.admin_tenant}",
239 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
240 "OS_REGION_NAME=${keystone.region}",
241 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
242 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
243 'rally task start combined_scenario.yaml ' +
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800244 '--task-args-file /opt/devops-qa-tools/rally-scenarios/task_arguments.yaml; '
245 if (repository != '' ) {
246 cmd = "git clone -b ${branch ?: 'master'} ${repository} test_config; " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400247 'rally deployment create --fromenv --name=existing; ' +
Sergey Galkinea53f922017-11-29 19:11:54 +0400248 'rally deployment config; '
249 if (scenarios == '') {
250 cmd += 'rally task start test_config/rally/scenario.yaml '
251 } else {
252 cmd += "rally task start ${scenarios} "
253 }
254 switch(tasks_args_file) {
255 case 'none':
256 cmd += '; '
257 break
258 case '':
259 cmd += '--task-args-file test_config/rally/task_arguments.yaml; '
260 break
261 default:
262 cmd += "--task-args-file ${tasks_args_file}; "
263 break
264 }
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800265 }
266 cmd += "rally task export --type junit-xml --to ${dest_folder}/report-rally.xml; " +
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700267 "rally task report --out ${dest_folder}/report-rally.html"
268 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400269 "-v ${results}:${dest_folder} --entrypoint /bin/bash ${dockerImageLink} " +
270 "-c \"${cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700271 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700272}
273
274/**
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700275 * Generate test report
276 *
277 * @param target Host to run script from
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700278 * @param dockerImageLink Docker image link
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700279 * @param output_dir Directory for results
280 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700281def generateTestReport(master, target, dockerImageLink, output_dir) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700282 def report_file = 'jenkins_test_report.html'
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700283 def salt = new com.mirantis.mk.Salt()
284 def common = new com.mirantis.mk.Common()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700285 def results = '/root/qa_results'
286 def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results'
287 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
288 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
289 def reports = ['report-tempest.json',
290 'report-rally.xml',
291 'report-k8s-e2e-tests.txt',
292 'report-ha.json',
293 'report-spt.txt']
294 for ( report in reports ) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700295 if ( fileExists("${output_dir}${report}") ) {
296 common.infoMsg("Copying ${report} to docker container")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700297 def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " +
298 "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " +
299 "rm ${output_dir}${report}_encoded; " +
300 "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true)
301 for ( item in items.tokenize() ) {
302 def content = sh(script: "cat ${output_dir}${item}", returnStdout: true)
303 salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false)
304 sh(script: "rm ${output_dir}${item}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700305 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700306 salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " +
307 "rm ${results}/${report}_encoded", false, null, false)
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700308 }
309 }
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700310
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700311 def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " +
312 "cp ${report_file} ${dest_folder}/${report_file}"
313 salt.cmdRun(master, target, "docker run -i --rm --net=host " +
314 "-v ${results}:${dest_folder} ${dockerImageLink} " +
315 "/bin/bash -c \"${cmd}\"")
316 def report_content = salt.getFileContent(master, target, "${results}/${report_file}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700317 writeFile file: "${output_dir}${report_file}", text: report_content
318}
319
320/**
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700321 * Execute SPT tests
322 *
323 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700324 * @param dockerImageLink Docker image link
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700325 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700326 * @param ext_variables The list of external variables
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700327 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700328def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = []) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700329 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700330 def results = '/root/qa_results'
331 def dest_folder = '/home/rally/qa_results'
332 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
333 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
334 def nodes = getNodeList(master)
335 def nodes_hw = getNodeList(master, 'G@virtual:physical')
336 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
337 def keystone = _pillar['return'][0].values()[0]
338 def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
339 def env_vars = ( ['tempest_version=15.0.0',
340 "OS_USERNAME=${keystone.admin_name}",
341 "OS_PASSWORD=${keystone.admin_password}",
342 "OS_TENANT_NAME=${keystone.admin_tenant}",
343 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
344 "OS_REGION_NAME=${keystone.region}",
345 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
346 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes])
347 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw])
348 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
349 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' +
350 "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " +
351 'sudo chmod 600 /root/.ssh/id_rsa; ' +
352 "sudo timmy -c simplified-performance-testing/config.yaml " +
353 "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " +
354 "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " +
355 "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " +
356 "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz"
357 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
358 "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " +
359 "\"${cmd}\" > ${results}/docker-spt.log")
360 addFiles(master, target, results, output_dir)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700361}
362
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700363/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600364 * Configure docker container
365 *
366 * @param target Host to run container
367 * @param proxy Proxy for accessing github and pip
368 * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc.
369 * @param tempest_repo Url to tempest for cloning. Can be github or internal gerrit. If not specified, tempest will not be configured.
370 * @param tempest_endpoint_type internalURL or adminURL or publicURL
371 * @param tempest_version Version of tempest to use
372 */
373def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo,
374 tempest_endpoint_type="internalURL", tempest_version="15.0.0",
375 configure_script="/home/rally/testing-stuff/configure.sh", ext_variables = []) {
376 def salt = new com.mirantis.mk.Salt()
377 if (testing_tools_repo != "" ) {
378 salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo}")
379 }
380 salt.cmdRun(master, target, "docker exec -e tempest_version=${tempest_version} -e PROXY=${proxy} " +
381 " -e TEMPEST_ENDPOINT=${tempest_repo} -e TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type} " +
382 ext_variables.join(' -e ') +
383 " cvp bash -c ${configure_script}")
384}
385
386/**
387 * Run Tempest
388 *
389 * @param target Host to run container
390 * @param test_pattern Test pattern to run
391 * @param skip_list Path to skip-list
392 * @param output_dir Directory on target host for storing results (containers is not a good place)
393 */
394def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") {
395 def salt = new com.mirantis.mk.Salt()
396 def xml_file = "${output_filename}.xml"
397 def log_file = "${output_filename}.log"
398 skip_list_cmd = ''
399 if (skip_list != '') {
400 skip_list_cmd = "--skip-list ${skip_list}"
401 }
402 salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} " +
403 "--detailed > ${log_file}", false)
404 salt.cmdRun(master, target, "cat ${log_file}")
405 salt.cmdRun(master, target, "docker exec cvp rally verify report --type junit-xml --to /home/rally/${xml_file}")
406 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
407 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]
408}
409
410/**
411 * Run Rally
412 *
413 * @param target Host to run container
414 * @param test_pattern Test pattern to run
415 * @param scenarios_path Path to Rally scenarios
416 * @param output_dir Directory on target host for storing results (containers is not a good place)
417 */
418def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally") {
419 def salt = new com.mirantis.mk.Salt()
420 def xml_file = "${output_filename}.xml"
421 def log_file = "${output_filename}.log"
422 def html_file = "${output_filename}.html"
423 salt.cmdRun(master, target, "docker exec cvp rally task start ${scenarios_path} > ${log_file}", false)
424 salt.cmdRun(master, target, "cat ${log_file}")
425 salt.cmdRun(master, target, "docker exec cvp rally task report --out ${html_file}")
426 salt.cmdRun(master, target, "docker exec cvp rally task export --type junit-xml --to ${xml_file}")
427 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
428 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
429}
430
431
432/**
433 * Shutdown node
434 *
435 * @param target Host to run command
436 * @param mode How to shutdown node
437 * @param retries # of retries to make to check node status
438 */
439def shutdown_vm_node(master, target, mode, retries=200) {
440 def salt = new com.mirantis.mk.Salt()
441 def common = new com.mirantis.mk.Common()
442 if (mode == 'reboot') {
443 try {
444 def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3)
445 } catch (Exception e) {
446 common.warningMsg('Timeout from minion: node must be rebooting now')
447 }
448 common.warningMsg("Checking that minion is down")
449 status = "True"
450 for (i = 0; i < retries; i++) {
451 status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1)
452 if (status != "True") {
453 break
454 }
455 }
456 if (status == "True") {
457 throw new Exception("Tired to wait for minion ${target} to stop responding")
458 }
459 }
460 if (mode == 'hard_shutdown' || mode == 'soft_shutdown') {
461 kvm = locate_node_on_kvm(master, target)
462 if (mode == 'soft_shutdown') {
463 salt.cmdRun(master, target, "shutdown -h 0")
464 }
465 if (mode == 'hard_shutdown') {
466 salt.cmdRun(master, kvm, "virsh destroy ${target}")
467 }
468 common.warningMsg("Checking that vm on kvm is in power off state")
469 status = 'running'
470 for (i = 0; i < retries; i++) {
471 status = check_vm_status(master, target, kvm)
472 echo "Current status - ${status}"
473 if (status != 'running') {
474 break
475 }
476 sleep (1)
477 }
478 if (status == 'running') {
479 throw new Exception("Tired to wait for node ${target} to shutdown")
480 }
481 }
482}
483
484
485/**
486 * Locate kvm where target host is located
487 *
488 * @param target Host to check
489 */
490def locate_node_on_kvm(master, target) {
491 def salt = new com.mirantis.mk.Salt()
492 def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
493 for (item in list.keySet()) {
494 if (list[item]) {
495 return item
496 }
497 }
498}
499
500/**
501 * Check target host status
502 *
503 * @param target Host to check
504 * @param kvm KVM node where target host is located
505 */
506def check_vm_status(master, target, kvm) {
507 def salt = new com.mirantis.mk.Salt()
508 def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
509 for (item in list.keySet()) {
510 if (list[item]) {
511 return list[item].split()[2]
512 }
513 }
514}
515
516/**
517 * Find vip on nodes
518 *
519 * @param target Pattern, e.g. ctl*
520 */
521def get_vip_node(master, target) {
522 def salt = new com.mirantis.mk.Salt()
523 def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep global | grep -v brd"])['return'][0]
524 for (item in list.keySet()) {
525 if (list[item]) {
526 return item
527 }
528 }
529}
530
531/**
532 * Find vip on nodes
533 *
534 * @param target Host with cvp container
535 */
536def openstack_cleanup(master, target, script_path="/home/rally/testing-stuff/clean.sh") {
537 def salt = new com.mirantis.mk.Salt()
538 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec cvp bash -c ${script_path}"])
539}
540
541
542/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700543 * Cleanup
544 *
545 * @param target Host to run commands
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700546 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700547def runCleanup(master, target) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700548 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov321405a2017-08-16 16:38:51 -0700549 if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) {
550 salt.cmdRun(master, target, "docker rm -f qa_tools")
551 }
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600552 if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) {
553 salt.cmdRun(master, target, "docker rm -f cvp")
554 }
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700555}
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500556/**
557 * Prepare venv for any python project
558 * Note: <repo_name>\/requirements.txt content will be used
559 * for this venv
560 *
561 * @param repo_url Repository url to clone
562 * @param proxy Proxy address to use
563 */
564def prepareVenv(repo_url, proxy) {
565 def python = new com.mirantis.mk.Python()
566 repo_name = "${repo_url}".tokenize("/").last()
567 sh "rm -rf ${repo_name}"
568 withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
569 sh "git clone ${repo_url}"
570 python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true)
571 }
572}
573
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700574/** Install docker if needed
575 *
576 * @param target Target node to install docker pkg
577 */
578def installDocker(master, target) {
579 def salt = new com.mirantis.mk.Salt()
580 if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) {
581 salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
582 }
583}