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