5 Resource DataModels.robot
7 Resource SSHKeywords.robot
9 Resource ../variables/netvirt/Variables.robot
10 Resource ../variables/Variables.robot
11 Resource VpnOperations.robot
12 Variables ../variables/coe/Modules.py
13 Variables ../variables/netvirt/Modules.py
14 Resource ToolsSystem.robot
18 ${BUSY_BOX} ${CURDIR}/../variables/coe/busy-box.yaml
19 ${CNI_BINARY_FILE} /opt/cni/bin/odlovs-cni
20 ${CONFIG_FILE} /etc/cni/net.d/odlovs-cni.conf
21 ${CONFIG_FILE_TEMPLATE} ${CURDIR}/../variables/coe/odlovs-cni.conf.j2
22 ${HOST_INVENTORY} ${CURDIR}/../variables/coe/hosts.yaml
23 ${K8s_MASTER_IP} ${TOOLS_SYSTEM_1_IP}
24 ${HOSTS_FILE_TEMPLATE} ${CURDIR}/../variables/coe/minions_template.yaml
25 ${NODE_READY_STATUS} \\sReady # The check using this variable should not mess up with NotReady
26 ${PLAYBOOK_FILE} ${CURDIR}/../variables/coe/coe_play.yaml
27 ${POD_RUNNING_STATUS} \\sRunning
28 ${VARIABLES_PATH} ${CURDIR}/../variables/coe
29 ${WATCHER_COE} ${CURDIR}/../variables/coe/coe.yaml
30 @{COE_DIAG_SERVICES} OPENFLOW IFM ITM DATASTORE ELAN OVSDB
35 [Documentation] COE project requires start suite to be executed only for the first test suite.This keyword find the current suite,compares it with the stored first suite value and executes Coe.Start suite only if the cuurent suite is equal to the first suite.
36 ToolsSystem.Get Tools System Nodes Data
37 Coe.Set Connection ids and Bridge
38 Coe.Derive Coe Data Models
39 ${current suite} ${suite names updated} = Extract current suite name
40 ${first_suite} = Set Variable ${suite names updated[0]}
41 ${status} = BuiltIn.Evaluate '${first_suite}' == '${current suite}'
42 IF '${status}' == 'True' Coe.Start Suite
45 [Documentation] Suite setup keyword.
46 Coe.Configuration Playbook
47 Coe.Verify Config Files
48 Coe.Verify Watcher Is Running
49 BuiltIn.Wait Until Keyword Succeeds 40s 2s Coe.Check Node Status Is Ready
51 BuiltIn.Wait Until Keyword Succeeds
54 ... ClusterManagement.Check Status Of Services Is OPERATIONAL
55 ... @{COE_DIAG_SERVICES}
57 Set Connection ids and Bridge
58 [Documentation] Sets the connection ids for all the nodes and get the bridge from configuration file .
59 FOR ${conn_id} IN @{TOOLS_SYSTEM_ALL_CONN_IDS}
60 SSHLibrary.Switch Connection ${conn_id}
61 SSHKeywords.Flexible_SSH_Login ${DEFAULT_USER} ${DEFAULT_PASSWORD}
63 ${file} = OperatingSystem.Get File ${CONFIG_FILE_TEMPLATE}
64 ${ovs bridge output} ${bridge} = BuiltIn.Should Match Regexp ${file} "ovsBridge": "(\\w.*)"
65 BuiltIn.Set Suite Variable ${bridge}
67 Configuration Playbook
68 [Documentation] Ansible playbook which does all basic configuration for kubernetes nodes.
69 ${playbook minions} ${playbook hosts} ${host file} = Modifying templates in playbook
70 ${playbook} = OperatingSystem.Get File ${PLAYBOOK_FILE}
71 ${playbook} = String.Replace String ${playbook} coe-hosts ${playbook hosts}
72 ${playbook} = String.Replace String ${playbook} coe-minions ${playbook minions}
73 OperatingSystem.Create File ${PLAYBOOK_FILE} ${playbook}
74 OperatingSystem.Create File ${USER_HOME}/hosts.yaml ${host file}
75 ${watcher} = OperatingSystem.Get File ${WATCHER_COE}
76 ${watcher} = String.Replace String ${watcher} odlip ${ODL_SYSTEM_IP}
77 ${watcher} = String.Replace String ${watcher} port ${RESTCONFPORT}
78 OperatingSystem.Create File ${WATCHER_COE} ${watcher}
79 SSHKeywords.Copy_File_To_Remote_System ${K8s_MASTER_IP} ${WATCHER_COE} ${USER_HOME}
80 OperatingSystem.Copy File ${PLAYBOOK_FILE} ${USER_HOME}
81 ${branch_ref_spec} = BuiltIn.Catenate SEPARATOR= refs/heads/ ${GERRIT_BRANCH}
82 ${gerrit_ref_spec} = BuiltIn.Set Variable If
83 ... '${GERRIT_PROJECT}' != 'coe'
84 ... ${branch_ref_spec}
86 Run Coe Playbook ${gerrit_ref_spec}
89 [Arguments] ${gerrit_ref_spec}
90 ${play_output} = OperatingSystem.Run
91 ... ansible-playbook -v ${USER_HOME}/coe_play.yaml -i ${USER_HOME}/hosts.yaml --extra-vars '{"gerrit_branch":"FETCH_HEAD","gerrit_refspec":"${gerrit_ref_spec}"}'
92 BuiltIn.Log ${play_output}
94 Modifying templates in playbook
95 ${inventory} = OperatingSystem.Get File ${HOST_INVENTORY}
96 ${template} = OperatingSystem.Get File ${HOSTS_FILE_TEMPLATE}
97 ${template} = String.Replace String ${template} minion_ip ${TOOLS_SYSTEM_ALL_IPS[0]}
98 @{minions} = Create List coe-minion
99 ${hosts} = Set Variable coe-master:
100 FOR ${i} IN RANGE 1 ${NUM_TOOLS_SYSTEM}
101 Append To List ${minions} coe-minion${i}
102 ${hosts} = Catenate ${hosts} coe-minion${i}:
104 ${hosts} = Replace String Using Regexp ${hosts} :$ ${EMPTY}
105 ${hosts} = Remove Space on String ${hosts}
106 ${minion hosts} = Replace String Using Regexp ${hosts} ^[\\w-]+: ${EMPTY}
107 FOR ${i} IN RANGE 1 ${NUM_TOOLS_SYSTEM}
108 ${j} = Evaluate ${i}+1
109 ${template} = String.Replace String ${template} ${minions[${i}-1]} ${minions[${i}]}
110 ${template} = String.Replace String
112 ... ${TOOLS_SYSTEM_ALL_IPS[${i}-1]}
113 ... ${TOOLS_SYSTEM_ALL_IPS[${i}]}
114 ${template} = String.Replace String ${template} 192.168.50.1${i} 192.168.50.1${j}
115 ${template} = String.Replace String ${template} 10.11.${i}.0/24 10.11.${j}.0/24
116 ${template} = String.Replace String ${template} 10.11.${i}.1 10.11.${j}.1
117 Append To File ${HOST_INVENTORY} ${template}
119 ${host file} = OperatingSystem.Get File ${HOST_INVENTORY}
120 ${host file} = String.Replace String ${host file} master_ip ${TOOLS_SYSTEM_ALL_IPS[0]}
121 ${host file} = String.Replace String ${host file} odl_ip ${ODL_SYSTEM_IP}
122 ${host file} = String.Replace String ${host file} mport ${OVSDBPORT}
123 ${host file} = String.Replace String ${host file} cport ${ODL_OF_PORT_6653}
124 ${host file} = String.Replace String ${host file} filepath ${CONFIG_FILE_TEMPLATE}
125 ${host file} = String.Replace String ${host file} yamlpath ${USER_HOME}/coe.yaml
127 RETURN ${minion hosts} ${hosts} ${host file}
130 [Documentation] Checks if the configuration files are present in all nodes
131 FOR ${nodes} IN @{TOOLS_SYSTEM_ALL_IPS}
132 Utils.Verify File Exists On Remote System ${nodes} ${CONFIG_FILE}
134 FOR ${nodes} IN @{TOOLS_SYSTEM_ALL_IPS}
135 Utils.Verify File Exists On Remote System ${nodes} ${CNI_BINARY_FILE}
138 Verify Watcher Is Running
139 [Documentation] Checks if watcher is running in the background
140 ${watcher status} = Utils.Run Command On Remote System ${K8s_MASTER_IP} ps -ef | grep watcher
141 BuiltIn.Should Match Regexp ${watcher status} .* watcher odl
143 Check Node Status Is Ready
144 [Documentation] Checks the status of nodes.This keyword is repeated until the status of all nodes is Ready
145 ${nodes} = Utils.Run Command On Remote System And Log
147 ... kubectl get nodes
149 ... ${DEFAULT_PASSWORD}
150 ... ${DEFAULT_LINUX_PROMPT_STRICT}
151 ${node_status} = String.Get Lines Matching Regexp ${nodes} ${NODE_READY_STATUS} partial_match=True
152 ${lines_containing_ready} = String.Get Line Count ${node_status}
153 BuiltIn.Should Be Equal As Strings ${lines_containing_ready} ${NUM_TOOLS_SYSTEM}
156 [Documentation] Create labels for minions so that random allocation of pods to minions is avoided
157 ${i} = BuiltIn.Set Variable 1
158 ${get nodes} = Utils.Run Command On Remote System And Log ${K8s_MASTER_IP} kubectl get nodes
159 @{get nodes} = String.Split To Lines ${get nodes} 2
160 FOR ${status} IN @{get nodes}
161 ${minion} = BuiltIn.Should Match Regexp ${status} ^\\w+-.*-\\d+
162 Utils.Run Command On Remote System And Log ${K8s_MASTER_IP} kubectl label nodes ${minion} disktype=ss${i}
163 ${i} = BuiltIn.Evaluate ${i}+1
165 Utils.Run Command On Remote System And Log ${K8s_MASTER_IP} kubectl get nodes --show-labels
167 Derive Coe Data Models
168 [Documentation] Data models is created by integrating netvirt and coe data models which is given as input to get the model dumps
169 FOR ${models} IN @{netvirt_data_models}
170 Collections.Append To List ${coe_data_models} ${models}
173 Check Pod Status Is Running
174 [Documentation] Checks the status of pods.This keyword is repeated until the status of all pods is Running
175 ${pods} = Utils.Run Command On Remote System And Log
177 ... kubectl get pods -o wide
179 ... ${DEFAULT_PASSWORD}
180 ... ${DEFAULT_LINUX_PROMPT_STRICT}
181 @{cluster} = String.Split To Lines ${pods} 1
182 FOR ${pod} IN @{cluster}
183 BuiltIn.Should Match Regexp ${pod} ${POD_RUNNING_STATUS}
187 [Documentation] Test teardown to get dumpflows,ovsconfig,model dump,node status,pod status and to dump config files \ and delete pods.
188 FOR ${conn_id} IN @{TOOLS_SYSTEM_ALL_CONN_IDS}
189 OVSDB.Get DumpFlows And Ovsconfig ${conn_id} ${bridge}
191 BuiltIn.Run Keyword And Ignore Error DataModels.Get Model Dump ${ODL_SYSTEM_IP} ${coe_data_models}
193 Utils.Run Command On Remote System And Log
195 ... kubectl get nodes
197 ... ${DEFAULT_PASSWORD}
198 ... ${DEFAULT_LINUX_PROMPT_STRICT}
199 Utils.Run Command On Remote System And Log
201 ... kubectl get pods -o wide
203 ... ${DEFAULT_PASSWORD}
204 ... ${DEFAULT_LINUX_PROMPT_STRICT}
208 [Documentation] Waits till the keyword delete status succeeds implying that all pods created have been deleted
209 ${get pods} = Utils.Run Command On Remote System ${K8s_MASTER_IP} kubectl get pods -o wide
210 @{get pods} = String.Split To Lines ${get pods} 1
211 FOR ${status} IN @{get pods}
212 ${pod_name} = BuiltIn.Should Match Regexp ${status} ^\\w+-\\w+
213 Utils.Run Command On Remote System ${K8s_MASTER_IP} kubectl delete pods ${pod_name}
215 BuiltIn.Wait Until Keyword Succeeds 60s 3s Coe.Check If Pods Are Terminated
216 Coe.Check For Stale veth Ports
218 Check If Pods Are Terminated
219 [Documentation] Checks if the pods created have been terminated.The keyword is repeated until the pods are deleted
220 ${status} = Utils.Run Command On Remote System
222 ... kubectl get pods -o wide
224 ... ${DEFAULT_PASSWORD}
225 ... ${DEFAULT_LINUX_PROMPT_STRICT}
226 ... ${DEFAULT_TIMEOUT}
227 ... return_stdout=False
228 ... return_stderr=True
229 BuiltIn.Should Contain ${status} No resources
232 [Documentation] Logs the configuration files present in all nodes
233 FOR ${nodes} IN @{TOOLS_SYSTEM_ALL_IPS}
234 Utils.Run Command On Remote System And Log ${nodes} cat ${CONFIG_FILE}
238 [Documentation] Suite teardown keyword
239 Coe.Collect Watcher Log
240 Coe.Collect Journalctl Log
243 SSHLibrary.Close All Connections
246 [Documentation] Watcher running in background logs into watcher.out which is copied to ${JENKINS_WORKSPACE}/archives/watcher.log
247 SSHLibrary.Switch Connection ${TOOLS_SYSTEM_ALL_CONN_IDS[0]}
248 SSHLibrary.Get File /tmp/watcher.out ${JENKINS_WORKSPACE}/archives/watcher.log
250 Collect Journalctl Log
251 [Documentation] Logs of the command journalctl -u kubelet is copied to ${JENKINS_WORKSPACE}/archives/journal.log
252 Utils.Run Command On Remote System And Log
254 ... sudo journalctl -u kubelet > ${USER_HOME}/journal.txt
255 SSHLibrary.Switch Connection ${TOOLS_SYSTEM_ALL_CONN_IDS[0]}
256 SSHLibrary.Get File ${USER_HOME}/journal.txt ${JENKINS_WORKSPACE}/archives/journalctl.log
259 [Documentation] Kill the watcher running at the background after completion of tests cases
260 ${watcher status} = Utils.Run Command On Remote System ${K8s_MASTER_IP} ps -ef | grep watcher
261 ${watcher} ${pid} = BuiltIn.Should Match Regexp ${watcher status} \\w+\\s+(\\d+).*watcher odl
262 Utils.Run Command On Remote System ${K8s_MASTER_IP} kill -9 ${pid}
265 [Documentation] Reset K8s to clear up all stale entries
266 FOR ${nodes} IN @{TOOLS_SYSTEM_ALL_IPS}
267 ${kube} = Utils.Run Command On Remote System And Log ${nodes} sudo kubeadm reset
268 BuiltIn.Should Contain ${kube} Stopping the kubelet service.
272 [Documentation] Creates pods using the labels of the nodes and busy box names passed as arguments.
273 [Arguments] ${label} ${yaml} ${name}
274 ${busybox} = OperatingSystem.Get File ${BUSY_BOX}
275 ${busybox} = String.Replace String ${busybox} string ${label}
276 ${busybox} = String.Replace String ${busybox} busyboxname ${name}
277 OperatingSystem.Create File ${VARIABLES_PATH}/${yaml} ${busybox}
278 SSHKeywords.Move_file_To_Remote_System ${K8s_MASTER_IP} ${VARIABLES_PATH}/${yaml} ${USER_HOME}
279 Utils.Run Command On Remote System And Log ${K8s_MASTER_IP} kubectl create -f ${yaml}
281 Collect Pod Names and Ping
282 [Documentation] This keyword collects the pod names and checks connectivity between each and every pod with respect to one another.
283 SSHLibrary.Switch Connection ${TOOLS_SYSTEM_ALL_CONN_IDS[0]}
284 ${get pods} = Write Commands Until Expected Prompt kubectl get pods -o wide ${DEFAULT_LINUX_PROMPT_STRICT}
285 @{pod ips} = String.Get Regexp Matches ${get pods} \\d+\\.\\d+\\.\\d+\\.\\d+
286 @{pod names} = String.Get Regexp Matches ${get pods} ss\\w+-\\w+
287 FOR ${pod_name} IN @{pod names}
288 ${logs} = Log Statements ${pod ips} ${pod names} ${pod_name}
289 Ping Pods ${pod_name} ${pod ips} ${logs}
293 [Arguments] ${pod ips} ${pod names} ${pod_name}
294 @{log statement} = Create List
295 ${i} = Set Variable 0
296 FOR ${pod_ip} IN @{pod ips}
297 ${ping statement} = Set Variable Ping from ${pod_name} to ${pod names[${i}]} (${pod ip})
298 Append To List ${log statement} ${ping statement}
299 ${i} = Evaluate ${i}+1
301 RETURN @{log statement}
304 [Arguments] ${pod_name} ${pod ips} ${logs}
305 ${i} = Set Variable 0
306 FOR ${ping info} IN @{logs}
307 ${ping} = Write Commands Until Expected Prompt
308 ... kubectl exec -it ${pod_name} -- ping -c 3 ${pod ips[${i}]}
309 ... ${DEFAULT_LINUX_PROMPT_STRICT}
311 BuiltIn.Should Contain ${ping} 64 bytes
312 ${i} = Evaluate ${i}+1
316 [Documentation] COE project requires stop suite to be executed only for the last test suite.This keyword find the current suite,compares it with the stored last suite value and executes Coe.Stop suite only if the cuurent suite is equal to the last suite.
317 ${current suite} ${suite names updated} = Extract current suite name
318 ${last_suite} = Set Variable ${suite names updated[-1]}
319 ${status} = BuiltIn.Evaluate '${last_suite}' == '${current suite}'
320 IF '${status}' == 'True' Coe.Stop Suite
322 Extract current suite name
323 [Documentation] This keyword returns the name of current test suite.Appropriate replacement in text is done to make test suite names in SUITES and SUITE_NAME similar.
324 BuiltIn.Log SUITE_NAME: ${SUITE_NAME}
325 BuiltIn.Log SUITES: ${SUITES}
326 @{suite_names} = Get Regexp Matches ${SUITES} coe\\/(\\w+).robot 1
327 @{suite_names_updated} = Create List
328 FOR ${suite} IN @{suite_names}
329 ${suite} = Replace String ${suite} _ ${SPACE}
330 Append To List ${suite_names_updated} ${suite}
332 ${num_suites} = BuiltIn.Get Length ${suite_names_updated}
333 IF ${num_suites} > ${1}
334 ${suite line} ${current_suite} = Should Match Regexp ${SUITE_NAME} .txt.(\\w.*)
336 ${suite line} ${current_suite} = BuiltIn.Set Variable
337 ... ${suite_names_updated}[0]
338 ... ${suite_names_updated}[0]
340 RETURN ${current_suite} ${suite_names_updated}
342 Check For Stale veth Ports
343 [Documentation] Check on switches(except master) where pods were created and deleted to ensure there are no stale veth ports left behind.
344 FOR ${minion_index} IN RANGE 2 ${NUM_TOOLS_SYSTEM}+1
345 ${switch output} = Utils.Run Command On Remote System And Log
346 ... ${TOOLS_SYSTEM_${minion_index}_IP}
347 ... sudo ovs-vsctl show
348 BuiltIn.Should Not Contain ${switch output} veth