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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 Library cluster.cluster.Cluster WITH NAME Cluster
18 Library crl.remotesession.remotesession.RemoteSession
19 ... WITH NAME RemoteSession
21 Test Setup Run Keywords
22 ... ssh.Setup Connections
24 ... Create Kubernetes service with type NodePort
25 Test Teardown Run Keywords
31 ${test_base_dir} /cloudtaf/testcases/kube-service
32 ${service_yaml_name} service.yaml
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
42 Should contain ${out} ${search}
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}
50 Should contain ${out} ${search}
52 Get the Node IP of the pod and Port number of the service and Test the service
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!
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
71 Should contain ${out} ${search}
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
78 Should contain ${out} ${search}
81 Verify creating and testing services
82 Get the Node IP of the pod and Port number of the service and Test the service