Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 1 | /** |
| 2 | * |
Oleksii Zhurba | 8fa12d1 | 2017-12-07 13:45:53 -0600 | [diff] [blame] | 3 | * Launch HA test for the cloud |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 4 | * |
| 5 | * Expected parameters: |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 6 | * |
Oleksii Zhurba | 8fa12d1 | 2017-12-07 13:45:53 -0600 | [diff] [blame] | 7 | * SALT_MASTER_URL URL of Salt master |
| 8 | * SALT_MASTER_CREDENTIALS Credentials that are used in this Jenkins for accessing Salt master (usually "salt") |
| 9 | * PROXY Proxy address (if any) for accessing the Internet. It will be used for cloning repos and installing pip dependencies |
| 10 | * TEST_IMAGE Docker image link to use for running container with testing tools. |
| 11 | * TOOLS_REPO URL of repo where testing tools, scenarios, configs are located |
| 12 | * |
| 13 | * DEBUG_MODE If you need to debug (keep container after test), please enabled this |
| 14 | * MANUAL_CONFIRMATION Ask for confirmation before doing something destructive (reboot/shutdown node) |
| 15 | * RETRY_CHECK_STATUS Number of retries to check node status |
| 16 | * SKIP_LIST_PATH Path to tempest skip list file in TOOLS_REPO |
| 17 | * TARGET_NODES Nodes to test |
| 18 | * TEMPEST_REPO Tempest repo to clone and use |
| 19 | * TEMPEST_TARGET_NODE Node, where tests will be executed |
| 20 | * TEMPEST_TEST_PATTERN Tests to run during HA scenarios |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | common = new com.mirantis.mk.Common() |
| 25 | salt = new com.mirantis.mk.Salt() |
| 26 | validate = new com.mirantis.mcp.Validate() |
| 27 | |
| 28 | def saltMaster |
| 29 | def artifacts_dir = 'validation_artifacts/' |
| 30 | def remote_artifacts_dir = '/root/qa_results/' |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 31 | def current_target_node = null |
| 32 | def first_node = null |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 33 | def tempest_result = '' |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 34 | timeout(time: 12, unit: 'HOURS') { |
| 35 | node() { |
| 36 | def num_retries = Integer.parseInt(RETRY_CHECK_STATUS) |
| 37 | try { |
| 38 | stage('Initialization') { |
| 39 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 40 | validate.runBasicContainer(saltMaster, TEMPEST_TARGET_NODE, TEST_IMAGE) |
| 41 | sh "rm -rf ${artifacts_dir}" |
Oleksii Zhurba | 4927588 | 2018-03-21 15:41:57 -0500 | [diff] [blame] | 42 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "rm -rf ${remote_artifacts_dir}") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 43 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "mkdir -p ${remote_artifacts_dir}") |
| 44 | validate.configureContainer(saltMaster, TEMPEST_TARGET_NODE, PROXY, TOOLS_REPO, TEMPEST_REPO) |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 45 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 46 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 47 | stage('Initial env check') { |
| 48 | sh "mkdir -p ${artifacts_dir}" |
| 49 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_initial") |
| 50 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 51 | if (tempest_result != "finished") { |
| 52 | currentBuild.result = "FAILURE" |
| 53 | throw new Exception("Tempest tests failed") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 54 | } |
| 55 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 56 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 57 | stage('Soft Shutdown') { |
| 58 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 59 | stage('Ask for manual confirmation') { |
| 60 | input message: "Are you sure you want to shutdown current vip node?" |
| 61 | } |
| 62 | } |
| 63 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 64 | if (current_target_node == null) { |
| 65 | throw new Exception("Cannot current vip node in ${TARGET_NODES} nodes") |
| 66 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 67 | common.warningMsg("Shutdown current vip node ${current_target_node}") |
| 68 | validate.shutdown_vm_node(saltMaster, current_target_node, 'soft_shutdown') |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 69 | sleep 15 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 70 | } |
| 71 | stage('Check during shutdown') { |
| 72 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_shutdown") |
| 73 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 74 | if (tempest_result != "finished") { |
| 75 | currentBuild.result = "FAILURE" |
| 76 | throw new Exception("Tempest tests failed") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 77 | } |
| 78 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 79 | stage('Power on') { |
| 80 | common.infoMsg('Powering on node') |
| 81 | kvm = validate.locate_node_on_kvm(saltMaster, current_target_node) |
| 82 | salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}") |
| 83 | common.infoMsg("Checking that node is UP") |
| 84 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 85 | if (status == null) { |
| 86 | throw new Exception("Node ${current_target_node} cannot start") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 87 | } |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 88 | first_node = current_target_node |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 89 | current_target_node = null |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 90 | sleep 30 |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 91 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 92 | stage('Check after shutdown') { |
| 93 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after_shutdown") |
| 94 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 95 | if (tempest_result != "finished") { |
| 96 | currentBuild.result = "FAILURE" |
| 97 | throw new Exception("Tempest tests failed") |
| 98 | } |
| 99 | sleep 15 |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 100 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 101 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 102 | stage('Hard Shutdown') { |
| 103 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 104 | stage('Ask for manual confirmation') { |
| 105 | input message: "Are you sure you want to hard shutdown current vip node?" |
| 106 | } |
| 107 | } |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 108 | salt.cmdRun(saltMaster, first_node, "service keepalived stop") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 109 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
| 110 | common.warningMsg("Shutdown current vip node ${current_target_node}") |
| 111 | validate.shutdown_vm_node(saltMaster, current_target_node, 'hard_shutdown') |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 112 | //TODO:if previous command fails, keeaplived will not be started on first_node |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 113 | sleep 10 |
| 114 | salt.cmdRun(saltMaster, first_node, "service keepalived start") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 115 | } |
| 116 | stage('Check during hard shutdown') { |
| 117 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_hard_shutdown") |
| 118 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 119 | if (tempest_result != "finished") { |
| 120 | currentBuild.result = "FAILURE" |
| 121 | throw new Exception("Tempest tests failed") |
| 122 | } |
| 123 | } |
| 124 | stage('Power on') { |
| 125 | common.infoMsg('Powering on node') |
| 126 | kvm = validate.locate_node_on_kvm(saltMaster, current_target_node) |
| 127 | salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}") |
| 128 | common.infoMsg("Checking that node is UP") |
| 129 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 130 | if (status == null) { |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 131 | throw new Exception("Node ${current_target_node} cannot start") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 132 | } |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 133 | current_target_node = null |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 134 | sleep 30 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 135 | } |
| 136 | stage('Check after hard shutdown') { |
| 137 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after_hard_shutdown") |
| 138 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 139 | if (tempest_result != "finished") { |
| 140 | currentBuild.result = "FAILURE" |
| 141 | throw new Exception("Tempest tests failed") |
| 142 | } |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 143 | sleep 5 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | stage('Reboot') { |
| 147 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 148 | stage('Ask for manual confirmation') { |
| 149 | input message: "Are you sure you want to reboot current vip node?" |
| 150 | } |
| 151 | } |
| 152 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
| 153 | common.warningMsg("Rebooting current vip node ${current_target_node}") |
| 154 | validate.shutdown_vm_node(saltMaster, current_target_node, 'reboot') |
| 155 | sleep 5 |
| 156 | } |
| 157 | stage('Check during reboot') { |
| 158 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_reboot") |
| 159 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 160 | if (tempest_result != "finished") { |
| 161 | currentBuild.result = "FAILURE" |
| 162 | throw new Exception("Tempest tests failed") |
| 163 | } |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 164 | sleep 30 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 165 | } |
| 166 | stage('Check after reboot') { |
| 167 | common.warningMsg("Checking that node is UP") |
| 168 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 169 | if (status == null) { |
| 170 | throw new Exception("Node ${current_target_node} cannot start") |
| 171 | } |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 172 | current_target_node = null |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 173 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after") |
| 174 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 175 | if (tempest_result != "finished") { |
| 176 | currentBuild.result = "FAILURE" |
| 177 | throw new Exception("Tempest tests failed") |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | stage('Collect results') { |
| 182 | validate.addFiles(saltMaster, TEMPEST_TARGET_NODE, remote_artifacts_dir, artifacts_dir) |
| 183 | archiveArtifacts artifacts: "${artifacts_dir}/*" |
| 184 | if (DEBUG_MODE == 'false') { |
| 185 | validate.runCleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 186 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "rm -rf ${remote_artifacts_dir}") |
| 187 | } |
| 188 | } |
| 189 | } finally { |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 190 | if (DEBUG_MODE == 'false') { |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 191 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "rm -rf ${remote_artifacts_dir}") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 192 | validate.runCleanup(saltMaster, TEMPEST_TARGET_NODE) |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 193 | if (current_target_node != null) { |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 194 | common.warningMsg("Powering on node ${current_target_node}") |
| 195 | kvm = validate.locate_node_on_kvm(saltMaster, current_target_node) |
| 196 | salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}") |
| 197 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 198 | } |
| 199 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 200 | } |
| 201 | } |