From 05abef267c8334a6203636b23d512f2d050e8d4c Mon Sep 17 00:00:00 2001 From: Indumathi Buddi Date: Fri, 30 Aug 2019 17:15:46 +0000 Subject: [PATCH] REC-13 Creating and testing Services Signed-off-by: Indumathi Buddi Change-Id: Ie3b03442aa606475235b2d328087ea9fc9c64667 --- testcases/kube-service/kube-service.robot | 82 +++++++++++++++++++++++++++++++ testcases/kube-service/service.yaml | 25 ++++++++++ 2 files changed, 107 insertions(+) create mode 100644 testcases/kube-service/kube-service.robot create mode 100755 testcases/kube-service/service.yaml diff --git a/testcases/kube-service/kube-service.robot b/testcases/kube-service/kube-service.robot new file mode 100644 index 0000000..e42d9ea --- /dev/null +++ b/testcases/kube-service/kube-service.robot @@ -0,0 +1,82 @@ +# Copyright 2019 AT&T +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +*** Settings *** +Library Collections +Library cluster.cluster.Cluster WITH NAME Cluster +Library crl.remotesession.remotesession.RemoteSession +... WITH NAME RemoteSession +Resource ssh.robot +Test Setup Run Keywords +... ssh.Setup Connections +... Create pod +... Create Kubernetes service with type NodePort +Test Teardown Run Keywords +... Delete pod +... Delete service + +*** Variables *** + +${test_base_dir} /cloudtaf/testcases/kube-service +${service_yaml_name} service.yaml + +*** Keywords *** + +Create pod + ${search}= set variable pod/my-pod created + ${command}= set variable kubectl run --generator=run-pod/v1 my-pod --image=nginx --port=80 --labels="name=mypod" + ${out}= ssh.Execute Command ${command} controller-1 + Sleep 30s + log ${out} + Should contain ${out} ${search} + +Create Kubernetes service with type NodePort + [Arguments] ${node}=sudo-default + ${search}= set variable service/my-service created + ${command}= set variable kubectl apply -f ${test_base_dir}/${service_yaml_name} + ${out}= ssh.Execute Command ${command} ${node} + log ${out} + Should contain ${out} ${search} + +Get the Node IP of the pod and Port number of the service and Test the service + + ${command}= set variable kubectl get pods --all-namespaces -o wide | grep my-pod | awk '{ print $8 }' + ${result}= RemoteSession.Execute Command In Target ${command} + ${ip_address}= set variable ${result.stdout} + Log ip_address=${ip_address} + ${command}= set variable kubectl get services | grep my-service | awk '{ print $5 }' | awk -F ':' '{print $2}' | tr -d /TCP + ${result}= RemoteSession.Execute Command In Target ${command} + ${node_port}= set variable ${result.stdout} + Log node_port=${node_port} + ${command}= set variable curl http://${ip_address}:${node_port} + ${result}= RemoteSession.Execute Command In Target ${command} + Should Contain ${result.stdout} Welcome to nginx! + +Delete pod + ${search}= set variable pod "my-pod" deleted + ${command}= set variable kubectl delete pod my-pod + ${out}= ssh.Execute Command ${command} controller-1 + log ${out} + Should contain ${out} ${search} + +Delete service + ${search}= set variable service "my-service" deleted + ${command}= set variable kubectl delete service my-service + ${out}= ssh.Execute Command ${command} controller-1 + log ${out} + Should contain ${out} ${search} + +*** Test Cases *** +Verify creating and testing services + Get the Node IP of the pod and Port number of the service and Test the service diff --git a/testcases/kube-service/service.yaml b/testcases/kube-service/service.yaml new file mode 100755 index 0000000..93941ed --- /dev/null +++ b/testcases/kube-service/service.yaml @@ -0,0 +1,25 @@ +# Copyright 2019 AT&T +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: Service +metadata: + name: my-service +spec: + type: NodePort + ports: + - targetPort: 80 + port: 80 + selector: + name: mypod -- 2.16.6