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/' |
| 31 | def current_target_node = '' |
| 32 | def tempest_result = '' |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 33 | timeout(time: 12, unit: 'HOURS') { |
| 34 | node() { |
| 35 | def num_retries = Integer.parseInt(RETRY_CHECK_STATUS) |
| 36 | try { |
| 37 | stage('Initialization') { |
| 38 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 39 | validate.runBasicContainer(saltMaster, TEMPEST_TARGET_NODE, TEST_IMAGE) |
| 40 | sh "rm -rf ${artifacts_dir}" |
| 41 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "mkdir -p ${remote_artifacts_dir}") |
| 42 | validate.configureContainer(saltMaster, TEMPEST_TARGET_NODE, PROXY, TOOLS_REPO, TEMPEST_REPO) |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 43 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 44 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 45 | stage('Initial env check') { |
| 46 | sh "mkdir -p ${artifacts_dir}" |
| 47 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_initial") |
| 48 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 49 | if (tempest_result != "finished") { |
| 50 | currentBuild.result = "FAILURE" |
| 51 | throw new Exception("Tempest tests failed") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 52 | } |
| 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('Soft Shutdown') { |
| 56 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 57 | stage('Ask for manual confirmation') { |
| 58 | input message: "Are you sure you want to shutdown current vip node?" |
| 59 | } |
| 60 | } |
| 61 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
| 62 | common.warningMsg("Shutdown current vip node ${current_target_node}") |
| 63 | validate.shutdown_vm_node(saltMaster, current_target_node, 'soft_shutdown') |
| 64 | } |
| 65 | stage('Check during shutdown') { |
| 66 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_shutdown") |
| 67 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 68 | if (tempest_result != "finished") { |
| 69 | currentBuild.result = "FAILURE" |
| 70 | throw new Exception("Tempest tests failed") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 71 | } |
| 72 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 73 | stage('Power on') { |
| 74 | common.infoMsg('Powering on node') |
| 75 | kvm = validate.locate_node_on_kvm(saltMaster, current_target_node) |
| 76 | salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}") |
| 77 | common.infoMsg("Checking that node is UP") |
| 78 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 79 | if (status == null) { |
| 80 | throw new Exception("Node ${current_target_node} cannot start") |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 81 | } |
| 82 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 83 | stage('Check after shutdown') { |
| 84 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after_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") |
| 89 | } |
| 90 | sleep 15 |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 91 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 92 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 93 | stage('Hard Shutdown') { |
| 94 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 95 | stage('Ask for manual confirmation') { |
| 96 | input message: "Are you sure you want to hard shutdown current vip node?" |
| 97 | } |
| 98 | } |
| 99 | salt.cmdRun(saltMaster, current_target_node, "service keepalived stop") |
| 100 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
| 101 | common.warningMsg("Shutdown current vip node ${current_target_node}") |
| 102 | validate.shutdown_vm_node(saltMaster, current_target_node, 'hard_shutdown') |
| 103 | } |
| 104 | stage('Check during hard shutdown') { |
| 105 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_hard_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 | } |
| 112 | stage('Power on') { |
| 113 | common.infoMsg('Powering on node') |
| 114 | kvm = validate.locate_node_on_kvm(saltMaster, current_target_node) |
| 115 | salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}") |
| 116 | common.infoMsg("Checking that node is UP") |
| 117 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 118 | if (status == null) { |
| 119 | throw new Exception("Command execution failed") |
| 120 | } |
| 121 | salt.cmdRun(saltMaster, TARGET_NODES, "service keepalived start") |
| 122 | } |
| 123 | stage('Check after hard shutdown') { |
| 124 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after_hard_shutdown") |
| 125 | validate.openstack_cleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 126 | if (tempest_result != "finished") { |
| 127 | currentBuild.result = "FAILURE" |
| 128 | throw new Exception("Tempest tests failed") |
| 129 | } |
| 130 | sleep 15 |
| 131 | } |
| 132 | |
| 133 | stage('Reboot') { |
| 134 | if (MANUAL_CONFIRMATION.toBoolean() == true) { |
| 135 | stage('Ask for manual confirmation') { |
| 136 | input message: "Are you sure you want to reboot current vip node?" |
| 137 | } |
| 138 | } |
| 139 | current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES) |
| 140 | common.warningMsg("Rebooting current vip node ${current_target_node}") |
| 141 | validate.shutdown_vm_node(saltMaster, current_target_node, 'reboot') |
| 142 | sleep 5 |
| 143 | } |
| 144 | stage('Check during reboot') { |
| 145 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_reboot") |
| 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 | } |
| 151 | } |
| 152 | stage('Check after reboot') { |
| 153 | common.warningMsg("Checking that node is UP") |
| 154 | status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries) |
| 155 | if (status == null) { |
| 156 | throw new Exception("Node ${current_target_node} cannot start") |
| 157 | } |
| 158 | tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after") |
| 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 | } |
| 164 | } |
| 165 | |
| 166 | stage('Collect results') { |
| 167 | validate.addFiles(saltMaster, TEMPEST_TARGET_NODE, remote_artifacts_dir, artifacts_dir) |
| 168 | archiveArtifacts artifacts: "${artifacts_dir}/*" |
| 169 | if (DEBUG_MODE == 'false') { |
| 170 | validate.runCleanup(saltMaster, TEMPEST_TARGET_NODE) |
| 171 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "rm -rf ${remote_artifacts_dir}") |
| 172 | } |
| 173 | } |
| 174 | } finally { |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 175 | if (DEBUG_MODE == 'false') { |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 176 | salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "rm -rf ${remote_artifacts_dir}") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 177 | validate.runCleanup(saltMaster, TEMPEST_TARGET_NODE) |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 178 | } |
| 179 | } |
Oleksii Zhurba | 3f43894 | 2017-11-13 20:00:06 -0600 | [diff] [blame] | 180 | } |
| 181 | } |