Joey Armstrong | 9fadcbe | 2024-01-17 19:00:37 -0500 | [diff] [blame^] | 1 | # Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
uwe ottrembka | 504ca3e | 2020-11-23 12:02:20 +0100 | [diff] [blame] | 2 | # delivered by ADTRAN, Inc. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | *** Settings *** |
| 17 | Documentation Library for basics of the dmi definition |
| 18 | Library Collections |
| 19 | Library BuiltIn |
| 20 | |
| 21 | *** Variables *** |
| 22 | |
| 23 | *** Keywords *** |
| 24 | Get Managed Devices |
| 25 | [Documentation] search and return for known/active devices |
| 26 | [Arguments] ${lib_instance} |
| 27 | ${name_active_olts}= Create List |
| 28 | ${response}= Run Keyword ${lib_instance}.Hw Management Service Get Managed Devices |
Hardik Windlass | e01d3af | 2022-02-11 06:19:07 +0000 | [diff] [blame] | 29 | Log ${response} |
| 30 | Check Dmi Status ${response} OK_STATUS |
| 31 | ${keys}= Create List |
| 32 | ${keys}= Get Dictionary Keys ${response} |
| 33 | ${devices_key_found}= Set Variable False |
| 34 | ${length}= Get Length ${keys} |
| 35 | FOR ${I} IN RANGE 0 ${length} |
| 36 | ${value}= Get From List ${keys} ${I} |
| 37 | ${devices_key_found}= Set Variable If '${value}'=='devices' True False |
| 38 | Exit For Loop If ${devices_key_found} |
| 39 | END |
| 40 | Return From Keyword If '${devices_key_found}'=='False' ${name_active_olts} |
uwe ottrembka | 504ca3e | 2020-11-23 12:02:20 +0100 | [diff] [blame] | 41 | ${devices}= Get From Dictionary ${response} devices |
Hardik Windlass | e01d3af | 2022-02-11 06:19:07 +0000 | [diff] [blame] | 42 | FOR ${device} IN @{devices} |
uwe ottrembka | 504ca3e | 2020-11-23 12:02:20 +0100 | [diff] [blame] | 43 | ${name}= Get From Dictionary ${device} name |
| 44 | Append To List ${name_active_olts} ${name} |
| 45 | END |
| 46 | [Return] ${name_active_olts} |
| 47 | |
| 48 | Stop Managing Devices |
| 49 | [Documentation] remove given devices from device manager |
| 50 | [Arguments] ${lib_instance} ${name_active_olts} |
| 51 | FOR ${device_name} IN @{name_active_olts} |
| 52 | &{name}= Evaluate {'name':'${device_name}'} |
| 53 | Run Keyword ${lib_instance}.Hw Management Service Stop Managing Device ${name} |
| 54 | END |
| 55 | |
| 56 | Search For Managed Devices And Stop Managing It |
| 57 | [Documentation] search for known/active devices and remove it from device manager |
| 58 | [Arguments] ${lib_instance} |
| 59 | Run Keyword ${lib_instance}.Connection Open ${DEVICEMANAGER_IP} ${DEVICEMANAGER_PORT} |
| 60 | ${active_devices}= Get Managed Devices ${lib_instance} |
| 61 | ${size}= Get Length ${active_devices} |
| 62 | Run Keyword If ${size} != ${0} Stop Managing Devices ${lib_instance} ${active_devices} |
| 63 | Run Keyword If ${size} != ${0} Fail test case '${PREV_TEST_NAME}' failed! |
| 64 | ${active_devices}= Get Managed Devices ${lib_instance} |
| 65 | Should Be Empty ${active_devices} |
| 66 | Run Keyword ${lib_instance}.Connection Close |
| 67 | |
| 68 | Increment If Equal |
| 69 | [Documentation] increment given value if condition 1 and condition 2 is equal |
| 70 | [Arguments] ${condition_1} ${condition_2} ${value} |
| 71 | ${value}= Set Variable If ${condition_1} == ${condition_2} |
| 72 | ... ${value+1} ${value} |
| 73 | [Return] ${value} |
| 74 | |
| 75 | Increment If Contained |
| 76 | [Documentation] increment given value 'string' contained in 'message' |
| 77 | [Arguments] ${message} ${string} ${value} |
| 78 | ${hit}= Run Keyword And Return Status Should Contain ${message} ${string} |
| 79 | ${value}= Increment If Equal ${hit} ${True} ${value} |
| 80 | [Return] ${value} |
| 81 | |
| 82 | Start Managing Device |
| 83 | [Documentation] add a given device to the device manager |
| 84 | [Arguments] ${lib_instance} ${olt_ip} ${device_name} ${check_result}=${True} |
| 85 | ${dev_name}= Convert To String ${device_name} |
| 86 | &{component}= Evaluate {'name':'${dev_name}', 'uri':{'uri':'${olt_ip}'}} |
| 87 | ${response}= Run Keyword ${lib_instance}.Hw Management Service Start Managing Device ${component} |
| 88 | ${list}= Get From List ${response} 0 |
| 89 | Run Keyword If ${check_result} == ${True} Should Be Equal ${list}[status] OK_STATUS |
| 90 | ${uuid}= Get From Dictionary ${list} device_uuid |
| 91 | [Return] ${uuid} |
| 92 | |
| 93 | Stop Managing Device |
| 94 | [Documentation] remove a given device from the device manager |
| 95 | [Arguments] ${lib_instance} ${device_name} ${check_result}=${True} |
| 96 | &{name}= Evaluate {'name':'${device_name}'} |
| 97 | ${response}= Run Keyword ${lib_instance}.Hw Management Service Stop Managing Device ${name} |
| 98 | Run Keyword If ${check_result} == ${True} Should Be Equal ${response}[status] OK_STATUS |
| 99 | |
| 100 | Check Dmi Status |
| 101 | [Documentation] check if the given state in the given result |
| 102 | [Arguments] ${result} ${state} |
Hardik Windlass | e01d3af | 2022-02-11 06:19:07 +0000 | [diff] [blame] | 103 | ${state_in_result}= Get From Dictionary ${result} status |
uwe ottrembka | 504ca3e | 2020-11-23 12:02:20 +0100 | [diff] [blame] | 104 | Should Be Equal ${state} ${state_in_result} |