| 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 SDNCs. |
| 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 | ${SDNC_DELETE_MAX_WAIT_TIME} 1min |
| 28 | ${SDNC_DELETE_POL_TIME} 15sec |
| 29 | ${SDNC_STATUS_MAX_WAIT_TIME} 6min |
| 30 | ${SDNC_STATUS_POL_TIME} 1min |
| 31 | |
| 32 | |
| 33 | *** Keywords *** |
| 34 | Create SDNC |
| 35 | [Documentation] Register an SDN Controller in OSM. |
| 36 | ... 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 |
| 37 | ... Returns the ID of the created SDNC Target. |
| 38 | ... Example of execution: |
| 39 | ... \${sdnc_id}= Create SDNC \${sdnc_name} \${sdnc_user} \${sdnc_password} \${sdnc_url} \${sdnc_type} switch_dpid='{...}' |
| 40 | [Arguments] ${sdnc_name} ${sdnc_user} ${sdnc_password} ${sdnc_url} ${sdnc_type} @{optional_parameters} |
| 41 | ${osm_sdnc_create_command}= Set Variable osm sdnc-create --name ${sdnc_name} --user ${sdnc_user} --password ${sdnc_password} --url ${sdnc_url} --type ${sdnc_type} |
| 42 | FOR ${param} IN @{optional_parameters} |
| 43 | ${match} ${param_name} ${param_value}= Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in optional parameters |
| 44 | Log ${match},${param_name},${param_value} |
| 45 | ${osm_sdnc_create_command}= Catenate ${osm_sdnc_create_command} --${param_name}=${param_value} |
| 46 | END |
| 47 | ${rc} ${stdout}= Run And Return Rc And Output ${osm_sdnc_create_command} |
| 48 | Log ${stdout} |
| 49 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 50 | RETURN ${stdout} |
| 51 | |
| 52 | Check For SDNC To Be Deleted |
| 53 | [Documentation] Check if an SDN controller identified by name is not present in OSM. |
| 54 | [Arguments] ${sdnc_name} |
| 55 | ${rc} ${stdout}= Run And Return Rc And Output osm sdnc-list | awk '{print $2}' | grep ${sdnc_name} |
| 56 | Log ${rc},${stdout} |
| 57 | Should Not Be Equal As Strings ${stdout} ${sdnc_name} |
| 58 | |
| 59 | Delete SDNC |
| 60 | [Documentation] Unregister/delete from OSM an SDN controller identified by name. |
| 61 | [Arguments] ${sdnc_name} |
| 62 | ${rc} ${stdout}= Run Keyword And Continue On Failure Run And Return Rc And Output osm sdnc-delete ${sdnc_name} |
| 63 | Log ${stdout} |
| 64 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False |
| 65 | Wait Until Keyword Succeeds ${SDNC_DELETE_MAX_WAIT_TIME} ${SDNC_DELETE_POL_TIME} Check For SDNC To Be Deleted ${sdnc_name} |
| 66 | |
| 67 | Get SDNC List |
| 68 | [Documentation] Get the list of SDN controllers from OSM and log it. |
| 69 | ${rc} ${stdout}= Run And Return Rc And Output osm sdnc-list |
| 70 | Log ${stdout} |
| 71 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 72 | |
| 73 | Check For SDNC |
| 74 | [Documentation] Check if an SDN Controller identified by name or id exists in OSM and is enabled. |
| 75 | [Arguments] ${sdnc_id} |
| 76 | ${rc} ${stdout}= Run And Return Rc And Output osm sdnc-show ${sdnc_id} | grep -io ENABLED |
| 77 | Log ${stdout} |
| 78 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 79 | |
| 80 | Check For SDNC Status |
| 81 | [Documentation] Check in a loop if the value of the metric osm_sdnc_status in Prometheus for the SDN controller is 1 (reachable). |
| garciadeblas | d569106 | 2024-09-15 22:35:20 +0200 | [diff] [blame] | 82 | [Arguments] ${sdnc_id} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| 83 | Wait Until Keyword Succeeds ${SDNC_STATUS_MAX_WAIT_TIME} ${SDNC_STATUS_POL_TIME} Check If SDNC Is Available ${sdnc_id} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 84 | |
| 85 | Get SDNC ID |
| 86 | [Documentation] Check if an SDN controller identified by name exists in OSM, and return the id. |
| 87 | [Arguments] ${sdnc_name} |
| 88 | ${rc} ${stdout}= Run And Return Rc And Output osm sdnc-list | grep " ${sdnc_name} " | awk '{print $4}' |
| 89 | Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} |
| 90 | Should Not Be Equal As Strings ${stdout} ${EMPTY} msg=SDNC '${sdnc_name}' not found values=false |
| 91 | RETURN ${stdout} |
| 92 | |
| 93 | Check If SDNC Is Available |
| 94 | [Documentation] Check if the value of the metric osm_sdnc_status in Prometheus for the SDN controller is 1 (reachable). |
| garciadeblas | d569106 | 2024-09-15 22:35:20 +0200 | [diff] [blame] | 95 | [Arguments] ${sdnc_id} ${prometheus_url} ${prometheus_user} ${prometheus_password} |
| 96 | ${metric}= Get Metric ${prometheus_url} ${prometheus_user} ${prometheus_password} osm_sdnc_status sdnc_id=${sdnc_id} |
| garciadeblas | 7a9e031 | 2023-12-11 22:24:46 +0100 | [diff] [blame] | 97 | Should Be Equal As Integers ${metric} 1 msg=SDNC '${sdnc_id}' is not active values=false |