hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 1 | #Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | *** Settings *** |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 16 | Documentation Provide the function to perform system related test |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 17 | Library OperatingSystem |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 18 | Resource ../../libraries/k8s.robot |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 19 | |
| 20 | *** Variables *** |
| 21 | ${timeout} 60s |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 22 | ${desired_ETCD_cluster_size} 3 |
| 23 | ${minimal_ETCD_cluster_size} 2 |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 24 | ${namespace} voltha |
hwchiu | 7438081 | 2020-01-08 18:05:18 +0800 | [diff] [blame] | 25 | ${ETCD_resources} etcdclusters.etcd.database.coreos.com |
| 26 | ${ETCD_name} voltha-etcd-cluster |
| 27 | ${ETCD_pod_label_key} etcd_cluster |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 28 | ${common_pod_label_key} app |
| 29 | ${rwcore_pod_label_value} rw-core |
| 30 | ${ofagent_pod_label_value} ofagent |
| 31 | ${adapter_openolt_pod_label_value} adapter-open-olt |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 32 | |
| 33 | *** Test Cases *** |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 34 | Scale Down ETCD Cluster |
| 35 | [Documentation] Scale Down the ETCD cluster to minimal size, skip test if current cluster size < 3 |
| 36 | [Tags] scaledown ETCDdown |
| 37 | ${current_size}= Get ETCD Running Size voltha |
| 38 | Pass Execution If '${current_size}' != '${desired_ETCD_cluster_size}' |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 39 | ... 'Skip the test if the cluster size smaller than minimal size 3' |
| 40 | # The minimal cluster size after scale down |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 41 | # based on https://github.com/ETCD-io/ETCD/blob/master/Documentation/faq.md#what-is-failure-tolerance |
| 42 | Scale ETCD ${namespace} ${minimal_ETCD_cluster_size} |
| 43 | Wait Until Keyword Succeeds ${timeout} 2s Validate ETCD Size ${namespace} ${minimal_ETCD_cluster_size} |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 44 | |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 45 | Scale Up ETCD Cluster |
| 46 | [Documentation] Recover the ETCD cluster by scaling up its size |
| 47 | [Tags] scaleup ETCDup |
| 48 | ${current_size}= Get ETCD Running Size voltha |
| 49 | Pass Execution If '${current_size}' != '${minimal_ETCD_cluster_size}' |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 50 | ... 'Skip the test if the cluster size smaller than minimal size 3' |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 51 | Scale ETCD ${namespace} ${desired_ETCD_cluster_size} |
| 52 | # We scale up the size to 3, the recommended size of ETCD cluster. |
| 53 | Wait Until Keyword Succeeds ${timeout} 2s Validate ETCD Size ${namespace} ${desired_ETCD_cluster_size} |
| 54 | |
| 55 | ETCD Failure Test |
| 56 | [Documentation] Failure Scenario Test: ETCD Crash |
| 57 | [Tags] FailureTest |
| 58 | Delete K8s Pods By Label ${namespace} ${ETCD_pod_label_key} ${ETCD_name} |
| 59 | Wait Until Keyword Succeeds ${timeout} 2s |
| 60 | ... Pods Does Not Exist By Label ${namespace} ${ETCD_pod_label_key} ${ETCD_name} |
| 61 | Wait Until Keyword Succeeds ${timeout} 2s |
| 62 | ... Pods Does Not Ready By Label ${namespace} ${common_pod_label_key} ${rwcore_pod_label_value} |
| 63 | Wait Until Keyword Succeeds ${timeout} 2s |
| 64 | ... Pods Does Not Ready By Label ${namespace} ${common_pod_label_key} ${ofagent_pod_label_value} |
| 65 | Wait Until Keyword Succeeds ${timeout} 2s |
| 66 | ... Pods Does Not Ready By Label ${namespace} ${common_pod_label_key} ${adapter_openolt_pod_label_value} |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 67 | |
| 68 | *** Keywords *** |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 69 | Get ETCD Running Size |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 70 | [Arguments] ${namespace} |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 71 | [Documentation] Get the number of running ETCD nodes |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 72 | ${rc} ${size}= Run and Return Rc and Output |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 73 | ... kubectl -n ${namespace} get ${ETCD_resources} ${ETCD_name} -o jsonpath='{.status.size}' |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 74 | Should Be Equal As Integers ${rc} 0 |
| 75 | [Return] ${size} |
| 76 | |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 77 | Scale ETCD |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 78 | [Arguments] ${namespace} ${size} |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 79 | [Documentation] Scale down the number of ETCD pod |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 80 | ${rc}= Run and Return Rc |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 81 | ... kubectl -n ${namespace} patch ${ETCD_resources} ${ETCD_name} --type='merge' -p '{"spec":{"size":${size}}}' |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 82 | Should Be Equal As Integers ${rc} 0 |
| 83 | |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 84 | Validate ETCD Size |
| 85 | [Arguments] ${namespace} ${ETCD_cluster_size} |
| 86 | [Documentation] Scale down the number of ETCD pod |
hwchiu | 20f35d9 | 2019-11-05 05:22:58 +0000 | [diff] [blame] | 87 | ${rc} ${size}= Run and Return Rc and Output |
hwchiu | 8569593 | 2019-12-18 08:05:25 +0000 | [diff] [blame] | 88 | ... kubectl -n ${namespace} get ${ETCD_resources} ${ETCD_name} -o jsonpath='{.status.size}' |
| 89 | Should Be Equal As Integers ${size} ${ETCD_cluster_size} |