blob: 9d07d47a4c3a15f9fd2aa433bad85b38447c256b [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 }
Vasyl Saienko9a2bd372020-01-13 10:00:04 +020042 // NOTE(vsaienko): pin setuptools explicitly for latest version that works with python2
43 runVirtualenvCommand(path, "pip install -U \"setuptools<45.0.0\" ${pipPackage}")
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000044 } catch (Exception e) {
45 common.warningMsg("Setuptools and pip cannot be updated, you might be offline but OFFLINE_DEPLOYMENT global property not initialized!")
46 }
Yuriy Taraday67352e92017-10-12 10:54:23 +000047 }
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000048 if (reqs_path == null) {
Vladislav Naumov11103862017-07-19 17:02:39 +030049 def args = ""
50 for (req in reqs) {
51 args = args + "${req}\n"
52 }
53 writeFile file: "${path}/requirements.txt", text: args
54 reqs_path = "${path}/requirements.txt"
Sergey Kolekonovba203982016-12-21 18:32:17 +040055 }
Jakub Josefa2491ad2018-01-15 16:26:27 +010056 runVirtualenvCommand(path, "pip install -r ${reqs_path}", true)
Sergey Kolekonovba203982016-12-21 18:32:17 +040057}
58
59/**
60 * Run command in specific python virtualenv
61 *
azvyagintsev386e94e2019-06-13 13:39:04 +030062 * @param path Path to virtualenv
63 * @param cmd Command to be executed
Jakub Josefe2f4ebb2018-01-15 16:11:51 +010064 * @param silent dont print any messages (optional, default false)
azvyagintsev386e94e2019-06-13 13:39:04 +030065 * @param flexAnswer return answer like a dict, with format ['status' : int, 'stderr' : str, 'stdout' : str ]
Sergey Kolekonovba203982016-12-21 18:32:17 +040066 */
azvyagintsev386e94e2019-06-13 13:39:04 +030067def runVirtualenvCommand(path, cmd, silent = false, flexAnswer = false) {
Tomáš Kukrál69c25452017-07-27 14:59:40 +020068 def common = new com.mirantis.mk.Common()
azvyagintsev386e94e2019-06-13 13:39:04 +030069 def res
70 def virtualenv_cmd = "set +x; . ${path}/bin/activate; ${cmd}"
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +000071 if (!silent) {
Jakub Josefe2f4ebb2018-01-15 16:11:51 +010072 common.infoMsg("[Python ${path}] Run command ${cmd}")
73 }
azvyagintsev386e94e2019-06-13 13:39:04 +030074 if (flexAnswer) {
75 res = common.shCmdStatus(virtualenv_cmd)
76 } else {
77 res = sh(
78 returnStdout: true,
79 script: virtualenv_cmd
80 ).trim()
81 }
82 return res
Sergey Kolekonovba203982016-12-21 18:32:17 +040083}
84
Ales Komarekd874d482016-12-26 10:33:29 +010085/**
Dennis Dmitriev8ac1fe72019-08-01 06:16:49 +030086 * Another command runner to control outputs and exit code
87 *
88 * - always print the executing command to control the pipeline execution
89 * - always allows to get the stdout/stderr/status in the result, even with enabled console enabled
90 * - throws an exception with stderr content, so it could be read from the job status and processed
91 *
92 * @param cmd String, command to be executed
93 * @param virtualenv String, path to Python virtualenv (optional, default: '')
94 * @param verbose Boolean, true: (default) mirror stdout to console and to the result['stdout'] at the same time,
95 * false: store stdout only to result['stdout']
96 * @param check_status Boolean, true: (default) throw an exception which contains result['stderr'] if exit code is not 0,
97 * false: only print stderr if not empty, and return the result
98 * @return Map, ['status' : int, 'stderr' : str, 'stdout' : str ]
99 */
100def runCmd(String cmd, String virtualenv='', Boolean verbose=true, Boolean check_status=true) {
101 def common = new com.mirantis.mk.Common()
102
103 def script
104 def redirect_output
105 def result = [:]
106 def stdout_path = sh(script: '#!/bin/bash +x\nmktemp', returnStdout: true).trim()
107 def stderr_path = sh(script: '#!/bin/bash +x\nmktemp', returnStdout: true).trim()
108
109 if (verbose) {
110 // show stdout to console and store to stdout_path
111 redirect_output = " 1> >(tee -a ${stdout_path}) 2>${stderr_path}"
112 } else {
113 // only store stdout to stdout_path
114 redirect_output = " 1>${stdout_path} 2>${stderr_path}"
115 }
116
117 if (virtualenv) {
118 common.infoMsg("Run shell command in Python virtualenv [${virtualenv}]:\n" + cmd)
119 script = """#!/bin/bash +x
120 . ${virtualenv}/bin/activate
121 ( ${cmd.stripIndent()} ) ${redirect_output}
122 """
123 } else {
124 common.infoMsg('Run shell command:\n' + cmd)
125 script = """#!/bin/bash +x
126 ( ${cmd.stripIndent()} ) ${redirect_output}
127 """
128 }
129
130 result['status'] = sh(script: script, returnStatus: true)
131 result['stdout'] = readFile(stdout_path)
132 result['stderr'] = readFile(stderr_path)
133 def cleanup_script = """#!/bin/bash +x
134 rm ${stdout_path} || true
135 rm ${stderr_path} || true
136 """
137 sh(script: cleanup_script)
138
139 if (result['status'] != 0 && check_status) {
140 def error_message = '\nScript returned exit code: ' + result['status'] + '\n<<<<<< STDERR: >>>>>>\n' + result['stderr']
141 common.errorMsg(error_message)
142 common.printMsg('', 'reset')
143 throw new Exception(error_message)
144 }
145
146 if (result['stderr'] && verbose) {
147 def warning_message = '\nScript returned exit code: ' + result['status'] + '\n<<<<<< STDERR: >>>>>>\n' + result['stderr']
148 common.warningMsg(warning_message)
149 common.printMsg('', 'reset')
150 }
151
152 return result
153}
154
155/**
Ales Komarekd874d482016-12-26 10:33:29 +0100156 * Install docutils in isolated environment
157 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000158 * @param path Path where virtualenv is created
Ales Komarekd874d482016-12-26 10:33:29 +0100159 */
Vasyl Saienko9a2bd372020-01-13 10:00:04 +0200160def setupDocutilsVirtualenv(path, python="python2") {
Ales Komarekd874d482016-12-26 10:33:29 +0100161 requirements = [
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000162 'docutils',
Ales Komarekd874d482016-12-26 10:33:29 +0100163 ]
Vasyl Saienko9a2bd372020-01-13 10:00:04 +0200164 setupVirtualenv(path, python, requirements)
Ales Komarekd874d482016-12-26 10:33:29 +0100165}
166
167
Sergey Kolekonovba203982016-12-21 18:32:17 +0400168@NonCPS
169def loadJson(rawData) {
170 return new groovy.json.JsonSlurperClassic().parseText(rawData)
171}
172
173/**
174 * Parse content from markup-text tables to variables
175 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000176 * @param tableStr String representing the table
177 * @param mode Either list (1st row are keys) or item (key, value rows)
178 * @param format Format of the table
Sergey Kolekonovba203982016-12-21 18:32:17 +0400179 */
Ales Komarekd874d482016-12-26 10:33:29 +0100180def parseTextTable(tableStr, type = 'item', format = 'rest', path = none) {
Ales Komarek0e558ee2016-12-23 13:02:55 +0100181 parserFile = "${env.WORKSPACE}/textTableParser.py"
182 parserScript = """import json
183import argparse
184from docutils.parsers.rst import tableparser
185from docutils import statemachine
186
187def parse_item_table(raw_data):
188 i = 1
189 pretty_raw_data = []
190 for datum in raw_data:
191 if datum != "":
192 if datum[3] != ' ' and i > 4:
193 pretty_raw_data.append(raw_data[0])
194 if i == 3:
195 pretty_raw_data.append(datum.replace('-', '='))
196 else:
197 pretty_raw_data.append(datum)
198 i += 1
199 parser = tableparser.GridTableParser()
200 block = statemachine.StringList(pretty_raw_data)
201 docutils_data = parser.parse(block)
202 final_data = {}
203 for line in docutils_data[2]:
204 key = ' '.join(line[0][3]).strip()
205 value = ' '.join(line[1][3]).strip()
206 if key != "":
207 try:
208 value = json.loads(value)
209 except:
210 pass
211 final_data[key] = value
212 i+=1
213 return final_data
214
215def parse_list_table(raw_data):
216 i = 1
217 pretty_raw_data = []
218 for datum in raw_data:
219 if datum != "":
220 if datum[3] != ' ' and i > 4:
221 pretty_raw_data.append(raw_data[0])
222 if i == 3:
223 pretty_raw_data.append(datum.replace('-', '='))
224 else:
225 pretty_raw_data.append(datum)
226 i += 1
227 parser = tableparser.GridTableParser()
228 block = statemachine.StringList(pretty_raw_data)
229 docutils_data = parser.parse(block)
230 final_data = []
231 keys = []
232 for line in docutils_data[1]:
233 for item in line:
234 keys.append(' '.join(item[3]).strip())
235 for line in docutils_data[2]:
236 final_line = {}
237 key = ' '.join(line[0][3]).strip()
238 value = ' '.join(line[1][3]).strip()
239 if key != "":
240 try:
241 value = json.loads(value)
242 except:
243 pass
244 final_data[key] = value
245 i+=1
246 return final_data
247
248def parse_list_table(raw_data):
249 i = 1
250 pretty_raw_data = []
251 for datum in raw_data:
252 if datum != "":
253 if datum[3] != ' ' and i > 4:
254 pretty_raw_data.append(raw_data[0])
255 if i == 3:
256 pretty_raw_data.append(datum.replace('-', '='))
257 else:
258 pretty_raw_data.append(datum)
259 i += 1
260 parser = tableparser.GridTableParser()
261 block = statemachine.StringList(pretty_raw_data)
262 docutils_data = parser.parse(block)
263 final_data = []
264 keys = []
265 for line in docutils_data[1]:
266 for item in line:
267 keys.append(' '.join(item[3]).strip())
268 for line in docutils_data[2]:
269 final_line = {}
270 i = 0
271 for item in line:
272 value = ' '.join(item[3]).strip()
273 try:
274 value = json.loads(value)
275 except:
276 pass
277 final_line[keys[i]] = value
278 i += 1
279 final_data.append(final_line)
280 return final_data
281
282def read_table_file(file):
283 table_file = open(file, 'r')
Ales Komarekc000c152016-12-23 15:32:54 +0100284 raw_data = table_file.read().split('\\n')
Ales Komarek0e558ee2016-12-23 13:02:55 +0100285 table_file.close()
286 return raw_data
287
288parser = argparse.ArgumentParser()
289parser.add_argument('-f','--file', help='File with table data', required=True)
290parser.add_argument('-t','--type', help='Type of table (list/item)', required=True)
291args = vars(parser.parse_args())
292
293raw_data = read_table_file(args['file'])
294
295if args['type'] == 'list':
296 final_data = parse_list_table(raw_data)
297else:
298 final_data = parse_item_table(raw_data)
299
300print json.dumps(final_data)
301"""
302 writeFile file: parserFile, text: parserScript
Sergey Kolekonovba203982016-12-21 18:32:17 +0400303 tableFile = "${env.WORKSPACE}/prettytable.txt"
304 writeFile file: tableFile, text: tableStr
Ales Komarekd874d482016-12-26 10:33:29 +0100305
306 cmd = "python ${parserFile} --file '${tableFile}' --type ${type}"
307 if (path) {
Ales Komarekc6d28dd2016-12-28 12:59:38 +0100308 rawData = runVirtualenvCommand(path, cmd)
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000309 } else {
310 rawData = sh(
Ales Komarekd874d482016-12-26 10:33:29 +0100311 script: cmd,
312 returnStdout: true
313 ).trim()
314 }
Sergey Kolekonovba203982016-12-21 18:32:17 +0400315 data = loadJson(rawData)
316 echo("[Parsed table] ${data}")
317 return data
318}
319
320/**
321 * Install cookiecutter in isolated environment
322 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000323 * @param path Path where virtualenv is created
Sergey Kolekonovba203982016-12-21 18:32:17 +0400324 */
325def setupCookiecutterVirtualenv(path) {
326 requirements = [
327 'cookiecutter',
Jakub Josef4df78272017-04-26 14:36:36 +0200328 'jinja2==2.8.1',
Dmitry Pyzhovb883a2d2018-12-14 16:42:52 +0300329 'PyYAML==3.12',
330 'python-gnupg==0.4.3'
Sergey Kolekonovba203982016-12-21 18:32:17 +0400331 ]
332 setupVirtualenv(path, 'python2', requirements)
333}
334
335/**
336 * Generate the cookiecutter templates with given context
337 *
Jakub Josef4e10c372017-04-26 14:13:50 +0200338 * @param template template
339 * @param context template context
340 * @param path Path where virtualenv is created (optional)
341 * @param templatePath path to cookiecutter template repo (optional)
Sergey Kolekonovba203982016-12-21 18:32:17 +0400342 */
Jakub Josef4e10c372017-04-26 14:13:50 +0200343def buildCookiecutterTemplate(template, context, outputDir = '.', path = null, templatePath = ".") {
azvyagintsev7a123aa2019-01-09 21:38:56 +0200344 def common = new com.mirantis.mk.Common()
Tomáš Kukráldad7b462017-03-27 13:53:05 +0200345 configFile = "default_config.yaml"
Tomáš Kukrál6de85042017-04-12 17:49:05 +0200346 writeFile file: configFile, text: context
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000347 common.warningMsg('Old Cookiecutter env detected!')
348 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"
349 output = sh(returnStdout: true, script: command)
350 common.infoMsg('[Cookiecutter build] Result:' + output)
Sergey Kolekonovba203982016-12-21 18:32:17 +0400351}
352
353/**
Denis Egorenko6c2e3ae2018-10-17 16:45:56 +0400354 *
355 * @param context - context template
356 * @param contextName - context template name
357 * @param saltMasterName - hostname of Salt Master node
358 * @param virtualenv - pyvenv with CC and dep's
359 * @param templateEnvDir - root of CookieCutter
360 * @return
361 */
362def generateModel(context, contextName, saltMasterName, virtualenv, modelEnv, templateEnvDir, multiModels = true) {
Denis Egorenkofa2c6752018-10-18 15:51:45 +0400363 def common = new com.mirantis.mk.Common()
Denis Egorenko6c2e3ae2018-10-17 16:45:56 +0400364 def generatedModel = multiModels ? "${modelEnv}/${contextName}" : modelEnv
365 def templateContext = readYaml text: context
366 def clusterDomain = templateContext.default_context.cluster_domain
367 def clusterName = templateContext.default_context.cluster_name
368 def outputDestination = "${generatedModel}/classes/cluster/${clusterName}"
369 def templateBaseDir = templateEnvDir
370 def templateDir = "${templateEnvDir}/dir"
371 def templateOutputDir = templateBaseDir
372 dir(templateEnvDir) {
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000373 if (fileExists(new File(templateEnvDir, 'tox.ini').toString())) {
Aleksey Zvyagintsev07b07ba2019-02-28 13:34:13 +0000374 def tempContextFile = new File(templateEnvDir, 'tempContext.yaml').toString()
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000375 writeFile file: tempContextFile, text: context
376 common.warningMsg('Generating models using context:\n')
377 print(context)
378 withEnv(["CONFIG_FILE=$tempContextFile",
Aleksey Zvyagintsev07b07ba2019-02-28 13:34:13 +0000379 "OUTPUT_DIR=${modelEnv}",
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000380 ]) {
381 print('[Cookiecutter build] Result:\n' +
382 sh(returnStdout: true, script: 'tox -ve generate_auto'))
Aleksey Zvyagintsev4c745e52019-02-21 10:30:02 +0000383 }
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000384 } else {
385 common.warningMsg("Old format: Generating model from context ${contextName}")
386 def productList = ["infra", "cicd", "kdt", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"]
387 for (product in productList) {
388 // get templateOutputDir and productDir
389 templateOutputDir = "${templateEnvDir}/output/${product}"
390 productDir = product
391 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
392 // Bw for 2018.8.1 and older releases
393 if (product.startsWith("stacklight") && (!fileExists(templateDir))) {
394 common.warningMsg("Old release detected! productDir => 'stacklight2' ")
395 productDir = "stacklight2"
396 templateDir = "${templateEnvDir}/cluster_product/${productDir}"
397 }
398 // generate infra unless its explicitly disabled
399 if ((product == "infra" && templateContext.default_context.get("infra_enabled", "True").toBoolean())
400 || (templateContext.default_context.get(product + "_enabled", "False").toBoolean())) {
401
402 common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir)
403
404 sh "rm -rf ${templateOutputDir} || true"
405 sh "mkdir -p ${templateOutputDir}"
406 sh "mkdir -p ${outputDestination}"
407
408 buildCookiecutterTemplate(templateDir, context, templateOutputDir, virtualenv, templateBaseDir)
409 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
410 } else {
411 common.warningMsg("Product " + product + " is disabled")
412 }
413 }
414
415 def localRepositories = templateContext.default_context.local_repositories
416 localRepositories = localRepositories ? localRepositories.toBoolean() : false
417 def offlineDeployment = templateContext.default_context.offline_deployment
418 offlineDeployment = offlineDeployment ? offlineDeployment.toBoolean() : false
419 if (localRepositories && !offlineDeployment) {
420 def mcpVersion = templateContext.default_context.mcp_version
421 def aptlyModelUrl = templateContext.default_context.local_model_url
422 def ssh = new com.mirantis.mk.Ssh()
423 dir(path: modelEnv) {
424 ssh.agentSh "git submodule add \"${aptlyModelUrl}\" \"classes/cluster/${clusterName}/cicd/aptly\""
425 if (!(mcpVersion in ["nightly", "testing", "stable"])) {
426 ssh.agentSh "cd \"classes/cluster/${clusterName}/cicd/aptly\";git fetch --tags;git checkout ${mcpVersion}"
427 }
428 }
429 }
430
431 def nodeFile = "${generatedModel}/nodes/${saltMasterName}.${clusterDomain}.yml"
432 def nodeString = """classes:
433- cluster.${clusterName}.infra.config
434parameters:
435 _param:
436 linux_system_codename: xenial
437 reclass_data_revision: master
438 linux:
439 system:
440 name: ${saltMasterName}
441 domain: ${clusterDomain}
442 """
443 sh "mkdir -p ${generatedModel}/nodes/"
444 writeFile(file: nodeFile, text: nodeString)
445 }
Denis Egorenko6c2e3ae2018-10-17 16:45:56 +0400446 }
447}
448
449/**
Sergey Kolekonovba203982016-12-21 18:32:17 +0400450 * Install jinja rendering in isolated environment
451 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000452 * @param path Path where virtualenv is created
Sergey Kolekonovba203982016-12-21 18:32:17 +0400453 */
454def setupJinjaVirtualenv(path) {
455 requirements = [
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000456 'jinja2-cli',
457 'pyyaml',
Sergey Kolekonovba203982016-12-21 18:32:17 +0400458 ]
459 setupVirtualenv(path, 'python2', requirements)
460}
461
462/**
463 * Generate the Jinja templates with given context
464 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000465 * @param path Path where virtualenv is created
Sergey Kolekonovba203982016-12-21 18:32:17 +0400466 */
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000467def jinjaBuildTemplate(template, context, path = none) {
Sergey Kolekonovba203982016-12-21 18:32:17 +0400468 contextFile = "jinja_context.yml"
469 contextString = ""
470 for (parameter in context) {
471 contextString = "${contextString}${parameter.key}: ${parameter.value}\n"
472 }
473 writeFile file: contextFile, text: contextString
474 cmd = "jinja2 ${template} ${contextFile} --format=yaml"
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000475 data = sh(returnStdout: true, script: cmd)
Sergey Kolekonovba203982016-12-21 18:32:17 +0400476 echo(data)
477 return data
478}
Oleg Grigorovbec45582017-09-12 20:29:24 +0300479
480/**
481 * Install salt-pepper in isolated environment
482 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000483 * @param path Path where virtualenv is created
484 * @param url SALT_MASTER_URL
485 * @param credentialsId Credentials to salt api
Oleg Grigorovbec45582017-09-12 20:29:24 +0300486 */
Jakub Josefc9b6d662018-02-21 16:21:03 +0100487def setupPepperVirtualenv(path, url, credentialsId) {
chnydaa0dbb252017-10-05 10:46:09 +0200488 def common = new com.mirantis.mk.Common()
489
490 // virtualenv setup
Mykyta Karpin81756c92018-03-02 13:03:26 +0200491 // pin pepper till https://mirantis.jira.com/browse/PROD-18188 is fixed
492 requirements = ['salt-pepper>=0.5.2,<0.5.4']
Jakub Josefc9b6d662018-02-21 16:21:03 +0100493 setupVirtualenv(path, 'python2', requirements, null, true, true)
chnydabcfff182017-11-29 10:24:36 +0100494
chnydaa0dbb252017-10-05 10:46:09 +0200495 // pepperrc creation
496 rcFile = "${path}/pepperrc"
497 creds = common.getPasswordCredentials(credentialsId)
498 rc = """\
499[main]
500SALTAPI_EAUTH=pam
501SALTAPI_URL=${url}
502SALTAPI_USER=${creds.username}
503SALTAPI_PASS=${creds.password.toString()}
504"""
505 writeFile file: rcFile, text: rc
506 return rcFile
Jakub Josefd067f612017-09-26 13:42:56 +0200507}
Oleh Hryhorov44569fb2017-10-26 17:04:55 +0300508
509/**
510 * Install devops in isolated environment
511 *
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000512 * @param path Path where virtualenv is created
513 * @param clean Define to true is the venv have to cleaned up before install a new one
Oleh Hryhorov44569fb2017-10-26 17:04:55 +0300514 */
Aleksey Zvyagintsevc4f66f62019-02-21 10:39:34 +0000515def setupDevOpsVenv(venv, clean = false) {
Oleh Hryhorov44569fb2017-10-26 17:04:55 +0300516 requirements = ['git+https://github.com/openstack/fuel-devops.git']
517 setupVirtualenv(venv, 'python2', requirements, null, false, clean)
518}