blob: 3b1ee17bb2e4f75f487d9e63fa742e3c6c502692 [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
Hanna Arhipova5173aad2019-11-11 12:42:31 +020013 * TCP_QA_REFS Reference to the tcp-qa change on Gerrit, like refs/changes/46/418546/41
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030014 * SHUTDOWN_ENV_ON_TEARDOWN optional, shutdown fuel-devops environment at the end of the job
Anna Arhipova37739ee2022-08-10 11:46:45 +020015 * LAB_CONFIG_NAME
Tatyana Leontovichf3718442018-10-31 13:36:13 +020016 * TEMPEST_IMAGE_VERSION Tempest image version: pike by default, can be queens.
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +020017 * TEMPEST_TARGET Node where tempest will be run
Dennis Dmitriev02447412019-04-17 18:02:46 +030018 * MAKE_SNAPSHOT_STAGES optional, use "dos.py snapshot" to snapshot stages
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030019 */
20
21@Library('tcp-qa')_
22
23common = new com.mirantis.mk.Common()
24shared = new com.mirantis.system_qa.SharedPipeline()
Dennis Dmitriev02447412019-04-17 18:02:46 +030025make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030026
27if (! env.PARENT_NODE_NAME) {
28 error "'PARENT_NODE_NAME' must be set from the parent deployment job!"
29}
30
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030031currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}"
32
PGlazov2d1a1742021-08-06 15:35:11 +040033timeout(time: 20, unit: 'HOURS') {
Hanna Arhipova6736dab2020-05-07 14:33:35 +030034 timestamps {
35 node ("${PARENT_NODE_NAME}") {
36 if (! fileExists("${PARENT_WORKSPACE}")) {
37 error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'."
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030038 }
Hanna Arhipova6736dab2020-05-07 14:33:35 +030039 dir("${PARENT_WORKSPACE}") {
40 try {
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030041
Hanna Arhipova6736dab2020-05-07 14:33:35 +030042 if (env.TCP_QA_REFS) {
43 stage("Update working dir to patch ${TCP_QA_REFS}") {
44 shared.update_working_dir()
45 }
Dennis Dmitriev02447412019-04-17 18:02:46 +030046 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030047
Hanna Arhipova6736dab2020-05-07 14:33:35 +030048 stage("Run tests") {
49 def steps = shared.get_steps_list(PASSED_STEPS)
50 def sources = """\
51 cd ${PARENT_WORKSPACE}
52 export ENV_NAME=${ENV_NAME}
53 . ./tcp_tests/utils/env_salt"""
54 if (steps.contains('k8s')) {
55 sources += """
56 . ./tcp_tests/utils/env_k8s\n"""
57 }
58 if (steps.contains('openstack')) {
59 sources += """
60 export TEMPEST_IMAGE_VERSION=${TEMPEST_IMAGE_VERSION}
61 export TEMPEST_TARGET=${TEMPEST_TARGET}
62 # TODO: . ./tcp_tests/utils/env_keystonercv3\n"""
63 }
64 def installed = steps.collect {"""\
65 export ${it}_installed=true"""}.join("\n")
66
67 shared.run_sh(sources + installed + """
PGlazov271e7952022-01-13 16:11:31 +040068 mkdir -p tmp
dtsapikov9f8d8892022-04-04 15:35:30 +040069 echo ${RUN_TEST_OPTS} > tmp/test-run.txt
dtsapikov269f5192021-08-12 13:35:43 +040070 export PYTHONHTTPSVERIFY=0
Hanna Arhipova6736dab2020-05-07 14:33:35 +030071 export TESTS_CONFIGS=${ENV_NAME}_salt_deployed.ini
72 export ENV_MANAGER=$ENV_MANAGER # use 'hardware' fixture to manage fuel-devops environment
Anna Arhipova37739ee2022-08-10 11:46:45 +020073 export LAB_CONFIG_NAME=${LAB_CONFIG_NAME}
Hanna Arhipova6736dab2020-05-07 14:33:35 +030074 export salt_master_host=\$SALT_MASTER_IP # skip salt_deployed fixture
75 export salt_master_port=6969
76 export SALT_USER=\$SALTAPI_USER
77 export SALT_PASSWORD=\$SALTAPI_PASS
78
79 export LOG_NAME=swarm_run_pytest.log
80 py.test --junit-xml=nosetests.xml ${RUN_TEST_OPTS}
81
82 """)
83
dtsapikov269f5192021-08-12 13:35:43 +040084 archiveArtifacts artifacts: "tmp/*"
85 shared.run_sh("""
86 cd ${PARENT_WORKSPACE}
PGlazov271e7952022-01-13 16:11:31 +040087 cp tmp/* ./
dtsapikov269f5192021-08-12 13:35:43 +040088 rm -rf tmp/
89 """)
90
Hanna Arhipova6736dab2020-05-07 14:33:35 +030091 def snapshot_name = "test_completed"
92 shared.download_logs("test_completed_${ENV_NAME}")
93
94 if (make_snapshot_stages) {
95 shared.run_cmd("""\
96 dos.py suspend ${ENV_NAME}
97 dos.py snapshot ${ENV_NAME} ${snapshot_name}
98 """)
99 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
100 shared.run_cmd("""\
101 dos.py resume ${ENV_NAME}
102 """)
103 }
104 shared.devops_snapshot_info(snapshot_name)
105 }
106 }
107
108 } catch (e) {
109 common.printMsg("Job is failed", "purple")
110 // Downloading logs usually not needed here
111 // because tests should use the decorator @pytest.mark.grab_versions
112 // shared.download_logs("test_failed_${ENV_NAME}")
113 throw e
114 } finally {
115 // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'"
116 // and report appropriate data to TestRail
117 if (make_snapshot_stages) {
118 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
119 shared.run_cmd("""\
120 dos.py destroy ${ENV_NAME}
121 """)
122 }
123 }
Dennis Dmitriev02447412019-04-17 18:02:46 +0300124 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300125 }
Hanna Arhipova6736dab2020-05-07 14:33:35 +0300126 } //node
127 } // timestamps
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300128} // timeout