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