blob: 6d74e19cf07f75593f50eb13ca6446f61cd3d96e [file] [log] [blame]
hwchiu20f35d92019-11-05 05:22:58 +00001#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 ***
hwchiu85695932019-12-18 08:05:25 +000016Documentation Provide the function to perform system related test
hwchiuab524f02020-02-03 23:24:19 +000017Suite Setup Common Test Suite Setup
18Test Setup Setup
19Test Teardown Teardown
hwchiuab524f02020-02-03 23:24:19 +000020Resource ../../libraries/onos.robot
21Resource ../../libraries/voltctl.robot
22Resource ../../libraries/voltha.robot
23Resource ../../libraries/utils.robot
hwchiu85695932019-12-18 08:05:25 +000024Resource ../../libraries/k8s.robot
hwchiuab524f02020-02-03 23:24:19 +000025Resource ../../variables/variables.robot
hwchiu20f35d92019-11-05 05:22:58 +000026
27*** Variables ***
hwchiu58af72d2020-01-14 00:50:35 +000028${timeout} 120s
Zack Williamsa8fe75a2020-01-10 14:25:27 -070029${desired_ETCD_cluster_size} 3
30${minimal_ETCD_cluster_size} 2
31${namespace} voltha
Andy Bavier80ece1f2020-06-12 17:46:53 -070032${ETCD_namespace} default
33${ETCD_resources} statefulsets
34${ETCD_name} etcd
35${ETCD_pod_label_key} app
hwchiu85695932019-12-18 08:05:25 +000036${common_pod_label_key} app
37${rwcore_pod_label_value} rw-core
38${ofagent_pod_label_value} ofagent
39${adapter_openolt_pod_label_value} adapter-open-olt
hwchiu20f35d92019-11-05 05:22:58 +000040
Andy Bavier80ece1f2020-06-12 17:46:53 -070041# Per-test logging on failure is turned off by default; set this variable to enable
42${container_log_dir} ${None}
43
hwchiu20f35d92019-11-05 05:22:58 +000044*** Test Cases ***
Andy Bavier80ece1f2020-06-12 17:46:53 -070045ETCD Scale Test
hwchiuab524f02020-02-03 23:24:19 +000046 [Documentation] Perform the sanity test if some ETCD endpoints crash
47 [Tags] functional bbsim
Andy Bavier80ece1f2020-06-12 17:46:53 -070048 [Setup] Run Keywords Start Logging EtcdScaleTest
49 ... AND Setup
hwchiu3d9a0982020-02-06 00:19:19 +000050 [Teardown] Run Keywords Collect Logs
51 ... AND Announce Message END TEST SanityTest
52 ... AND Teardown Suite
Andy Bavier80ece1f2020-06-12 17:46:53 -070053 ... AND Stop Logging EtcdScaleTest
54 ${current_size}= Get ETCD Replica Count ${ETCD_namespace}
hwchiu85695932019-12-18 08:05:25 +000055 Pass Execution If '${current_size}' != '${desired_ETCD_cluster_size}'
hwchiu20f35d92019-11-05 05:22:58 +000056 ... 'Skip the test if the cluster size smaller than minimal size 3'
57 # The minimal cluster size after scale down
hwchiu85695932019-12-18 08:05:25 +000058 # based on https://github.com/ETCD-io/ETCD/blob/master/Documentation/faq.md#what-is-failure-tolerance
Andy Bavier80ece1f2020-06-12 17:46:53 -070059 Scale ETCD ${ETCD_namespace} ${minimal_ETCD_cluster_size}
hwchiu58af72d2020-01-14 00:50:35 +000060 Wait Until Keyword Succeeds ${timeout} 2s
Andy Bavier80ece1f2020-06-12 17:46:53 -070061 ... Validate ETCD Size ${ETCD_namespace} ${minimal_ETCD_cluster_size}
hwchiuab524f02020-02-03 23:24:19 +000062 # Perform the sanity-test
63 Wait Until Keyword Succeeds ${timeout} 2s Perform Sanity Test
hwchiu85695932019-12-18 08:05:25 +000064 # We scale up the size to 3, the recommended size of ETCD cluster.
Andy Bavier80ece1f2020-06-12 17:46:53 -070065 Scale ETCD ${ETCD_namespace} ${desired_ETCD_cluster_size}
Zack Williamsa8fe75a2020-01-10 14:25:27 -070066 Wait Until Keyword Succeeds ${timeout} 2s
Andy Bavier80ece1f2020-06-12 17:46:53 -070067 ... Validate ETCD Size ${ETCD_namespace} ${desired_ETCD_cluster_size}
hwchiu85695932019-12-18 08:05:25 +000068
69ETCD Failure Test
70 [Documentation] Failure Scenario Test: ETCD Crash
71 [Tags] FailureTest
Andy Bavier80ece1f2020-06-12 17:46:53 -070072 [Setup] Start Logging EtcdFailureTest
73 [Teardown] Run Keywords Collect Logs
74 ... AND Stop Logging EtcdFailureTest
75 Delete K8s Pods By Label ${ETCD_namespace} ${ETCD_pod_label_key} ${ETCD_name}
76 #Wait Until Keyword Succeeds ${timeout} 2s
77 #... Pods Do Not Exist By Label ${ETCD_namespace} ${ETCD_pod_label_key} ${ETCD_name}
Zack Williamsa8fe75a2020-01-10 14:25:27 -070078 Wait Until Keyword Succeeds ${timeout} 2s
79 ... Pods Are Ready By Label ${namespace} ${common_pod_label_key} ${rwcore_pod_label_value}
80 Wait Until Keyword Succeeds ${timeout} 2s
81 ... Pods Are Ready By Label ${namespace} ${common_pod_label_key} ${ofagent_pod_label_value}
82 Wait Until Keyword Succeeds ${timeout} 2s
83 ... Pods Are Ready By Label ${namespace} ${common_pod_label_key} ${adapter_openolt_pod_label_value}
hwchiu20f35d92019-11-05 05:22:58 +000084
85*** Keywords ***
Andy Bavier80ece1f2020-06-12 17:46:53 -070086Get ETCD Replica Count
hwchiu20f35d92019-11-05 05:22:58 +000087 [Arguments] ${namespace}
Andy Bavier80ece1f2020-06-12 17:46:53 -070088 [Documentation] Get the number of configured ETCD nodes
hwchiu20f35d92019-11-05 05:22:58 +000089 ${rc} ${size}= Run and Return Rc and Output
Andy Bavier80ece1f2020-06-12 17:46:53 -070090 ... kubectl -n ${namespace} get ${ETCD_resources} ${ETCD_name} -o jsonpath='{.status.replicas}'
hwchiu20f35d92019-11-05 05:22:58 +000091 Should Be Equal As Integers ${rc} 0
92 [Return] ${size}
93
hwchiu85695932019-12-18 08:05:25 +000094Scale ETCD
hwchiu20f35d92019-11-05 05:22:58 +000095 [Arguments] ${namespace} ${size}
hwchiu85695932019-12-18 08:05:25 +000096 [Documentation] Scale down the number of ETCD pod
hwchiu20f35d92019-11-05 05:22:58 +000097 ${rc}= Run and Return Rc
Andy Bavier80ece1f2020-06-12 17:46:53 -070098 ... kubectl -n ${namespace} patch ${ETCD_resources} ${ETCD_name} -p '{"spec":{"replicas": ${size}}}'
hwchiu20f35d92019-11-05 05:22:58 +000099 Should Be Equal As Integers ${rc} 0
100
hwchiu85695932019-12-18 08:05:25 +0000101Validate ETCD Size
102 [Arguments] ${namespace} ${ETCD_cluster_size}
103 [Documentation] Scale down the number of ETCD pod
hwchiu20f35d92019-11-05 05:22:58 +0000104 ${rc} ${size}= Run and Return Rc and Output
Andy Bavier80ece1f2020-06-12 17:46:53 -0700105 ... kubectl -n ${namespace} get ${ETCD_resources} ${ETCD_name} -o jsonpath='{.status.replicas}'
106 Should Be Equal As Integers ${rc} 0
107 Should Be Equal As Integers ${size} ${ETCD_cluster_size} Unexpected number of replicas
108 ${rc} ${size}= Run and Return Rc and Output
109 ... kubectl -n ${namespace} get ${ETCD_resources} ${ETCD_name} -o jsonpath='{.status.readyReplicas}'
110 Should Be Equal As Integers ${rc} 0
111 Should Be Equal As Integers ${size} ${ETCD_cluster_size} Unexpected number of ready replicas