blob: d82f68a84edb912344c6dc6bb856e500c1d73e14 [file] [log] [blame]
Sergey Kolekonovba203982016-12-21 18:32:17 +04001package com.mirantis.mk
2
3/**
4 *
5 * Python functions
6 *
7 */
8
9/**
10 * Install python virtualenv
11 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000012 * @param path Path to virtualenv
13 * @param python Version of Python (python/python3)
14 * @param reqs Environment requirements in list format
15 * @param reqs_path Environment requirements path in str format
Sergey Kolekonovba203982016-12-21 18:32:17 +040016 */
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000017def setupVirtualenv(path, python = 'python2', reqs = [], reqs_path = null, clean = false, useSystemPackages = false) {
Tomáš Kukrál69c25452017-07-27 14:59:40 +020018 def common = new com.mirantis.mk.Common()
19
Jakub Josef87a8a3c2018-01-26 12:11:11 +010020 def offlineDeployment = env.getEnvironment().containsKey("OFFLINE_DEPLOYMENT") && env["OFFLINE_DEPLOYMENT"].toBoolean()
Mykyta Karpin1e4bfc92017-11-01 14:38:25 +020021 def virtualenv_cmd = "virtualenv ${path} --python ${python}"
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000022 if (useSystemPackages) {
Jakub Josef996f4ef2017-10-24 13:20:43 +020023 virtualenv_cmd += " --system-site-packages"
24 }
Tomáš Kukrál69c25452017-07-27 14:59:40 +020025 if (clean) {
26 common.infoMsg("Cleaning venv directory " + path)
27 sh("rm -rf \"${path}\"")
28 }
29
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000030 if (offlineDeployment) {
31 virtualenv_cmd += " --no-download"
Jakub Josef87a8a3c2018-01-26 12:11:11 +010032 }
Tomáš Kukrál69c25452017-07-27 14:59:40 +020033 common.infoMsg("[Python ${path}] Setup ${python} environment")
Sergey Kolekonovba203982016-12-21 18:32:17 +040034 sh(returnStdout: true, script: virtualenv_cmd)
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000035 if (!offlineDeployment) {
36 try {
Denis Egorenko89171f92019-11-12 13:49:23 +040037 def pipPackage = 'pip'
38 if (python == 'python2') {
39 pipPackage = "\"pip<=19.3.1\""
40 common.infoMsg("Pinning pip package due to end of life of Python2 to ${pipPackage} version.")
41 }
42 runVirtualenvCommand(path, "pip install -U setuptools ${pipPackage}")
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000043 } catch (Exception e) {
44 common.warningMsg("Setuptools and pip cannot be updated, you might be offline but OFFLINE_DEPLOYMENT global property not initialized!")
45 }
Yuriy Taraday67352e92017-10-12 10:54:23 +000046 }
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000047 if (reqs_path == null) {
Vladislav Naumov11103862017-07-19 17:02:39 +030048 def args = ""
49 for (req in reqs) {
50 args = args + "${req}\n"
51 }
52 writeFile file: "${path}/requirements.txt", text: args
53 reqs_path = "${path}/requirements.txt"
Sergey Kolekonovba203982016-12-21 18:32:17 +040054 }
Jakub Josefa2491ad2018-01-15 16:26:27 +010055 runVirtualenvCommand(path, "pip install -r ${reqs_path}", true)
Sergey Kolekonovba203982016-12-21 18:32:17 +040056}
57
58/**
59 * Run command in specific python virtualenv
60 *
azvyagintsev386e94e2019-06-13 13:39:04 +030061 * @param path Path to virtualenv
62 * @param cmd Command to be executed
Jakub Josefe2f4ebb2018-01-15 16:11:51 +010063 * @param silent dont print any messages (optional, default false)
azvyagintsev386e94e2019-06-13 13:39:04 +030064 * @param flexAnswer return answer like a dict, with format ['status' : int, 'stderr' : str, 'stdout' : str ]
Sergey Kolekonovba203982016-12-21 18:32:17 +040065 */
azvyagintsev386e94e2019-06-13 13:39:04 +030066def runVirtualenvCommand(path, cmd, silent = false, flexAnswer = false) {
Tomáš Kukrál69c25452017-07-27 14:59:40 +020067 def common = new com.mirantis.mk.Common()
azvyagintsev386e94e2019-06-13 13:39:04 +030068 def res
69 def virtualenv_cmd = "set +x; . ${path}/bin/activate; ${cmd}"
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000070 if (!silent) {
Jakub Josefe2f4ebb2018-01-15 16:11:51 +010071 common.infoMsg("[Python ${path}] Run command ${cmd}")
72 }
azvyagintsev386e94e2019-06-13 13:39:04 +030073 if (flexAnswer) {
74 res = common.shCmdStatus(virtualenv_cmd)
75 } else {
76 res = sh(
77 returnStdout: true,
78 script: virtualenv_cmd
79 ).trim()
80 }
81 return res
Sergey Kolekonovba203982016-12-21 18:32:17 +040082}
83
Ales Komarekd874d482016-12-26 10:33:29 +010084/**
Dennis Dmitriev8ac1fe72019-08-01 06:16:49 +030085 * Another command runner to control outputs and exit code
86 *
87 * - always print the executing command to control the pipeline execution
88 * - always allows to get the stdout/stderr/status in the result, even with enabled console enabled
89 * - throws an exception with stderr content, so it could be read from the job status and processed
90 *
91 * @param cmd String, command to be executed
92 * @param virtualenv String, path to Python virtualenv (optional, default: '')
93 * @param verbose Boolean, true: (default) mirror stdout to console and to the result['stdout'] at the same time,
94 * false: store stdout only to result['stdout']
95 * @param check_status Boolean, true: (default) throw an exception which contains result['stderr'] if exit code is not 0,
96 * false: only print stderr if not empty, and return the result
97 * @return Map, ['status' : int, 'stderr' : str, 'stdout' : str ]
98 */
99def runCmd(String cmd, String virtualenv='', Boolean verbose=true, Boolean check_status=true) {
100 def common = new com.mirantis.mk.Common()
101
102 def script
103 def redirect_output
104 def result = [:]
105 def stdout_path = sh(script: '#!/bin/bash +x\nmktemp', returnStdout: true).trim()
106 def stderr_path = sh(script: '#!/bin/bash +x\nmktemp', returnStdout: true).trim()
107
108 if (verbose) {
109 // show stdout to console and store to stdout_path
110 redirect_output = " 1> >(tee -a ${stdout_path}) 2>${stderr_path}"
111 } else {
112 // only store stdout to stdout_path
113 redirect_output = " 1>${stdout_path} 2>${stderr_path}"
114 }
115
116 if (virtualenv) {
117 common.infoMsg("Run shell command in Python virtualenv [${virtualenv}]:\n" + cmd)
118 script = """#!/bin/bash +x
119 . ${virtualenv}/bin/activate
120 ( ${cmd.stripIndent()} ) ${redirect_output}
121 """
122 } else {
123 common.infoMsg('Run shell command:\n' + cmd)
124 script = """#!/bin/bash +x
125 ( ${cmd.stripIndent()} ) ${redirect_output}
126 """
127 }
128
129 result['status'] = sh(script: script, returnStatus: true)
130 result['stdout'] = readFile(stdout_path)
131 result['stderr'] = readFile(stderr_path)
132 def cleanup_script = """#!/bin/bash +x
133 rm ${stdout_path} || true
134 rm ${stderr_path} || true
135 """
136 sh(script: cleanup_script)
137
138 if (result['status'] != 0 && check_status) {
139 def error_message = '\nScript returned exit code: ' + result['status'] + '\n<<<<<< STDERR: >>>>>>\n' + result['stderr']
140 common.errorMsg(error_message)
141 common.printMsg('', 'reset')
142 throw new Exception(error_message)
143 }
144
145 if (result['stderr'] && verbose) {
146 def warning_message = '\nScript returned exit code: ' + result['status'] + '\n<<<<<< STDERR: >>>>>>\n' + result['stderr']
147 common.warningMsg(warning_message)
148 common.printMsg('', 'reset')
149 }
150
151 return result
152}
153
154/**
Ales Komarekd874d482016-12-26 10:33:29 +0100155 * Install docutils in isolated environment
156 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000157 * @param path Path where virtualenv is created
Ales Komarekd874d482016-12-26 10:33:29 +0100158 */
159def setupDocutilsVirtualenv(path) {
160 requirements = [
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000161 'docutils',
Ales Komarekd874d482016-12-26 10:33:29 +0100162 ]
163 setupVirtualenv(path, 'python2', requirements)
164}
165
166
Sergey Kolekonovba203982016-12-21 18:32:17 +0400167@NonCPS
168def loadJson(rawData) {
169 return new groovy.json.JsonSlurperClassic().parseText(rawData)
170}
171
172/**
173 * Parse content from markup-text tables to variables
174 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000175 * @param tableStr String representing the table
176 * @param mode Either list (1st row are keys) or item (key, value rows)
177 * @param format Format of the table
Sergey Kolekonovba203982016-12-21 18:32:17 +0400178 */
Ales Komarekd874d482016-12-26 10:33:29 +0100179def parseTextTable(tableStr, type = 'item', format = 'rest', path = none) {
Ales Komarek0e558ee2016-12-23 13:02:55 +0100180 parserFile = "${env.WORKSPACE}/textTableParser.py"
181 parserScript = """import json
182import argparse
183from docutils.parsers.rst import tableparser
184from docutils import statemachine
185
186def parse_item_table(raw_data):
187 i = 1
188 pretty_raw_data = []
189 for datum in raw_data:
190 if datum != "":
191 if datum[3] != ' ' and i > 4:
192 pretty_raw_data.append(raw_data[0])
193 if i == 3:
194 pretty_raw_data.append(datum.replace('-', '='))
195 else:
196 pretty_raw_data.append(datum)
197 i += 1
198 parser = tableparser.GridTableParser()
199 block = statemachine.StringList(pretty_raw_data)
200 docutils_data = parser.parse(block)
201 final_data = {}
202 for line in docutils_data[2]:
203 key = ' '.join(line[0][3]).strip()
204 value = ' '.join(line[1][3]).strip()
205 if key != "":
206 try:
207 value = json.loads(value)
208 except:
209 pass
210 final_data[key] = value
211 i+=1
212 return final_data
213
214def parse_list_table(raw_data):
215 i = 1
216 pretty_raw_data = []
217 for datum in raw_data:
218 if datum != "":
219 if datum[3] != ' ' and i > 4:
220 pretty_raw_data.append(raw_data[0])
221 if i == 3:
222 pretty_raw_data.append(datum.replace('-', '='))
223 else:
224 pretty_raw_data.append(datum)
225 i += 1
226 parser = tableparser.GridTableParser()
227 block = statemachine.StringList(pretty_raw_data)
228 docutils_data = parser.parse(block)
229 final_data = []
230 keys = []
231 for line in docutils_data[1]:
232 for item in line:
233 keys.append(' '.join(item[3]).strip())
234 for line in docutils_data[2]:
235 final_line = {}
236 key = ' '.join(line[0][3]).strip()
237 value = ' '.join(line[1][3]).strip()
238 if key != "":
239 try:
240 value = json.loads(value)
241 except:
242 pass
243 final_data[key] = value
244 i+=1
245 return final_data
246
247def parse_list_table(raw_data):
248 i = 1
249 pretty_raw_data = []
250 for datum in raw_data:
251 if datum != "":
252 if datum[3] != ' ' and i > 4:
253 pretty_raw_data.append(raw_data[0])
254 if i == 3:
255 pretty_raw_data.append(datum.replace('-', '='))
256 else:
257 pretty_raw_data.append(datum)
258 i += 1
259 parser = tableparser.GridTableParser()
260 block = statemachine.StringList(pretty_raw_data)
261 docutils_data = parser.parse(block)
262 final_data = []
263 keys = []
264 for line in docutils_data[1]:
265 for item in line:
266 keys.append(' '.join(item[3]).strip())
267 for line in docutils_data[2]:
268 final_line = {}
269 i = 0
270 for item in line:
271 value = ' '.join(item[3]).strip()
272 try:
273 value = json.loads(value)
274 except:
275 pass
276 final_line[keys[i]] = value
277 i += 1
278 final_data.append(final_line)
279 return final_data
280
281def read_table_file(file):
282 table_file = open(file, 'r')
Ales Komarekc000c152016-12-23 15:32:54 +0100283 raw_data = table_file.read().split('\\n')
Ales Komarek0e558ee2016-12-23 13:02:55 +0100284 table_file.close()
285 return raw_data
286
287parser = argparse.ArgumentParser()
288parser.add_argument('-f','--file', help='File with table data', required=True)
289parser.add_argument('-t','--type', help='Type of table (list/item)', required=True)
290args = vars(parser.parse_args())
291
292raw_data = read_table_file(args['file'])
293
294if args['type'] == 'list':
295 final_data = parse_list_table(raw_data)
296else:
297 final_data = parse_item_table(raw_data)
298
299print json.dumps(final_data)
300"""
301 writeFile file: parserFile, text: parserScript
Sergey Kolekonovba203982016-12-21 18:32:17 +0400302 tableFile = "${env.WORKSPACE}/prettytable.txt"
303 writeFile file: tableFile, text: tableStr
Ales Komarekd874d482016-12-26 10:33:29 +0100304
305 cmd = "python ${parserFile} --file '${tableFile}' --type ${type}"
306 if (path) {
Ales Komarekc6d28dd2016-12-28 12:59:38 +0100307 rawData = runVirtualenvCommand(path, cmd)
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000308 } else {
309 rawData = sh(
Ales Komarekd874d482016-12-26 10:33:29 +0100310 script: cmd,
311 returnStdout: true
312 ).trim()
313 }
Sergey Kolekonovba203982016-12-21 18:32:17 +0400314 data = loadJson(rawData)
315 echo("[Parsed table] ${data}")
316 return data
317}
318
319/**
320 * Install cookiecutter in isolated environment
321 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000322 * @param path Path where virtualenv is created
Sergey Kolekonovba203982016-12-21 18:32:17 +0400323 */
324def setupCookiecutterVirtualenv(path) {
325 requirements = [
326 'cookiecutter',
Jakub Josef4df78272017-04-26 14:36:36 +0200327 'jinja2==2.8.1',
Dmitry Pyzhovb883a2d2018-12-14 16:42:52 +0300328 'PyYAML==3.12',
329 'python-gnupg==0.4.3'
Sergey Kolekonovba203982016-12-21 18:32:17 +0400330 ]
331 setupVirtualenv(path, 'python2', requirements)
332}
333
334/**
335 * Generate the cookiecutter templates with given context
336 *
Jakub Josef4e10c372017-04-26 14:13:50 +0200337 * @param template template
338 * @param context template context
339 * @param path Path where virtualenv is created (optional)
340 * @param templatePath path to cookiecutter template repo (optional)
Sergey Kolekonovba203982016-12-21 18:32:17 +0400341 */
Jakub Josef4e10c372017-04-26 14:13:50 +0200342def buildCookiecutterTemplate(template, context, outputDir = '.', path = null, templatePath = ".") {
azvyagintsev7a123aa2019-01-09 21:38:56 +0200343 def common = new com.mirantis.mk.Common()
Tomáš Kukráldad7b462017-03-27 13:53:05 +0200344 configFile = "default_config.yaml"
Tomáš Kukrál6de85042017-04-12 17:49:05 +0200345 writeFile file: configFile, text: context
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000346 common.warningMsg('Old Cookiecutter env detected!')
347 command = ". ${path}/bin/activate; if [ -f ${templatePath}/generate.py ]; then python ${templatePath}/generate.py --config-file ${configFile} --template ${template} --output-dir ${outputDir}; else cookiecutter --config-file ${configFile} --output-dir ${outputDir} --overwrite-if-exists --verbose --no-input ${template}; fi"
348 output = sh(returnStdout: true, script: command)
349 common.infoMsg('[Cookiecutter build] Result:' + output)
Sergey Kolekonovba203982016-12-21 18:32:17 +0400350}
351
352/**
Denis Egorenko6c2e3ae2018-10-17 16:45:56 +0400353 *
354 * @param context - context template
355 * @param contextName - context template name
356 * @param saltMasterName - hostname of Salt Master node
357 * @param virtualenv - pyvenv with CC and dep's
358 * @param templateEnvDir - root of CookieCutter
359 * @return
360 */
361def generateModel(context, contextName, saltMasterName, virtualenv, modelEnv, templateEnvDir, multiModels = true) {
Denis Egorenkofa2c6752018-10-18 15:51:45 +0400362 def common = new com.mirantis.mk.Common()
Denis Egorenko6c2e3ae2018-10-17 16:45:56 +0400363 def generatedModel = multiModels ? "${modelEnv}/${contextName}" : modelEnv
364 def templateContext = readYaml text: context
365 def clusterDomain = templateContext.default_context.cluster_domain
366 def clusterName = templateContext.default_context.cluster_name
367 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
368 def templateBaseDir = templateEnvDir
369 def templateDir = "${templateEnvDir}/dir"
370 def templateOutputDir = templateBaseDir
371 dir(templateEnvDir) {
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000372 if (fileExists(new File(templateEnvDir, 'tox.ini').toString())) {
Aleksey Zvyagintsev07b07ba2019-02-28 13:34:13 +0000373 def tempContextFile = new File(templateEnvDir, 'tempContext.yaml').toString()
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000374 writeFile file: tempContextFile, text: context
375 common.warningMsg('Generating models using context:\n')
376 print(context)
377 withEnv(["CONFIG_FILE=$tempContextFile",
Aleksey Zvyagintsev07b07ba2019-02-28 13:34:13 +0000378 "OUTPUT_DIR=${modelEnv}",
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000379 ]) {
380 print('[Cookiecutter build] Result:\n' +
381 sh(returnStdout: true, script: 'tox -ve generate_auto'))
Aleksey Zvyagintsev4c745e52019-02-21 10:30:02 +0000382 }
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000383 } else {
384 common.warningMsg("Old format: Generating model from context ${contextName}")
385 def productList = ["infra", "cicd", "kdt", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
386 for (product in productList) {
387 // get templateOutputDir and productDir
388 templateOutputDir = "${templateEnvDir}/output/${product}"
389 productDir = product
390 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
391 // Bw for 2018.8.1 and older releases
392 if (product.startsWith("stacklight") && (!fileExists(templateDir))) {
393 common.warningMsg("Old release detected! productDir => 'stacklight2' ")
394 productDir = "stacklight2"
395 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
396 }
397 // generate infra unless its explicitly disabled
398 if ((product == "infra" && templateContext.default_context.get("infra_enabled", "True").toBoolean())
399 || (templateContext.default_context.get(product + "_enabled", "False").toBoolean())) {
400
401 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
402
403 sh "rm -rf ${templateOutputDir} || true"
404 sh "mkdir -p ${templateOutputDir}"
405 sh "mkdir -p ${outputDestination}"
406
407 buildCookiecutterTemplate(templateDir, context, templateOutputDir, virtualenv, templateBaseDir)
408 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
409 } else {
410 common.warningMsg("Product " + product + " is disabled")
411 }
412 }
413
414 def localRepositories = templateContext.default_context.local_repositories
415 localRepositories = localRepositories ? localRepositories.toBoolean() : false
416 def offlineDeployment = templateContext.default_context.offline_deployment
417 offlineDeployment = offlineDeployment ? offlineDeployment.toBoolean() : false
418 if (localRepositories && !offlineDeployment) {
419 def mcpVersion = templateContext.default_context.mcp_version
420 def aptlyModelUrl = templateContext.default_context.local_model_url
421 def ssh = new com.mirantis.mk.Ssh()
422 dir(path: modelEnv) {
423 ssh.agentSh "git submodule add \"${aptlyModelUrl}\" \"classes/cluster/${clusterName}/cicd/aptly\""
424 if (!(mcpVersion in ["nightly", "testing", "stable"])) {
425 ssh.agentSh "cd \"classes/cluster/${clusterName}/cicd/aptly\";git fetch --tags;git checkout ${mcpVersion}"
426 }
427 }
428 }
429
430 def nodeFile = "${generatedModel}/nodes/${saltMasterName}.${clusterDomain}.yml"
431 def nodeString = """classes:
432- cluster.${clusterName}.infra.config
433parameters:
434 _param:
435 linux_system_codename: xenial
436 reclass_data_revision: master
437 linux:
438 system:
439 name: ${saltMasterName}
440 domain: ${clusterDomain}
441 """
442 sh "mkdir -p ${generatedModel}/nodes/"
443 writeFile(file: nodeFile, text: nodeString)
444 }
Denis Egorenko6c2e3ae2018-10-17 16:45:56 +0400445 }
446}
447
448/**
Sergey Kolekonovba203982016-12-21 18:32:17 +0400449 * Install jinja rendering in isolated environment
450 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000451 * @param path Path where virtualenv is created
Sergey Kolekonovba203982016-12-21 18:32:17 +0400452 */
453def setupJinjaVirtualenv(path) {
454 requirements = [
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000455 'jinja2-cli',
456 'pyyaml',
Sergey Kolekonovba203982016-12-21 18:32:17 +0400457 ]
458 setupVirtualenv(path, 'python2', requirements)
459}
460
461/**
462 * Generate the Jinja templates with given context
463 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000464 * @param path Path where virtualenv is created
Sergey Kolekonovba203982016-12-21 18:32:17 +0400465 */
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000466def jinjaBuildTemplate(template, context, path = none) {
Sergey Kolekonovba203982016-12-21 18:32:17 +0400467 contextFile = "jinja_context.yml"
468 contextString = ""
469 for (parameter in context) {
470 contextString = "${contextString}${parameter.key}: ${parameter.value}\n"
471 }
472 writeFile file: contextFile, text: contextString
473 cmd = "jinja2 ${template} ${contextFile} --format=yaml"
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000474 data = sh(returnStdout: true, script: cmd)
Sergey Kolekonovba203982016-12-21 18:32:17 +0400475 echo(data)
476 return data
477}
Oleg Grigorovbec45582017-09-12 20:29:24 +0300478
479/**
480 * Install salt-pepper in isolated environment
481 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000482 * @param path Path where virtualenv is created
483 * @param url SALT_MASTER_URL
484 * @param credentialsId Credentials to salt api
Oleg Grigorovbec45582017-09-12 20:29:24 +0300485 */
Jakub Josefc9b6d662018-02-21 16:21:03 +0100486def setupPepperVirtualenv(path, url, credentialsId) {
chnydaa0dbb252017-10-05 10:46:09 +0200487 def common = new com.mirantis.mk.Common()
488
489 // virtualenv setup
Mykyta Karpin81756c92018-03-02 13:03:26 +0200490 // pin pepper till https://mirantis.jira.com/browse/PROD-18188 is fixed
491 requirements = ['salt-pepper>=0.5.2,<0.5.4']
Jakub Josefc9b6d662018-02-21 16:21:03 +0100492 setupVirtualenv(path, 'python2', requirements, null, true, true)
chnydabcfff182017-11-29 10:24:36 +0100493
chnydaa0dbb252017-10-05 10:46:09 +0200494 // pepperrc creation
495 rcFile = "${path}/pepperrc"
496 creds = common.getPasswordCredentials(credentialsId)
497 rc = """\
498[main]
499SALTAPI_EAUTH=pam
500SALTAPI_URL=${url}
501SALTAPI_USER=${creds.username}
502SALTAPI_PASS=${creds.password.toString()}
503"""
504 writeFile file: rcFile, text: rc
505 return rcFile
Jakub Josefd067f612017-09-26 13:42:56 +0200506}
Oleh Hryhorov44569fb2017-10-26 17:04:55 +0300507
508/**
509 * Install devops in isolated environment
510 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000511 * @param path Path where virtualenv is created
512 * @param clean Define to true is the venv have to cleaned up before install a new one
Oleh Hryhorov44569fb2017-10-26 17:04:55 +0300513 */
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000514def setupDevOpsVenv(venv, clean = false) {
Oleh Hryhorov44569fb2017-10-26 17:04:55 +0300515 requirements = ['git+https://github.com/openstack/fuel-devops.git']
516 setupVirtualenv(venv, 'python2', requirements, null, false, clean)
517}