blob: 2f50c9c5d578d923490e5d9956cd0b89d32fd056 [file] [log] [blame]
uwe ottrembka504ca3e2020-11-23 12:02:20 +01001# Copyright 2020 Open Networking Foundation
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 ***
17Documentation Library for basics of the dmi definition
18Library Collections
19Library BuiltIn
20
21*** Variables ***
22
23*** Keywords ***
24Get 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 Windlasse01d3af2022-02-11 06:19:07 +000029 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 ottrembka504ca3e2020-11-23 12:02:20 +010041 ${devices}= Get From Dictionary ${response} devices
Hardik Windlasse01d3af2022-02-11 06:19:07 +000042 FOR ${device} IN @{devices}
uwe ottrembka504ca3e2020-11-23 12:02:20 +010043 ${name}= Get From Dictionary ${device} name
44 Append To List ${name_active_olts} ${name}
45 END
46 [Return] ${name_active_olts}
47
48Stop 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
56Search 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
68Increment 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
75Increment 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
82Start 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
93Stop 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
100Check Dmi Status
101 [Documentation] check if the given state in the given result
102 [Arguments] ${result} ${state}
Hardik Windlasse01d3af2022-02-11 06:19:07 +0000103 ${state_in_result}= Get From Dictionary ${result} status
uwe ottrembka504ca3e2020-11-23 12:02:20 +0100104 Should Be Equal ${state} ${state_in_result}