blob: 282775d5b3d7cbc9e655590f26be0e1caa216b79 [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 ***
25${profile} rcord-lite
26${deployment} virtual
27@{physical_nodes} head1 compute1 compute2
28@{minikube_nodes} minikube
29${resources_file} ${CURDIR}/data/k8resources.json
30
31
32*** Test Cases ***
33Validate K8 Nodes
34 [Documentation] Validates that all nodes that are running in the K8 are healthy
35 [Tags] xos-core
36 ${nodes}= Run kubectl get nodes -o json
37 Log ${nodes}
38 @{nodes}= Get Names ${nodes}
39 ##set nodes based on deployment
40 @{nodes_expected}= Set Variable If '${deployment}' == 'physical' ${physical_nodes} ${minikube_nodes}
41 Log ${nodes_expected}
42 #validates that all expected nodes to be running
43 : FOR ${i} IN @{nodes_expected}
44 \ List Should Contain Value ${nodes} ${i}
45 : FOR ${i} IN @{nodes}
46 \ ${status}= Run kubectl get nodes ${i} -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
47 \ ${outofdisk}= Run kubectl get nodes ${i} -o jsonpath='{.status.conditions[?(@.type=="OutOfDisk")].status}'
48 \ ${memorypressure}= Run kubectl get nodes ${i} -o jsonpath='{.status.conditions[?(@.type=="MemoryPressure")].status}'
49 \ ${diskpressure}= Run kubectl get nodes ${i} -o jsonpath='{.status.conditions[?(@.type=="DiskPressure")].status}'
50 \ Should Be Equal ${status} True
51 \ Should Be Equal ${outofdisk} False
52 \ Should Be Equal ${memorypressure} False
53 \ Should Be Equal ${diskpressure} False
54
55Validate XOS Core Containers
56 [Documentation] Validates that all xos core containers that are running in the K8 Pods are healthy
57 [Tags] xos-core
58 @{core_container_names}= Run Keyword and Continue on Failure Validate Pods xos-
59 #validates that all expected containers to be running are in one of the pods inspected above
60 : FOR ${i} IN @{core_containers}
61 \ Run Keyword and Continue on Failure List Should Contain Value ${core_container_names} ${i}
62
63Validate RCord-Lite Containers
64 [Documentation] Validates that all rcord-lite containers that are running in the K8 Pods are healthy
65 [Tags] rcord-lite
66 @{rcord_container_names}= Run Keyword and Continue on Failure Validate Pods rcord-lite-
67 #validates that all expected containers to be running are in one of the pods inspected above
68 : FOR ${i} IN @{rcord_lite_containers}
69 \ Run Keyword and Continue on Failure List Should Contain Value ${rcord_container_names} ${i}
70
71Validate ONOS-Fabric Containers
72 [Documentation] Validates that all onos-fabric containers that are running in the K8 Pods are healthy
73 [Tags] onos-fabric
74 @{onos_container_names}= Run Keyword and Continue on Failure Validate Pods onos-fabric
75 #validates that all expected containers to be running are in one of the pods inspected above
76 : FOR ${i} IN @{onos_fabric_containers}
77 \ Run Keyword and Continue on Failure List Should Contain Value ${onos_container_names} ${i}
78
79Validate XOS Core Deployments
80 [Documentation] Validates that all xos-core deployments successfully rolled out and available
81 [Tags] deployments xos-core
82 Validate Deployments xos- ${core_deployments}
83
84Validate RCord-Lite Deployments
85 [Documentation] Validates that all rcord-lite deployments successfully rolled out and available
86 [Tags] deployments rcord-lite
87 Validate Deployments rcord-lite- ${rcord_lite_deployments}
88
89Validate ONOS-Fabric Deployments
90 [Documentation] Validates that all onos-fabric deployments successfully rolled out and available
91 [Tags] deployments onos-fabric
92 Validate Deployments onos-fabric ${onos_fabric_deployments}
93
94Validate XOS Core Services
95 [Documentation] Validates that all expected xos-core services that are running in K8s
96 [Tags] services xos-core
97 ${services}= Run kubectl get services -o json
98 Log ${services}
99 @{services}= Get Names ${services}
100 #validates that all expected services are running
101 : FOR ${i} IN @{xos_core_services}
102 \ Run Keyword and Continue on Failure List Should Contain Value ${services} ${i}
103 ##check for appropriate ports for each service and match with values in helm charts
104 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].port}'
105 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].targetPort}'
106
107Validate ONOS-Fabric Services
108 [Documentation] Validates that all expected onos-fabric services that are running in K8s
109 [Tags] services onos-fabric
110 ${services}= Run kubectl get services -o json
111 Log ${services}
112 @{services}= Get Names ${services}
113 #validates that all expected services are running
114 : FOR ${i} IN @{onos_fabric_services}
115 \ Run Keyword and Continue on Failure List Should Contain Value ${services} ${i}
116 ##check for appropriate ports for each service and match with values in helm charts
117 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].port}'
118 ## eg. kubectl get svc xos-core -o jsonpath='{.spec.ports[?(@.name=="secure")].targetPort}'
119
120*** Keywords ***
121Setup
122 Log Setting up
123 @{core_containers}= Create List
124 @{rcord_lite_containers}= Create List
125 @{onos_fabric_containers}= Create List
126 @{core_deployments}= Create List
127 @{rcord_lite_deployments}= Create List
128 @{onos_fabric_deployments}= Create List
129 @{xos_core_services}= Create List
130 @{onos_fabric_services}= Create List
131 ${xos-core_containers} utils.jsonToList ${resources_file} xos-core-containers
132 : FOR ${container} IN @{xos-core_containers}
133 \ Append To List ${core_containers} ${container}
134 ${rcord_containers} utils.jsonToList ${resources_file} rcord-lite-containers
135 : FOR ${container} IN @{rcord_containers}
136 \ Append To List ${rcord_lite_containers} ${container}
137 ${onosfabric_containers} utils.jsonToList ${resources_file} onos-fabric-containers
138 : FOR ${container} IN @{onosfabric_containers}
139 \ Append To List ${onos_fabric_containers} ${container}
140 ${xos-core_deployments} utils.jsonToList ${resources_file} xos-core-deployments
141 : FOR ${deployment} IN @{xos-core_containers}
142 \ Append To List ${core_deployments} ${deployment}
143 ${rcord_deployments} utils.jsonToList ${resources_file} rcord-lite-deployments
144 : FOR ${deployment} IN @{rcord_deployments}
145 \ Append To List ${rcord_lite_deployments} ${deployment}
146 ${onosfabric_deployments} utils.jsonToList ${resources_file} rcord-lite-deployments
147 : FOR ${deployment} IN @{onosfabric_deployments}
148 \ Append To List ${onos_fabric_deployments} ${deployment}
149 ${core_services} utils.jsonToList ${resources_file} xos-core-services
150 : FOR ${service} IN @{core_services}
151 \ Append To List ${xos_core_services} ${service}
152 ${onos_services} utils.jsonToList ${resources_file} onos-fabric-services
153 : FOR ${service} IN @{onos_services}
154 \ Append To List ${onos_fabric_services} ${service}
155 Set Suite Variable @{core_containers}
156 Set Suite Variable @{rcord_lite_containers}
157 Set Suite Variable @{onos_fabric_containers}
158 Set Suite Variable @{core_deployments}
159 Set Suite Variable @{rcord_lite_deployments}
160 Set Suite Variable @{onos_fabric_deployments}
161 Set Suite Variable @{xos_core_services}
162 Set Suite Variable @{onos_fabric_services}
163
164Teardown
165 Log Tearing down
166
167Get Names
168 [Documentation] Gets names of K8 resources running
169 [Arguments] ${output}
170 @{names}= Create List
171 ${output}= To JSON ${output}
172 ${len}= Get Length ${output}
173 ${length}= Get Length ${output['items']}
174 : FOR ${INDEX} IN RANGE 0 ${length}
175 \ ${item}= Get From List ${output['items']} ${INDEX}
176 \ ${metadata}= Get From Dictionary ${item} metadata
177 \ ${name}= Get From Dictionary ${metadata} name
178 \ Append To List ${names} ${name}
179 [Return] @{names}
180
181Validate Pods
182 [Arguments] ${component}
183 @{container_names}= Create List
184 ${pods}= Run kubectl get pods -o json
185 Log ${pods}
186 ${pods}= To JSON ${pods}
187 ${len}= Get Length ${pods}
188 ${length}= Get Length ${pods['items']}
189 : FOR ${INDEX} IN RANGE 0 ${length}
190 \ ${item}= Get From List ${pods['items']} ${INDEX}
191 \ ${metadata}= Get From Dictionary ${item} metadata
192 \ ${name}= Get From Dictionary ${metadata} name
193 \ Continue For Loop If '${component}' not in '''${name}'''
194 \ ${status}= Get From Dictionary ${item} status
195 \ ${containerStatuses}= Get From Dictionary ${status} containerStatuses
196 \ Log ${containerStatuses}
197 \ ${cstatus}= Get From List ${containerStatuses} 0
198 \ Log ${cstatus}
199 \ ${restartCount}= Get From Dictionary ${cstatus} restartCount
200 \ Should Be Equal As Integers ${restartCount} 0
201 \ ${container_name}= Get From Dictionary ${cstatus} name
202 \ ${state}= Get From Dictionary ${cstatus} state
203 \ Should Contain ${state} running
204 \ Should Not Contain ${state} stopped
205 \ Log ${state}
206 \ Append To List ${container_names} ${container_name}
207 [Return] ${container_names}
208
209Validate Deployments
210 [Arguments] ${component} ${expected_deployments}
211 ${deployments}= Run kubectl get deployments -o json
212 @{deployments}= Get Names ${deployments}
213 : FOR ${i} IN @{deployments}
214 \ Continue For Loop If '${component}' not in '''${i}'''
215 \ ${rollout_status}= Run kubectl rollout status deployment/${i}
216 \ Should Be Equal ${rollout_status} deployment "${i}" successfully rolled out
217 \ ##validate replication sets
218 \ ${desired}= Run kubectl get deployments ${i} -o jsonpath='{.status.replicas}'
219 \ ${available}= Run kubectl get deployments ${i} -o jsonpath='{.status.availableReplicas}'
220 \ Should Be Equal ${desired} ${available}
221 #validates that all expected deployments to exist
222 : FOR ${i} IN @{expected_deployments}
223 \ List Should Contain Value ${deployments} ${i}