blob: 2c96802c286e1519b294192480aa82f29c959672 [file] [log] [blame]
Felipe Vicensf96bb452020-06-22 08:12:30 +02001# Licensed under the Apache License, Version 2.0 (the "License");
2# you may not use this file except in compliance with the License.
3# You may obtain a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10# See the License for the specific language governing permissions and
11# limitations under the License.
12
13*** Settings ***
garciadeblasf4ebaa82022-06-23 13:33:26 +020014Documentation Library to manage VIM Targets.
Felipe Vicensf96bb452020-06-22 08:12:30 +020015
16Library String
17Library Collections
18Library OperatingSystem
19
garciadeblasa351dd22023-06-27 12:07:08 +020020# Gerardo
Felipe Vicensf96bb452020-06-22 08:12:30 +020021Resource %{ROBOT_DEVOPS_FOLDER}/lib/prometheus_lib.robot
22
23
24*** Variables ***
25${success_return_code} 0
26${delete_max_wait_time} 1min
27${delete_pol_time} 15sec
aguilard0a366322021-09-09 07:52:37 +000028${vim_status_max_wait_time} 3min
Felipe Vicensf96bb452020-06-22 08:12:30 +020029${vim_status_pol_time} 15sec
aguilard0a366322021-09-09 07:52:37 +000030${vim_opstate_max_wait_time} 40sec
31${vim_opstate_pol_time} 10sec
Felipe Vicensf96bb452020-06-22 08:12:30 +020032
33
34*** Keywords ***
35Create VIM Target
garciadeblasf4ebaa82022-06-23 13:33:26 +020036 [Documentation] Create a VIM Target in OSM.
Felipe Vicensf96bb452020-06-22 08:12:30 +020037 ... 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
38 ... Return the ID of the created VIM Target.
39 ... Example of execution:
garciadeblasf4ebaa82022-06-23 13:33:26 +020040 ... \${vim_account_id}= Create VIM Target \${vim_name} \${vim_user} \${vim_password} \${vim_auth_url} \${vim_tenant} \${vim_account_type} config='{...}'
Felipe Vicensf96bb452020-06-22 08:12:30 +020041
garciadeblasf4ebaa82022-06-23 13:33:26 +020042 [Arguments] ${vim_name} ${vim_user} ${vim_password} ${vim_auth_url} ${vim_tenant} ${vim_account_type} @{optional_parameters}
Felipe Vicensf96bb452020-06-22 08:12:30 +020043
garciadeblasf4ebaa82022-06-23 13:33:26 +020044 ${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}
45 FOR ${param} IN @{optional_parameters}
46 ${match} ${param_name} ${param_value} = Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in optional parameters
47 ${osm_vim_create_command}= Catenate ${osm_vim_create_command} --${param_name}=${param_value}
Felipe Vicensf96bb452020-06-22 08:12:30 +020048 END
garciadeblasf4ebaa82022-06-23 13:33:26 +020049 ${rc} ${stdout}= Run and Return RC and Output ${osm_vim_create_command}
garciadeblas321726f2022-12-21 11:43:06 +010050 Log ${stdout}
garciadeblasf4ebaa82022-06-23 13:33:26 +020051 Should Be Equal As Integers ${rc} ${success_return_code}
52 [Return] ${stdout}
Felipe Vicensf96bb452020-06-22 08:12:30 +020053
54
55Delete VIM Target
56 [Arguments] ${vim_name}
57
garciadeblasf4ebaa82022-06-23 13:33:26 +020058 ${rc} ${stdout}= Run Keyword And Continue On Failure Run and Return RC and Output osm vim-delete ${vim_name}
garciadeblas321726f2022-12-21 11:43:06 +010059 Log ${stdout}
garciadeblasf4ebaa82022-06-23 13:33:26 +020060 Wait Until Keyword Succeeds ${delete_max_wait_time} ${delete_pol_time} Check for VIM Target ${vim_name}
Felipe Vicensf96bb452020-06-22 08:12:30 +020061
62
63Get VIM Targets
garciadeblasf4ebaa82022-06-23 13:33:26 +020064 ${rc} ${stdout}= Run and Return RC and Output osm vim-list
garciadeblas321726f2022-12-21 11:43:06 +010065 Log ${stdout}
garciadeblasf4ebaa82022-06-23 13:33:26 +020066 Should Be Equal As Integers ${rc} ${success_return_code}
Felipe Vicensf96bb452020-06-22 08:12:30 +020067
68
69Check for VIM Target
garciadeblasf4ebaa82022-06-23 13:33:26 +020070 [Arguments] ${vim_name}
Felipe Vicensf96bb452020-06-22 08:12:30 +020071
garciadeblasf4ebaa82022-06-23 13:33:26 +020072 ${rc} ${stdout}= Run and Return RC and Output osm vim-list | awk '{print $2}' | grep ${vim_name}
73 Should Not Be Equal As Strings ${stdout} ${vim_name}
Felipe Vicensf96bb452020-06-22 08:12:30 +020074
75
garciadeblas15589052020-10-02 15:40:25 +000076Check for VIM Target Metric
Guillermo Calvino063677c2022-11-21 18:13:58 +010077 [Arguments] ${vim_name} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
garciadeblas15589052020-10-02 15:40:25 +000078
garciadeblasf4ebaa82022-06-23 13:33:26 +020079 ${vim_account_id}= Get VIM Target ID ${vim_name}
Guillermo Calvino063677c2022-11-21 18:13:58 +010080 Wait Until Keyword Succeeds ${vim_status_max_wait_time} ${vim_status_pol_time} Check If VIM Target Has Metric ${vim_account_id} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
garciadeblas15589052020-10-02 15:40:25 +000081
82
Felipe Vicensf96bb452020-06-22 08:12:30 +020083Check for VIM Target Status
Guillermo Calvino063677c2022-11-21 18:13:58 +010084 [Arguments] ${vim_name} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
Felipe Vicensf96bb452020-06-22 08:12:30 +020085
garciadeblasf4ebaa82022-06-23 13:33:26 +020086 ${vim_account_id}= Get VIM Target ID ${vim_name}
Guillermo Calvino063677c2022-11-21 18:13:58 +010087 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} ${prometheus_user} ${prometheus_password}
Felipe Vicensf96bb452020-06-22 08:12:30 +020088
89
90Get VIM Target ID
garciadeblasf4ebaa82022-06-23 13:33:26 +020091 [Arguments] ${vim_name}
Felipe Vicensf96bb452020-06-22 08:12:30 +020092
garciadeblasf4ebaa82022-06-23 13:33:26 +020093 ${rc} ${stdout}= Run and Return RC and Output osm vim-list | grep " ${vim_name} " | awk '{print $4}'
94 Should Be Equal As Integers ${rc} ${success_return_code}
95 Should Not Be Equal As Strings ${stdout} ${EMPTY} msg=VIM Target '${vim_name}' not found values=false
96 [Return] ${stdout}
Felipe Vicensf96bb452020-06-22 08:12:30 +020097
98
aguilard0a366322021-09-09 07:52:37 +000099Check VIM Target Operational State
garciadeblasf4ebaa82022-06-23 13:33:26 +0200100 [Arguments] ${vim_name}
aguilard0a366322021-09-09 07:52:37 +0000101
garciadeblasf4ebaa82022-06-23 13:33:26 +0200102 Wait Until Keyword Succeeds ${vim_opstate_max_wait_time} ${vim_opstate_pol_time} Check If VIM Target Is Enabled ${vim_name}
aguilard0a366322021-09-09 07:52:37 +0000103
104
105Check If VIM Target Is Enabled
garciadeblasf4ebaa82022-06-23 13:33:26 +0200106 [Arguments] ${vim_name}
aguilard0a366322021-09-09 07:52:37 +0000107
garciadeblasf4ebaa82022-06-23 13:33:26 +0200108 ${rc} ${stdout}= Run and Return RC and Output osm vim-list | grep " ${vim_name} " | awk '{print $6}'
109 Should Be Equal As Integers ${rc} ${success_return_code}
110 Should Be Equal As Strings ${stdout} ENABLED msg=VIM Target '${vim_name}' is not enabled values=false
aguilard0a366322021-09-09 07:52:37 +0000111
112
Felipe Vicensf96bb452020-06-22 08:12:30 +0200113Check If VIM Target Is Available
Guillermo Calvino063677c2022-11-21 18:13:58 +0100114 [Arguments] ${vim_account_id} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
Felipe Vicensf96bb452020-06-22 08:12:30 +0200115
Guillermo Calvino063677c2022-11-21 18:13:58 +0100116 ${metric}= Get Metric ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password} osm_vim_status vim_account_id=${vim_account_id}
garciadeblasf4ebaa82022-06-23 13:33:26 +0200117 Should Be Equal As Integers ${metric} 1 msg=VIM Target '${vim_account_id}' is not active values=false
garciadeblas15589052020-10-02 15:40:25 +0000118
119
120Check If VIM Target Has Metric
Guillermo Calvino063677c2022-11-21 18:13:58 +0100121 [Arguments] ${vim_account_id} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
garciadeblas15589052020-10-02 15:40:25 +0000122
Guillermo Calvino063677c2022-11-21 18:13:58 +0100123 ${metric}= Get Metric ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password} osm_vim_status vim_account_id=${vim_account_id}
garciadeblas15589052020-10-02 15:40:25 +0000124 Should Be True ${metric} <2 msg=VIM Target '${vim_account_id}' has no metric