REC-13 Creating and testing Services
[ta/cloudtaf.git] / testcases / kube-service / kube-service.robot
1 # Copyright 2019 AT&T
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 *** Settings ***
16 Library             Collections
17 Library             cluster.cluster.Cluster    WITH NAME    Cluster
18 Library             crl.remotesession.remotesession.RemoteSession
19 ...                 WITH NAME    RemoteSession
20 Resource            ssh.robot
21 Test Setup          Run Keywords
22 ...                 ssh.Setup Connections
23 ...                 Create pod
24 ...                 Create Kubernetes service with type NodePort
25 Test Teardown       Run Keywords
26 ...                 Delete pod
27 ...                 Delete service
28
29 *** Variables ***
30
31 ${test_base_dir}                /cloudtaf/testcases/kube-service
32 ${service_yaml_name}            service.yaml
33
34 *** Keywords ***
35
36 Create pod
37     ${search}=     set variable    pod/my-pod created
38     ${command}=    set variable    kubectl run --generator=run-pod/v1 my-pod --image=nginx --port=80 --labels="name=mypod"
39     ${out}=    ssh.Execute Command    ${command}    controller-1
40     Sleep  30s
41     log    ${out}
42     Should contain    ${out}    ${search}
43
44 Create Kubernetes service with type NodePort
45     [Arguments]    ${node}=sudo-default
46     ${search}=     set variable    service/my-service created
47     ${command}=    set variable    kubectl apply -f ${test_base_dir}/${service_yaml_name}
48     ${out}=    ssh.Execute Command    ${command}    ${node}
49     log    ${out}
50     Should contain    ${out}    ${search}
51
52 Get the Node IP of the pod and Port number of the service and Test the service
53
54     ${command}=    set variable    kubectl get pods --all-namespaces -o wide | grep my-pod | awk '{ print $8 }'
55     ${result}=    RemoteSession.Execute Command In Target    ${command}
56     ${ip_address}=     set variable    ${result.stdout}
57     Log    ip_address=${ip_address}
58     ${command}=    set variable    kubectl get services | grep my-service | awk '{ print $5 }' | awk -F ':' '{print $2}' | tr -d /TCP
59     ${result}=    RemoteSession.Execute Command In Target    ${command}
60     ${node_port}=     set variable    ${result.stdout}
61     Log    node_port=${node_port}
62     ${command}=    set variable    curl http://${ip_address}:${node_port}
63     ${result}=    RemoteSession.Execute Command In Target    ${command}
64     Should Contain    ${result.stdout}    Welcome to nginx!
65
66 Delete pod
67     ${search}=     set variable    pod "my-pod" deleted
68     ${command}=    set variable    kubectl delete pod my-pod
69     ${out}=    ssh.Execute Command    ${command}    controller-1
70     log    ${out}
71     Should contain    ${out}    ${search}
72
73 Delete service
74     ${search}=     set variable    service "my-service" deleted
75     ${command}=    set variable    kubectl delete service my-service
76     ${out}=    ssh.Execute Command    ${command}    controller-1
77     log    ${out}
78     Should contain    ${out}    ${search}
79
80 *** Test Cases ***
81 Verify creating and testing services
82     Get the Node IP of the pod and Port number of the service and Test the service