blob: b51fd547816a8c61f526aaebb453b5521a2ba5cc [file] [log] [blame]
Kailash Khalasi27139312018-05-29 08:43:50 -07001# 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
16*** Settings ***
17Documentation Test suite to validate K8s in the experimental ControlKube Scenario
18Suite Setup Setup
19Library OperatingSystem
20Library ../cord-api/Framework/utils/onosUtils.py
21Library ../cord-api/Framework/utils/utils.py
22Resource ../cord-api/Framework/utils/utils.robot
23
24*** Variables ***
Kailash Khalasi55c65a72018-06-05 11:28:20 -070025${deployment} physical
26@{physical_nodes} node1 node2 node3
Kailash Khalasi27139312018-05-29 08:43:50 -070027@{minikube_nodes} minikube
28${resources_file} ${CURDIR}/data/k8resources.json
29
30
31*** Test Cases ***
32Validate K8 Nodes
33 [Documentation] Validates that all nodes that are running in the K8 are healthy
Kailash Khalasi55c65a72018-06-05 11:28:20 -070034 [Tags] nodes
Kailash Khalasi27139312018-05-29 08:43:50 -070035 ${nodes}= Run kubectl get nodes -o json
36 Log ${nodes}
37 @{nodes}= Get Names ${nodes}
38 ##set nodes based on deployment
39 @{nodes_expected}= Set Variable If '${deployment}' == 'physical' ${physical_nodes} ${minikube_nodes}
40 Log ${nodes_expected}
41 #validates that all expected nodes to be running
42 : FOR ${i} IN @{nodes_expected}
43 \ List Should Contain Value ${nodes} ${i}
44 : FOR ${i} IN @{nodes}
45 \ ${status}= Run kubectl get nodes ${i} -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
46 \ ${outofdisk}= Run kubectl get nodes ${i} -o jsonpath='{.status.conditions[?(@.type=="OutOfDisk")].status}'
47 \ ${memorypressure}= Run kubectl get nodes ${i} -o jsonpath='{.status.conditions[?(@.type=="MemoryPressure")].status}'
48 \ ${diskpressure}= Run kubectl get nodes ${i} -o jsonpath='{.status.conditions[?(@.type=="DiskPressure")].status}'
49 \ Should Be Equal ${status} True
50 \ Should Be Equal ${outofdisk} False
51 \ Should Be Equal ${memorypressure} False
52 \ Should Be Equal ${diskpressure} False
53
54Validate XOS Core Containers
55 [Documentation] Validates that all xos core containers that are running in the K8 Pods are healthy
56 [Tags] xos-core
57 @{core_container_names}= Run Keyword and Continue on Failure Validate Pods xos-
58 #validates that all expected containers to be running are in one of the pods inspected above
59 : FOR ${i} IN @{core_containers}
60 \ Run Keyword and Continue on Failure List Should Contain Value ${core_container_names} ${i}
61
62Validate RCord-Lite Containers
63 [Documentation] Validates that all rcord-lite containers that are running in the K8 Pods are healthy
64 [Tags] rcord-lite
65 @{rcord_container_names}= Run Keyword and Continue on Failure Validate Pods rcord-lite-
66 #validates that all expected containers to be running are in one of the pods inspected above
67 : FOR ${i} IN @{rcord_lite_containers}
68 \ Run Keyword and Continue on Failure List Should Contain Value ${rcord_container_names} ${i}
69
Kailash Khalasi55c65a72018-06-05 11:28:20 -070070Validate Voltha Containers
71 [Documentation] Validates that all voltha containers that are running in the K8 Pods are healthy
72 [Tags] voltha
73 @{voltha_container_names}= Run Keyword and Continue on Failure Validate Pods voltha-
74 #validates that all expected containers to be running are in one of the pods inspected above
75 : FOR ${i} IN @{voltha_containers}
76 \ Run Keyword and Continue on Failure List Should Contain Value ${voltha_container_names} ${i}
77
Kailash Khalasi27139312018-05-29 08:43:50 -070078Validate ONOS-Fabric Containers
79 [Documentation] Validates that all onos-fabric containers that are running in the K8 Pods are healthy
80 [Tags] onos-fabric
81 @{onos_container_names}= Run Keyword and Continue on Failure Validate Pods onos-fabric
82 #validates that all expected containers to be running are in one of the pods inspected above
83 : FOR ${i} IN @{onos_fabric_containers}
84 \ Run Keyword and Continue on Failure List Should Contain Value ${onos_container_names} ${i}
85
86Validate XOS Core Deployments
87 [Documentation] Validates that all xos-core deployments successfully rolled out and available
Kailash Khalasi55c65a72018-06-05 11:28:20 -070088 [Tags] xos-core
Kailash Khalasi27139312018-05-29 08:43:50 -070089 Validate Deployments xos- ${core_deployments}
90
91Validate RCord-Lite Deployments
92 [Documentation] Validates that all rcord-lite deployments successfully rolled out and available
Kailash Khalasi55c65a72018-06-05 11:28:20 -070093 [Tags] rcord-lite
Kailash Khalasi27139312018-05-29 08:43:50 -070094 Validate Deployments rcord-lite- ${rcord_lite_deployments}
95
96Validate ONOS-Fabric Deployments
97 [Documentation] Validates that all onos-fabric deployments successfully rolled out and available
Kailash Khalasi55c65a72018-06-05 11:28:20 -070098 [Tags] onos-fabric
Kailash Khalasi27139312018-05-29 08:43:50 -070099 Validate Deployments onos-fabric ${onos_fabric_deployments}
100
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700101Validate Voltha Deployments
102 [Documentation] Validates that all voltha deployments successfully rolled out and available
103 [Tags] voltha
104 Validate Deployments voltha ${voltha_deployments}
105
Kailash Khalasi27139312018-05-29 08:43:50 -0700106Validate XOS Core Services
107 [Documentation] Validates that all expected xos-core services that are running in K8s
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700108 [Tags] xos-core
Kailash Khalasi27139312018-05-29 08:43:50 -0700109 ${services}= Run kubectl get services -o json
110 Log ${services}
111 @{services}= Get Names ${services}
112 #validates that all expected services are running
113 : FOR ${i} IN @{xos_core_services}
114 \ Run Keyword and Continue on Failure List Should Contain Value ${services} ${i}
115 ##check for appropriate ports for each service and match with values in helm charts
116 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].port}'
117 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].targetPort}'
118
119Validate ONOS-Fabric Services
120 [Documentation] Validates that all expected onos-fabric services that are running in K8s
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700121 [Tags] onos-fabric
Kailash Khalasi27139312018-05-29 08:43:50 -0700122 ${services}= Run kubectl get services -o json
123 Log ${services}
124 @{services}= Get Names ${services}
125 #validates that all expected services are running
126 : FOR ${i} IN @{onos_fabric_services}
127 \ Run Keyword and Continue on Failure List Should Contain Value ${services} ${i}
128 ##check for appropriate ports for each service and match with values in helm charts
129 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].port}'
130 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].targetPort}'
131
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700132Validate Voltha Services
133 [Documentation] Validates that all expected voltha services that are running in K8s
134 [Tags] voltha
135 ${services}= Run kubectl get services -o json
136 Log ${services}
137 @{services}= Get Names ${services}
138 #validates that all expected services are running
139 : FOR ${i} IN @{voltha_services}
140 \ Run Keyword and Continue on Failure List Should Contain Value ${services} ${i}
141 ##check for appropriate ports for each service and match with values in helm charts
142 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].port}'
143 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].targetPort}'
144
Kailash Khalasi27139312018-05-29 08:43:50 -0700145*** Keywords ***
146Setup
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700147 Log Parsing the datafile for Kubernetes resources for each helm chart
Kailash Khalasi27139312018-05-29 08:43:50 -0700148 @{core_containers}= Create List
149 @{rcord_lite_containers}= Create List
150 @{onos_fabric_containers}= Create List
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700151 @{voltha_containers}= Create List
Kailash Khalasi27139312018-05-29 08:43:50 -0700152 @{core_deployments}= Create List
153 @{rcord_lite_deployments}= Create List
154 @{onos_fabric_deployments}= Create List
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700155 @{voltha_deployments}= Create List
Kailash Khalasi27139312018-05-29 08:43:50 -0700156 @{xos_core_services}= Create List
157 @{onos_fabric_services}= Create List
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700158 @{voltha_services}= Create List
Kailash Khalasi27139312018-05-29 08:43:50 -0700159 ${xos-core_containers} utils.jsonToList ${resources_file} xos-core-containers
160 : FOR ${container} IN @{xos-core_containers}
161 \ Append To List ${core_containers} ${container}
162 ${rcord_containers} utils.jsonToList ${resources_file} rcord-lite-containers
163 : FOR ${container} IN @{rcord_containers}
164 \ Append To List ${rcord_lite_containers} ${container}
165 ${onosfabric_containers} utils.jsonToList ${resources_file} onos-fabric-containers
166 : FOR ${container} IN @{onosfabric_containers}
167 \ Append To List ${onos_fabric_containers} ${container}
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700168 ${volthaContainers} utils.jsonToList ${resources_file} voltha-containers
169 : FOR ${container} IN @{volthaContainers}
170 \ Append To List ${voltha_containers} ${container}
Kailash Khalasi27139312018-05-29 08:43:50 -0700171 ${xos-core_deployments} utils.jsonToList ${resources_file} xos-core-deployments
172 : FOR ${deployment} IN @{xos-core_containers}
173 \ Append To List ${core_deployments} ${deployment}
174 ${rcord_deployments} utils.jsonToList ${resources_file} rcord-lite-deployments
175 : FOR ${deployment} IN @{rcord_deployments}
176 \ Append To List ${rcord_lite_deployments} ${deployment}
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700177 ${onosfabric_deployments} utils.jsonToList ${resources_file} onos-fabric-deployments
Kailash Khalasi27139312018-05-29 08:43:50 -0700178 : FOR ${deployment} IN @{onosfabric_deployments}
179 \ Append To List ${onos_fabric_deployments} ${deployment}
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700180 ${volthaDeployments} utils.jsonToList ${resources_file} voltha-deployments
181 : FOR ${deployment} IN @{volthaDeployments}
182 \ Append To List ${voltha_deployments} ${deployment}
Kailash Khalasi27139312018-05-29 08:43:50 -0700183 ${core_services} utils.jsonToList ${resources_file} xos-core-services
184 : FOR ${service} IN @{core_services}
185 \ Append To List ${xos_core_services} ${service}
186 ${onos_services} utils.jsonToList ${resources_file} onos-fabric-services
187 : FOR ${service} IN @{onos_services}
188 \ Append To List ${onos_fabric_services} ${service}
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700189 ${volthaServices} utils.jsonToList ${resources_file} voltha-services
190 : FOR ${service} IN @{volthaServices}
191 \ Append To List ${voltha_services} ${service}
Kailash Khalasi27139312018-05-29 08:43:50 -0700192 Set Suite Variable @{core_containers}
193 Set Suite Variable @{rcord_lite_containers}
194 Set Suite Variable @{onos_fabric_containers}
195 Set Suite Variable @{core_deployments}
196 Set Suite Variable @{rcord_lite_deployments}
197 Set Suite Variable @{onos_fabric_deployments}
198 Set Suite Variable @{xos_core_services}
199 Set Suite Variable @{onos_fabric_services}
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700200 Set Suite Variable @{voltha_containers}
201 Set Suite Variable @{voltha_services}
202 Set Suite Variable @{voltha_deployments}
Kailash Khalasi27139312018-05-29 08:43:50 -0700203
204Get Names
205 [Documentation] Gets names of K8 resources running
206 [Arguments] ${output}
207 @{names}= Create List
208 ${output}= To JSON ${output}
209 ${len}= Get Length ${output}
210 ${length}= Get Length ${output['items']}
211 : FOR ${INDEX} IN RANGE 0 ${length}
212 \ ${item}= Get From List ${output['items']} ${INDEX}
213 \ ${metadata}= Get From Dictionary ${item} metadata
214 \ ${name}= Get From Dictionary ${metadata} name
215 \ Append To List ${names} ${name}
216 [Return] @{names}
217
218Validate Pods
219 [Arguments] ${component}
220 @{container_names}= Create List
221 ${pods}= Run kubectl get pods -o json
222 Log ${pods}
223 ${pods}= To JSON ${pods}
224 ${len}= Get Length ${pods}
225 ${length}= Get Length ${pods['items']}
226 : FOR ${INDEX} IN RANGE 0 ${length}
227 \ ${item}= Get From List ${pods['items']} ${INDEX}
228 \ ${metadata}= Get From Dictionary ${item} metadata
229 \ ${name}= Get From Dictionary ${metadata} name
230 \ Continue For Loop If '${component}' not in '''${name}'''
Kailash Khalasi615940e2018-06-18 10:29:16 -0700231 \ Continue For Loop If 'tosca-loader' in '''${name}'''
Kailash Khalasid314adb2018-07-23 11:42:45 -0700232 \ Continue For Loop If '-test' in '''${name}'''
Kailash Khalasi27139312018-05-29 08:43:50 -0700233 \ ${status}= Get From Dictionary ${item} status
234 \ ${containerStatuses}= Get From Dictionary ${status} containerStatuses
235 \ Log ${containerStatuses}
236 \ ${cstatus}= Get From List ${containerStatuses} 0
237 \ Log ${cstatus}
238 \ ${restartCount}= Get From Dictionary ${cstatus} restartCount
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700239 \ Run Keyword and Continue On Failure Should Be Equal As Integers ${restartCount} 0
Kailash Khalasi27139312018-05-29 08:43:50 -0700240 \ ${container_name}= Get From Dictionary ${cstatus} name
241 \ ${state}= Get From Dictionary ${cstatus} state
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700242 \ Run Keyword and Continue On Failure Should Contain ${state} running
243 \ Run Keyword and Continue On Failure Should Not Contain ${state} stopped
Kailash Khalasi27139312018-05-29 08:43:50 -0700244 \ Log ${state}
245 \ Append To List ${container_names} ${container_name}
246 [Return] ${container_names}
247
248Validate Deployments
249 [Arguments] ${component} ${expected_deployments}
250 ${deployments}= Run kubectl get deployments -o json
251 @{deployments}= Get Names ${deployments}
252 : FOR ${i} IN @{deployments}
253 \ Continue For Loop If '${component}' not in '''${i}'''
254 \ ${rollout_status}= Run kubectl rollout status deployment/${i}
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700255 \ Run Keyword and Continue On Failure Should Be Equal ${rollout_status} deployment "${i}" successfully rolled out
Kailash Khalasi27139312018-05-29 08:43:50 -0700256 \ ##validate replication sets
257 \ ${desired}= Run kubectl get deployments ${i} -o jsonpath='{.status.replicas}'
258 \ ${available}= Run kubectl get deployments ${i} -o jsonpath='{.status.availableReplicas}'
Kailash Khalasi55c65a72018-06-05 11:28:20 -0700259 \ Run Keyword and Continue On Failure Should Be Equal ${desired} ${available}
Kailash Khalasi27139312018-05-29 08:43:50 -0700260 #validates that all expected deployments to exist
261 : FOR ${i} IN @{expected_deployments}
Kailash Khalasid314adb2018-07-23 11:42:45 -0700262 \ Run Keyword and Continue On Failure List Should Contain Value ${deployments} ${i}