Scalability Of Pods In COE
[integration/test.git] / csit / libraries / Coe.robot
1 *** Settings ***
2 Library           BuiltIn
3 Library           SSHLibrary
4 Library           String
5 Resource          DataModels.robot
6 Resource          Genius.robot
7 Resource          OVSDB.robot
8 Resource          SSHKeywords.robot
9 Resource          Utils.robot
10 Resource          ../variables/netvirt/Variables.robot
11 Resource          ../variables/Variables.robot
12 Resource          VpnOperations.robot
13 Variables         ../variables/coe/Modules.py
14 Variables         ../variables/netvirt/Modules.py
15
16 *** Variables ***
17 ${BUSY_BOX}       ${CURDIR}/../variables/coe/busy-box.yaml
18 ${CNI_BINARY_FILE}    /opt/cni/bin/odlovs-cni
19 ${CONFIG_FILE}    /etc/cni/net.d/odlovs-cni.conf
20 ${CONFIG_FILE_TEMPLATE}    ${CURDIR}/../variables/coe/odlovs-cni.conf.j2
21 ${HOST_INVENTORY}    ${CURDIR}/../variables/coe/hosts.yaml
22 ${K8s_MASTER_IP}    ${TOOLS_SYSTEM_1_IP}
23 ${K8s_MINION1_IP}    ${TOOLS_SYSTEM_2_IP}
24 ${K8s_MINION2_IP}    ${TOOLS_SYSTEM_3_IP}
25 ${NODE_READY_STATUS}    \\sReady
26 ${PLAYBOOK}       ${CURDIR}/../variables/coe/coe_play.yaml
27 ${POD_RUNNING_STATUS}    \\sRunning
28 ${WATCHER_COE}    ${CURDIR}/../variables/coe/coe.yaml
29 @{NODE_IPs}       ${K8s_MASTER_IP}    ${K8s_MINION1_IP}    ${K8s_MINION2_IP}
30 @{COE_DIAG_SERVICES}    OPENFLOW    IFM    ITM    DATASTORE    ELAN    OVSDB
31 ${VARIABLES_PATH}    ${CURDIR}/../variables/coe
32
33 *** Keywords ***
34 Start Suite
35     [Documentation]    Suite setup keyword.
36     Coe.Configuration Playbook
37     Coe.Set Connection ids and Bridge
38     Coe.Verify Config Files
39     Coe.Verify Watcher Is Running
40     BuiltIn.Wait Until Keyword Succeeds    40s    2s    Coe.Check Node Status Is Ready
41     Coe.Label Nodes
42     BuiltIn.Wait Until Keyword Succeeds    60    2    ClusterManagement.Check Status Of Services Is OPERATIONAL    @{COE_DIAG_SERVICES}
43     Genius.Verify Tunnel Status as UP    default-transport-zone
44     Coe.Derive Coe Data Models
45
46 Configuration Playbook
47     [Documentation]    Ansible playbook which does all basic configuration for kubernetes nodes.
48     ${hosts} =    OperatingSystem.Get File    ${HOST_INVENTORY}
49     ${hosts} =    String.Replace String    ${hosts}    master_ip    ${K8s_MASTER_IP}
50     ${hosts} =    String.Replace String    ${hosts}    minion1_ip    ${K8s_MINION1_IP}
51     ${hosts} =    String.Replace String    ${hosts}    minion2_ip    ${K8s_MINION2_IP}
52     ${hosts} =    String.Replace String    ${hosts}    odl_ip    ${ODL_SYSTEM_IP}
53     ${hosts} =    String.Replace String    ${hosts}    mport    ${OVSDBPORT}
54     ${hosts} =    String.Replace String    ${hosts}    cport    ${ODL_OF_PORT_6653}
55     ${hosts} =    String.Replace String    ${hosts}    filepath    ${CONFIG_FILE_TEMPLATE}
56     ${hosts} =    String.Replace String    ${hosts}    yamlpath    ${USER_HOME}/coe.yaml
57     OperatingSystem.Create File    ${USER_HOME}/hosts.yaml    ${hosts}
58     ${watcher} =    OperatingSystem.Get File    ${WATCHER_COE}
59     ${watcher} =    String.Replace String    ${watcher}    odlip    ${ODL_SYSTEM_IP}
60     ${watcher} =    String.Replace String    ${watcher}    port    ${RESTCONFPORT}
61     OperatingSystem.Create File    ${WATCHER_COE}    ${watcher}
62     SSHKeywords.Copy_File_To_Remote_System    ${K8s_MASTER_IP}    ${WATCHER_COE}    ${USER_HOME}
63     OperatingSystem.Copy File    ${PLAYBOOK}    ${USER_HOME}
64     ${play_output} =    OperatingSystem.Run    ansible-playbook ${USER_HOME}/coe_play.yaml -i ${USER_HOME}/hosts.yaml
65     BuiltIn.Log    ${play_output}
66
67 Set Connection ids and Bridge
68     [Documentation]    Sets the connection ids for all the nodes and get the bridge from configuration file .
69     ${conn_id_1} =    SSHLibrary.Open Connection    ${K8s_MASTER_IP}
70     SSHKeywords.Flexible_SSH_Login    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}
71     BuiltIn.Set Global Variable    ${conn_id_1}
72     ${conn_id_2} =    SSHLibrary.Open Connection    ${K8s_MINION1_IP}
73     SSHKeywords.Flexible_SSH_Login    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}
74     BuiltIn.Set Global Variable    ${conn_id_2}
75     ${conn_id_3} =    SSHLibrary.Open Connection    ${K8s_MINION2_IP}
76     SSHKeywords.Flexible_SSH_Login    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}
77     BuiltIn.Set Global Variable    ${conn_id_3}
78     ${file} =    OperatingSystem.Get File    ${CONFIG_FILE_TEMPLATE}
79     ${line}    ${bridge} =    Should Match Regexp    ${file}    "ovsBridge": "(\\w.*)"
80     BuiltIn.Set Global Variable    ${bridge}
81
82 Verify Config Files
83     [Documentation]    Checks if the configuration files are present in all nodes
84     : FOR    ${nodes}    IN    @{NODE_IPs}
85     \    Utils.Verify File Exists On Remote System    ${nodes}    ${CONFIG_FILE}
86     : FOR    ${nodes}    IN    @{NODE_IPs}
87     \    Utils.Verify File Exists On Remote System    ${nodes}    ${CNI_BINARY_FILE}
88
89 Verify Watcher Is Running
90     [Documentation]    Checks if watcher is running in the background
91     ${lines} =    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    ps -ef | grep watcher
92     BuiltIn.Should Match Regexp    ${lines}    .* watcher odl
93
94 Check Node Status Is Ready
95     [Documentation]    Checks the status of nodes.This keyword is repeated until the status of all nodes is Ready
96     ${nodes} =    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    kubectl get nodes    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}    ${DEFAULT_LINUX_PROMPT_STRICT}
97     @{cluster} =    String.Split To Lines    ${nodes}    1
98     : FOR    ${node}    IN    @{cluster}
99     \    BuiltIn.Should Match Regexp    ${node}    ${NODE_READY_STATUS}
100
101 Label Nodes
102     [Documentation]    Create labels for minions so that random allocation of pods to minions is avoided
103     ${nodes} =    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    kubectl get nodes
104     ${node_1} =    String.Get Line    ${nodes}    2
105     ${minion_1} =    BuiltIn.Should Match Regexp    ${node_1}    ^\\w+-.*-\\d+
106     ${node_2} =    String.Get Line    ${nodes}    3
107     ${minion_2} =    BuiltIn.Should Match Regexp    ${node_2}    ^\\w+-.*-\\d+
108     Utils.Run Command On Remote System And Log    ${K8s_MASTER_IP}    kubectl label nodes ${minion_1} disktype=ssd
109     Utils.Run Command On Remote System And Log    ${K8s_MASTER_IP}    kubectl label nodes ${minion_2} disktype=ssl
110     Utils.Run Command On Remote System And Log    ${K8s_MASTER_IP}    kubectl get nodes --show-labels
111
112 Derive Coe Data Models
113     [Documentation]    Data models is created by integrating netvirt and coe data models which is given as input to get the model dumps
114     : FOR    ${models}    IN    @{netvirt_data_models}
115     \    Collections.Append To List    ${coe_data_models}    ${models}
116
117 Check Pod Status Is Running
118     [Documentation]    Checks the status of pods.This keyword is repeated until the status of all pods is Running
119     ${pods} =    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    kubectl get pods -o wide    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}    ${DEFAULT_LINUX_PROMPT_STRICT}
120     @{cluster} =    String.Split To Lines    ${pods}    1
121     : FOR    ${pod}    IN    @{cluster}
122     \    BuiltIn.Should Match Regexp    ${pod}    ${POD_RUNNING_STATUS}
123
124 Tear Down
125     [Documentation]    Test teardown to get dumpflows,ovsconfig,model dump,node status,pod status and to dump config files \ and delete pods.
126     OVSDB.Get DumpFlows And Ovsconfig    ${conn_id_1}    ${bridge}
127     OVSDB.Get DumpFlows And Ovsconfig    ${conn_id_2}    ${bridge}
128     OVSDB.Get DumpFlows And Ovsconfig    ${conn_id_3}    ${bridge}
129     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${ODL_SYSTEM_IP}    ${coe_data_models}
130     Coe.DumpConfig File
131     Utils.Run Command On Remote System And Log    ${K8s_MASTER_IP}    kubectl get nodes    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}    ${DEFAULT_LINUX_PROMPT_STRICT}
132     Utils.Run Command On Remote System And Log    ${K8s_MASTER_IP}    kubectl get pods -o wide    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}    ${DEFAULT_LINUX_PROMPT_STRICT}
133     Coe.Delete Pods
134
135 Delete Pods
136     [Documentation]    Waits till the keyword delete status succeeds implying that all pods created have been deleted
137     ${lines} =    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    kubectl get pods -o wide
138     @{lines} =    String.Split To Lines    ${lines}    1
139     : FOR    ${status}    IN    @{lines}
140     \    ${pod_name} =    BuiltIn.Should Match Regexp    ${status}    ^\\w+
141     \    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    kubectl delete pods ${pod_name}
142     BuiltIn.Wait Until Keyword Succeeds    60s    3s    Coe.Check If Pods Are Terminated
143
144 Check If Pods Are Terminated
145     [Documentation]    Checks if the pods created have been terminated.The keyword is repeated until the pods are deleted
146     ${status} =    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    kubectl get pods -o wide    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}    ${DEFAULT_LINUX_PROMPT_STRICT}
147     ...    ${DEFAULT_TIMEOUT}    return_stdout=False    return_stderr=True
148     BuiltIn.Should Contain    ${status}    No resources
149
150 Dump Config File
151     [Documentation]    Logs the configuration files present in all nodes
152     : FOR    ${nodes}    IN    @{NODE_IPs}
153     \    Utils.Run Command On Remote System And Log    ${nodes}    cat ${CONFIG_FILE}
154
155 Stop Suite
156     [Documentation]    Suite teardown keyword
157     Coe.Collect Watcher Log
158     Coe.Collect Journalctl Log
159     Coe.Stop_Watcher
160     Coe.Kube_reset
161     SSHLibrary.Close All Connections
162
163 Collect Watcher Log
164     [Documentation]    Watcher running in background logs into watcher.out which is copied to ${JENKINS_WORKSPACE}/archives/watcher.log
165     SSHLibrary.Open Connection    ${K8s_MASTER_IP}
166     SSHKeywords.Flexible_SSH_Login    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}
167     SSHLibrary.Get File    /tmp/watcher.out    ${JENKINS_WORKSPACE}/archives/watcher.log
168     SSHLibrary.Close Connection
169
170 Collect Journalctl Log
171     [Documentation]    Logs of the command journalctl -u kubelet is copied to ${JENKINS_WORKSPACE}/archives/journal.log
172     Utils.Run Command On Remote System And Log    ${K8s_MASTER_IP}    sudo journalctl -u kubelet > ${USER_HOME}/journal.txt
173     SSHLibrary.Open Connection    ${K8s_MASTER_IP}
174     SSHKeywords.Flexible_SSH_Login    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}
175     SSHLibrary.Get File    ${USER_HOME}/journal.txt    ${JENKINS_WORKSPACE}/archives/journalctl.log
176     SSHLibrary.Close Connection
177
178 Stop Watcher
179     [Documentation]    Kill the watcher running at the background after completion of tests cases
180     ${lines} =    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    ps -ef | grep watcher
181     ${line}    ${pid} =    BuiltIn.Should Match Regexp    ${lines}    \\w+\\s+(\\d+).*watcher odl
182     Utils.Run Command On Remote System    ${K8s_MASTER_IP}    kill -9 ${pid}
183
184 Kube reset
185     [Documentation]    Reset K8s to clear up all stale entries
186     : FOR    ${nodes}    IN    @{NODE_IPs}
187     \    ${kube} =    Utils.Run Command On Remote System And Log    ${nodes}    sudo kubeadm reset
188     \    BuiltIn.Should Contain    ${kube}    Stopping the kubelet service.
189
190 Create Pods
191     [Arguments]    ${label}    ${yaml}    ${name}
192     [Documentation]    Creates pods using the labels of the nodes and busy box names passed as arguments.
193     ${busybox} =    OperatingSystem.Get File    ${BUSY_BOX}
194     ${busybox} =    String.Replace String    ${busybox}    string    ${label}
195     ${busybox} =    String.Replace String    ${busybox}    busyboxname    ${name}
196     OperatingSystem.Create File    ${VARIABLES_PATH}/${yaml}    ${busybox}
197     SSHKeywords.Move_file_To_Remote_System    ${K8s_MASTER_IP}    ${VARIABLES_PATH}/${yaml}    ${USER_HOME}
198     Utils.Run Command On Remote System And Log    ${K8s_MASTER_IP}    kubectl create -f ${yaml}
199
200 Collect Pod Names and Ping
201     [Documentation]    This keyword collects the pod names and checks connectivity between each and every pod with respect to one another.
202     ${lines} =    Utils.Run Command On Remote System    ${K8s_MASTER_IP}    kubectl get pods -o wide
203     @{lines} =    String.Split To Lines    ${lines}    1
204     : FOR    ${status}    IN    @{lines}
205     \    ${pod_name} =    Builtin.Should Match Regexp    ${status}    ^\\w+
206     \    Ping Pods    ${pod_name}    @{lines}
207
208 Ping Pods
209     [Arguments]    ${pod_name}    @{lines}
210     [Documentation]    Ping pods to check connectivity between them
211     : FOR    ${pod ip}    IN    @{lines}
212     \    ${status} =    Run Keyword And Return Status    Should Contain    ${pod ip}    ${pod_name}
213     \    BuiltIn.Continue For Loop If    ${status} == True
214     \    ${pod_ip} =    Builtin.Should Match Regexp    ${pod ip}    \\d+.\\d+.\\d+.\\d+
215     \    ${ping} =    Utils.Run Command On Remote System And Log    ${K8s_MASTER_IP}    kubectl exec -it ${pod_name} -- ping -c 3 ${pod_ip}
216     \    Builtin.Should Match Regexp    ${ping}    ${PING_REGEXP}
217
218 Coe Suite Setup
219     @{suite names}    Get Regexp Matches    ${SUITES}    coe\\/(\\w+).robot    1
220     @{suite names updated}    Create List
221     : FOR    ${suites}    IN    @{suite names}
222     \    ${suites}    Replace String    ${suites}    _    ${SPACE}
223     \    Append To List    ${suite names updated}    ${suites}
224     ${first suite} =    Set Variable    ${suite names updated[0]}
225     ${line}    ${current suite}    Should Match Regexp    ${SUITE_NAME}    .txt.(\\w.*)
226     ${status} =    BuiltIn.Evaluate    '${first suite}' == '${current suite}'
227     Run Keyword If    '${status}' == 'True'    Coe.Start Suite
228
229 Coe Suite Teardown
230     @{suite names}    Get Regexp Matches    ${SUITES}    coe\\/(\\w+).robot    1
231     @{suite names updated}    Create List
232     : FOR    ${suites}    IN    @{suite names}
233     \    ${suites}    Replace String    ${suites}    _    ${SPACE}
234     \    Append To List    ${suite names updated}    ${suites}
235     ${last suite} =    Set Variable    ${suite names updated[-1]}
236     ${line}    ${current suite}    Should Match Regexp    ${SUITE_NAME}    .txt.(\\w.*)
237     ${status} =    BuiltIn.Evaluate    '${last suite}' == '${current suite}'
238     Run Keyword If    '${status}' == 'True'    Coe.Stop Suite