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 *** |
| 16 | Documentation Provide the function to scale up/down the etcd cluster |
| 17 | Library OperatingSystem |
| 18 | |
| 19 | *** Variables *** |
| 20 | ${timeout} 60s |
| 21 | ${desired_etcd_cluster_size} 3 |
| 22 | ${minimal_etcd_cluster_size} 2 |
| 23 | ${namespace} voltha |
| 24 | ${etcd__resources} etcdclusters.etcd.database.coreos.com |
| 25 | ${etcd_name} voltha-etcd-cluster |
| 26 | |
| 27 | *** Test Cases *** |
| 28 | Scale Down etcd Cluster |
| 29 | [Documentation] Scale Down the etcd cluster to minimal size, skip test if current cluster size < 3 |
| 30 | [Tags] scaledown etcddown |
| 31 | ${current_size}= Get etcd Running Size voltha |
| 32 | Pass Execution If '${current_size}' != '${desired_etcd_cluster_size}' |
| 33 | ... 'Skip the test if the cluster size smaller than minimal size 3' |
| 34 | # The minimal cluster size after scale down |
| 35 | # based on https://github.com/etcd-io/etcd/blob/master/Documentation/faq.md#what-is-failure-tolerance |
| 36 | Scale etcd ${namespace} ${minimal_etcd_cluster_size} |
| 37 | Wait Until Keyword Succeeds ${timeout} 2s Validate etcd Size ${namespace} ${minimal_etcd_cluster_size} |
| 38 | |
| 39 | Scale Up etcd Cluster |
| 40 | [Documentation] Recover the etcd cluster by scaling up its size |
| 41 | [Tags] scaleup etcdup |
| 42 | ${current_size}= Get etcd Running Size voltha |
| 43 | Pass Execution If '${current_size}' != '${minimal_etcd_cluster_size}' |
| 44 | ... 'Skip the test if the cluster size smaller than minimal size 3' |
| 45 | Scale etcd ${namespace} ${desired_etcd_cluster_size} |
| 46 | # We scale up the size to 3, the recommended size of etcd cluster. |
| 47 | Wait Until Keyword Succeeds ${timeout} 2s Validate etcd Size ${namespace} ${desired_etcd_cluster_size} |
| 48 | |
| 49 | *** Keywords *** |
| 50 | Get etcd Running Size |
| 51 | [Arguments] ${namespace} |
| 52 | [Documentation] Get the number of running etcd nodes |
| 53 | ${rc} ${size}= Run and Return Rc and Output |
| 54 | ... kubectl -n ${namespace} get ${etcd__resources} ${etcd_name} -o jsonpath='{.status.size}' |
| 55 | Should Be Equal As Integers ${rc} 0 |
| 56 | [Return] ${size} |
| 57 | |
| 58 | Scale etcd |
| 59 | [Arguments] ${namespace} ${size} |
| 60 | [Documentation] Scale down the number of etcd pod |
| 61 | ${rc}= Run and Return Rc |
| 62 | ... kubectl -n ${namespace} patch ${etcd__resources} ${etcd_name} --type='merge' -p '{"spec":{"size":${size}}}' |
| 63 | Should Be Equal As Integers ${rc} 0 |
| 64 | |
| 65 | Validate etcd Size |
| 66 | [Arguments] ${namespace} ${etcd_cluster_size} |
| 67 | [Documentation] Scale down the number of etcd pod |
| 68 | ${rc} ${size}= Run and Return Rc and Output |
| 69 | ... kubectl -n ${namespace} get ${etcd__resources} ${etcd_name} -o jsonpath='{.status.size}' |
| 70 | Should Be Equal As Integers ${size} ${etcd_cluster_size} |