blob: 23b183a9a839b07faa1c5d4f90b693a2163ac97e [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/**
10 * Configure docker image with tests
11 *
12 * @param dockerImageLink Docker image link with rally and tempest
13 * @param target Host to run tests
14 * @param output_dir Directory for results
Dmitrii Kabanov65fdc282017-09-29 10:53:08 -070015 * @param ext_variables The set of external variables
Petr Lomakin47fee0a2017-08-01 10:46:05 -070016 */
Dmitrii Kabanov65fdc282017-09-29 10:53:08 -070017def runContainerConfiguration(master, dockerImageLink, target, output_dir, ext_variables){
Petr Lomakin47fee0a2017-08-01 10:46:05 -070018 def salt = new com.mirantis.mk.Salt()
19 def common = new com.mirantis.mk.Common()
20 def output_file = 'docker.log'
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070021 def nodes = getNodeList(master)
22 def nodes_hw = getNodeList(master, 'G@virtual:physical')
Sam Stoelinga28bdb722017-09-25 18:29:59 -070023 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
24 def keystone = _pillar['return'][0].values()[0]
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070025 def ssh_key = getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
Petr Lomakin47fee0a2017-08-01 10:46:05 -070026 salt.cmdRun(master, target, "docker run -tid --net=host --name=qa_tools " +
Dmitrii Kabanov65fdc282017-09-29 10:53:08 -070027 " ${ext_variables} " +
Petr Lomakin47fee0a2017-08-01 10:46:05 -070028 "-e tempest_version=15.0.0 -e OS_USERNAME=${keystone.admin_name} " +
29 "-e OS_PASSWORD=${keystone.admin_password} -e OS_TENANT_NAME=${keystone.admin_tenant} " +
30 "-e OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0 " +
31 "-e OS_REGION_NAME=${keystone.region} -e OS_ENDPOINT_TYPE=admin ${dockerImageLink} /bin/bash")
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070032 salt.cmdRun(master, target, "docker exec qa_tools bash -c \"sudo mkdir -p /root/.ssh; " +
33 "echo \'${ssh_key}\' | sudo tee /root/.ssh/id_rsa > /dev/null; " +
34 "sudo chmod 700 /root/.ssh; sudo chmod 600 /root/.ssh/id_rsa; " +
35 "echo -e '${nodes}' > nodes.json; echo -e '${nodes_hw}' > nodes_hw.json\"")
Petr Lomakin47fee0a2017-08-01 10:46:05 -070036 salt.cmdRun(master, target, "docker exec qa_tools bash -c /opt/devops-qa-tools/deployment/configure.sh > ${output_file}")
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070037 def file_content = getFileContent(master, target, output_file)
Petr Lomakin47fee0a2017-08-01 10:46:05 -070038 writeFile file: "${output_dir}${output_file}", text: file_content
39}
40
41/**
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070042 * Get file content (encoded). The content encoded by Base64.
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070043 *
44 * @param target Compound target (should target only one host)
45 * @param file File path to read
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070046 * @return The encoded content of the file
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070047 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070048def getFileContentEncoded(master, target, file) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070049 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070050 def file_content = ''
51 def cmd = "base64 -w0 ${file} > ${file}_encoded; " +
52 "split -b 1MB -d ${file}_encoded ${file}__; " +
53 "rm ${file}_encoded"
54 salt.cmdRun(master, target, cmd, false, null, false)
55 def filename = file.tokenize('/').last()
56 def folder = file - filename
57 def parts = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*"])
58 for ( part in parts['return'][0].values()[0]) {
59 def _result = salt.cmdRun(master, target, "cat ${part}", false, null, false)
60 file_content = file_content + _result['return'][0].values()[0].replaceAll('Salt command execution success','')
61 }
62 salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f", "name=${filename}__*", "delete"])
63 return file_content
64}
65
66/**
67 * Copy files from remote to local directory. The content of files will be
68 * decoded by Base64.
69 *
70 * @param target Compound target (should target only one host)
71 * @param folder The path to remote folder.
72 * @param output_dir The path to local folder.
73 */
74def addFiles(master, target, folder, output_dir) {
75 def salt = new com.mirantis.mk.Salt()
76 def _result = salt.runSaltProcessStep(master, target, 'file.find', ["${folder}", "type=f"])
77 def files = _result['return'][0].values()[0]
78 for (file in files) {
79 def file_content = getFileContentEncoded(master, target, "${file}")
80 def fileName = file.tokenize('/').last()
81 writeFile file: "${output_dir}${fileName}_encoded", text: file_content
82 def cmd = "base64 -d ${output_dir}${fileName}_encoded > ${output_dir}${fileName}; " +
83 "rm ${output_dir}${fileName}_encoded"
84 sh(script: cmd)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -070085 }
86}
87
88/**
89 * Get reclass value
90 *
91 * @param target The host for which the values will be provided
92 * @param filter Parameters divided by dots
93 * @return The pillar data
94 */
95def getReclassValue(master, target, filter) {
96 def common = new com.mirantis.mk.Common()
97 def salt = new com.mirantis.mk.Salt()
98 def items = filter.tokenize('.')
Dmitrii Kabanov23901c22017-10-20 10:25:36 -070099 def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -p ${target}", false, null, false)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700100 _result = common.parseJSON(_result['return'][0].values()[0])
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700101 for (int k = 0; k < items.size(); k++) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700102 if ( _result ) {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700103 _result = _result["${items[k]}"]
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700104 }
105 }
106 return _result
107}
108
109/**
110 * Create list of nodes in JSON format.
111 *
112 * @param filter The Salt's matcher
113 * @return JSON list of nodes
114 */
115def getNodeList(master, filter = null) {
116 def salt = new com.mirantis.mk.Salt()
117 def common = new com.mirantis.mk.Common()
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700118 def nodes = []
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700119 def filtered_list = null
120 def controllers = salt.getMinions(master, 'I@nova:controller')
121 def hw_nodes = salt.getMinions(master, 'G@virtual:physical')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700122 if ( filter ) {
123 filtered_list = salt.getMinions(master, filter)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700124 }
125 def _result = salt.cmdRun(master, 'I@salt:master', "reclass-salt -o json -t", false, null, false)
126 def reclass_top = common.parseJSON(_result['return'][0].values()[0])
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700127 def nodesList = reclass_top['base'].keySet()
128 for (int i = 0; i < nodesList.size(); i++) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700129 if ( filtered_list ) {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700130 if ( ! filtered_list.contains(nodesList[i]) ) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700131 continue
132 }
133 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700134 def ip = getReclassValue(master, nodesList[i], '_param.linux_single_interface.address')
135 def network_data = [ip: ip, name: 'management']
136 def roles = [nodesList[i].tokenize('.')[0]]
137 if ( controllers.contains(nodesList[i]) ) {
138 roles.add('controller')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700139 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700140 if ( hw_nodes.contains(nodesList[i]) ) {
141 roles.add('hw_node')
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700142 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700143 nodes.add([id: i+1, ip: ip, roles: roles, network_data: [network_data]])
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700144 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700145 return common.prettify(nodes)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700146}
147
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500148/**
149 * Execute mcp sanity tests
150 *
151 * @param salt_url Salt master url
152 * @param salt_credentials Salt credentials
153 * @param test_set Test set for mcp sanity framework
154 * @param output_dir Directory for results
155 */
156def runSanityTests(salt_url, salt_credentials, test_set, output_dir) {
157 def common = new com.mirantis.mk.Common()
158 creds = common.getCredentials(salt_credentials)
159 username = creds.username
160 password = creds.password
161 def script = ". ${env.WORKSPACE}/venv/bin/activate; pytest --junitxml ${output_dir}cvp_sanity.xml -sv ${env.WORKSPACE}/cvp-sanity-checks/cvp_checks/tests/${test_set}"
162 withEnv(["SALT_USERNAME=${username}", "SALT_PASSWORD=${password}", "SALT_URL=${salt_url}"]) {
163 def statusCode = sh script:script, returnStatus:true
164 }
165}
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700166
167/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700168 * Execute tempest tests
169 *
170 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700171 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700172 * @param pattern If not false, will run only tests matched the pattern
173 * @param output_dir Directory for results
174 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700175def runTempestTests(master, target, dockerImageLink, output_dir, pattern = "false") {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700176 def salt = new com.mirantis.mk.Salt()
177 def output_file = 'docker-tempest.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700178 def results = '/root/qa_results'
179 def dest_folder = '/home/rally/qa_results'
180 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
181 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
182 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
183 def keystone = _pillar['return'][0].values()[0]
184 def env_vars = ['tempest_version=15.0.0',
185 "OS_USERNAME=${keystone.admin_name}",
186 "OS_PASSWORD=${keystone.admin_password}",
187 "OS_TENANT_NAME=${keystone.admin_tenant}",
188 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
189 "OS_REGION_NAME=${keystone.region}",
190 'OS_ENDPOINT_TYPE=admin'].join(' -e ')
191 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; '
192 if (pattern == 'false') {
193 cmd += 'rally verify start --pattern set=full --detailed; '
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700194 }
195 else {
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700196 cmd += "rally verify start --pattern set=${pattern} --detailed; "
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700197 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700198 cmd += "rally verify report --type json --to ${dest_folder}/report-tempest.json; " +
199 "rally verify report --type html --to ${dest_folder}/report-tempest.html"
200 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
201 "-v ${results}:${dest_folder} ${dockerImageLink} " +
202 "/bin/bash -c \"${cmd}\" > ${results}/${output_file}")
203 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700204}
205
206/**
207 * Execute rally tests
208 *
209 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700210 * @param dockerImageLink Docker image link
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700211 * @param pattern If not false, will run only tests matched the pattern
212 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700213 * @param ext_variables The list of external variables
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700214 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700215def runRallyTests(master, target, dockerImageLink, output_dir, ext_variables = []) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700216 def salt = new com.mirantis.mk.Salt()
217 def output_file = 'docker-rally.log'
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700218 def results = '/root/qa_results'
219 def dest_folder = '/home/rally/qa_results'
220 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
221 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
222 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
223 def keystone = _pillar['return'][0].values()[0]
224 def env_vars = ( ['tempest_version=15.0.0',
225 "OS_USERNAME=${keystone.admin_name}",
226 "OS_PASSWORD=${keystone.admin_password}",
227 "OS_TENANT_NAME=${keystone.admin_tenant}",
228 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
229 "OS_REGION_NAME=${keystone.region}",
230 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
231 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
232 'rally task start combined_scenario.yaml ' +
233 "--task-args-file /opt/devops-qa-tools/rally-scenarios/task_arguments.yaml; " +
234 "rally task export --type junit-xml --to ${dest_folder}/report-rally.xml; " +
235 "rally task report --out ${dest_folder}/report-rally.html"
236 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
237 "-v ${results}:${dest_folder} ${dockerImageLink} " +
238 "/bin/bash -c \"${cmd}\" > ${results}/${output_file}")
239 addFiles(master, target, results, output_dir)
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700240}
241
242/**
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700243 * Generate test report
244 *
245 * @param target Host to run script from
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700246 * @param dockerImageLink Docker image link
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700247 * @param output_dir Directory for results
248 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700249def generateTestReport(master, target, dockerImageLink, output_dir) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700250 def report_file = 'jenkins_test_report.html'
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700251 def salt = new com.mirantis.mk.Salt()
252 def common = new com.mirantis.mk.Common()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700253 def results = '/root/qa_results'
254 def dest_folder = '/opt/devops-qa-tools/generate_test_report/test_results'
255 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
256 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
257 def reports = ['report-tempest.json',
258 'report-rally.xml',
259 'report-k8s-e2e-tests.txt',
260 'report-ha.json',
261 'report-spt.txt']
262 for ( report in reports ) {
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700263 if ( fileExists("${output_dir}${report}") ) {
264 common.infoMsg("Copying ${report} to docker container")
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700265 def items = sh(script: "base64 -w0 ${output_dir}${report} > ${output_dir}${report}_encoded; " +
266 "split -b 100KB -d -a 4 ${output_dir}${report}_encoded ${output_dir}${report}__; " +
267 "rm ${output_dir}${report}_encoded; " +
268 "find ${output_dir} -type f -name ${report}__* -printf \'%f\\n\' | sort", returnStdout: true)
269 for ( item in items.tokenize() ) {
270 def content = sh(script: "cat ${output_dir}${item}", returnStdout: true)
271 salt.cmdRun(master, target, "echo \"${content}\" >> ${results}/${report}_encoded", false, null, false)
272 sh(script: "rm ${output_dir}${item}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700273 }
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700274 salt.cmdRun(master, target, "base64 -d ${results}/${report}_encoded > ${results}/${report}; " +
275 "rm ${results}/${report}_encoded", false, null, false)
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700276 }
277 }
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700278
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700279 def cmd = "jenkins_report.py --path /opt/devops-qa-tools/generate_test_report/; " +
280 "cp ${report_file} ${dest_folder}/${report_file}"
281 salt.cmdRun(master, target, "docker run -i --rm --net=host " +
282 "-v ${results}:${dest_folder} ${dockerImageLink} " +
283 "/bin/bash -c \"${cmd}\"")
284 def report_content = salt.getFileContent(master, target, "${results}/${report_file}")
Tetiana Korchak3383cc92017-08-25 09:36:19 -0700285 writeFile file: "${output_dir}${report_file}", text: report_content
286}
287
288/**
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700289 * Execute SPT tests
290 *
291 * @param target Host to run tests
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700292 * @param dockerImageLink Docker image link
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700293 * @param output_dir Directory for results
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700294 * @param ext_variables The list of external variables
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700295 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700296def runSptTests(master, target, dockerImageLink, output_dir, ext_variables = []) {
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700297 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700298 def results = '/root/qa_results'
299 def dest_folder = '/home/rally/qa_results'
300 salt.runSaltProcessStep(master, target, 'file.remove', ["${results}"])
301 salt.runSaltProcessStep(master, target, 'file.mkdir', ["${results}", "mode=777"])
302 def nodes = getNodeList(master)
303 def nodes_hw = getNodeList(master, 'G@virtual:physical')
304 def _pillar = salt.getPillar(master, 'I@keystone:server', 'keystone:server')
305 def keystone = _pillar['return'][0].values()[0]
306 def ssh_key = salt.getFileContent(master, 'I@salt:master', '/root/.ssh/id_rsa')
307 def env_vars = ( ['tempest_version=15.0.0',
308 "OS_USERNAME=${keystone.admin_name}",
309 "OS_PASSWORD=${keystone.admin_password}",
310 "OS_TENANT_NAME=${keystone.admin_tenant}",
311 "OS_AUTH_URL=http://${keystone.bind.private_address}:${keystone.bind.private_port}/v2.0",
312 "OS_REGION_NAME=${keystone.region}",
313 'OS_ENDPOINT_TYPE=admin'] + ext_variables ).join(' -e ')
314 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes.json", nodes])
315 salt.runSaltProcessStep(master, target, 'file.write', ["${results}/nodes_hw.json", nodes_hw])
316 def cmd = '/opt/devops-qa-tools/deployment/configure.sh; ' +
317 'sudo mkdir -p /root/.ssh; sudo chmod 700 /root/.ssh; ' +
318 "echo \\\"${ssh_key}\\\" | sudo tee /root/.ssh/id_rsa > /dev/null; " +
319 'sudo chmod 600 /root/.ssh/id_rsa; ' +
320 "sudo timmy -c simplified-performance-testing/config.yaml " +
321 "--nodes-json ${dest_folder}/nodes.json --log-file ${dest_folder}/docker-spt2.log; " +
322 "./simplified-performance-testing/SPT_parser.sh > ${dest_folder}/report-spt.txt; " +
323 "custom_spt_parser.sh ${dest_folder}/nodes_hw.json > ${dest_folder}/report-spt-hw.txt; " +
324 "cp /tmp/timmy/archives/general.tar.gz ${dest_folder}/results-spt.tar.gz"
325 salt.cmdRun(master, target, "docker run -i --rm --net=host -e ${env_vars} " +
326 "-v ${results}:${dest_folder} ${dockerImageLink} /bin/bash -c " +
327 "\"${cmd}\" > ${results}/docker-spt.log")
328 addFiles(master, target, results, output_dir)
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700329}
330
Dmitrii Kabanovd5f1c5f2017-08-30 14:51:41 -0700331/**
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700332 * Cleanup
333 *
334 * @param target Host to run commands
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700335 */
Dmitrii Kabanov23901c22017-10-20 10:25:36 -0700336def runCleanup(master, target) {
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700337 def salt = new com.mirantis.mk.Salt()
Dmitrii Kabanov321405a2017-08-16 16:38:51 -0700338 if ( salt.cmdRun(master, target, "docker ps -f name=qa_tools -q", false, null, false)['return'][0].values()[0] ) {
339 salt.cmdRun(master, target, "docker rm -f qa_tools")
340 }
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700341}
342
Oleksii Zhurbabcb97e22017-10-05 14:10:39 -0500343/**
344 * Prepare venv for any python project
345 * Note: <repo_name>\/requirements.txt content will be used
346 * for this venv
347 *
348 * @param repo_url Repository url to clone
349 * @param proxy Proxy address to use
350 */
351def prepareVenv(repo_url, proxy) {
352 def python = new com.mirantis.mk.Python()
353 repo_name = "${repo_url}".tokenize("/").last()
354 sh "rm -rf ${repo_name}"
355 withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
356 sh "git clone ${repo_url}"
357 python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true)
358 }
359}
360
Petr Lomakin47fee0a2017-08-01 10:46:05 -0700361/** Install docker if needed
362 *
363 * @param target Target node to install docker pkg
364 */
365def installDocker(master, target) {
366 def salt = new com.mirantis.mk.Salt()
367 if ( ! salt.runSaltProcessStep(master, target, 'pkg.version', ["docker-engine"]) ) {
368 salt.runSaltProcessStep(master, target, 'pkg.install', ["docker.io"])
369 }
370}