blob: d4038610b3c8223dbe87a3fcdf67c63d6d586bb0 [file] [log] [blame]
Dennis Dmitrievfde667f2018-07-23 16:26:50 +03001/**
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 Leontovichf3718442018-10-31 13:36:13 +020019 * TEMPEST_IMAGE_VERSION Tempest image version: pike by default, can be queens.
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +020020 * TEMPEST_TARGET Node where tempest will be run
Dennis Dmitriev02447412019-04-17 18:02:46 +030021 * MAKE_SNAPSHOT_STAGES optional, use "dos.py snapshot" to snapshot stages
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030022 */
23
24@Library('tcp-qa')_
25
26common = new com.mirantis.mk.Common()
27shared = new com.mirantis.system_qa.SharedPipeline()
Dennis Dmitriev02447412019-04-17 18:02:46 +030028make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030029
30if (! env.PARENT_NODE_NAME) {
31 error "'PARENT_NODE_NAME' must be set from the parent deployment job!"
32}
33
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030034currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}"
35
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030036node ("${PARENT_NODE_NAME}") {
37 if (! fileExists("${PARENT_WORKSPACE}")) {
38 error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'."
39 }
40 dir("${PARENT_WORKSPACE}") {
41 try {
42
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030043 if (env.TCP_QA_REFS) {
44 stage("Update working dir to patch ${TCP_QA_REFS}") {
45 shared.update_working_dir()
46 }
47 }
48
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030049 stage("Run tests") {
50 def steps = shared.get_steps_list(PASSED_STEPS)
51 def sources = """\
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030052 cd ${PARENT_WORKSPACE}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030053 export ENV_NAME=${ENV_NAME}
54 . ./tcp_tests/utils/env_salt"""
55 if (steps.contains('k8s')) {
56 sources += """
57 . ./tcp_tests/utils/env_k8s\n"""
58 }
59 if (steps.contains('openstack')) {
60 sources += """
Tatyana Leontovichf3718442018-10-31 13:36:13 +020061 export TEMPEST_IMAGE_VERSION=${TEMPEST_IMAGE_VERSION}
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +020062 export TEMPEST_TARGET=${TEMPEST_TARGET}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030063 # TODO: . ./tcp_tests/utils/env_keystonercv3\n"""
64 }
65 def installed = steps.collect {"""\
66 export ${it}_installed=true"""}.join("\n")
67
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030068 shared.run_sh(sources + installed + """
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030069 export TESTS_CONFIGS=${ENV_NAME}_salt_deployed.ini
Dennis Dmitriev552454c2019-03-21 23:15:51 +020070 export ENV_MANAGER=devops # use 'hardware' fixture to manage fuel-devops environment
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030071 export salt_master_host=\$SALT_MASTER_IP # skip salt_deployed fixture
72 export salt_master_port=6969
73 export SALT_USER=\$SALTAPI_USER
74 export SALT_PASSWORD=\$SALTAPI_PASS
75
Dennis Dmitriev27007322019-05-03 19:21:44 +030076 export LOG_NAME=swarm_run_pytest.log
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030077 py.test --junit-xml=nosetests.xml ${RUN_TEST_OPTS}
78
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030079 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030080
81 def snapshot_name = "test_completed"
Dennis Dmitriev9cd5c132018-12-12 17:10:47 +020082 shared.download_logs("test_completed_${ENV_NAME}")
Dennis Dmitriev02447412019-04-17 18:02:46 +030083
84 if (make_snapshot_stages) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030085 shared.run_cmd("""\
Dennis Dmitriev02447412019-04-17 18:02:46 +030086 dos.py suspend ${ENV_NAME}
87 dos.py snapshot ${ENV_NAME} ${snapshot_name}
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030088 """)
Dennis Dmitriev02447412019-04-17 18:02:46 +030089 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
90 shared.run_cmd("""\
91 dos.py resume ${ENV_NAME}
92 """)
93 }
94 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030095 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030096 }
97
98 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030099 common.printMsg("Job is failed", "purple")
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300100 // Downloading logs usually not needed here
101 // because tests should use the decorator @pytest.mark.grab_versions
Dennis Dmitriev9cd5c132018-12-12 17:10:47 +0200102 // shared.download_logs("test_failed_${ENV_NAME}")
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300103 throw e
104 } finally {
105 // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'"
106 // and report appropriate data to TestRail
Dennis Dmitriev02447412019-04-17 18:02:46 +0300107 if (make_snapshot_stages) {
108 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
109 shared.run_cmd("""\
110 dos.py destroy ${ENV_NAME}
111 """)
112 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300113 }
114 }
115 }
116}