blob: 431d23819c06b7285abaf43fa21408d64610346f [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
Tatyana Leontovichf3718442018-10-31 13:36:13 +020015 * TEMPEST_IMAGE_VERSION Tempest image version: pike by default, can be queens.
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +020016 * TEMPEST_TARGET Node where tempest will be run
Dennis Dmitriev02447412019-04-17 18:02:46 +030017 * MAKE_SNAPSHOT_STAGES optional, use "dos.py snapshot" to snapshot stages
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030018 */
19
20@Library('tcp-qa')_
21
22common = new com.mirantis.mk.Common()
23shared = new com.mirantis.system_qa.SharedPipeline()
Dennis Dmitriev02447412019-04-17 18:02:46 +030024make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030025
26if (! env.PARENT_NODE_NAME) {
27 error "'PARENT_NODE_NAME' must be set from the parent deployment job!"
28}
29
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030030currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}"
31
PGlazov2d1a1742021-08-06 15:35:11 +040032timeout(time: 20, unit: 'HOURS') {
Hanna Arhipova6736dab2020-05-07 14:33:35 +030033 timestamps {
34 node ("${PARENT_NODE_NAME}") {
35 if (! fileExists("${PARENT_WORKSPACE}")) {
36 error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'."
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030037 }
Hanna Arhipova6736dab2020-05-07 14:33:35 +030038 dir("${PARENT_WORKSPACE}") {
39 try {
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030040
Hanna Arhipova6736dab2020-05-07 14:33:35 +030041 if (env.TCP_QA_REFS) {
42 stage("Update working dir to patch ${TCP_QA_REFS}") {
43 shared.update_working_dir()
44 }
Dennis Dmitriev02447412019-04-17 18:02:46 +030045 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030046
Hanna Arhipova6736dab2020-05-07 14:33:35 +030047 stage("Run tests") {
48 def steps = shared.get_steps_list(PASSED_STEPS)
49 def sources = """\
50 cd ${PARENT_WORKSPACE}
51 export ENV_NAME=${ENV_NAME}
52 . ./tcp_tests/utils/env_salt"""
53 if (steps.contains('k8s')) {
54 sources += """
55 . ./tcp_tests/utils/env_k8s\n"""
56 }
57 if (steps.contains('openstack')) {
58 sources += """
59 export TEMPEST_IMAGE_VERSION=${TEMPEST_IMAGE_VERSION}
60 export TEMPEST_TARGET=${TEMPEST_TARGET}
61 # TODO: . ./tcp_tests/utils/env_keystonercv3\n"""
62 }
63 def installed = steps.collect {"""\
64 export ${it}_installed=true"""}.join("\n")
65
66 shared.run_sh(sources + installed + """
PGlazov271e7952022-01-13 16:11:31 +040067 mkdir -p tmp
dtsapikov269f5192021-08-12 13:35:43 +040068 export PYTHONHTTPSVERIFY=0
Hanna Arhipova6736dab2020-05-07 14:33:35 +030069 export TESTS_CONFIGS=${ENV_NAME}_salt_deployed.ini
70 export ENV_MANAGER=$ENV_MANAGER # use 'hardware' fixture to manage fuel-devops environment
71 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
76 export LOG_NAME=swarm_run_pytest.log
77 py.test --junit-xml=nosetests.xml ${RUN_TEST_OPTS}
78
79 """)
80
dtsapikov269f5192021-08-12 13:35:43 +040081 archiveArtifacts artifacts: "tmp/*"
82 shared.run_sh("""
83 cd ${PARENT_WORKSPACE}
PGlazov271e7952022-01-13 16:11:31 +040084 cp tmp/* ./
dtsapikov269f5192021-08-12 13:35:43 +040085 rm -rf tmp/
86 """)
87
Hanna Arhipova6736dab2020-05-07 14:33:35 +030088 def snapshot_name = "test_completed"
89 shared.download_logs("test_completed_${ENV_NAME}")
90
91 if (make_snapshot_stages) {
92 shared.run_cmd("""\
93 dos.py suspend ${ENV_NAME}
94 dos.py snapshot ${ENV_NAME} ${snapshot_name}
95 """)
96 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
97 shared.run_cmd("""\
98 dos.py resume ${ENV_NAME}
99 """)
100 }
101 shared.devops_snapshot_info(snapshot_name)
102 }
103 }
104
105 } catch (e) {
106 common.printMsg("Job is failed", "purple")
107 // Downloading logs usually not needed here
108 // because tests should use the decorator @pytest.mark.grab_versions
109 // shared.download_logs("test_failed_${ENV_NAME}")
110 throw e
111 } finally {
112 // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'"
113 // and report appropriate data to TestRail
114 if (make_snapshot_stages) {
115 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
116 shared.run_cmd("""\
117 dos.py destroy ${ENV_NAME}
118 """)
119 }
120 }
Dennis Dmitriev02447412019-04-17 18:02:46 +0300121 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300122 }
Hanna Arhipova6736dab2020-05-07 14:33:35 +0300123 } //node
124 } // timestamps
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300125} // timeout