forked from contiv/vpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data test with 2 pods on one node
Signed-off-by: Peter Gubka <[email protected]>
- Loading branch information
Peter Gubka
committed
Oct 19, 2017
1 parent
84b36d5
commit 2558cde
Showing
4 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
*** Settings *** | ||
Documentation This is a library to handle kubectl commands on the remote machine, towards which | ||
... ssh connection is opened. | ||
Library Collections | ||
Library SSHLibrary | ||
Library String | ||
Library ${CURDIR}/kubectl_parser.py | ||
|
||
*** Keywords *** | ||
KubeCtl__Execute_Command_And_Log | ||
[Arguments] ${ssh_session} ${command} ${expected_rc}=0 | ||
SSHLibrary.Switch_Connection ${ssh_session} | ||
${stdout} ${stderr} ${rc} = SSHLibrary.Execute_Command ${command} return_stderr=True return_rc=True | ||
BuiltIn.Log ${stdout} | ||
BuiltIn.Log ${stderr} | ||
BuiltIn.Log ${rc} | ||
BuiltIn.Should_Be_Empty ${stderr} | ||
BuiltIn.Should_Be_Equal_As_Numbers ${rc} ${expected_rc} | ||
BuiltIn.Return_From_Keyword ${stdout} | ||
|
||
KubeCtl__Execute_Command_And_Log_With_File | ||
[Arguments] ${ssh_session} ${file_path} ${command_prefix} | ||
SSHLibrary.Switch_Connection ${ssh_session} | ||
SSHLibrary.Put_File ${file_path} . | ||
${splitted_path} = String.Split_String ${file_path} separator=${/} | ||
BuiltIn.Run_Keyword_And_Return KubeCtl__Execute_Command_And_Log ${ssh_session} ${command_prefix} @{splitted_path}[-1] | ||
|
||
Apply_F | ||
[Arguments] ${ssh_session} ${file_path} | ||
KubeCtl__Execute_Command_And_Log_With_File ${ssh_session} ${file_path} kubectl apply -f | ||
|
||
Apply_F_Url | ||
[Arguments] ${ssh_session} ${url} | ||
KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl apply -f ${url} | ||
|
||
Delete_F | ||
[Arguments] ${ssh_session} ${file_path} | ||
KubeCtl__Execute_Command_And_Log_With_File ${ssh_session} ${file_path} kubectl delete -f | ||
|
||
Delete_F_Url | ||
[Arguments] ${ssh_session} ${url} | ||
KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl delete -f ${url} | ||
|
||
Get_Pod | ||
[Arguments] ${ssh_session} ${pod_name} ${namespace}=default | ||
${stdout} = KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl get pod -n ${namespace} ${pod_name} | ||
${output} = kubectl_parser.parse_kubectl_get_pods ${stdout} | ||
BuiltIn.Return_From_Keyword ${output} | ||
|
||
Get_Pods | ||
[Arguments] ${ssh_session} ${namespace}=default | ||
${status} ${message} = BuiltIn.Run_Keyword_And_Ignore_Error KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl get pods -n ${namespace} | ||
BuiltIn.Run_Keyword_If """${status}""" == """FAIL""" and """No resources found""" not in """${message}""" FAIL msg=${message} | ||
${output} = kubectl_parser.parse_kubectl_get_pods ${message} | ||
BuiltIn.Return_From_Keyword ${output} | ||
|
||
Get_Pods_Wide | ||
[Arguments] ${ssh_session} | ||
${stdout} = KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl get pods -o wide | ||
${output} = kubectl_parser.parse_kubectl_get_pods ${stdout} | ||
BuiltIn.Return_From_Keyword ${output} | ||
|
||
Get_Pods_All_Namespaces | ||
[Arguments] ${ssh_session} | ||
${stdout} = KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl get pods --all-namespaces | ||
${output} = kubectl_parser.parse_kubectl_get_pods ${stdout} | ||
BuiltIn.Return_From_Keyword ${output} | ||
|
||
Logs | ||
[Arguments] ${ssh_session} ${cmd_param} | ||
BuiltIn.Run_Keyword_And_Return KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl logs ${cmd_param} | ||
|
||
Describe_Pod | ||
[Arguments] ${ssh_session} ${pod_name} | ||
${output} = KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl describe pod ${pod_name} | ||
${details} = kubectl_parser.parse_kubectl_describe_pod ${output} | ||
BuiltIn.Return_From_Keyword ${details} | ||
|
||
Get_Pod_Name_By_Prefix | ||
[Arguments] ${ssh_session} ${pod_prefix} | ||
${stdout} = KubeCtl__Execute_Command_And_Log ${ssh_session} kubectl get pods --all-namespaces | ||
${output} = kubectl_parser.parse_kubectl_get_pods_and_get_pod_name ${stdout} ${pod_prefix} | ||
BuiltIn.Return_From_Keyword ${output} | ||
|
||
Verify_Pod_Running_And_Ready | ||
[Arguments] ${ssh_session} ${pod_name} ${namespace}=default | ||
&{pods} = Get_Pods ${ssh_session} namespace=${namespace} | ||
${status} = BuiltIn.Evaluate &{pods}[${pod_name}]['STATUS'] | ||
BuiltIn.Should_Be_Equal_As_Strings ${status} Running | ||
${ready} = BuiltIn.Evaluate &{pods}[${pod_name}]['READY'] | ||
${ready_containers} ${out_of_containers} = String.Split_String ${ready} separator=${/} max_split=1 | ||
BuiltIn.Should_Be_Equal_As_Strings ${ready_containers} ${out_of_containers} | ||
|
||
Wait_Until_Pod_Started | ||
[Arguments] ${ssh_session} ${pod_name} ${timeout}=30s ${check_period}=5s ${namespace}=default | ||
BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} ${check_period} Verify_Pod_Running_And_Ready ${ssh_session} ${pod_name} namespace=${namespace} | ||
|
||
Verify_Pod_Not_Present | ||
[Arguments] ${ssh_session} ${pod_name} ${namespace}=default | ||
${pods} = Get_Pods ${ssh_session} namespace=${namespace} | ||
Collections.Dictionary_Should_Not_Contain_Key ${pods} ${pod_name} | ||
|
||
Wait_Until_Pod_Removed | ||
[Arguments] ${ssh_session} ${pod_name} ${timeout}=90s ${check_period}=5s ${namespace}=default | ||
BuiltIn.Wait_Until_Keyword_Succeeds ${timeout} ${check_period} Verify_Pod_Not_Present ${ssh_session} ${pod_name} namespace=${namespace} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Library to parse output (stdout) of kubectl command | ||
""" | ||
|
||
def parse_kubectl_get_pods(stdout): | ||
"""Parse kubectl get pods output""" | ||
lines = stdout.splitlines() | ||
result = {} | ||
if "No resources found." in stdout: | ||
return result | ||
kws = lines[0].split() | ||
for line in lines[1:]: | ||
parsed_line = line.split() | ||
item = {} | ||
for i in range(len(kws)): | ||
item[kws[i]] = parsed_line[i] | ||
print item, kws | ||
name = item.pop('NAME') | ||
result[name] = item | ||
return result | ||
|
||
def parse_kubectl_get_pods_and_get_pod_name(stdout, pod_prefix): | ||
"""Get list of pod names with given prefix""" | ||
pods = parse_kubectl_get_pods(stdout) | ||
print pods | ||
pod = [pod_name for pod_name, pod_value in pods.iteritems() if pod_prefix in pod_name] | ||
return pod | ||
|
||
|
||
def parse_kubectl_describe_pod(stdout): | ||
"""Parse kubectl describe pod output""" | ||
lines = stdout.splitlines() | ||
result = {} | ||
info = ["IP", "Name", "Status"] | ||
for line in lines: | ||
for item in info: | ||
if line.startswith("{}: ".format(item)): | ||
result[item] = line.split(":")[-1].strip() | ||
name = result.pop("Name") | ||
return {name: result} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: ubuntu | ||
spec: | ||
replicas: 2 | ||
template: | ||
metadata: | ||
labels: | ||
app: ubuntu | ||
spec: | ||
containers: | ||
- image: rastislavszabo/ubuntu | ||
imagePullPolicy: IfNotPresent | ||
name: ubuntu | ||
# Just spin & wait forever | ||
command: [ "/bin/bash", "-c", "--" ] | ||
args: [ "while true; do sleep 30; done;" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
*** Settings *** | ||
Documentation This suite simply deploy pod and delete it. | ||
Resource ${CURDIR}/../libraries/KubeCtl.robot | ||
Resource ${CURDIR}/../variables/${VARIABLES}_variables.robot | ||
Resource ${CURDIR}/../libraries/all_libs.robot | ||
Suite Setup BuiltIn.Run_Keywords Testsuite Setup AND Store_Initial_Variables | ||
Suite Teardown Testsuite Teardown | ||
|
||
*** Variables *** | ||
${POD_FILE} ${CURDIR}/../resources/ubuntu2.yaml | ||
${VARIABLES} common | ||
${ENV} common | ||
${PLUGIN_URL} https://raw.githubusercontent.com/contiv/vpp/master/k8s/contiv-vpp.yaml | ||
|
||
*** Test Cases *** | ||
Docker_Pull_Ksr | ||
Execute_Command_And_Log_All ${testbed_connection} docker pull contivvpp/ksr:latest | ||
|
||
Docker_Pull_Cni | ||
Execute_Command_And_Log_All ${testbed_connection} docker pull contivvpp/cni:latest | ||
|
||
Docker_Pull_Vswitch | ||
Execute_Command_And_Log_All ${testbed_connection} docker pull contivvpp/vswitch:latest | ||
|
||
Apply Network Plugin | ||
KubeCtl.Apply_F_Url ${testbed_connection} ${PLUGIN_URL} | ||
${etcd_pod_list} = KubeCtl.Get_Pod_Name_By_Prefix ${testbed_connection} contiv-etcd- | ||
BuiltIn.Length_Should_Be ${etcd_pod_list} 1 | ||
KubeCtl.Wait_Until_Pod_Started ${testbed_connection} @{etcd_pod_list}[0] namespace=kube-system | ||
BuiltIn.Set_Suite_Variable ${etcd_pod} @{etcd_pod_list}[0] | ||
${ksr_pod_list} = KubeCtl.Get_Pod_Name_By_Prefix ${testbed_connection} contiv-ksr- | ||
BuiltIn.Length_Should_Be ${ksr_pod_list} 1 | ||
KubeCtl.Wait_Until_Pod_Started ${testbed_connection} @{ksr_pod_list}[0] namespace=kube-system | ||
BuiltIn.Set_Suite_Variable ${ksr_pod} @{ksr_pod_list}[0] | ||
${vswitch_pod_list} = KubeCtl.Get_Pod_Name_By_Prefix ${testbed_connection} contiv-vswitch- | ||
BuiltIn.Length_Should_Be ${vswitch_pod_list} 1 | ||
KubeCtl.Wait_Until_Pod_Started ${testbed_connection} @{vswitch_pod_list}[0] namespace=kube-system | ||
BuiltIn.Set_Suite_Variable ${vswitch_pod} @{vswitch_pod_list}[0] | ||
|
||
Deploy_Pods | ||
KubeCtl.Apply_F ${testbed_connection} ${CURDIR}/../resources/ubuntu.yaml | ||
${pods_dict} = KubeCtl.Get_Pods ${testbed_connection} | ||
BuiltIn.Log ${pods_dict} | ||
BuiltIn.Length_Should_Be ${pods_dict} 2 | ||
${pod_names} = Collections.Get_Dictionary_Keys ${pods_dict} | ||
: FOR ${pod_name} IN @{pod_names} | ||
\ KubeCtl.Wait_Until_Pod_Started ${testbed_connection} ${pod_name} | ||
|
||
Ping | ||
[Setup] Setup_Hosts_Connections | ||
${stdout} = Run_Finite_Command ping -c 5 ${server_ip} ssh_session=${client_connection} | ||
BuiltIn.Should_Contain ${stdout} 5 received, 0% packet loss | ||
${stdout} = Run_Finite_Command ping -c 5 ${client_ip} ssh_session=${server_connection} | ||
BuiltIn.Should_Contain ${stdout} 5 received, 0% packet loss | ||
[Teardown] Teardown_Hosts_Connections | ||
|
||
Udp | ||
[Setup] Setup_Hosts_Connections | ||
Init_Infinite_Command nc -ul -p 7000 ssh_session=${server_connection} | ||
Init_Infinite_Command nc -u ${server_ip} 7000 ssh_session=${client_connection} | ||
${text} = BuiltIn.Set_Variable Text to be received | ||
SSHLibrary.Write ${text} | ||
${client_stdout} = Stop_Infinite_Command ssh_session=${client_connection} | ||
${server_stdout} = Stop_Infinite_Command ssh_session=${server_connection} | ||
BuiltIn.Should_Contain ${server_stdout} ${text} | ||
[Teardown] Teardown_Hosts_Connections | ||
|
||
Tcp | ||
[Setup] Setup_Hosts_Connections | ||
${text} = BuiltIn.Set_Variable Text to be received | ||
Run_Finite_Command cd; echo "${text}" > some.file ssh_session=${client_connection} | ||
Init_Infinite_Command nc -l -p 4444 ssh_session=${server_connection} | ||
Init_Infinite_Command cd; nc ${server_ip} 4444 < some.file ssh_session=${client_connection} | ||
${server_stdout} = Stop_Infinite_Command ssh_session=${server_connection} | ||
BuiltIn.Should_Contain ${server_stdout} ${text} | ||
${client_stdout} = Stop_Infinite_Command ssh_session=${client_connection} | ||
[Teardown] Teardown_Hosts_Connections | ||
|
||
|
||
Delete_Pods | ||
KubeCtl.Delete_F ${testbed_connection} ${CURDIR}/../resources/ubuntu.yaml | ||
${pods_dict} = KubeCtl.Get_Pods ${testbed_connection} | ||
Log ${pods_dict} | ||
BuiltIn.Length_Should_Be ${pods_dict} 2 | ||
${pod_names} = Collections.Get_Dictionary_Keys ${pods_dict} | ||
: FOR ${pod_name} IN @{pod_names} | ||
\ KubeCtl.Wait_Until_Pod_Removed ${testbed_connection} ${pod_name} | ||
|
||
Delete_Network_Plugin | ||
KubeCtl.Delete_F_Url ${testbed_connection} ${PLUGIN_URL} | ||
KubeCtl.Wait_Until_Pod_Removed ${testbed_connection} ${etcd_pod} | ||
KubeCtl.Wait_Until_Pod_Removed ${testbed_connection} ${vswitch_pod} | ||
KubeCtl.Wait_Until_Pod_Removed ${testbed_connection} ${ksr_pod} | ||
|
||
*** Keywords *** | ||
Store_Initial_Variables | ||
${conn} = SSHLibrary.Get_Connection | ||
Set_Suite_Variable ${testbed_connection} ${conn.index} | ||
|
||
Setup_Hosts_Connections | ||
[Arguments] ${user}=localadmin ${password}=cisco123 | ||
${conn} = SSHLibrary.Get_Connection ${testbed_connection} | ||
${client_connection} = SSHLibrary.Open_Connection ${conn.host} timeout=10 | ||
SSHLibrary.Login ${user} ${password} | ||
BuiltIn.Set_Suite_Variable ${client_connection} | ||
${server_connection} = SSHLibrary.Open_Connection ${conn.host} timeout=10 | ||
SSHLibrary.Login ${user} ${password} | ||
BuiltIn.Set_Suite_Variable ${server_connection} | ||
${pods_dict} = Get_Pods ${testbed_connection} | ||
Log ${pods_dict} | ||
BuiltIn.Length_Should_Be ${pods_dict} 2 | ||
${pod_names} = Collections.Get_Dictionary_Keys ${pods_dict} | ||
BuiltIn.Set_Suite_Variable ${client_pod_name} @{pod_names}[0] | ||
BuiltIn.Set_Suite_Variable ${server_pod_name} @{pod_names}[1] | ||
Get_Into_Container_Prompt ${client_connection} @{pod_names}[0] prompt=# | ||
Get_Into_Container_Prompt ${server_connection} @{pod_names}[1] prompt=# | ||
${client_pod_details} = Describe_Pod ${testbed_connection} ${client_pod_name} | ||
${server_pod_details} = Describe_Pod ${testbed_connection} ${server_pod_name} | ||
${server_ip} = BuiltIn.Evaluate &{server_pod_details}[${server_pod_name}]["IP"] | ||
${client_ip} = BuiltIn.Evaluate &{client_pod_details}[${client_pod_name}]["IP"] | ||
BuiltIn.Set_Suite_Variable ${server_ip} | ||
BuiltIn.Set_Suite_Variable ${client_ip} | ||
|
||
Teardown_Hosts_Connections | ||
Leave_Container_Prompt ${client_connection} | ||
Leave_Container_Prompt ${server_connection} | ||
SSHLibrary.Switch_Connection ${client_connection} | ||
SSHLibrary.Close_Connection | ||
SSHLibrary.Switch_Connection ${server_connection} | ||
SSHLibrary.Close_Connection | ||
|
||
Execute_Command_And_Log_All | ||
[Arguments] ${ssh_session} ${command} ${expected_rc}=0 | ||
SSHLibrary.Switch_Connection ${ssh_session} | ||
${stdout} ${stderr} ${rc} = SSHLibrary.Execute_Command ${command} return_stderr=True return_rc=True | ||
BuiltIn.Log ${stdout} | ||
BuiltIn.Log ${stderr} | ||
BuiltIn.Log ${rc} | ||
BuiltIn.Should_Be_Empty ${stderr} | ||
BuiltIn.Should_Be_Equal_As_Numbers ${rc} ${expected_rc} | ||
BuiltIn.Return_From_Keyword ${stdout} | ||
|
||
Run_Finite_Command | ||
[Arguments] ${command} ${ssh_session}=${EMPTY} ${prompt}=${EMPTY} | ||
BuiltIn.Run_Keyword_If """${ssh_session}""" != """${EMPTY}""" SSHLibrary.Switch_Connection ${ssh_session} | ||
BuiltIn.Run_Keyword_If """${prompt}""" != """${EMPTY}""" SSHLibrary.Set_Client_Configuration prompt=${prompt} | ||
SSHLibrary.Write ${command} | ||
${stdout} = SSHLibrary.Read_Until_Prompt | ||
Log ${stdout} | ||
BuiltIn.Return_From_Keyword ${stdout} | ||
|
||
Init_Infinite_Command | ||
[Arguments] ${command} ${ssh_session}=${EMPTY} ${prompt}=${EMPTY} | ||
BuiltIn.Run_Keyword_If """${ssh_session}""" != """${EMPTY}""" SSHLibrary.Switch_Connection ${ssh_session} | ||
BuiltIn.Run_Keyword_If """${prompt}""" != """${EMPTY}""" SSHLibrary.Set_Client_Configuration prompt=${prompt} | ||
SSHLibrary.Write ${command} | ||
|
||
Stop_Infinite_Command | ||
[Arguments] ${ssh_session}=${EMPTY} ${prompt}=${EMPTY} | ||
BuiltIn.Run_Keyword_If """${ssh_session}""" != """${EMPTY}""" SSHLibrary.Switch_Connection ${ssh_session} | ||
BuiltIn.Run_Keyword_If """${prompt}""" != """${EMPTY}""" SSHLibrary.Set_Client_Configuration prompt=${prompt} | ||
Write_Bare_Ctrl_C | ||
${stdout} = SSHLibrary.Read_Until_Prompt | ||
Log ${stdout} | ||
BuiltIn.Return_From_Keyword ${stdout} | ||
|
||
Write_Bare_Ctrl_C | ||
[Documentation] Construct ctrl+c character and SSH-write it (without endline) to the current SSH connection. | ||
... Do not read anything yet. | ||
${ctrl_c} = BuiltIn.Evaluate chr(int(3)) | ||
SSHLibrary.Write_Bare ${ctrl_c} | ||
|
||
Get_Into_Container_Prompt | ||
[Arguments] ${ssh_session} ${pod_name} ${prompt}=${EMPTY} | ||
SSHLibrary.Switch_Connection ${ssh_session} | ||
BuiltIn.Run_Keyword_If """${prompt}""" != """${EMPTY}""" SSHLibrary.Set_Client_Configuration prompt=${prompt} | ||
SSHLibrary.Write kubectl exec -it ${pod_name} -- /bin/bash | ||
${stdout} = SSHLibrary.Read_Until_Prompt | ||
Log ${stdout} | ||
|
||
Leave_Container_Prompt | ||
[Arguments] ${ssh_session} ${prompt}=$ | ||
SSHLibrary.Switch_Connection ${ssh_session} | ||
SSHLibrary.Set_Client_Configuration prompt=${prompt} | ||
SSHLibrary.Write exit | ||
${stdout} = SSHLibrary.Read_Until_Prompt | ||
Log ${stdout} |