From: Felipe Vicens Date: Tue, 23 Jun 2020 13:55:08 +0000 (+0200) Subject: Adding kubernetes tests X-Git-Tag: v0.0.1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=5c54d2714e0e755e47f220f885817b683096b238;hp=f96bb45c0a03f2188688d90d67ea718851cec2de;p=osm%2Ftests.git Adding kubernetes tests Change-Id: Ibed1eadd12eef34cb9b810292913ad5bc8222b0b Signed-off-by: Felipe Vicens --- diff --git a/Dockerfile b/Dockerfile index 05598fb..51f4c53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,9 @@ ENV PACKAGES_FOLDER=/robot-systest/osm-packages # Folder where test results should be exported ENV ROBOT_REPORT_FOLDER=/robot-systest/results +# Kubeconfig file +ENV K8S_CREDENTIALS=/root/.kube/config + ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 diff --git a/README.md b/README.md index eb13bf0..cd81fd2 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ This bash script can be used to setup your environment to execute the tests. add-apt-repository -y ppa:rmescandon/yq && apt update && apt install yq git iputils-ping ssh -y pip install haikunator requests robotframework robotframework-seleniumlibrary robotframework-requests robotframework-jsonlibrary \ robotframework-sshlibrary + snap install charm # Download community packages git clone https://osm.etsi.org/gitlab/vnf-onboarding/osm-packages.git ${PACKAGES_FOLDER} ``` @@ -43,16 +44,24 @@ This bash script can be used to setup your environment to execute the tests. envfile.rc ```bash - # VIM setup + # VIM Setup OS_USERNAME= OS_PASSWORD= OS_TENANT_NAME= OS_AUTH_URL= OS_TENANT_ID= + + # OSM Setup OSM_HOSTNAME= VIM_TARGET= VIM_MGMT_NET= + # Clouds file datacenter + OS_CLOUD= + + # K8S config file + K8S_CREDENTIALS= + # The following set of environment variables will be used in host # of the robot framework. Not needed for docker execution @@ -90,12 +99,16 @@ Volumes: * [OPTIONAL]: It is the absolute path to reports location in the host * [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host +* [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters ```bash docker run --rm=true -t osmtests --env-file \ - -v :/reports osmtests -v :/robot-systest/clouds.yaml \ - -v :/robot-systest/kubeconfig.yaml - -o -p -t + -v :/reports osmtests \ + -v :/robot-systest/clouds.yaml \ + -v :/root/.kube/config \ + -o \ + -p \ + -t ``` 1. Running the tests manually: diff --git a/clouds-local.yaml b/clouds-local.yaml new file mode 100644 index 0000000..39d19c7 --- /dev/null +++ b/clouds-local.yaml @@ -0,0 +1,9 @@ +clouds: + openstack: + auth: + auth_url: + project_name: + username: + password: + user_domain_name: + project_domain_name: diff --git a/clouds.yaml b/clouds.yaml deleted file mode 100644 index b627183..0000000 --- a/clouds.yaml +++ /dev/null @@ -1,9 +0,0 @@ -clouds: - openstack: - auth: - auth_url: http://172.21.247.1:5000/v3 - project_name: fvicens - username: fvicens - password: fvicens19 - user_domain_name: Default - project_domain_name: Default diff --git a/envconfig-local.rc b/envconfig-local.rc new file mode 100644 index 0000000..954be6f --- /dev/null +++ b/envconfig-local.rc @@ -0,0 +1,33 @@ +# 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. + +# VIM setup +OS_USERNAME= +OS_PASSWORD= +OS_TENANT_NAME= +OS_AUTH_URL= +OS_TENANT_ID= + +# OSM Setup +OSM_HOSTNAME= +VIM_TARGET= +VIM_MGMT_NET= + +# Robot setup +ENVIRONMENTS_FOLDER=environments +PACKAGES_FOLDER=/robot-systest/osm-packages + +# Clouds file datacenter +OS_CLOUD=openstack + +LC_ALL=C.UTF-8 +LANG=C.UTF-8 diff --git a/envconfig.rc b/envconfig.rc deleted file mode 100644 index 7d2bb6f..0000000 --- a/envconfig.rc +++ /dev/null @@ -1,15 +0,0 @@ -# VIM setup -OS_USERNAME=fvicens -OS_PASSWORD=fvicens19 -OS_TENANT_NAME=admin -OS_AUTH_URL=https://172.21.247.1:5000/v3 -OS_TENANT_ID=fvicens -OSM_HOSTNAME=172.21.248.28 -VIM_TARGET=osm -VIM_MGMT_NET=osm-ext -ENVIRONMENTS_FOLDER=environments -PACKAGES_FOLDER=/robot-systest/osm-packages -OS_CLOUD=openstack - -LC_ALL=C.UTF-8 -LANG=C.UTF-8 diff --git a/robot-systest/lib/k8scluster_lib.robot b/robot-systest/lib/k8scluster_lib.robot new file mode 100644 index 0000000..3896941 --- /dev/null +++ b/robot-systest/lib/k8scluster_lib.robot @@ -0,0 +1,58 @@ +# Copyright 2020 Canonical Ltd. +# +# 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. + +*** Variables *** +${success_return_code} 0 +${k8scluster_launch_max_wait_time} 2min +${k8scluster_launch_pol_time} 30sec +${k8scluster_delete_max_wait_time} 2min +${k8scluster_delete_pol_time} 15sec + +*** Keywords *** +Create K8s Cluster + [Arguments] ${k8scluster_creds} ${k8scluster_version} ${k8scluster_vim} ${k8scluster_net} ${k8scluster_name} + ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-add --creds ${k8scluster_creds} --version ${k8scluster_version} --vim ${k8scluster_vim} --k8s-nets '{"net1": "${k8scluster_net}"}' ${k8scluster_name} --description "Robot cluster" + log ${stdout} + Should Be Equal As Integers ${rc} ${success_return_code} + WAIT UNTIL KEYWORD SUCCEEDS ${k8scluster_launch_max_wait_time} ${k8scluster_launch_pol_time} Check For K8s Cluster To Be Ready ${k8scluster_name} + [Return] ${stdout} + +Delete K8s Cluster + [Arguments] ${k8scluster_name} + ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-delete ${k8scluster_name} + Should Be Equal As Integers ${rc} ${success_return_code} + WAIT UNTIL KEYWORD SUCCEEDS ${k8scluster_delete_max_wait_time} ${k8scluster_delete_pol_time} Check For K8s Cluster To Be Deleted ${k8scluster_name} + +Get K8s Cluster + ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-list + Should Be Equal As Integers ${rc} ${success_return_code} + log ${stdout} + [Return] ${stdout} + +Check for K8s Cluster + [Arguments] ${k8scluster_name} + ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-list --filter name="${k8scluster_name}" + Should Be Equal As Integers ${rc} ${success_return_code} + [Return] ${stdout} + +Check For K8s Cluster To Be Deleted + [Arguments] ${k8scluster_name} + ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-list --filter name="${k8scluster_name}" | awk '{print $2}' | grep ${k8scluster_name} + Should Be Empty ${stdout} + +Check For K8s Cluster To Be Ready + [Arguments] ${k8scluster_name} + ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-list --filter name="${k8scluster_name}" --filter _admin.operationalState="ENABLED" | awk '{print $2}' | grep ${k8scluster_name} + Should Be Equal As Integers ${rc} ${success_return_code} + Should Be Equal As Strings ${stdout} ${k8scluster_name} diff --git a/robot-systest/resources/k8s_02-k8scluster_creation_data.py b/robot-systest/resources/k8s_02-k8scluster_creation_data.py new file mode 100644 index 0000000..8a816ab --- /dev/null +++ b/robot-systest/resources/k8s_02-k8scluster_creation_data.py @@ -0,0 +1,24 @@ +# Copyright 2020 Canonical Ltd. +# +# 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. + +from pathlib import Path + +# Get ${HOME} from local machine +home = str(Path.home()) +# K8s cluster name +k8scluster_name = 'k8s-test' +k8scluster_version = 'v1' +# SSH keys to be used +publickey = home + '/.ssh/id_rsa.pub' +privatekey = home + '/.ssh/id_rsa' diff --git a/robot-systest/resources/k8s_03-simple_k8s_data.py b/robot-systest/resources/k8s_03-simple_k8s_data.py index 4ecfe59..f4f99bf 100644 --- a/robot-systest/resources/k8s_03-simple_k8s_data.py +++ b/robot-systest/resources/k8s_03-simple_k8s_data.py @@ -18,11 +18,11 @@ home = str(Path.home()) k8scluster_name = 'k8s-test' k8scluster_version = 'v1' # NS and VNF descriptor package files -vnfd_pkg = 'hackfest_simple_k8s_vnfd.tar.gz' -nsd_pkg = 'hackfest_simple_k8s_nsd.tar.gz' +vnfd_pkg = 'hackfest_simple_k8s_vnf' +nsd_pkg = 'hackfest_simple_k8s_ns' # NS and VNF descriptor package files -vnfd_name = 'hackfest-simple-k8s-vnfd' -nsd_name = 'hackfest-simple-k8s-nsd' +vnfd_name = 'hackfest-simple-k8s-vnf' +nsd_name = 'hackfest-simple-k8s-ns' # NS instance name ns_name = 'simple-k8s' # SSH keys to be used diff --git a/robot-systest/run_test.sh b/robot-systest/run_test.sh index 7a05681..1f8636d 100755 --- a/robot-systest/run_test.sh +++ b/robot-systest/run_test.sh @@ -53,9 +53,12 @@ while (( "$#" )); do Usage: docker run --rm=true -t osmtests --env-file \\ - -v :/reports osmtests -v :/robot-systest/clouds.yaml \\ - -v :/robot-systest/kubeconfig.yaml \\ - -o -p -t + -v :/reports osmtests \\ + -v :/robot-systest/clouds.yaml \\ + -v :/root/.kube/config \\ + -o \\ + -p \\ + -t Options: --env-file: It is the environmental file where is described the OSM target and VIM @@ -65,7 +68,8 @@ Options: Volumes: [OPTIONAL]: It is the absolute path to reports location in the host - [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host" + [OPTIONAL]: It is the absolute path to the clouds.yaml file in the host + [OPTIONAL]: It is the kubeconfig file to be used for k8s clusters" exit 0 ;; diff --git a/robot-systest/testsuite/k8s_02-k8scluster_creation.robot b/robot-systest/testsuite/k8s_02-k8scluster_creation.robot new file mode 100644 index 0000000..625b6f6 --- /dev/null +++ b/robot-systest/testsuite/k8s_02-k8scluster_creation.robot @@ -0,0 +1,44 @@ +# Copyright 2020 Canonical Ltd. +# +# 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 OperatingSystem +Library String +Library Collections +Library Process + +Resource %{ROBOT_DEVOPS_FOLDER}/lib/k8scluster_lib.robot + +Variables %{ROBOT_DEVOPS_FOLDER}/resources/k8s_02-k8scluster_creation_data.py + +Suite Teardown Run Keyword And Ignore Error Test Cleanup + +*** Test Cases *** +Add K8s Cluster To OSM + [Tags] k8scluster sanity regression + Create K8s Cluster %{K8S_CREDENTIALS} ${k8scluster_version} %{VIM_TARGET} %{VIM_MGMT_NET} ${k8scluster_name} + +List K8s Clusters + [Tags] k8scluster sanity regression + ${stdout}= Get K8s Cluster + Log To Console \n${stdout} + +Remove K8s Cluster from OSM + [Tags] k8scluster sanity regression + Delete K8s Cluster ${k8scluster_name} + +*** Keywords *** +Test Cleanup + [Documentation] Test Suit Cleanup: Deleting K8s Cluster + Run Keyword If Test Failed Delete K8s Cluster ${k8scluster_name} diff --git a/robot-systest/testsuite/k8s_03-simple_k8s.robot b/robot-systest/testsuite/k8s_03-simple_k8s.robot index 6fd6551..5b0db07 100644 --- a/robot-systest/testsuite/k8s_03-simple_k8s.robot +++ b/robot-systest/testsuite/k8s_03-simple_k8s.robot @@ -35,36 +35,36 @@ ${publickey} ${EMPTY} *** Test Cases *** Create Simple K8s VNF Descriptor - [Tags] simple_k8s + [Tags] simple_k8s sanity regression Create VNFD '%{PACKAGES_FOLDER}/${vnfd_pkg}' Create Simple K8s Descriptor - [Tags] simple_k8s + [Tags] simple_k8s sanity regression Create NSD '%{PACKAGES_FOLDER}/${nsd_pkg}' Add K8s Cluster To OSM - [Tags] k8scluster + [Tags] k8scluster sanity regression Create K8s Cluster %{K8S_CREDENTIALS} ${k8scluster_version} %{VIM_TARGET} %{VIM_MGMT_NET} ${k8scluster_name} Network Service K8s Instance Test - [Tags] simple_k8s + [Tags] simple_k8s sanity regression ${id}= Create Network Service ${nsd_name} %{VIM_TARGET} ${ns_name} ${ns_config} ${publickey} Set Suite Variable ${ns_id} ${id} Delete NS K8s Instance Test - [Tags] simple_k8s cleanup + [Tags] simple_k8s sanity regression cleanup Delete NS ${ns_name} Remove K8s Cluster from OSM - [Tags] k8scluster + [Tags] k8scluster sanity regression Delete K8s Cluster ${k8scluster_name} Delete NS Descriptor Test - [Tags] simple_k8s cleanup + [Tags] simple_k8s sanity regression cleanup Delete NSD ${nsd_name} Delete VNF Descriptor Test - [Tags] simple_k8s cleanup + [Tags] simple_k8s sanity regression cleanup Delete VNFD ${vnfd_name}