From 7b58bc1e2ec68906304d0f4a11e0cda0f671d537 Mon Sep 17 00:00:00 2001 From: limon Date: Thu, 14 May 2020 18:32:51 +0200 Subject: [PATCH] Robot libraries for Prometheus, VIM and NS instances. Change-Id: I7105cfbfb2755a09f267a584ec79e5e5962bd9de Signed-off-by: limon --- robot-systest/README.md | 4 +- robot-systest/lib/ns_lib.robot | 90 +++++++++++++++++++++++++ robot-systest/lib/prometheus_lib.robot | 60 +++++++++++++++++ robot-systest/lib/vim_lib.robot | 93 ++++++++++++++++++++++++++ 4 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 robot-systest/lib/prometheus_lib.robot create mode 100644 robot-systest/lib/vim_lib.robot diff --git a/robot-systest/README.md b/robot-systest/README.md index 99e957d7..a81da8ac 100644 --- a/robot-systest/README.md +++ b/robot-systest/README.md @@ -32,9 +32,7 @@ ```bash sudo -H python3 -m pip install --ignore-installed haikunator requests pyvcloud progressbar pathlib robotframework robotframework-seleniumlibrary robotframework-requests robotframework-SSHLibrary -curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - -sudo add-apt-repository -y "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" -sudo apt-get install -y google-chrome-stable chromium-chromedriver +sudo snap install yq sudo apt-get install -y python3-openstackclient # Installs Queens by default ``` diff --git a/robot-systest/lib/ns_lib.robot b/robot-systest/lib/ns_lib.robot index cc252fba..4be7fe44 100644 --- a/robot-systest/lib/ns_lib.robot +++ b/robot-systest/lib/ns_lib.robot @@ -16,6 +16,11 @@ ${ns_launch_max_wait_time} 5min ${ns_launch_pol_time} 30sec ${ns_delete_max_wait_time} 1min ${ns_delete_pol_time} 15sec +${ns_action_max_wait_time} 1min +${ns_action_pol_time} 15sec +${vnf_scale_max_wait_time} 5min +${vnf_scale_pol_time} 30sec + *** Keywords *** Create Network Service @@ -80,3 +85,88 @@ Delete NS Should Be Equal As Integers ${rc} ${success_return_code} WAIT UNTIL KEYWORD SUCCEEDS ${ns_delete_max_wait_time} ${ns_delete_pol_time} Check For NS Instance To Be Deleted ${ns} + +Execute NS Action + [Documentation] Execute an action over the desired NS. + ... Parameters are given to this function in key=value format (one argument per key/value pair). + ... Return the ID of the operation associated to the executed action. + ... Examples of execution: + ... \${ns_op_id}= Execute NS Action \${ns_name} \${ns_action} \${vnf_member_index} + ... \${ns_op_id}= Execute NS Action \${ns_name} \${ns_action} \${vnf_member_index} \${param1}=\${value1} \${param2}=\${value2} + + [Arguments] ${ns_name} ${ns_action} ${vnf_member_index} @{action_params} + + ${params}= Set Variable ${EMPTY} + FOR ${param} IN @{action_params} + ${match} ${param_name} ${param_value} = Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in parameters + ${params}= Catenate SEPARATOR= ${params} "${param_name}":"${param_value}", + END + ${osm_ns_action_command}= Set Variable osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index} + ${osm_ns_action_command}= Run Keyword If '${params}'!='${EMPTY}' Catenate ${osm_ns_action_command} --params '{${params}}' + ... ELSE Set Variable ${osm_ns_action_command} + ${osm_ns_action_command}= Catenate ${osm_ns_action_command} ${ns_name} + ${rc} ${stdout}= Run and Return RC and Output ${osm_ns_action_command} + Should Be Equal As Integers ${rc} ${success_return_code} msg=${stdout} values=False + Wait Until Keyword Succeeds ${ns_action_max_wait_time} ${ns_action_pol_time} Check For NS Operation Completed ${stdout} + [Return] ${stdout} + + +Execute Manual VNF Scale + [Documentation] Execute a manual VNF Scale action. + ... The parameter 'scale_type' must be SCALE_IN or SCALE_OUT. + ... Return the ID of the operation associated to the executed scale action. + + [Arguments] ${ns_name} ${vnf_member_index} ${scaling_group} ${scale_type} + + Should Contain Any ${scale_type} SCALE_IN SCALE_OUT msg=Unknown scale type: ${scale_type} values=False + ${osm_vnf_scale_command}= Set Variable osm vnf-scale --scaling-group ${scaling_group} + ${osm_vnf_scale_command}= Run Keyword If '${scale_type}'=='SCALE_IN' Catenate ${osm_vnf_scale_command} --scale-in + ... ELSE Catenate ${osm_vnf_scale_command} --scale-out + ${osm_vnf_scale_command}= Catenate ${osm_vnf_scale_command} ${ns_name} ${vnf_member_index} + ${rc} ${stdout}= Run and Return RC and Output ${osm_vnf_scale_command} + Should Be Equal As Integers ${rc} ${success_return_code} msg=${stdout} values=False + Wait Until Keyword Succeeds ${ns_action_max_wait_time} ${ns_action_pol_time} Check For NS Operation Completed ${stdout} + [Return] ${stdout} + + +Get Operations List + [Arguments] ${ns_name} + + ${rc} ${stdout}= Run and Return RC and Output osm ns-op-list ${ns_name} + log ${stdout} + log ${rc} + Should Be Equal As Integers ${rc} ${success_return_code} + + +Check For NS Operation Completed + [Documentation] Check wheter the status of the desired operation is "COMPLETED" or not. + + [Arguments] ${ns_operation_id} + + ${rc} ${stdout}= Run and Return RC and Output osm ns-op-show ${ns_operation_id} --literal | yq r - operationState + log ${stdout} + Should Be Equal As Integers ${rc} ${success_return_code} + Should Contain ${stdout} COMPLETED msg=Timeout waiting for ns-action with id ${ns_operation_id} values=False + + +Get Ns Vnfr Ids + [Documentation] Return a list with the IDs of the VNF records of a NS instance. + + [Arguments] ${ns_id} + + ${rc} ${stdout}= Run and Return RC and Output osm vnf-list | grep ${ns_id} | awk '{print $2}' 2>&1 + Should Be Equal As Integers ${rc} ${success_return_code} msg=${stdout} values=False + @{vdur} = Split String ${stdout} + [Return] @{vdur} + + +Get Vnf Vdur Names + [Documentation] Return a list with the names of the VDU records of a VNF instance. + + [Arguments] ${vnf_id} + + ${rc} ${stdout}= Run and Return RC and Output osm vnf-show ${vnf_id} --literal | yq r - vdur.*.name + Should Be Equal As Integers ${rc} ${success_return_code} msg=${stdout} values=False + @{vdur} = Split String ${stdout} + [Return] @{vdur} + diff --git a/robot-systest/lib/prometheus_lib.robot b/robot-systest/lib/prometheus_lib.robot new file mode 100644 index 00000000..d4c6b143 --- /dev/null +++ b/robot-systest/lib/prometheus_lib.robot @@ -0,0 +1,60 @@ +# 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 obtain metrics from Prometheus. + +Library String +Library Collections +Library RequestsLibrary + + +*** Variables *** +${timeout} 1000 +${max_retries} 1 + + +*** Keywords *** +Get Metric + [Documentation] Get the instant value of a metric from Prometheus using multiple filter parameters. + ... The filter parameters are given to this function in key=value format (one argument per key/value pair). + ... Fails if the metric is not found or has multiple values. + ... Examples of execution: + ... \${metric}= Get Metric \${prometheus_ip} \${prometheus_port} \${metric} + ... \${metric}= Get Metric \${prometheus_ip} \${prometheus_port} \${metric} \${param1}=\${value1} \${param2}=\${value2} + + [Arguments] ${prometheus_ip} ${prometheus_port} ${metric} @{filter_parameters} + + ${filter}= Set Variable ${EMPTY} + FOR ${param} IN @{filter_parameters} + ${match} ${param_name} ${param_value} = Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in filter parameters + ${filter}= Catenate SEPARATOR= ${filter} ${param_name}="${param_value}", + END + ${resp}= Execute Prometheus Instant Query ${prometheus_host} ${prometheus_port} query=${metric}{${filter}} + ${result_list}= Convert To List ${resp["data"]["result"]} + ${results}= Get Length ${result_list} + Should Not Be Equal As Numbers 0 ${results} msg=Metric ${metric} not found values=false + Should Be Equal As Integers 1 ${results} msg=Metric ${metric} with multiple values values=false + [Return] ${result_list[0]["value"][1]} + + +Execute Prometheus Instant Query + [Documentation] Execute a Prometheus Instant Query using HTTP API. + ... Return an inline json with the result of the query. + ... The requested URL is the next: http://\${prometheus_ip}:\${prometheus_port}/api/v1/query?\${querystring} + + [Arguments] ${prometheus_ip} ${prometheus_port} ${querystring} + + Create Session prometheus http://${prometheus_ip}:${prometheus_port} timeout=${timeout} max_retries=${max_retries} + ${resp}= Get Request prometheus /api/v1/query?${querystring} timeout=${timeout} + Status Should Be 200 ${resp} + [Return] ${resp.json()} diff --git a/robot-systest/lib/vim_lib.robot b/robot-systest/lib/vim_lib.robot new file mode 100644 index 00000000..b6c452f3 --- /dev/null +++ b/robot-systest/lib/vim_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 VIM Targets. + +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 +${vim_status_max_wait_time} 1min +${vim_status_pol_time} 15sec + + +*** Keywords *** +Create VIM Target + [Documentation] Create a VIM Target in OSM. + ... The optional parameters (such as 'config' or 'sdn_controller') are given to this function in name=value format. These parameters will be appended to the 'osm vim-create' command with the next syntax: --param_name=param_value + ... Return the ID of the created VIM Target. + ... Example of execution: + ... \${vim_account_id}= Create VIM Target \${vim_name} \${vim_user} \${vim_password} \${vim_auth_url} \${vim_tenant} \${vim_account_type} config='{...}' + + [Arguments] ${vim_name} ${vim_user} ${vim_password} ${vim_auth_url} ${vim_tenant} ${vim_account_type} @{optional_parameters} + + ${osm_vim_create_command}= Set Variable osm vim-create --name ${vim_name} --user ${vim_user} --password ${vim_password} --auth_url ${vim_auth_url} --tenant ${vim_tenant} --account_type ${vim_account_type} + FOR ${param} IN @{optional_parameters} + ${match} ${param_name} ${param_value} = Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in optional parameters + ${osm_vim_create_command}= Catenate ${osm_vim_create_command} --${param_name}=${param_value} + END + ${rc} ${stdout}= Run and Return RC and Output ${osm_vim_create_command} + log ${stdout} + Should Be Equal As Integers ${rc} ${success_return_code} + [Return] ${stdout} + + +Delete VIM Target + [Arguments] ${vim_name} + + ${rc} ${stdout}= Run Keyword And Continue On Failure Run and Return RC and Output osm vim-delete ${vim_name} + log ${stdout} + Wait Until Keyword Succeeds ${delete_max_wait_time} ${delete_pol_time} Check for VIM Target ${vim_name} + + +Get VIM Targets + ${rc} ${stdout}= Run and Return RC and Output osm vim-list + log ${stdout} + Should Be Equal As Integers ${rc} ${success_return_code} + + +Check for VIM Target + [Arguments] ${vim_name} + + ${rc} ${stdout}= Run and Return RC and Output osm vim-list | awk '{print $2}' | grep ${vim_name} + Should Not Be Equal As Strings ${stdout} ${vim_name} + + +Check for VIM Target Status + [Arguments] ${vim_name} ${prometheus_host} ${prometheus_port} + + ${vim_account_id}= Get VIM Target ID ${vim_name} + Wait Until Keyword Succeeds ${vim_status_max_wait_time} ${vim_status_pol_time} Check If VIM Target Is Available ${vim_account_id} ${prometheus_host} ${prometheus_port} + + +Get VIM Target ID + [Arguments] ${vim_name} + + ${rc} ${stdout}= Run and Return RC and Output osm vim-list | grep " ${vim_name} " | awk '{print $4}' + Should Be Equal As Integers ${rc} ${success_return_code} + Should Not Be Equal As Strings ${stdout} ${EMPTY} msg=VIM Target '${vim_name}' not found values=false + [Return] ${stdout} + + +Check If VIM Target Is Available + [Arguments] ${vim_account_id} ${prometheus_host} ${prometheus_port} + + ${metric}= Get Metric ${prometheus_host} ${prometheus_port} osm_vim_status vim_account_id=${vim_account_id} + Should Be Equal As Integers ${metric} 1 msg=VIM Target '${vim_account_id}' is not active values=false -- 2.17.1