| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 1 | *** Comments *** |
| 2 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | # you may not use this file except in compliance with the License. |
| 4 | # You may obtain a copy of the License at |
| 5 | # |
| 6 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | # |
| 8 | # Unless required by applicable law or agreed to in writing, software |
| 9 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
| 13 | |
| 14 | |
| 15 | *** Settings *** |
| 16 | Documentation Library to manage VIM Targets. |
| 17 | |
| 18 | Library String |
| 19 | Library Collections |
| 20 | Library OperatingSystem |
| 21 | |
| 22 | Resource ../lib/prometheus_lib.resource |
| 23 | |
| 24 | |
| 25 | *** Variables *** |
| 26 | ${SUCCESS_RETURN_CODE} 0 |
| 27 | ${VIM_DELETE_MAX_WAIT_TIME} 1min |
| 28 | ${VIM_DELETE_POL_TIME} 15sec |
| 29 | ${VIM_STATUS_MAX_WAIT_TIME} 3min |
| 30 | ${VIM_STATUS_POL_TIME} 15sec |
| 31 | ${VIM_OPSTATE_MAX_WAIT_TIME} 40sec |
| 32 | ${VIM_OPSTATE_POL_TIME} 10sec |
| 33 | |
| 34 | |
| 35 | *** Keywords *** |
| 36 | Create VIM Target |
| 37 | [Documentation] Register a VIM account in OSM and return the id. |
| 38 | ... 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 |
| 39 | ... Return the ID of the created VIM Target. |
| 40 | ... Example of execution: |
| 41 | ... \${vim_account_id}= Create VIM Target \${vim_name} \${vim_user} \${vim_password} \${vim_auth_url} \${vim_tenant} \${vim_account_type} config='{...}' |
| 42 | [Arguments] ${vim_name} ${vim_user} ${vim_password} ${vim_auth_url} ${vim_tenant} ${vim_account_type} @{optional_parameters} |
| 43 | ${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 | Log ${match},${param_name},${param_value} |
| 47 | ${osm_vim_create_command}= Catenate ${osm_vim_create_command} --${param_name}=${param_value} |
| 48 | END |
| 49 | ${rc} ${stdout}= Run And Return Rc And Output ${osm_vim_create_command} |
| 50 | Log ${stdout} |
| 51 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 52 | RETURN ${stdout} |
| 53 | |
| 54 | Delete VIM Target |
| 55 | [Documentation] Unregister/delete a VIM account from OSM. |
| 56 | [Arguments] ${vim_name} |
| 57 | ${rc} ${stdout}= Run Keyword And Continue On Failure Run And Return Rc And Output osm vim-delete ${vim_name} |
| 58 | Log ${rc},${stdout} |
| 59 | Wait Until Keyword Succeeds ${VIM_DELETE_MAX_WAIT_TIME} ${VIM_DELETE_POL_TIME} Check For VIM Target ${vim_name} |
| 60 | |
| 61 | Get VIM Targets |
| 62 | [Documentation] Get the list of VIM accounts in OSM. |
| 63 | ${rc} ${stdout}= Run And Return Rc And Output osm vim-list |
| 64 | Log ${stdout} |
| 65 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 66 | |
| 67 | Check For VIM Target |
| 68 | [Documentation] Check if a VIM account has been registered in OSM. |
| 69 | [Arguments] ${vim_name} |
| 70 | ${rc} ${stdout}= Run And Return Rc And Output osm vim-list | awk '{print $2}' | grep ${vim_name} |
| 71 | Log ${rc},${stdout} |
| 72 | Should Not Be Equal As Strings ${stdout} ${vim_name} |
| 73 | |
| 74 | Check For VIM Target Metric |
| 75 | [Documentation] Check in a loop if the metric of osm_vim_status is present in Prometheus for the VIM account in OSM. |
| garciadeblas | d569106 | 2024-09-15 22:35:20 +0200 | [diff] [blame] | 76 | [Arguments] ${vim_name} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 77 | ${vim_account_id}= Get VIM Target ID ${vim_name} |
| garciadeblas | d569106 | 2024-09-15 22:35:20 +0200 | [diff] [blame] | 78 | Wait Until Keyword Succeeds ${VIM_STATUS_MAX_WAIT_TIME} ${VIM_STATUS_POL_TIME} Check If VIM Target Has Metric ${vim_account_id} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 79 | |
| 80 | Check For VIM Target Status |
| 81 | [Documentation] Check in a loop if the value of the metric osm_vim_status in Prometheus for the VIM account is 1 (reachable). |
| garciadeblas | d569106 | 2024-09-15 22:35:20 +0200 | [diff] [blame] | 82 | [Arguments] ${vim_name} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 83 | ${vim_account_id}= Get VIM Target ID ${vim_name} |
| garciadeblas | d569106 | 2024-09-15 22:35:20 +0200 | [diff] [blame] | 84 | Wait Until Keyword Succeeds ${VIM_STATUS_MAX_WAIT_TIME} ${VIM_STATUS_POL_TIME} Check If VIM Target Is Available ${vim_account_id} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 85 | |
| 86 | Get VIM Target ID |
| 87 | [Documentation] Get from OSM the VIM account id associated to the VIM account name passed as parameter. |
| 88 | [Arguments] ${vim_name} |
| 89 | ${rc} ${stdout}= Run And Return Rc And Output osm vim-list | grep " ${vim_name} " | awk '{print $4}' |
| 90 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 91 | Should Not Be Equal As Strings ${stdout} ${EMPTY} msg=VIM Target '${vim_name}' not found values=false |
| 92 | RETURN ${stdout} |
| 93 | |
| 94 | Check VIM Target Operational State |
| 95 | [Documentation] Check if the VIM account in OSM is enabled. |
| 96 | [Arguments] ${vim_name} |
| 97 | Wait Until Keyword Succeeds ${VIM_OPSTATE_MAX_WAIT_TIME} ${VIM_OPSTATE_POL_TIME} Check If VIM Target Is Enabled ${vim_name} |
| 98 | |
| 99 | Check If VIM Target Is Enabled |
| 100 | [Documentation] Check if the VIM account passed as argument is enabled in OSM (meaning that the RO could reach the VIM account). |
| 101 | [Arguments] ${vim_name} |
| 102 | ${rc} ${stdout}= Run And Return Rc And Output osm vim-list | grep " ${vim_name} " | awk '{print $6}' |
| 103 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 104 | Should Be Equal As Strings ${stdout} ENABLED msg=VIM Target '${vim_name}' is not enabled values=false |
| 105 | |
| 106 | Check If VIM Target Is Available |
| 107 | [Documentation] Check if the value of the metric osm_vim_status in Prometheus for the VIM account is 1 (reachable). |
| garciadeblas | d569106 | 2024-09-15 22:35:20 +0200 | [diff] [blame] | 108 | [Arguments] ${vim_account_id} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| 109 | Log ${prometheus_url} |
| 110 | Log ${prometheus_user} |
| 111 | Log ${prometheus_password} |
| 112 | Log ${vim_account_id} |
| 113 | ${metric}= Get Metric ${prometheus_url} ${prometheus_user} ${prometheus_password} osm_vim_status vim_account_id=${vim_account_id} |
| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 114 | Should Be Equal As Integers ${metric} 1 msg=VIM Target '${vim_account_id}' is not active values=false |
| 115 | |
| 116 | Check If VIM Target Has Metric |
| 117 | [Documentation] Check if the metric of osm_vim_status is present in Prometheus for the VIM account in OSM. |
| garciadeblas | d569106 | 2024-09-15 22:35:20 +0200 | [diff] [blame] | 118 | [Arguments] ${vim_account_id} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| 119 | ${metric}= Get Metric ${prometheus_url} ${prometheus_user} ${prometheus_password} osm_vim_status vim_account_id=${vim_account_id} |
| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 120 | Should Be True ${metric} <2 msg=VIM Target '${vim_account_id}' has no metric |