Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Deploy the product cluster using Jenkins master on CICD cluster |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | |
| 7 | * ENV_NAME Fuel-devops environment name |
| 8 | * PASSED_STEPS Steps passed to install components using Jenkins on CICD cluster: "salt,core,cicd,openstack:3200,stacklight:2400", |
| 9 | where 3200 and 2400 might be timeouts (not used in the testing pipeline) |
| 10 | * RUN_TEST_OPTS Pytest option -k or -m, with expression to select necessary tests. Additional pytest options are allowed. |
| 11 | * PARENT_NODE_NAME Name of the jenkins slave to create the environment |
| 12 | * PARENT_WORKSPACE Path to the workspace of the parent job to use tcp-qa repo |
| 13 | * TCP_QA_REFS Reference to the tcp-qa change on review.gerrithub.io, like refs/changes/46/418546/41 |
| 14 | * SHUTDOWN_ENV_ON_TEARDOWN optional, shutdown fuel-devops environment at the end of the job |
| 15 | * LAB_CONFIG_NAME Not used (backward compatibility, for manual deployment steps only) |
| 16 | * REPOSITORY_SUITE Not used (backward compatibility, for manual deployment steps only) |
| 17 | * MCP_IMAGE_PATH1604 Not used (backward compatibility, for manual deployment steps only) |
| 18 | * IMAGE_PATH_CFG01_DAY01 Not used (backward compatibility, for manual deployment steps only) |
| 19 | */ |
| 20 | |
| 21 | @Library('tcp-qa')_ |
| 22 | |
| 23 | common = new com.mirantis.mk.Common() |
| 24 | shared = new com.mirantis.system_qa.SharedPipeline() |
| 25 | |
| 26 | if (! env.PARENT_NODE_NAME) { |
| 27 | error "'PARENT_NODE_NAME' must be set from the parent deployment job!" |
| 28 | } |
| 29 | |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 30 | currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}" |
| 31 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 32 | node ("${PARENT_NODE_NAME}") { |
| 33 | if (! fileExists("${PARENT_WORKSPACE}")) { |
| 34 | error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'." |
| 35 | } |
| 36 | dir("${PARENT_WORKSPACE}") { |
| 37 | try { |
| 38 | |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 39 | if (env.TCP_QA_REFS) { |
| 40 | stage("Update working dir to patch ${TCP_QA_REFS}") { |
| 41 | shared.update_working_dir() |
| 42 | } |
| 43 | } |
| 44 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 45 | stage("Run tests") { |
| 46 | def steps = shared.get_steps_list(PASSED_STEPS) |
| 47 | def sources = """\ |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 48 | cd ${PARENT_WORKSPACE} |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 49 | export ENV_NAME=${ENV_NAME} |
| 50 | . ./tcp_tests/utils/env_salt""" |
| 51 | if (steps.contains('k8s')) { |
| 52 | sources += """ |
| 53 | . ./tcp_tests/utils/env_k8s\n""" |
| 54 | } |
| 55 | if (steps.contains('openstack')) { |
| 56 | sources += """ |
| 57 | # TODO: . ./tcp_tests/utils/env_keystonercv3\n""" |
| 58 | } |
| 59 | def installed = steps.collect {"""\ |
| 60 | export ${it}_installed=true"""}.join("\n") |
| 61 | |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 62 | shared.run_sh(sources + installed + """ |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 63 | export TESTS_CONFIGS=${ENV_NAME}_salt_deployed.ini |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 64 | export MANAGER=devops # use 'hardware' fixture to manage fuel-devops environment |
| 65 | export salt_master_host=\$SALT_MASTER_IP # skip salt_deployed fixture |
| 66 | export salt_master_port=6969 |
| 67 | export SALT_USER=\$SALTAPI_USER |
| 68 | export SALT_PASSWORD=\$SALTAPI_PASS |
| 69 | |
| 70 | py.test --junit-xml=nosetests.xml ${RUN_TEST_OPTS} |
| 71 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 72 | """) |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame^] | 73 | |
| 74 | def snapshot_name = "test_completed" |
| 75 | shared.run_cmd("""\ |
| 76 | dos.py suspend ${ENV_NAME} |
| 77 | dos.py snapshot ${ENV_NAME} ${snapshot_name} |
| 78 | """) |
| 79 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 80 | shared.run_cmd("""\ |
| 81 | dos.py resume ${ENV_NAME} |
| 82 | """) |
| 83 | } |
| 84 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame^] | 88 | common.printMsg("Job is failed", "purple") |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 89 | throw e |
| 90 | } finally { |
| 91 | // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'" |
| 92 | // and report appropriate data to TestRail |
| 93 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") { |
| 94 | shared.run_cmd("""\ |
| 95 | dos.py destroy ${ENV_NAME} |
| 96 | """) |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |