blob: 7ec4bfe08ae0bb63c26b5ea6222a58eaf608f6ae [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 ')
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400242 def cmd0 = ''
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700243 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
244 'rally task start combined_scenario.yaml ' +
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800245 '--task-args-file /opt/devops-qa-tools/rally-scenarios/task_arguments.yaml; '
246 if (repository != '' ) {
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400247 cmd = '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 {
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400252 cmd += "rally task start scenarios.yaml "
253 cmd0 = "git clone -b ${branch ?: 'master'} ${repository} test_config; " +
254 "if [ -f ${scenarios} ]; then cp ${scenarios} scenarios.yaml; " +
255 "else " +
Sergey Galkin60ea8962018-01-17 14:48:11 +0400256 "find -L ${scenarios} -name '*.yaml' -exec cat {} >> scenarios.yaml \\; ; " +
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400257 "sed -i '/---/d' scenarios.yaml; fi; "
Sergey Galkinea53f922017-11-29 19:11:54 +0400258 }
259 switch(tasks_args_file) {
260 case 'none':
261 cmd += '; '
262 break
263 case '':
264 cmd += '--task-args-file test_config/rally/task_arguments.yaml; '
265 break
266 default:
267 cmd += "--task-args-file ${tasks_args_file}; "
268 break
269 }
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800270 }
271 cmd += "rally task export --type junit-xml --to ${dest_folder}/report-rally.xml; " +
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700272 "rally task report --out ${dest_folder}/report-rally.html"
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400273 full_cmd = cmd0 + cmd
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700274 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400275 "-v ${results}:${dest_folder} " +
276 "--entrypoint /bin/bash ${dockerImageLink} " +
277 "-c \"${full_cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700278 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700279}
280
281/**
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700282 * Generate test report
283 *
284 * @param target Host to run script from
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700285 * @param dockerImageLink Docker image link
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700286 * @param output_dir Directory for results
287 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700288def generateTestReport(master, target, dockerImageLink, output_dir) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700289 def report_file = 'jenkins_test_report.html'
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700290 def salt = new com.mirantis.mk.Salt()
291 def common = new com.mirantis.mk.Common()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700292 def results = '/root/qa_results'
293 def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results'
294 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
295 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
296 def reports = ['report-tempest.json',
297 'report-rally.xml',
298 'report-k8s-e2e-tests.txt',
299 'report-ha.json',
300 'report-spt.txt']
301 for ( report in reports ) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700302 if ( fileExists("${output_dir}${report}") ) {
303 common.infoMsg("Copying ${report} to docker container")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700304 def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " +
305 "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " +
306 "rm ${output_dir}${report}_encoded; " +
307 "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true)
308 for ( item in items.tokenize() ) {
309 def content = sh(script: "cat ${output_dir}${item}", returnStdout: true)
310 salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false)
311 sh(script: "rm ${output_dir}${item}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700312 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700313 salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " +
314 "rm ${results}/${report}_encoded", false, null, false)
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700315 }
316 }
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700317
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700318 def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " +
319 "cp ${report_file} ${dest_folder}/${report_file}"
320 salt.cmdRun(master, target, "docker run -i --rm --net=host " +
321 "-v ${results}:${dest_folder} ${dockerImageLink} " +
322 "/bin/bash -c \"${cmd}\"")
323 def report_content = salt.getFileContent(master, target, "${results}/${report_file}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700324 writeFile file: "${output_dir}${report_file}", text: report_content
325}
326
327/**
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700328 * Execute SPT tests
329 *
330 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700331 * @param dockerImageLink Docker image link
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700332 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700333 * @param ext_variables The list of external variables
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700334 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700335def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = []) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700336 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700337 def results = '/root/qa_results'
338 def dest_folder = '/home/rally/qa_results'
339 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
340 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
341 def nodes = getNodeList(master)
342 def nodes_hw = getNodeList(master, 'G@virtual:physical')
343 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
344 def keystone = _pillar['return'][0].values()[0]
345 def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
346 def env_vars = ( ['tempest_version=15.0.0',
347 "OS_USERNAME=${keystone.admin_name}",
348 "OS_PASSWORD=${keystone.admin_password}",
349 "OS_TENANT_NAME=${keystone.admin_tenant}",
350 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
351 "OS_REGION_NAME=${keystone.region}",
352 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
353 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes])
354 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw])
355 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
356 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' +
357 "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " +
358 'sudo chmod 600 /root/.ssh/id_rsa; ' +
359 "sudo timmy -c simplified-performance-testing/config.yaml " +
360 "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " +
361 "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " +
362 "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " +
363 "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz"
364 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
365 "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " +
366 "\"${cmd}\" > ${results}/docker-spt.log")
367 addFiles(master, target, results, output_dir)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700368}
369
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700370/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600371 * Configure docker container
372 *
373 * @param target Host to run container
374 * @param proxy Proxy for accessing github and pip
375 * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc.
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600376 * @param tempest_repo Tempest repo to clone. Can be upstream tempest (default, recommended), your customized tempest in local/remote repo or path inside container. If not specified, tempest will not be configured.
377 * @param tempest_endpoint_type internalURL or adminURL or publicURL to use in tests
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600378 * @param tempest_version Version of tempest to use
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600379 * @param conf_script_path Path to configuration script.
380 * @param ext_variables Some custom extra variables to add into container
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600381 */
382def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo,
383 tempest_endpoint_type="internalURL", tempest_version="15.0.0",
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600384 conf_script_path="", ext_variables = []) {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600385 def salt = new com.mirantis.mk.Salt()
386 if (testing_tools_repo != "" ) {
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600387 salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo} cvp-configuration")
388 configure_script = conf_script_path != "" ? conf_script_path : "/home/rally/cvp-configuration/configure.sh"
389 } else {
390 configure_script = conf_script_path != "" ? conf_script_path : "/opt/devops-qa-tools/deployment/configure.sh"
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600391 }
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600392 ext_variables.addAll("PROXY=${proxy}", "TEMPEST_REPO=${tempest_repo}",
393 "TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type}",
394 "tempest_version=${tempest_version}")
395 salt.cmdRun(master, target, "docker exec -e " + ext_variables.join(' -e ') + " cvp bash -c ${configure_script}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600396}
397
398/**
399 * Run Tempest
400 *
401 * @param target Host to run container
402 * @param test_pattern Test pattern to run
403 * @param skip_list Path to skip-list
404 * @param output_dir Directory on target host for storing results (containers is not a good place)
405 */
406def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") {
407 def salt = new com.mirantis.mk.Salt()
408 def xml_file = "${output_filename}.xml"
Oleksii Zhurba44045312017-12-12 15:38:26 -0600409 def html_file = "${output_filename}.html"
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600410 def log_file = "${output_filename}.log"
411 skip_list_cmd = ''
412 if (skip_list != '') {
413 skip_list_cmd = "--skip-list ${skip_list}"
414 }
415 salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} " +
416 "--detailed > ${log_file}", false)
417 salt.cmdRun(master, target, "cat ${log_file}")
418 salt.cmdRun(master, target, "docker exec cvp rally verify report --type junit-xml --to /home/rally/${xml_file}")
Oleksii Zhurba44045312017-12-12 15:38:26 -0600419 salt.cmdRun(master, target, "docker exec cvp rally verify report --type html --to /home/rally/${html_file}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600420 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
Oleksii Zhurba44045312017-12-12 15:38:26 -0600421 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600422 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]
423}
424
425/**
426 * Run Rally
427 *
428 * @param target Host to run container
429 * @param test_pattern Test pattern to run
430 * @param scenarios_path Path to Rally scenarios
431 * @param output_dir Directory on target host for storing results (containers is not a good place)
432 */
433def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally") {
434 def salt = new com.mirantis.mk.Salt()
435 def xml_file = "${output_filename}.xml"
436 def log_file = "${output_filename}.log"
437 def html_file = "${output_filename}.html"
438 salt.cmdRun(master, target, "docker exec cvp rally task start ${scenarios_path} > ${log_file}", false)
439 salt.cmdRun(master, target, "cat ${log_file}")
440 salt.cmdRun(master, target, "docker exec cvp rally task report --out ${html_file}")
441 salt.cmdRun(master, target, "docker exec cvp rally task export --type junit-xml --to ${xml_file}")
442 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
443 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
444}
445
446
447/**
448 * Shutdown node
449 *
450 * @param target Host to run command
451 * @param mode How to shutdown node
452 * @param retries # of retries to make to check node status
453 */
454def shutdown_vm_node(master, target, mode, retries=200) {
455 def salt = new com.mirantis.mk.Salt()
456 def common = new com.mirantis.mk.Common()
457 if (mode == 'reboot') {
458 try {
459 def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3)
460 } catch (Exception e) {
461 common.warningMsg('Timeout from minion: node must be rebooting now')
462 }
463 common.warningMsg("Checking that minion is down")
464 status = "True"
465 for (i = 0; i < retries; i++) {
466 status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1)
467 if (status != "True") {
468 break
469 }
470 }
471 if (status == "True") {
472 throw new Exception("Tired to wait for minion ${target} to stop responding")
473 }
474 }
475 if (mode == 'hard_shutdown' || mode == 'soft_shutdown') {
476 kvm = locate_node_on_kvm(master, target)
477 if (mode == 'soft_shutdown') {
478 salt.cmdRun(master, target, "shutdown -h 0")
479 }
480 if (mode == 'hard_shutdown') {
481 salt.cmdRun(master, kvm, "virsh destroy ${target}")
482 }
483 common.warningMsg("Checking that vm on kvm is in power off state")
484 status = 'running'
485 for (i = 0; i < retries; i++) {
486 status = check_vm_status(master, target, kvm)
487 echo "Current status - ${status}"
488 if (status != 'running') {
489 break
490 }
491 sleep (1)
492 }
493 if (status == 'running') {
494 throw new Exception("Tired to wait for node ${target} to shutdown")
495 }
496 }
497}
498
499
500/**
501 * Locate kvm where target host is located
502 *
503 * @param target Host to check
504 */
505def locate_node_on_kvm(master, target) {
506 def salt = new com.mirantis.mk.Salt()
507 def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
508 for (item in list.keySet()) {
509 if (list[item]) {
510 return item
511 }
512 }
513}
514
515/**
516 * Check target host status
517 *
518 * @param target Host to check
519 * @param kvm KVM node where target host is located
520 */
521def check_vm_status(master, target, kvm) {
522 def salt = new com.mirantis.mk.Salt()
523 def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
524 for (item in list.keySet()) {
525 if (list[item]) {
526 return list[item].split()[2]
527 }
528 }
529}
530
531/**
532 * Find vip on nodes
533 *
534 * @param target Pattern, e.g. ctl*
535 */
536def get_vip_node(master, target) {
537 def salt = new com.mirantis.mk.Salt()
538 def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep global | grep -v brd"])['return'][0]
539 for (item in list.keySet()) {
540 if (list[item]) {
541 return item
542 }
543 }
544}
545
546/**
547 * Find vip on nodes
548 *
549 * @param target Host with cvp container
550 */
Oleksii Zhurbad13e9c82017-12-14 17:41:32 -0600551def openstack_cleanup(master, target, script_path="/home/rally/cvp-configuration/clean.sh") {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600552 def salt = new com.mirantis.mk.Salt()
553 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec cvp bash -c ${script_path}"])
554}
555
556
557/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700558 * Cleanup
559 *
560 * @param target Host to run commands
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700561 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700562def runCleanup(master, target) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700563 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov321405a2017-08-16 16:38:51 -0700564 if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) {
565 salt.cmdRun(master, target, "docker rm -f qa_tools")
566 }
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600567 if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) {
568 salt.cmdRun(master, target, "docker rm -f cvp")
569 }
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700570}
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500571/**
572 * Prepare venv for any python project
573 * Note: <repo_name>\/requirements.txt content will be used
574 * for this venv
575 *
576 * @param repo_url Repository url to clone
577 * @param proxy Proxy address to use
578 */
579def prepareVenv(repo_url, proxy) {
580 def python = new com.mirantis.mk.Python()
581 repo_name = "${repo_url}".tokenize("/").last()
582 sh "rm -rf ${repo_name}"
583 withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
584 sh "git clone ${repo_url}"
585 python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true)
586 }
587}
588
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700589/** Install docker if needed
590 *
591 * @param target Target node to install docker pkg
592 */
593def installDocker(master, target) {
594 def salt = new com.mirantis.mk.Salt()
595 if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) {
596 salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
597 }
598}