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) |
Tatyana Leontovich | f371844 | 2018-10-31 13:36:13 +0200 | [diff] [blame] | 19 | * TEMPEST_IMAGE_VERSION Tempest image version: pike by default, can be queens. |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 20 | * TEMPEST_TARGET Node where tempest will be run |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 21 | * MAKE_SNAPSHOT_STAGES optional, use "dos.py snapshot" to snapshot stages |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | @Library('tcp-qa')_ |
| 25 | |
| 26 | common = new com.mirantis.mk.Common() |
| 27 | shared = new com.mirantis.system_qa.SharedPipeline() |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 28 | make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 29 | |
| 30 | if (! env.PARENT_NODE_NAME) { |
| 31 | error "'PARENT_NODE_NAME' must be set from the parent deployment job!" |
| 32 | } |
| 33 | |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 34 | currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}" |
| 35 | |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 36 | timeout(time: 10, unit: 'HOURS') { |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 37 | node ("${PARENT_NODE_NAME}") { |
| 38 | if (! fileExists("${PARENT_WORKSPACE}")) { |
| 39 | error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'." |
| 40 | } |
| 41 | dir("${PARENT_WORKSPACE}") { |
| 42 | try { |
| 43 | |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 44 | if (env.TCP_QA_REFS) { |
| 45 | stage("Update working dir to patch ${TCP_QA_REFS}") { |
| 46 | shared.update_working_dir() |
| 47 | } |
| 48 | } |
| 49 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 50 | stage("Run tests") { |
| 51 | def steps = shared.get_steps_list(PASSED_STEPS) |
| 52 | def sources = """\ |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 53 | cd ${PARENT_WORKSPACE} |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 54 | export ENV_NAME=${ENV_NAME} |
| 55 | . ./tcp_tests/utils/env_salt""" |
| 56 | if (steps.contains('k8s')) { |
| 57 | sources += """ |
| 58 | . ./tcp_tests/utils/env_k8s\n""" |
| 59 | } |
| 60 | if (steps.contains('openstack')) { |
| 61 | sources += """ |
Tatyana Leontovich | f371844 | 2018-10-31 13:36:13 +0200 | [diff] [blame] | 62 | export TEMPEST_IMAGE_VERSION=${TEMPEST_IMAGE_VERSION} |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 63 | export TEMPEST_TARGET=${TEMPEST_TARGET} |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 64 | # TODO: . ./tcp_tests/utils/env_keystonercv3\n""" |
| 65 | } |
| 66 | def installed = steps.collect {"""\ |
| 67 | export ${it}_installed=true"""}.join("\n") |
| 68 | |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 69 | shared.run_sh(sources + installed + """ |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 70 | export TESTS_CONFIGS=${ENV_NAME}_salt_deployed.ini |
sgudz | 099e0f8 | 2019-05-22 15:02:13 +0300 | [diff] [blame] | 71 | export ENV_MANAGER=$ENV_MANAGER # use 'hardware' fixture to manage fuel-devops environment |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 72 | export salt_master_host=\$SALT_MASTER_IP # skip salt_deployed fixture |
| 73 | export salt_master_port=6969 |
| 74 | export SALT_USER=\$SALTAPI_USER |
| 75 | export SALT_PASSWORD=\$SALTAPI_PASS |
| 76 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 77 | export LOG_NAME=swarm_run_pytest.log |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 78 | py.test --junit-xml=nosetests.xml ${RUN_TEST_OPTS} |
| 79 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 80 | """) |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 81 | |
| 82 | def snapshot_name = "test_completed" |
Dennis Dmitriev | 9cd5c13 | 2018-12-12 17:10:47 +0200 | [diff] [blame] | 83 | shared.download_logs("test_completed_${ENV_NAME}") |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 84 | |
| 85 | if (make_snapshot_stages) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 86 | shared.run_cmd("""\ |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 87 | dos.py suspend ${ENV_NAME} |
| 88 | dos.py snapshot ${ENV_NAME} ${snapshot_name} |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 89 | """) |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 90 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 91 | shared.run_cmd("""\ |
| 92 | dos.py resume ${ENV_NAME} |
| 93 | """) |
| 94 | } |
| 95 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 96 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 100 | common.printMsg("Job is failed", "purple") |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 101 | // Downloading logs usually not needed here |
| 102 | // because tests should use the decorator @pytest.mark.grab_versions |
Dennis Dmitriev | 9cd5c13 | 2018-12-12 17:10:47 +0200 | [diff] [blame] | 103 | // shared.download_logs("test_failed_${ENV_NAME}") |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 104 | throw e |
| 105 | } finally { |
| 106 | // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'" |
| 107 | // and report appropriate data to TestRail |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 108 | if (make_snapshot_stages) { |
| 109 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") { |
| 110 | shared.run_cmd("""\ |
| 111 | dos.py destroy ${ENV_NAME} |
| 112 | """) |
| 113 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | } |
| 117 | } |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 118 | } // timeout |