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
23 ... Copy artifacts to Target
25 ... Create Kubernetes service with type NodePort
26 Test Teardown Run Keywords
29 ... Cleanup artifacts, copied files, and images on Target
33 ${test_base_dir} testcases/kube-service
34 ${service_yaml_name} service.yaml
35 ${image_name} registry.kube-system.svc.rec.io:5555/nginx:1.7
36 ${artifacts} nginx.tar
40 Copy artifacts to Target
41 [Arguments] ${node}=sudo-default
42 ${pull_an_image}= ssh.Execute command docker pull nginx ${node}
43 ${save_image}= set variable docker save -o ${artifacts} nginx
44 ${out}= ssh.Execute Command ${save_image} ${node}
45 ${load_image}= set variable docker load -i ${artifacts}
46 ${out}= ssh.Execute Command ${load_image} ${node}
47 ${tag_image}= ssh.Execute Command docker tag nginx ${image_name} ${node}
48 ${push_image}= ssh.Execute Command docker push ${image_name} ${node}
51 [Arguments] ${node}=sudo-default
52 ${search}= set variable pod/my-pod created
53 ${command}= set variable kubectl run --generator=run-pod/v1 my-pod --image=${image_name} --port=80 --labels="name=mypod"
54 ${out}= ssh.Execute Command ${command} ${node}
57 Should contain ${out} ${search}
59 Create Kubernetes service with type NodePort
60 [Arguments] ${node}=sudo-default
61 ${search}= set variable service/my-service created
62 RemoteSession.Copy File To Target ${test_base_dir}/${service_yaml_name} target=${node}
63 ${command}= set variable kubectl apply -f ${service_yaml_name}
64 ${out}= ssh.Execute Command ${command} ${node}
66 Should contain ${out} ${search}
68 Get the Node IP of the pod and Port number of the service and Test the service
69 ${command}= set variable kubectl get pods --all-namespaces -o wide | grep my-pod | awk '{ print $8 }'
70 ${result}= RemoteSession.Execute Command In Target ${command}
71 ${ip_address}= set variable ${result.stdout}
72 Log ip_address=${ip_address}
73 ${command}= set variable kubectl get services | grep my-service | awk '{ print $5 }' | awk -F ':' '{print $2}' | tr -d /TCP
74 ${result}= RemoteSession.Execute Command In Target ${command}
75 ${node_port}= set variable ${result.stdout}
76 Log node_port=${node_port}
77 ${command}= set variable curl http://${ip_address}:${node_port}
78 ${result}= RemoteSession.Execute Command In Target ${command}
79 Should Contain ${result.stdout} Welcome to nginx!
82 [Arguments] ${node}=sudo-default
83 ${search}= set variable pod "my-pod" deleted
84 ${command}= set variable kubectl delete pod my-pod
85 ${out}= ssh.Execute Command ${command} ${node}
87 Should contain ${out} ${search}
90 [Arguments] ${node}=sudo-default
91 ${search}= set variable service "my-service" deleted
92 ${command}= set variable kubectl delete service my-service
93 ${out}= ssh.Execute Command ${command} ${node}
95 Should contain ${out} ${search}
97 Cleanup artifacts, copied files, and images on Target
98 [Arguments] ${node}=sudo-default
99 ${cleanup_copied_files}= ssh.Execute Command rm -rf ${service_yaml_name} ${node}
100 ${remove_images}= set variable docker image rm nginx | docker rmi ${image_name}
101 ${out}= ssh.Execute Command ${remove_images} ${node}
102 ${remove_artifacts}= ssh.Execute Command rm -rf ${artifacts} ${node}
105 Verify creating and testing services
106 Get the Node IP of the pod and Port number of the service and Test the service