blob: c1eaf911053e822c618aa8680afccaa3f422ea2d [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
20Resource %{ROBOT_DEVOPS_FOLDER}/lib/prometheus_lib.robot
21
22
23*** Variables ***
24${success_return_code} 0
25${delete_max_wait_time} 1min
26${delete_pol_time} 15sec
aguilard0a366322021-09-09 07:52:37 +000027${vim_status_max_wait_time} 3min
Felipe Vicensf96bb452020-06-22 08:12:30 +020028${vim_status_pol_time} 15sec
aguilard0a366322021-09-09 07:52:37 +000029${vim_opstate_max_wait_time} 40sec
30${vim_opstate_pol_time} 10sec
Felipe Vicensf96bb452020-06-22 08:12:30 +020031
32
33*** Keywords ***
34Create VIM Target
garciadeblasf4ebaa82022-06-23 13:33:26 +020035 [Documentation] Create a VIM Target in OSM.
Felipe Vicensf96bb452020-06-22 08:12:30 +020036 ... 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
37 ... Return the ID of the created VIM Target.
38 ... Example of execution:
garciadeblasf4ebaa82022-06-23 13:33:26 +020039 ... \${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 +020040
garciadeblasf4ebaa82022-06-23 13:33:26 +020041 [Arguments] ${vim_name} ${vim_user} ${vim_password} ${vim_auth_url} ${vim_tenant} ${vim_account_type} @{optional_parameters}
Felipe Vicensf96bb452020-06-22 08:12:30 +020042
garciadeblasf4ebaa82022-06-23 13:33:26 +020043 ${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}
44 FOR ${param} IN @{optional_parameters}
45 ${match} ${param_name} ${param_value} = Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in optional parameters
46 ${osm_vim_create_command}= Catenate ${osm_vim_create_command} --${param_name}=${param_value}
Felipe Vicensf96bb452020-06-22 08:12:30 +020047 END
garciadeblasf4ebaa82022-06-23 13:33:26 +020048 ${rc} ${stdout}= Run and Return RC and Output ${osm_vim_create_command}
garciadeblas321726f2022-12-21 11:43:06 +010049 Log ${stdout}
garciadeblasf4ebaa82022-06-23 13:33:26 +020050 Should Be Equal As Integers ${rc} ${success_return_code}
51 [Return] ${stdout}
Felipe Vicensf96bb452020-06-22 08:12:30 +020052
53
54Delete VIM Target
55 [Arguments] ${vim_name}
56
garciadeblasf4ebaa82022-06-23 13:33:26 +020057 ${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 +010058 Log ${stdout}
garciadeblasf4ebaa82022-06-23 13:33:26 +020059 Wait Until Keyword Succeeds ${delete_max_wait_time} ${delete_pol_time} Check for VIM Target ${vim_name}
Felipe Vicensf96bb452020-06-22 08:12:30 +020060
61
62Get VIM Targets
garciadeblasf4ebaa82022-06-23 13:33:26 +020063 ${rc} ${stdout}= Run and Return RC and Output osm vim-list
garciadeblas321726f2022-12-21 11:43:06 +010064 Log ${stdout}
garciadeblasf4ebaa82022-06-23 13:33:26 +020065 Should Be Equal As Integers ${rc} ${success_return_code}
Felipe Vicensf96bb452020-06-22 08:12:30 +020066
67
68Check for VIM Target
garciadeblasf4ebaa82022-06-23 13:33:26 +020069 [Arguments] ${vim_name}
Felipe Vicensf96bb452020-06-22 08:12:30 +020070
garciadeblasf4ebaa82022-06-23 13:33:26 +020071 ${rc} ${stdout}= Run and Return RC and Output osm vim-list | awk '{print $2}' | grep ${vim_name}
72 Should Not Be Equal As Strings ${stdout} ${vim_name}
Felipe Vicensf96bb452020-06-22 08:12:30 +020073
74
garciadeblas15589052020-10-02 15:40:25 +000075Check for VIM Target Metric
Guillermo Calvino063677c2022-11-21 18:13:58 +010076 [Arguments] ${vim_name} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
garciadeblas15589052020-10-02 15:40:25 +000077
garciadeblasf4ebaa82022-06-23 13:33:26 +020078 ${vim_account_id}= Get VIM Target ID ${vim_name}
Guillermo Calvino063677c2022-11-21 18:13:58 +010079 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 +000080
81
Felipe Vicensf96bb452020-06-22 08:12:30 +020082Check for VIM Target Status
Guillermo Calvino063677c2022-11-21 18:13:58 +010083 [Arguments] ${vim_name} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
Felipe Vicensf96bb452020-06-22 08:12:30 +020084
garciadeblasf4ebaa82022-06-23 13:33:26 +020085 ${vim_account_id}= Get VIM Target ID ${vim_name}
Guillermo Calvino063677c2022-11-21 18:13:58 +010086 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 +020087
88
89Get VIM Target ID
garciadeblasf4ebaa82022-06-23 13:33:26 +020090 [Arguments] ${vim_name}
Felipe Vicensf96bb452020-06-22 08:12:30 +020091
garciadeblasf4ebaa82022-06-23 13:33:26 +020092 ${rc} ${stdout}= Run and Return RC and Output osm vim-list | grep " ${vim_name} " | awk '{print $4}'
93 Should Be Equal As Integers ${rc} ${success_return_code}
94 Should Not Be Equal As Strings ${stdout} ${EMPTY} msg=VIM Target '${vim_name}' not found values=false
95 [Return] ${stdout}
Felipe Vicensf96bb452020-06-22 08:12:30 +020096
97
aguilard0a366322021-09-09 07:52:37 +000098Check VIM Target Operational State
garciadeblasf4ebaa82022-06-23 13:33:26 +020099 [Arguments] ${vim_name}
aguilard0a366322021-09-09 07:52:37 +0000100
garciadeblasf4ebaa82022-06-23 13:33:26 +0200101 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 +0000102
103
104Check If VIM Target Is Enabled
garciadeblasf4ebaa82022-06-23 13:33:26 +0200105 [Arguments] ${vim_name}
aguilard0a366322021-09-09 07:52:37 +0000106
garciadeblasf4ebaa82022-06-23 13:33:26 +0200107 ${rc} ${stdout}= Run and Return RC and Output osm vim-list | grep " ${vim_name} " | awk '{print $6}'
108 Should Be Equal As Integers ${rc} ${success_return_code}
109 Should Be Equal As Strings ${stdout} ENABLED msg=VIM Target '${vim_name}' is not enabled values=false
aguilard0a366322021-09-09 07:52:37 +0000110
111
Felipe Vicensf96bb452020-06-22 08:12:30 +0200112Check If VIM Target Is Available
Guillermo Calvino063677c2022-11-21 18:13:58 +0100113 [Arguments] ${vim_account_id} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
Felipe Vicensf96bb452020-06-22 08:12:30 +0200114
Guillermo Calvino063677c2022-11-21 18:13:58 +0100115 ${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 +0200116 Should Be Equal As Integers ${metric} 1 msg=VIM Target '${vim_account_id}' is not active values=false
garciadeblas15589052020-10-02 15:40:25 +0000117
118
119Check If VIM Target Has Metric
Guillermo Calvino063677c2022-11-21 18:13:58 +0100120 [Arguments] ${vim_account_id} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
garciadeblas15589052020-10-02 15:40:25 +0000121
Guillermo Calvino063677c2022-11-21 18:13:58 +0100122 ${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 +0000123 Should Be True ${metric} <2 msg=VIM Target '${vim_account_id}' has no metric