Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 1 | @Library('tcp-qa')_ |
| 2 | |
| 3 | def common = new com.mirantis.mk.Common() |
| 4 | def shared = new com.mirantis.system_qa.SharedPipeline() |
| 5 | def steps = "hardware,create_model,salt," + env.DRIVETRAIN_STACK_INSTALL + "," + env.PLATFORM_STACK_INSTALL |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 6 | def env_manager = env.ENV_MANAGER ?: 'devops' |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 7 | |
| 8 | if (env_manager == 'devops') { |
| 9 | jenkins_slave_node_name = "${NODE_NAME}" |
| 10 | make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false |
| 11 | } else if (env_manager == 'heat') { |
| 12 | jenkins_slave_node_name = "openstack_slave_${JOB_NAME}" |
| 13 | make_snapshot_stages = false |
| 14 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 15 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 16 | currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>" |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 17 | |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 18 | def deploy(shared, common, steps, env_manager) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 19 | def report_text = '' |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 20 | try { |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 21 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 22 | stage("Clean the environment and clone tcp-qa") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 23 | shared.prepare_working_dir(env_manager) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 24 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 25 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 26 | stage("Create environment, generate model, bootstrap the salt-cluster") { |
| 27 | // steps: "hardware,create_model,salt" |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 28 | if (env_manager == 'devops') { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 29 | shared.swarm_bootstrap_salt_cluster_devops() |
| 30 | } else if (env_manager == 'heat') { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 31 | // If shared.swarm_bootstrap_salt_cluster_heat() failed, |
| 32 | // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 33 | shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 34 | // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 35 | // disable dos.py snapshots for 'heat' manager |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 36 | } else { |
| 37 | throw new Exception("Unknow env_manager: '${env_manager}'") |
| 38 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 39 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 40 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 41 | stage("Install core infrastructure and deploy CICD nodes") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 42 | if (env.DRIVETRAIN_STACK_INSTALL) { |
| 43 | // steps: env.DRIVETRAIN_STACK_INSTALL |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 44 | shared.swarm_deploy_cicd(env.DRIVETRAIN_STACK_INSTALL, env.DRIVETRAIN_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 45 | } else { |
| 46 | common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green") |
| 47 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 48 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 49 | |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 50 | stage("Deploy platform components") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 51 | if (env.PLATFORM_STACK_INSTALL) { |
| 52 | // steps: env.PLATFORM_STACK_INSTALL |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 53 | shared.swarm_deploy_platform(env.PLATFORM_STACK_INSTALL, env.PLATFORM_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 54 | } else { |
| 55 | common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green") |
| 56 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 57 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 58 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 59 | currentBuild.result = 'SUCCESS' |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 60 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 61 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 62 | common.printMsg("Deploy is failed: " + e.message , "purple") |
| 63 | report_text = e.message |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 64 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 65 | def snapshot_name = "deploy_failed" |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 66 | shared.run_cmd("""\ |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 67 | dos.py suspend ${ENV_NAME} || true |
| 68 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 69 | """) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 70 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 71 | shared.run_cmd("""\ |
| 72 | dos.py resume ${ENV_NAME} || true |
| 73 | """) |
| 74 | } |
| 75 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 76 | } |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 77 | throw e |
| 78 | } finally { |
| 79 | shared.create_deploy_result_report(steps, currentBuild.result, report_text) |
| 80 | } |
| 81 | } |
| 82 | |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 83 | def test(shared, common, steps, env_manager) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 84 | try { |
| 85 | stage("Run tests") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 86 | if (env.RUN_TEST_OPTS) { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 87 | shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 88 | } else { |
| 89 | common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green") |
| 90 | } |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 94 | common.printMsg("Tests are failed: " + e.message, "purple") |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 95 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 96 | def snapshot_name = "tests_failed" |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 97 | shared.run_cmd("""\ |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 98 | dos.py suspend ${ENV_NAME} || true |
| 99 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 100 | """) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 101 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 102 | shared.run_cmd("""\ |
| 103 | dos.py resume ${ENV_NAME} || true |
| 104 | """) |
| 105 | } |
| 106 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 107 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 108 | throw e |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | // main |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 113 | // Temporary disable throttle to check how it will run |
| 114 | //throttle(['fuel_devops_environment']) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 115 | node ("${NODE_NAME}") { |
| 116 | try { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 117 | // run deploy stages |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 118 | deploy(shared, common, steps, env_manager) |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 119 | // run test stages |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 120 | test(shared, common, steps, env_manager) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 121 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 122 | common.printMsg("Job is failed: " + e.message, "purple") |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 123 | throw e |
| 124 | } finally { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 125 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 126 | // shutdown the environment if required |
| 127 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") { |
| 128 | shared.run_cmd("""\ |
| 129 | dos.py destroy ${ENV_NAME} || true |
| 130 | """) |
| 131 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 132 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 133 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 134 | if (fileExists("jenkins_agent_description.txt")) { |
| 135 | def String jenkins_agent_description = readFile("jenkins_agent_description.txt") |
| 136 | currentBuild.description += "${jenkins_agent_description}" |
| 137 | |
| 138 | // if there is a separated foundation node on $jenkins_slave_node_name, |
| 139 | // then archive artifacts also on that node |
| 140 | if (jenkins_slave_node_name != env.NODE_NAME) { |
| 141 | node ("${jenkins_slave_node_name}") { |
| 142 | stage("Archive all xml reports from node ${}") { |
| 143 | archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz" |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 149 | stage("Archive all xml reports") { |
| 150 | archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz" |
| 151 | } |
Vladimir Jigulin | 91bb7c9 | 2019-04-04 18:15:45 +0400 | [diff] [blame] | 152 | if ("${env.REPORT_TO_TESTRAIL}" != "false") { |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 153 | stage("report results to testrail") { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 154 | shared.swarm_testrail_report(steps) |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 155 | } |
| 156 | stage("Store TestRail reports to job description") { |
| 157 | def String description = readFile("description.txt") |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 158 | currentBuild.description += "${description}" |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 159 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 160 | } |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 161 | } // try |
| 162 | } // node |
| 163 | |
| 164 | |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 165 | //} |