Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * Python functions |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Install python virtualenv |
| 11 | * |
Vladislav Naumov | 1110386 | 2017-07-19 17:02:39 +0300 | [diff] [blame] | 12 | * @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 Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 16 | */ |
Jakub Josef | 996f4ef | 2017-10-24 13:20:43 +0200 | [diff] [blame] | 17 | def setupVirtualenv(path, python = 'python2', reqs=[], reqs_path=null, clean=false, useSystemPackages=false) { |
Tomáš Kukrál | 69c2545 | 2017-07-27 14:59:40 +0200 | [diff] [blame] | 18 | def common = new com.mirantis.mk.Common() |
| 19 | |
Jakub Josef | 87a8a3c | 2018-01-26 12:11:11 +0100 | [diff] [blame] | 20 | def offlineDeployment = env.getEnvironment().containsKey("OFFLINE_DEPLOYMENT") && env["OFFLINE_DEPLOYMENT"].toBoolean() |
Mykyta Karpin | 1e4bfc9 | 2017-11-01 14:38:25 +0200 | [diff] [blame] | 21 | def virtualenv_cmd = "virtualenv ${path} --python ${python}" |
Jakub Josef | 996f4ef | 2017-10-24 13:20:43 +0200 | [diff] [blame] | 22 | if (useSystemPackages){ |
| 23 | virtualenv_cmd += " --system-site-packages" |
| 24 | } |
Tomáš Kukrál | 69c2545 | 2017-07-27 14:59:40 +0200 | [diff] [blame] | 25 | if (clean) { |
| 26 | common.infoMsg("Cleaning venv directory " + path) |
| 27 | sh("rm -rf \"${path}\"") |
| 28 | } |
| 29 | |
Jakub Josef | 87a8a3c | 2018-01-26 12:11:11 +0100 | [diff] [blame] | 30 | if(offlineDeployment){ |
| 31 | virtualenv_cmd+=" --no-download" |
| 32 | } |
Tomáš Kukrál | 69c2545 | 2017-07-27 14:59:40 +0200 | [diff] [blame] | 33 | common.infoMsg("[Python ${path}] Setup ${python} environment") |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 34 | sh(returnStdout: true, script: virtualenv_cmd) |
Vasyl Saienko | a56c1ab | 2020-01-13 10:00:04 +0200 | [diff] [blame] | 35 | if (!offlineDeployment) { |
| 36 | try { |
| 37 | 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 | // NOTE(vsaienko): pin setuptools explicitly for latest version that works with python2 |
| 43 | runVirtualenvCommand(path, "pip install -U \"setuptools<45.0.0\" ${pipPackage}") |
| 44 | } 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 Taraday | 67352e9 | 2017-10-12 10:54:23 +0000 | [diff] [blame] | 47 | } |
Vladislav Naumov | 1110386 | 2017-07-19 17:02:39 +0300 | [diff] [blame] | 48 | if (reqs_path==null) { |
| 49 | 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 Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 55 | } |
Jakub Josef | a2491ad | 2018-01-15 16:26:27 +0100 | [diff] [blame] | 56 | runVirtualenvCommand(path, "pip install -r ${reqs_path}", true) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Run command in specific python virtualenv |
| 61 | * |
| 62 | * @param path Path to virtualenv |
| 63 | * @param cmd Command to be executed |
Jakub Josef | e2f4ebb | 2018-01-15 16:11:51 +0100 | [diff] [blame] | 64 | * @param silent dont print any messages (optional, default false) |
azvyagintsev | b8b7f92 | 2019-06-13 13:39:04 +0300 | [diff] [blame] | 65 | * @param flexAnswer return answer like a dict, with format ['status' : int, 'stderr' : str, 'stdout' : str ] |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 66 | */ |
azvyagintsev | b8b7f92 | 2019-06-13 13:39:04 +0300 | [diff] [blame] | 67 | def runVirtualenvCommand(path, cmd, silent = false, flexAnswer = false) { |
Tomáš Kukrál | 69c2545 | 2017-07-27 14:59:40 +0200 | [diff] [blame] | 68 | def common = new com.mirantis.mk.Common() |
azvyagintsev | b8b7f92 | 2019-06-13 13:39:04 +0300 | [diff] [blame] | 69 | def res |
| 70 | def virtualenv_cmd = "set +x; . ${path}/bin/activate; ${cmd}" |
| 71 | if (!silent) { |
Jakub Josef | e2f4ebb | 2018-01-15 16:11:51 +0100 | [diff] [blame] | 72 | common.infoMsg("[Python ${path}] Run command ${cmd}") |
| 73 | } |
azvyagintsev | b8b7f92 | 2019-06-13 13:39:04 +0300 | [diff] [blame] | 74 | 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 Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 83 | } |
| 84 | |
Ales Komarek | d874d48 | 2016-12-26 10:33:29 +0100 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Install docutils in isolated environment |
| 88 | * |
| 89 | * @param path Path where virtualenv is created |
| 90 | */ |
Vasyl Saienko | a56c1ab | 2020-01-13 10:00:04 +0200 | [diff] [blame] | 91 | def setupDocutilsVirtualenv(path, python="python2") { |
Ales Komarek | d874d48 | 2016-12-26 10:33:29 +0100 | [diff] [blame] | 92 | requirements = [ |
Denis Egorenko | 71754dc | 2020-01-13 14:22:49 +0400 | [diff] [blame] | 93 | 'docutils==0.16', |
Ales Komarek | d874d48 | 2016-12-26 10:33:29 +0100 | [diff] [blame] | 94 | ] |
Vasyl Saienko | a56c1ab | 2020-01-13 10:00:04 +0200 | [diff] [blame] | 95 | setupVirtualenv(path, python, requirements) |
Ales Komarek | d874d48 | 2016-12-26 10:33:29 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 99 | @NonCPS |
| 100 | def loadJson(rawData) { |
| 101 | return new groovy.json.JsonSlurperClassic().parseText(rawData) |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Parse content from markup-text tables to variables |
| 106 | * |
| 107 | * @param tableStr String representing the table |
| 108 | * @param mode Either list (1st row are keys) or item (key, value rows) |
| 109 | * @param format Format of the table |
| 110 | */ |
Ales Komarek | d874d48 | 2016-12-26 10:33:29 +0100 | [diff] [blame] | 111 | def parseTextTable(tableStr, type = 'item', format = 'rest', path = none) { |
Ales Komarek | 0e558ee | 2016-12-23 13:02:55 +0100 | [diff] [blame] | 112 | parserFile = "${env.WORKSPACE}/textTableParser.py" |
| 113 | parserScript = """import json |
| 114 | import argparse |
| 115 | from docutils.parsers.rst import tableparser |
| 116 | from docutils import statemachine |
| 117 | |
| 118 | def parse_item_table(raw_data): |
| 119 | i = 1 |
| 120 | pretty_raw_data = [] |
| 121 | for datum in raw_data: |
| 122 | if datum != "": |
| 123 | if datum[3] != ' ' and i > 4: |
| 124 | pretty_raw_data.append(raw_data[0]) |
| 125 | if i == 3: |
| 126 | pretty_raw_data.append(datum.replace('-', '=')) |
| 127 | else: |
| 128 | pretty_raw_data.append(datum) |
| 129 | i += 1 |
| 130 | parser = tableparser.GridTableParser() |
| 131 | block = statemachine.StringList(pretty_raw_data) |
| 132 | docutils_data = parser.parse(block) |
| 133 | final_data = {} |
| 134 | for line in docutils_data[2]: |
| 135 | key = ' '.join(line[0][3]).strip() |
| 136 | value = ' '.join(line[1][3]).strip() |
| 137 | if key != "": |
| 138 | try: |
| 139 | value = json.loads(value) |
| 140 | except: |
| 141 | pass |
| 142 | final_data[key] = value |
| 143 | i+=1 |
| 144 | return final_data |
| 145 | |
| 146 | def parse_list_table(raw_data): |
| 147 | i = 1 |
| 148 | pretty_raw_data = [] |
| 149 | for datum in raw_data: |
| 150 | if datum != "": |
| 151 | if datum[3] != ' ' and i > 4: |
| 152 | pretty_raw_data.append(raw_data[0]) |
| 153 | if i == 3: |
| 154 | pretty_raw_data.append(datum.replace('-', '=')) |
| 155 | else: |
| 156 | pretty_raw_data.append(datum) |
| 157 | i += 1 |
| 158 | parser = tableparser.GridTableParser() |
| 159 | block = statemachine.StringList(pretty_raw_data) |
| 160 | docutils_data = parser.parse(block) |
| 161 | final_data = [] |
| 162 | keys = [] |
| 163 | for line in docutils_data[1]: |
| 164 | for item in line: |
| 165 | keys.append(' '.join(item[3]).strip()) |
| 166 | for line in docutils_data[2]: |
| 167 | final_line = {} |
| 168 | key = ' '.join(line[0][3]).strip() |
| 169 | value = ' '.join(line[1][3]).strip() |
| 170 | if key != "": |
| 171 | try: |
| 172 | value = json.loads(value) |
| 173 | except: |
| 174 | pass |
| 175 | final_data[key] = value |
| 176 | i+=1 |
| 177 | return final_data |
| 178 | |
| 179 | def parse_list_table(raw_data): |
| 180 | i = 1 |
| 181 | pretty_raw_data = [] |
| 182 | for datum in raw_data: |
| 183 | if datum != "": |
| 184 | if datum[3] != ' ' and i > 4: |
| 185 | pretty_raw_data.append(raw_data[0]) |
| 186 | if i == 3: |
| 187 | pretty_raw_data.append(datum.replace('-', '=')) |
| 188 | else: |
| 189 | pretty_raw_data.append(datum) |
| 190 | i += 1 |
| 191 | parser = tableparser.GridTableParser() |
| 192 | block = statemachine.StringList(pretty_raw_data) |
| 193 | docutils_data = parser.parse(block) |
| 194 | final_data = [] |
| 195 | keys = [] |
| 196 | for line in docutils_data[1]: |
| 197 | for item in line: |
| 198 | keys.append(' '.join(item[3]).strip()) |
| 199 | for line in docutils_data[2]: |
| 200 | final_line = {} |
| 201 | i = 0 |
| 202 | for item in line: |
| 203 | value = ' '.join(item[3]).strip() |
| 204 | try: |
| 205 | value = json.loads(value) |
| 206 | except: |
| 207 | pass |
| 208 | final_line[keys[i]] = value |
| 209 | i += 1 |
| 210 | final_data.append(final_line) |
| 211 | return final_data |
| 212 | |
| 213 | def read_table_file(file): |
| 214 | table_file = open(file, 'r') |
Ales Komarek | c000c15 | 2016-12-23 15:32:54 +0100 | [diff] [blame] | 215 | raw_data = table_file.read().split('\\n') |
Ales Komarek | 0e558ee | 2016-12-23 13:02:55 +0100 | [diff] [blame] | 216 | table_file.close() |
| 217 | return raw_data |
| 218 | |
| 219 | parser = argparse.ArgumentParser() |
| 220 | parser.add_argument('-f','--file', help='File with table data', required=True) |
| 221 | parser.add_argument('-t','--type', help='Type of table (list/item)', required=True) |
| 222 | args = vars(parser.parse_args()) |
| 223 | |
| 224 | raw_data = read_table_file(args['file']) |
| 225 | |
| 226 | if args['type'] == 'list': |
| 227 | final_data = parse_list_table(raw_data) |
| 228 | else: |
| 229 | final_data = parse_item_table(raw_data) |
| 230 | |
| 231 | print json.dumps(final_data) |
| 232 | """ |
| 233 | writeFile file: parserFile, text: parserScript |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 234 | tableFile = "${env.WORKSPACE}/prettytable.txt" |
| 235 | writeFile file: tableFile, text: tableStr |
Ales Komarek | d874d48 | 2016-12-26 10:33:29 +0100 | [diff] [blame] | 236 | |
| 237 | cmd = "python ${parserFile} --file '${tableFile}' --type ${type}" |
| 238 | if (path) { |
Ales Komarek | c6d28dd | 2016-12-28 12:59:38 +0100 | [diff] [blame] | 239 | rawData = runVirtualenvCommand(path, cmd) |
Ales Komarek | d874d48 | 2016-12-26 10:33:29 +0100 | [diff] [blame] | 240 | } |
| 241 | else { |
| 242 | rawData = sh ( |
| 243 | script: cmd, |
| 244 | returnStdout: true |
| 245 | ).trim() |
| 246 | } |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 247 | data = loadJson(rawData) |
| 248 | echo("[Parsed table] ${data}") |
| 249 | return data |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Install cookiecutter in isolated environment |
| 254 | * |
| 255 | * @param path Path where virtualenv is created |
| 256 | */ |
| 257 | def setupCookiecutterVirtualenv(path) { |
| 258 | requirements = [ |
| 259 | 'cookiecutter', |
Jakub Josef | 4df7827 | 2017-04-26 14:36:36 +0200 | [diff] [blame] | 260 | 'jinja2==2.8.1', |
Dmitry Pyzhov | b883a2d | 2018-12-14 16:42:52 +0300 | [diff] [blame] | 261 | 'PyYAML==3.12', |
| 262 | 'python-gnupg==0.4.3' |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 263 | ] |
| 264 | setupVirtualenv(path, 'python2', requirements) |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Generate the cookiecutter templates with given context |
| 269 | * |
Jakub Josef | 4e10c37 | 2017-04-26 14:13:50 +0200 | [diff] [blame] | 270 | * @param template template |
| 271 | * @param context template context |
| 272 | * @param path Path where virtualenv is created (optional) |
| 273 | * @param templatePath path to cookiecutter template repo (optional) |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 274 | */ |
Jakub Josef | 4e10c37 | 2017-04-26 14:13:50 +0200 | [diff] [blame] | 275 | def buildCookiecutterTemplate(template, context, outputDir = '.', path = null, templatePath = ".") { |
Tomáš Kukrál | dad7b46 | 2017-03-27 13:53:05 +0200 | [diff] [blame] | 276 | configFile = "default_config.yaml" |
| 277 | configString = "default_context:\n" |
Tomáš Kukrál | 6de8504 | 2017-04-12 17:49:05 +0200 | [diff] [blame] | 278 | writeFile file: configFile, text: context |
Jakub Josef | 4e61cc0 | 2017-04-26 14:29:09 +0200 | [diff] [blame] | 279 | 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" |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 280 | output = sh (returnStdout: true, script: command) |
| 281 | echo("[Cookiecutter build] Output: ${output}") |
| 282 | } |
| 283 | |
| 284 | /** |
Denis Egorenko | 6c2e3ae | 2018-10-17 16:45:56 +0400 | [diff] [blame] | 285 | * |
| 286 | * @param context - context template |
| 287 | * @param contextName - context template name |
| 288 | * @param saltMasterName - hostname of Salt Master node |
| 289 | * @param virtualenv - pyvenv with CC and dep's |
| 290 | * @param templateEnvDir - root of CookieCutter |
| 291 | * @return |
| 292 | */ |
| 293 | def generateModel(context, contextName, saltMasterName, virtualenv, modelEnv, templateEnvDir, multiModels = true) { |
Denis Egorenko | fa2c675 | 2018-10-18 15:51:45 +0400 | [diff] [blame] | 294 | def common = new com.mirantis.mk.Common() |
Denis Egorenko | 6c2e3ae | 2018-10-17 16:45:56 +0400 | [diff] [blame] | 295 | def generatedModel = multiModels ? "${modelEnv}/${contextName}" : modelEnv |
| 296 | def templateContext = readYaml text: context |
| 297 | def clusterDomain = templateContext.default_context.cluster_domain |
| 298 | def clusterName = templateContext.default_context.cluster_name |
| 299 | def outputDestination = "${generatedModel}/classes/cluster/${clusterName}" |
| 300 | def templateBaseDir = templateEnvDir |
| 301 | def templateDir = "${templateEnvDir}/dir" |
| 302 | def templateOutputDir = templateBaseDir |
| 303 | dir(templateEnvDir) { |
| 304 | common.infoMsg("Generating model from context ${contextName}") |
| 305 | def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"] |
| 306 | for (product in productList) { |
| 307 | // get templateOutputDir and productDir |
| 308 | templateOutputDir = "${templateEnvDir}/output/${product}" |
| 309 | productDir = product |
| 310 | templateDir = "${templateEnvDir}/cluster_product/${productDir}" |
| 311 | // Bw for 2018.8.1 and older releases |
| 312 | if (product.startsWith("stacklight") && (!fileExists(templateDir))) { |
| 313 | common.warningMsg("Old release detected! productDir => 'stacklight2' ") |
| 314 | productDir = "stacklight2" |
| 315 | templateDir = "${templateEnvDir}/cluster_product/${productDir}" |
| 316 | } |
Adam Tengler | a237313 | 2018-10-18 15:40:16 +0200 | [diff] [blame] | 317 | // generate infra unless its explicitly disabled |
| 318 | if ((product == "infra" && templateContext.default_context.get("infra_enabled", "True").toBoolean()) |
| 319 | || (templateContext.default_context.get(product + "_enabled", "False").toBoolean())) { |
Denis Egorenko | 6c2e3ae | 2018-10-17 16:45:56 +0400 | [diff] [blame] | 320 | |
| 321 | common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir) |
| 322 | |
| 323 | sh "rm -rf ${templateOutputDir} || true" |
| 324 | sh "mkdir -p ${templateOutputDir}" |
| 325 | sh "mkdir -p ${outputDestination}" |
| 326 | |
| 327 | buildCookiecutterTemplate(templateDir, context, templateOutputDir, virtualenv, templateBaseDir) |
| 328 | sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}" |
| 329 | } else { |
| 330 | common.warningMsg("Product " + product + " is disabled") |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | def localRepositories = templateContext.default_context.local_repositories |
| 335 | localRepositories = localRepositories ? localRepositories.toBoolean() : false |
| 336 | def offlineDeployment = templateContext.default_context.offline_deployment |
| 337 | offlineDeployment = offlineDeployment ? offlineDeployment.toBoolean() : false |
| 338 | if (localRepositories && !offlineDeployment) { |
| 339 | def mcpVersion = templateContext.default_context.mcp_version |
| 340 | def aptlyModelUrl = templateContext.default_context.local_model_url |
| 341 | def ssh = new com.mirantis.mk.Ssh() |
| 342 | dir(path: modelEnv) { |
| 343 | ssh.agentSh "git submodule add \"${aptlyModelUrl}\" \"classes/cluster/${clusterName}/cicd/aptly\"" |
| 344 | if (!(mcpVersion in ["nightly", "testing", "stable"])) { |
| 345 | ssh.agentSh "cd \"classes/cluster/${clusterName}/cicd/aptly\";git fetch --tags;git checkout ${mcpVersion}" |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | def nodeFile = "${generatedModel}/nodes/${saltMasterName}.${clusterDomain}.yml" |
| 351 | def nodeString = """classes: |
| 352 | - cluster.${clusterName}.infra.config |
| 353 | parameters: |
| 354 | _param: |
| 355 | linux_system_codename: xenial |
| 356 | reclass_data_revision: master |
| 357 | linux: |
| 358 | system: |
| 359 | name: ${saltMasterName} |
| 360 | domain: ${clusterDomain} |
| 361 | """ |
| 362 | sh "mkdir -p ${generatedModel}/nodes/" |
| 363 | writeFile(file: nodeFile, text: nodeString) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | /** |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 368 | * Install jinja rendering in isolated environment |
| 369 | * |
| 370 | * @param path Path where virtualenv is created |
| 371 | */ |
| 372 | def setupJinjaVirtualenv(path) { |
| 373 | requirements = [ |
Denis Egorenko | 71754dc | 2020-01-13 14:22:49 +0400 | [diff] [blame] | 374 | 'jinja2-cli==0.7.0', |
| 375 | 'pyyaml==5.3', |
Sergey Kolekonov | ba20398 | 2016-12-21 18:32:17 +0400 | [diff] [blame] | 376 | ] |
| 377 | setupVirtualenv(path, 'python2', requirements) |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Generate the Jinja templates with given context |
| 382 | * |
| 383 | * @param path Path where virtualenv is created |
| 384 | */ |
| 385 | def jinjaBuildTemplate (template, context, path = none) { |
| 386 | contextFile = "jinja_context.yml" |
| 387 | contextString = "" |
| 388 | for (parameter in context) { |
| 389 | contextString = "${contextString}${parameter.key}: ${parameter.value}\n" |
| 390 | } |
| 391 | writeFile file: contextFile, text: contextString |
| 392 | cmd = "jinja2 ${template} ${contextFile} --format=yaml" |
| 393 | data = sh (returnStdout: true, script: cmd) |
| 394 | echo(data) |
| 395 | return data |
| 396 | } |
Oleg Grigorov | bec4558 | 2017-09-12 20:29:24 +0300 | [diff] [blame] | 397 | |
| 398 | /** |
| 399 | * Install salt-pepper in isolated environment |
| 400 | * |
| 401 | * @param path Path where virtualenv is created |
chnyda | a0dbb25 | 2017-10-05 10:46:09 +0200 | [diff] [blame] | 402 | * @param url SALT_MASTER_URL |
| 403 | * @param credentialsId Credentials to salt api |
Oleg Grigorov | bec4558 | 2017-09-12 20:29:24 +0300 | [diff] [blame] | 404 | */ |
Jakub Josef | c9b6d66 | 2018-02-21 16:21:03 +0100 | [diff] [blame] | 405 | def setupPepperVirtualenv(path, url, credentialsId) { |
chnyda | a0dbb25 | 2017-10-05 10:46:09 +0200 | [diff] [blame] | 406 | def common = new com.mirantis.mk.Common() |
| 407 | |
| 408 | // virtualenv setup |
Mykyta Karpin | 81756c9 | 2018-03-02 13:03:26 +0200 | [diff] [blame] | 409 | // pin pepper till https://mirantis.jira.com/browse/PROD-18188 is fixed |
| 410 | requirements = ['salt-pepper>=0.5.2,<0.5.4'] |
Jakub Josef | c9b6d66 | 2018-02-21 16:21:03 +0100 | [diff] [blame] | 411 | setupVirtualenv(path, 'python2', requirements, null, true, true) |
chnyda | bcfff18 | 2017-11-29 10:24:36 +0100 | [diff] [blame] | 412 | |
chnyda | a0dbb25 | 2017-10-05 10:46:09 +0200 | [diff] [blame] | 413 | // pepperrc creation |
| 414 | rcFile = "${path}/pepperrc" |
| 415 | creds = common.getPasswordCredentials(credentialsId) |
| 416 | rc = """\ |
| 417 | [main] |
| 418 | SALTAPI_EAUTH=pam |
| 419 | SALTAPI_URL=${url} |
| 420 | SALTAPI_USER=${creds.username} |
| 421 | SALTAPI_PASS=${creds.password.toString()} |
| 422 | """ |
| 423 | writeFile file: rcFile, text: rc |
| 424 | return rcFile |
Jakub Josef | d067f61 | 2017-09-26 13:42:56 +0200 | [diff] [blame] | 425 | } |
Oleh Hryhorov | 44569fb | 2017-10-26 17:04:55 +0300 | [diff] [blame] | 426 | |
| 427 | /** |
| 428 | * Install devops in isolated environment |
| 429 | * |
| 430 | * @param path Path where virtualenv is created |
| 431 | * @param clean Define to true is the venv have to cleaned up before install a new one |
| 432 | */ |
| 433 | def setupDevOpsVenv(venv, clean=false) { |
| 434 | requirements = ['git+https://github.com/openstack/fuel-devops.git'] |
| 435 | setupVirtualenv(venv, 'python2', requirements, null, false, clean) |
| 436 | } |