From 6403533bdacfc641c6a23810e6f9e8f912cd3831 Mon Sep 17 00:00:00 2001 From: garciaale Date: Tue, 14 Jul 2020 11:41:06 -0400 Subject: [PATCH] Adds Robot test EPA-03 with new SDNC library Change-Id: I316b238a9097d308c1fd0873ced65c93d1b4f415 Signed-off-by: garciaale --- README.md | 4 + envconfig-local.rc | 4 +- robot-systest/envfile.rc | 1 + robot-systest/lib/sdnc_lib.robot | 93 +++++++++++++++++++ .../epa_03-crud_operations_on_sdnc_data.py | 44 +++++++++ .../epa_03-crud_operations_on_sdnc.robot | 40 ++++++++ sdncs-local.yaml | 17 ++++ 7 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 robot-systest/lib/sdnc_lib.robot create mode 100644 robot-systest/resources/epa_03-crud_operations_on_sdnc_data.py create mode 100644 robot-systest/testsuite/epa_03-crud_operations_on_sdnc.robot create mode 100644 sdncs-local.yaml diff --git a/README.md b/README.md index 51a7ec5..065b878 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ envfile.rc # Clouds file datacenter OS_CLOUD= + # SDNCs file + OS_SDNC= # K8S config file K8S_CREDENTIALS= @@ -99,12 +101,14 @@ 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 sdncs.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/sdncs.yaml \ -v :/root/.kube/config \ -o \ -p \ diff --git a/envconfig-local.rc b/envconfig-local.rc index 954be6f..74786f8 100644 --- a/envconfig-local.rc +++ b/envconfig-local.rc @@ -10,7 +10,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# VIM setup +# Openstack Setup OS_USERNAME= OS_PASSWORD= OS_TENANT_NAME= @@ -28,6 +28,8 @@ PACKAGES_FOLDER=/robot-systest/osm-packages # Clouds file datacenter OS_CLOUD=openstack +# SDNCs file +OS_SDNC=onos LC_ALL=C.UTF-8 LANG=C.UTF-8 diff --git a/robot-systest/envfile.rc b/robot-systest/envfile.rc index c90ac06..e2a6d55 100644 --- a/robot-systest/envfile.rc +++ b/robot-systest/envfile.rc @@ -13,6 +13,7 @@ echo "Please set your environment variables." # export OSM_HOSTNAME= # export OS_CLOUD= +# export OS_SDNC= # export VIM_TARGET= # export VIM_MGMT_NET= # export PACKAGES_FOLDER= diff --git a/robot-systest/lib/sdnc_lib.robot b/robot-systest/lib/sdnc_lib.robot new file mode 100644 index 0000000..f1744b0 --- /dev/null +++ b/robot-systest/lib/sdnc_lib.robot @@ -0,0 +1,93 @@ +# 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 *** +Documentation Library to manage SDNCs. + +Library String +Library Collections +Library OperatingSystem + +Resource %{ROBOT_DEVOPS_FOLDER}/lib/prometheus_lib.robot + + +*** Variables *** +${success_return_code} 0 +${delete_max_wait_time} 1min +${delete_pol_time} 15sec +${sdnc_status_max_wait_time} 6min +${sdnc_status_pol_time} 1min + + +*** Keywords *** +Create SDNC + [Documentation] Creates an SDNC in OSM. + ... The optional parameters (such as 'switch_dpid' or 'ip-address') are given to this function in name=value format. These parameters will be appended to the 'osm sdnc-create' command with the next syntax: --param_name=param_value + ... Returns the ID of the created SDNC Target. + ... Example of execution: + ... \${sdnc_id}= Create SDNC \${sdnc_name} \${sdnc_user} \${sdnc_password} \${sdnc_url} \${sdnc_type} switch_dpid='{...}' + + [Arguments] ${sdcn_name} ${sdnc_user} ${sdnc_password} ${sdnc_url} ${sdnc_type} @{optional_parameters} + + ${osm_sdnc_create_command}= Set Variable osm sdnc-create --name ${sdnc_name} --user ${sdnc_user} --password ${sdnc_password} --url ${sdnc_url} --type ${sdnc_type} + FOR ${param} IN @{optional_parameters} + ${match} ${param_name} ${param_value} = Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in optional parameters + ${osm_sdnc_create_command}= Catenate ${osm_sdnc_create_command} --${param_name}=${param_value} + END + ${rc} ${stdout}= Run and Return RC and Output ${osm_sdnc_create_command} + log ${stdout} + Should Be Equal As Integers ${rc} ${success_return_code} + [Return] ${stdout} + + +Delete SDNC + [Arguments] ${sdnc_name} + + ${rc} ${stdout}= Run Keyword And Continue On Failure Run and Return RC and Output osm sdnc-delete ${sdnc_name} + log ${stdout} + Wait Until Keyword Succeeds ${delete_max_wait_time} ${delete_pol_time} Check for SDNC ${sdnc_name} + + +Get SDNC List + ${rc} ${stdout}= Run and Return RC and Output osm sdnc-list + log ${stdout} + Should Be Equal As Integers ${rc} ${success_return_code} + + +Check for SDNC + [Arguments] ${sdnc_name} + + ${rc} ${stdout}= Run and Return RC and Output osm sdnc-list | awk '{print $2}' | grep ${sdnc_name} + Should Be Equal As Strings ${stdout} ${sdnc_name} + + +Check for SDNC Status + [Arguments] ${sdnc_name} ${prometheus_host} ${prometheus_port} + + ${sdnc_id}= Get SDNC ID ${sdnc_name} + Wait Until Keyword Succeeds ${sdnc_status_max_wait_time} ${sdnc_status_pol_time} Check If SDNC Is Available ${sdnc_id} ${prometheus_host} ${prometheus_port} + + +Get SDNC ID + [Arguments] ${sdnc_name} + + ${rc} ${stdout}= Run and Return RC and Output osm sdnc-list | grep " ${sdnc_name} " | awk '{print $4}' + Should Be Equal As Integers ${rc} ${success_return_code} + Should Not Be Equal As Strings ${stdout} ${EMPTY} msg=SDNC '${sdnc_name}' not found values=false + [Return] ${stdout} + + +Check If SDNC Is Available + [Arguments] ${sdnc_id} ${prometheus_host} ${prometheus_port} + + ${metric}= Get Metric ${prometheus_host} ${prometheus_port} osm_sdnc_status sdnc_id=${sdnc_id} + Should Be Equal As Integers ${metric} 0 msg=SDNC '${sdnc_id}' is not active values=false diff --git a/robot-systest/resources/epa_03-crud_operations_on_sdnc_data.py b/robot-systest/resources/epa_03-crud_operations_on_sdnc_data.py new file mode 100644 index 0000000..72eb986 --- /dev/null +++ b/robot-systest/resources/epa_03-crud_operations_on_sdnc_data.py @@ -0,0 +1,44 @@ +# 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. + +import os +import yaml +from pathlib import Path + +# Prometheus host and port +if os.environ.get("PROMETHEUS_HOSTNAME", False): + prometheus_host = os.environ.get("PROMETHEUS_HOSTNAME") + prometheus_port = "9090" +else: + prometheus_host = os.environ.get("OSM_HOSTNAME") + prometheus_port = "9091" + +# VIM Configuration +sdnc_type = "onos" +sdnc_name = "epa_03_crud_operations_on_sdnc_test" +# Get credentials from ONOS SDNCs file +os_sdnc = os.environ.get("OS_SDNC") +sdncs_file_paths = ["./sdncs.yaml", str(Path.home()) + "/.config/onos/sdncs.yaml"] +for path in sdncs_file_paths: + sdncs_file_path = Path(path) + if sdncs_file_path.exists(): break +if not sdncs_file_path.exists(): raise Exception("ONOS sdncs file not found") +with sdncs_file_path.open() as sdncs_file: + sdncs = yaml.safe_load(sdncs_file) + if not os_sdnc in sdncs["sdncs"]: raise Exception("SDN controller '" + os_sdnc + "' not found") + sdnc = sdncs["sdncs"][os_sdnc] + if not "username" in sdnc["auth"]: raise Exception("Username not found in SDN controller '" + os_sdnc + "'") + sdnc_user = sdnc["auth"]["username"] + if not "password" in sdnc["auth"]: raise Exception("Password not found in SDN controller '" + os_sdnc + "'") + sdnc_password = sdnc["auth"]["password"] + if not "url" in sdnc["auth"]: raise Exception("URL not found in SDN controller '" + os_sdnc + "'") + sdnc_url = sdnc["auth"]["url"] diff --git a/robot-systest/testsuite/epa_03-crud_operations_on_sdnc.robot b/robot-systest/testsuite/epa_03-crud_operations_on_sdnc.robot new file mode 100644 index 0000000..c0e27da --- /dev/null +++ b/robot-systest/testsuite/epa_03-crud_operations_on_sdnc.robot @@ -0,0 +1,40 @@ +# 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 *** +Documentation [EPA-03] CRUD operations on SDNC accounts. + +Resource %{ROBOT_DEVOPS_FOLDER}/lib/sdnc_lib.robot + +Variables %{ROBOT_DEVOPS_FOLDER}/resources/epa_03-crud_operations_on_sdnc_data.py + +Suite Teardown Run Keyword And Ignore Error Delete Basic SDNC + + +*** Test Cases *** +Create Basic SDNC + [Tags] sdnc_crud sanity regression + + ${created_sdnc_id}= Create SDNC ${sdnc_name} ${sdnc_user} ${sdnc_password} ${sdnc_url} ${sdnc_type} + Check for SDNC ${sdnc_name} + + +Check SDNC Status Is Healthy + [Tags] sdnc_crud sanity regression + + Check for SDNC Status ${sdnc_name} ${prometheus_host} ${prometheus_port} + + +Delete Basic SDNC + [Tags] sdnc_crud sanity regression cleanup + + Delete SDNC ${sdnc_name} diff --git a/sdncs-local.yaml b/sdncs-local.yaml new file mode 100644 index 0000000..2fe3464 --- /dev/null +++ b/sdncs-local.yaml @@ -0,0 +1,17 @@ +# 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. +sdncs: + onos: + auth: + url: + username: + password: -- 2.17.1