blob: e33738c2eedea92362109baee6cba5ef2508dbf6 [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 Zhurba1bf9be12018-01-17 15:20:00 -060015def runBasicContainer(master, target, dockerImageLink="xrally/xrally-openstack:0.9.1"){
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 Zhurba1bf9be12018-01-17 15:20:00 -060027 "-e OS_REGION_NAME=${keystone.region} -e OS_ENDPOINT_TYPE=admin --entrypoint /bin/bash ${dockerImageLink}")
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/**
Oleksii Zhurba4e366ff2018-02-16 20:06:52 -0600165 * Execute pytest framework tests
166 *
167 * @param salt_url Salt master url
168 * @param salt_credentials Salt credentials
169 * @param test_set Test set to run
170 * @param env_vars Additional environment variables for cvp-sanity-checks
171 * @param output_dir Directory for results
172 */
173def runTests(salt_url, salt_credentials, test_set="", output_dir="validation_artifacts/", env_vars="") {
174 def common = new com.mirantis.mk.Common()
175 def creds = common.getCredentials(salt_credentials)
176 def username = creds.username
177 def password = creds.password
178 def settings = ""
179 if ( env_vars != "" ) {
180 for (var in env_vars.tokenize(";")) {
181 settings += "export ${var}; "
182 }
183 }
184 def script = ". ${env.WORKSPACE}/venv/bin/activate; ${settings}" +
185 "pytest --junitxml ${output_dir}report.xml --tb=short -sv ${env.WORKSPACE}/${test_set}"
186 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
187 def statusCode = sh script:script, returnStatus:true
188 }
189}
190
191/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700192 * Execute tempest tests
193 *
194 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700195 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700196 * @param pattern If not false, will run only tests matched the pattern
197 * @param output_dir Directory for results
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800198 * @param confRepository Git repository with configuration files for Tempest
199 * @param confBranch Git branch which will be used during the checkout
200 * @param repository Git repository with Tempest
201 * @param version Version of Tempest (tag, branch or commit)
Sergey Galkind1068e22018-02-13 13:59:32 +0400202 * @param results The reports directory
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700203 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400204def runTempestTests(master, target, dockerImageLink, output_dir, confRepository, confBranch, repository, version, pattern = "false", results = '/root/qa_results') {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700205 def salt = new com.mirantis.mk.Salt()
206 def output_file = 'docker-tempest.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700207 def dest_folder = '/home/rally/qa_results'
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800208 def skip_list = '--skip-list /opt/devops-qa-tools/deployment/skip_contrail.list'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700209 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
210 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
211 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
212 def keystone = _pillar['return'][0].values()[0]
213 def env_vars = ['tempest_version=15.0.0',
214 "OS_USERNAME=${keystone.admin_name}",
215 "OS_PASSWORD=${keystone.admin_password}",
216 "OS_TENANT_NAME=${keystone.admin_tenant}",
217 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
218 "OS_REGION_NAME=${keystone.region}",
219 'OS_ENDPOINT_TYPE=admin'].join(' -e ')
220 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; '
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800221 if (confRepository != '' ) {
222 cmd = "git clone -b ${confBranch ?: 'master'} ${confRepository} test_config; " +
223 'rally deployment create --fromenv --name=tempest; rally deployment config; ' +
224 'rally verify create-verifier --name tempest_verifier --type tempest ' +
225 "--source ${repository ?: '/tmp/tempest/'} --version ${version: '15.0.0'}; " +
226 'rally verify configure-verifier --extend test_config/tempest/tempest.conf --show; '
227 skip_list = '--skip-list test_config/tempest/skip-list.yaml'
228 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700229 if (pattern == 'false') {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800230 cmd += "rally verify start --pattern set=full ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700231 }
232 else {
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800233 cmd += "rally verify start --pattern set=${pattern} ${skip_list} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700234 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700235 cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " +
236 "rally verify report --type html --to ${dest_folder}/report-tempest.html"
237 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
Sergey Galkin193ef872017-11-29 14:20:35 +0400238 "-v ${results}:${dest_folder} --entrypoint /bin/bash ${dockerImageLink} " +
239 "-c \"${cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700240 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700241}
242
243/**
244 * Execute rally tests
245 *
246 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700247 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700248 * @param output_dir Directory for results
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800249 * @param repository Git repository with files for Rally
250 * @param branch Git branch which will be used during the checkout
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700251 * @param ext_variables The list of external variables
Sergey Galkind1068e22018-02-13 13:59:32 +0400252 * @param results The reports directory
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700253 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400254def runRallyTests(master, target, dockerImageLink, output_dir, repository, branch, scenarios, tasks_args_file, ext_variables = [], results = '/root/qa_results') {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700255 def salt = new com.mirantis.mk.Salt()
256 def output_file = 'docker-rally.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700257 def dest_folder = '/home/rally/qa_results'
258 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
259 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
260 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
261 def keystone = _pillar['return'][0].values()[0]
262 def env_vars = ( ['tempest_version=15.0.0',
263 "OS_USERNAME=${keystone.admin_name}",
264 "OS_PASSWORD=${keystone.admin_password}",
265 "OS_TENANT_NAME=${keystone.admin_tenant}",
266 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
267 "OS_REGION_NAME=${keystone.region}",
268 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400269 def cmd0 = ''
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700270 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
271 'rally task start combined_scenario.yaml ' +
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800272 '--task-args-file /opt/devops-qa-tools/rally-scenarios/task_arguments.yaml; '
273 if (repository != '' ) {
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400274 cmd = 'rally deployment create --fromenv --name=existing; ' +
Sergey Galkinea53f922017-11-29 19:11:54 +0400275 'rally deployment config; '
276 if (scenarios == '') {
277 cmd += 'rally task start test_config/rally/scenario.yaml '
278 } else {
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400279 cmd += "rally task start scenarios.yaml "
280 cmd0 = "git clone -b ${branch ?: 'master'} ${repository} test_config; " +
281 "if [ -f ${scenarios} ]; then cp ${scenarios} scenarios.yaml; " +
282 "else " +
Sergey Galkin60ea8962018-01-17 14:48:11 +0400283 "find -L ${scenarios} -name '*.yaml' -exec cat {} >> scenarios.yaml \\; ; " +
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400284 "sed -i '/---/d' scenarios.yaml; fi; "
Sergey Galkinea53f922017-11-29 19:11:54 +0400285 }
286 switch(tasks_args_file) {
287 case 'none':
288 cmd += '; '
289 break
290 case '':
291 cmd += '--task-args-file test_config/rally/task_arguments.yaml; '
292 break
293 default:
294 cmd += "--task-args-file ${tasks_args_file}; "
295 break
296 }
Dmitrii Kabanov999fda92017-11-10 00:18:30 -0800297 }
298 cmd += "rally task export --type junit-xml --to ${dest_folder}/report-rally.xml; " +
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700299 "rally task report --out ${dest_folder}/report-rally.html"
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400300 full_cmd = cmd0 + cmd
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700301 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
Sergey Galkin3c1e9e22018-01-12 16:31:53 +0400302 "-v ${results}:${dest_folder} " +
303 "--entrypoint /bin/bash ${dockerImageLink} " +
304 "-c \"${full_cmd}\" > ${results}/${output_file}")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700305 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700306}
307
308/**
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700309 * Generate test report
310 *
311 * @param target Host to run script from
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700312 * @param dockerImageLink Docker image link
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700313 * @param output_dir Directory for results
Sergey Galkind1068e22018-02-13 13:59:32 +0400314 * @param results The reports directory
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700315 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400316def generateTestReport(master, target, dockerImageLink, output_dir, results = '/root/qa_results') {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700317 def report_file = 'jenkins_test_report.html'
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700318 def salt = new com.mirantis.mk.Salt()
319 def common = new com.mirantis.mk.Common()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700320 def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results'
321 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
322 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
323 def reports = ['report-tempest.json',
324 'report-rally.xml',
325 'report-k8s-e2e-tests.txt',
326 'report-ha.json',
327 'report-spt.txt']
328 for ( report in reports ) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700329 if ( fileExists("${output_dir}${report}") ) {
330 common.infoMsg("Copying ${report} to docker container")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700331 def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " +
332 "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " +
333 "rm ${output_dir}${report}_encoded; " +
334 "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true)
335 for ( item in items.tokenize() ) {
336 def content = sh(script: "cat ${output_dir}${item}", returnStdout: true)
337 salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false)
338 sh(script: "rm ${output_dir}${item}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700339 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700340 salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " +
341 "rm ${results}/${report}_encoded", false, null, false)
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700342 }
343 }
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700344
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700345 def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " +
346 "cp ${report_file} ${dest_folder}/${report_file}"
347 salt.cmdRun(master, target, "docker run -i --rm --net=host " +
348 "-v ${results}:${dest_folder} ${dockerImageLink} " +
349 "/bin/bash -c \"${cmd}\"")
350 def report_content = salt.getFileContent(master, target, "${results}/${report_file}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700351 writeFile file: "${output_dir}${report_file}", text: report_content
352}
353
354/**
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700355 * Execute SPT tests
356 *
357 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700358 * @param dockerImageLink Docker image link
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700359 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700360 * @param ext_variables The list of external variables
Sergey Galkind1068e22018-02-13 13:59:32 +0400361 * @param results The reports directory
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700362 */
Sergey Galkind1068e22018-02-13 13:59:32 +0400363def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = [], results = '/root/qa_results') {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700364 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700365 def dest_folder = '/home/rally/qa_results'
366 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
367 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
368 def nodes = getNodeList(master)
369 def nodes_hw = getNodeList(master, 'G@virtual:physical')
370 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
371 def keystone = _pillar['return'][0].values()[0]
372 def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
373 def env_vars = ( ['tempest_version=15.0.0',
374 "OS_USERNAME=${keystone.admin_name}",
375 "OS_PASSWORD=${keystone.admin_password}",
376 "OS_TENANT_NAME=${keystone.admin_tenant}",
377 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
378 "OS_REGION_NAME=${keystone.region}",
379 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
380 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes])
381 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw])
382 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
383 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' +
384 "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " +
385 'sudo chmod 600 /root/.ssh/id_rsa; ' +
386 "sudo timmy -c simplified-performance-testing/config.yaml " +
387 "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " +
388 "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " +
389 "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " +
390 "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz"
391 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
392 "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " +
393 "\"${cmd}\" > ${results}/docker-spt.log")
394 addFiles(master, target, results, output_dir)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700395}
396
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700397/**
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600398 * Configure docker container
399 *
400 * @param target Host to run container
401 * @param proxy Proxy for accessing github and pip
402 * @param testing_tools_repo Repo with testing tools: configuration script, skip-list, etc.
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600403 * @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.
404 * @param tempest_endpoint_type internalURL or adminURL or publicURL to use in tests
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600405 * @param tempest_version Version of tempest to use
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600406 * @param conf_script_path Path to configuration script.
407 * @param ext_variables Some custom extra variables to add into container
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600408 */
409def configureContainer(master, target, proxy, testing_tools_repo, tempest_repo,
410 tempest_endpoint_type="internalURL", tempest_version="15.0.0",
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600411 conf_script_path="", ext_variables = []) {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600412 def salt = new com.mirantis.mk.Salt()
413 if (testing_tools_repo != "" ) {
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600414 salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo} cvp-configuration")
Oleksii Zhurba1bf9be12018-01-17 15:20:00 -0600415 configure_script = conf_script_path != "" ? conf_script_path : "cvp-configuration/configure.sh"
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600416 } else {
417 configure_script = conf_script_path != "" ? conf_script_path : "/opt/devops-qa-tools/deployment/configure.sh"
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600418 }
Oleksii Zhurba1579b972017-12-14 15:21:56 -0600419 ext_variables.addAll("PROXY=${proxy}", "TEMPEST_REPO=${tempest_repo}",
420 "TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type}",
421 "tempest_version=${tempest_version}")
422 salt.cmdRun(master, target, "docker exec -e " + ext_variables.join(' -e ') + " cvp bash -c ${configure_script}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600423}
424
425/**
426 * Run Tempest
427 *
428 * @param target Host to run container
429 * @param test_pattern Test pattern to run
430 * @param skip_list Path to skip-list
431 * @param output_dir Directory on target host for storing results (containers is not a good place)
432 */
433def runCVPtempest(master, target, test_pattern="set=smoke", skip_list="", output_dir, output_filename="docker-tempest") {
434 def salt = new com.mirantis.mk.Salt()
435 def xml_file = "${output_filename}.xml"
Oleksii Zhurba44045312017-12-12 15:38:26 -0600436 def html_file = "${output_filename}.html"
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600437 def log_file = "${output_filename}.log"
438 skip_list_cmd = ''
439 if (skip_list != '') {
440 skip_list_cmd = "--skip-list ${skip_list}"
441 }
442 salt.cmdRun(master, target, "docker exec cvp rally verify start --pattern ${test_pattern} ${skip_list_cmd} " +
443 "--detailed > ${log_file}", false)
444 salt.cmdRun(master, target, "cat ${log_file}")
445 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 -0600446 salt.cmdRun(master, target, "docker exec cvp rally verify report --type html --to /home/rally/${html_file}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600447 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
Oleksii Zhurba44045312017-12-12 15:38:26 -0600448 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
Oleksii Zhurba1bf9be12018-01-17 15:20:00 -0600449 return salt.cmdRun(master, target, "docker exec cvp rally verify show | head -5 | tail -1 | awk '{print \$4}'")['return'][0].values()[0].split()[0]
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600450}
451
452/**
453 * Run Rally
454 *
455 * @param target Host to run container
456 * @param test_pattern Test pattern to run
457 * @param scenarios_path Path to Rally scenarios
458 * @param output_dir Directory on target host for storing results (containers is not a good place)
459 */
460def runCVPrally(master, target, scenarios_path, output_dir, output_filename="docker-rally") {
461 def salt = new com.mirantis.mk.Salt()
462 def xml_file = "${output_filename}.xml"
463 def log_file = "${output_filename}.log"
464 def html_file = "${output_filename}.html"
465 salt.cmdRun(master, target, "docker exec cvp rally task start ${scenarios_path} > ${log_file}", false)
466 salt.cmdRun(master, target, "cat ${log_file}")
467 salt.cmdRun(master, target, "docker exec cvp rally task report --out ${html_file}")
Oleksii Zhurba1bf9be12018-01-17 15:20:00 -0600468 salt.cmdRun(master, target, "docker exec cvp rally task report --junit --out ${xml_file}")
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600469 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${xml_file} ${output_dir}")
470 salt.cmdRun(master, target, "docker cp cvp:/home/rally/${html_file} ${output_dir}")
471}
472
473
474/**
475 * Shutdown node
476 *
477 * @param target Host to run command
478 * @param mode How to shutdown node
479 * @param retries # of retries to make to check node status
480 */
481def shutdown_vm_node(master, target, mode, retries=200) {
482 def salt = new com.mirantis.mk.Salt()
483 def common = new com.mirantis.mk.Common()
484 if (mode == 'reboot') {
485 try {
486 def out = salt.runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'cmd.run', null, ['reboot'], null, 3, 3)
487 } catch (Exception e) {
488 common.warningMsg('Timeout from minion: node must be rebooting now')
489 }
490 common.warningMsg("Checking that minion is down")
491 status = "True"
492 for (i = 0; i < retries; i++) {
493 status = salt.minionsReachable(master, 'I@salt:master', target, null, 5, 1)
494 if (status != "True") {
495 break
496 }
497 }
498 if (status == "True") {
499 throw new Exception("Tired to wait for minion ${target} to stop responding")
500 }
501 }
502 if (mode == 'hard_shutdown' || mode == 'soft_shutdown') {
503 kvm = locate_node_on_kvm(master, target)
504 if (mode == 'soft_shutdown') {
505 salt.cmdRun(master, target, "shutdown -h 0")
506 }
507 if (mode == 'hard_shutdown') {
508 salt.cmdRun(master, kvm, "virsh destroy ${target}")
509 }
510 common.warningMsg("Checking that vm on kvm is in power off state")
511 status = 'running'
512 for (i = 0; i < retries; i++) {
513 status = check_vm_status(master, target, kvm)
514 echo "Current status - ${status}"
515 if (status != 'running') {
516 break
517 }
518 sleep (1)
519 }
520 if (status == 'running') {
521 throw new Exception("Tired to wait for node ${target} to shutdown")
522 }
523 }
524}
525
526
527/**
528 * Locate kvm where target host is located
529 *
530 * @param target Host to check
531 */
532def locate_node_on_kvm(master, target) {
533 def salt = new com.mirantis.mk.Salt()
534 def list = salt.runSaltProcessStep(master, "I@salt:control", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
535 for (item in list.keySet()) {
536 if (list[item]) {
537 return item
538 }
539 }
540}
541
542/**
543 * Check target host status
544 *
545 * @param target Host to check
546 * @param kvm KVM node where target host is located
547 */
548def check_vm_status(master, target, kvm) {
549 def salt = new com.mirantis.mk.Salt()
550 def list = salt.runSaltProcessStep(master, "${kvm}", 'cmd.run', ["virsh list --all | grep ' ${target}'"])['return'][0]
551 for (item in list.keySet()) {
552 if (list[item]) {
553 return list[item].split()[2]
554 }
555 }
556}
557
558/**
559 * Find vip on nodes
560 *
561 * @param target Pattern, e.g. ctl*
562 */
563def get_vip_node(master, target) {
564 def salt = new com.mirantis.mk.Salt()
565 def list = salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["ip a | grep global | grep -v brd"])['return'][0]
566 for (item in list.keySet()) {
567 if (list[item]) {
568 return item
569 }
570 }
571}
572
573/**
574 * Find vip on nodes
575 *
576 * @param target Host with cvp container
577 */
Oleksii Zhurbad13e9c82017-12-14 17:41:32 -0600578def openstack_cleanup(master, target, script_path="/home/rally/cvp-configuration/clean.sh") {
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600579 def salt = new com.mirantis.mk.Salt()
580 salt.runSaltProcessStep(master, "${target}", 'cmd.run', ["docker exec cvp bash -c ${script_path}"])
581}
582
583
584/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700585 * Cleanup
586 *
587 * @param target Host to run commands
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700588 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700589def runCleanup(master, target) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700590 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov321405a2017-08-16 16:38:51 -0700591 if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) {
592 salt.cmdRun(master, target, "docker rm -f qa_tools")
593 }
Oleksii Zhurba7b44ef12017-11-13 17:50:16 -0600594 if ( salt.cmdRun(master, target, "docker ps -f name=cvp -q", false, null, false)['return'][0].values()[0] ) {
595 salt.cmdRun(master, target, "docker rm -f cvp")
596 }
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700597}
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500598/**
599 * Prepare venv for any python project
600 * Note: <repo_name>\/requirements.txt content will be used
601 * for this venv
602 *
603 * @param repo_url Repository url to clone
604 * @param proxy Proxy address to use
605 */
606def prepareVenv(repo_url, proxy) {
607 def python = new com.mirantis.mk.Python()
608 repo_name = "${repo_url}".tokenize("/").last()
609 sh "rm -rf ${repo_name}"
610 withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
611 sh "git clone ${repo_url}"
612 python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true)
613 }
614}
615
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700616/** Install docker if needed
617 *
618 * @param target Target node to install docker pkg
619 */
620def installDocker(master, target) {
621 def salt = new com.mirantis.mk.Salt()
622 if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) {
623 salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
624 }
625}