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
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 Documentation Library to manage SDNCs.
20 Library OperatingSystem
22 Resource ../lib/prometheus_lib.resource
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
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}
47 ${rc} ${stdout}= Run And Return Rc And Output ${osm_sdnc_create_command}
49 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
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}
57 Should Not Be Equal As Strings ${stdout} ${sdnc_name}
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}
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}
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
71 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
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
78 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
81 [Documentation] Check in a loop if the value of the metric osm_sdnc_status in Prometheus for the SDN controller is 1 (reachable).
82 [Arguments] ${sdnc_id} ${prometheus_host} ${prometheus_port} ${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_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
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
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).
95 [Arguments] ${sdnc_id} ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password}
96 ${metric}= Get Metric ${prometheus_host} ${prometheus_port} ${prometheus_user} ${prometheus_password} osm_sdnc_status sdnc_id=${sdnc_id}
97 Should Be Equal As Integers ${metric} 1 msg=SDNC '${sdnc_id}' is not active values=false