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}" |
| 42 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "mkdir -p ${remote_artifacts_dir}") |
| 43 | validate.configureContainer(saltMaster, TEMPEST_TARGET_NODE, PROXY, TOOLS_REPO, TEMPEST_REPO) |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 44 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 45 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 46 | stage('Initial env check') { |
| 47 | sh "mkdir -p ${artifacts_dir}" |
| 48 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_initial") |
| 49 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 50 | if (tempest_result != "finished") { |
| 51 | currentBuild.result = "FAILURE" |
| 52 | throw new Exception("Tempest tests failed") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 53 | } |
| 54 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 55 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 56 | stage('Soft Shutdown') { |
| 57 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 58 | stage('Ask for manual confirmation') { |
| 59 | input message: "Are you sure you want to shutdown current vip node?" |
| 60 | } |
| 61 | } |
| 62 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 63 | if (current_target_node == null) { |
| 64 | throw new Exception("Cannot current vip node in ${TARGET_NODES} nodes") |
| 65 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 66 | common.warningMsg("Shutdown current vip node ${current_target_node}") |
| 67 | validate.shutdown_vm_node(saltMaster, current_target_node, 'soft_shutdown') |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 68 | sleep 15 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 69 | } |
| 70 | stage('Check during shutdown') { |
| 71 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_shutdown") |
| 72 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 73 | if (tempest_result != "finished") { |
| 74 | currentBuild.result = "FAILURE" |
| 75 | throw new Exception("Tempest tests failed") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 76 | } |
| 77 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 78 | stage('Power on') { |
| 79 | common.infoMsg('Powering on node') |
| 80 | kvm = validate.locate_node_on_kvm(saltMaster, current_target_node) |
| 81 | salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}") |
| 82 | common.infoMsg("Checking that node is UP") |
| 83 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 84 | if (status == null) { |
| 85 | throw new Exception("Node ${current_target_node} cannot start") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 86 | } |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 87 | first_node = current_target_node |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 88 | current_target_node = null |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 89 | sleep 30 |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 90 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 91 | stage('Check after shutdown') { |
| 92 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after_shutdown") |
| 93 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 94 | if (tempest_result != "finished") { |
| 95 | currentBuild.result = "FAILURE" |
| 96 | throw new Exception("Tempest tests failed") |
| 97 | } |
| 98 | sleep 15 |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 99 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 100 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 101 | stage('Hard Shutdown') { |
| 102 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 103 | stage('Ask for manual confirmation') { |
| 104 | input message: "Are you sure you want to hard shutdown current vip node?" |
| 105 | } |
| 106 | } |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 107 | salt.cmdRun(saltMaster, first_node, "service keepalived stop") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 108 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
| 109 | common.warningMsg("Shutdown current vip node ${current_target_node}") |
| 110 | validate.shutdown_vm_node(saltMaster, current_target_node, 'hard_shutdown') |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 111 | //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] | 112 | sleep 10 |
| 113 | salt.cmdRun(saltMaster, first_node, "service keepalived start") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 114 | } |
| 115 | stage('Check during hard shutdown') { |
| 116 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_hard_shutdown") |
| 117 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 118 | if (tempest_result != "finished") { |
| 119 | currentBuild.result = "FAILURE" |
| 120 | throw new Exception("Tempest tests failed") |
| 121 | } |
| 122 | } |
| 123 | stage('Power on') { |
| 124 | common.infoMsg('Powering on node') |
| 125 | kvm = validate.locate_node_on_kvm(saltMaster, current_target_node) |
| 126 | salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}") |
| 127 | common.infoMsg("Checking that node is UP") |
| 128 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 129 | if (status == null) { |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 130 | throw new Exception("Node ${current_target_node} cannot start") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 131 | } |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 132 | current_target_node = null |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 133 | sleep 30 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 134 | } |
| 135 | stage('Check after hard shutdown') { |
| 136 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after_hard_shutdown") |
| 137 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 138 | if (tempest_result != "finished") { |
| 139 | currentBuild.result = "FAILURE" |
| 140 | throw new Exception("Tempest tests failed") |
| 141 | } |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 142 | sleep 5 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | stage('Reboot') { |
| 146 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 147 | stage('Ask for manual confirmation') { |
| 148 | input message: "Are you sure you want to reboot current vip node?" |
| 149 | } |
| 150 | } |
| 151 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
| 152 | common.warningMsg("Rebooting current vip node ${current_target_node}") |
| 153 | validate.shutdown_vm_node(saltMaster, current_target_node, 'reboot') |
| 154 | sleep 5 |
| 155 | } |
| 156 | stage('Check during reboot') { |
| 157 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_reboot") |
| 158 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 159 | if (tempest_result != "finished") { |
| 160 | currentBuild.result = "FAILURE" |
| 161 | throw new Exception("Tempest tests failed") |
| 162 | } |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 163 | sleep 30 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 164 | } |
| 165 | stage('Check after reboot') { |
| 166 | common.warningMsg("Checking that node is UP") |
| 167 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 168 | if (status == null) { |
| 169 | throw new Exception("Node ${current_target_node} cannot start") |
| 170 | } |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 171 | current_target_node = null |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 172 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after") |
| 173 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 174 | if (tempest_result != "finished") { |
| 175 | currentBuild.result = "FAILURE" |
| 176 | throw new Exception("Tempest tests failed") |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | stage('Collect results') { |
| 181 | validate.addFiles(saltMaster, TEMPEST_TARGET_NODE, remote_artifacts_dir, artifacts_dir) |
| 182 | archiveArtifacts artifacts: "${artifacts_dir}/*" |
| 183 | if (DEBUG_MODE == 'false') { |
| 184 | validate.runCleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 185 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "rm -rf ${remote_artifacts_dir}") |
| 186 | } |
| 187 | } |
| 188 | } finally { |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 189 | if (DEBUG_MODE == 'false') { |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 190 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "rm -rf ${remote_artifacts_dir}") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 191 | validate.runCleanup(saltMaster, TEMPEST_TARGET_NODE) |
Oleksii Zhurba | 1c55a01 | 2018-04-30 16:18:59 -0500 | [diff] [blame] | 192 | if (current_target_node != null) { |
Oleksii Zhurba | b2eb1f9 | 2018-01-18 12:53:13 -0600 | [diff] [blame] | 193 | common.warningMsg("Powering on node ${current_target_node}") |
| 194 | kvm = validate.locate_node_on_kvm(saltMaster, current_target_node) |
| 195 | salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}") |
| 196 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 197 | } |
| 198 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 199 | } |
| 200 | } |