I like it --> beautyfing of dmi-hw-management.robot
there it is again, my old problem ;) beautyfing of dmi-hw-management.robot
update after review from tthieme
hopefully the last files for beautyfing --> dmi-components-adtran.yaml dmi-components-bbsim.yaml
next file for beautityfing :( -->libraries/utility.py
beautify file dmi-hw-management.robot
add license to file ./tests/data/dmi-components-adtran.yaml
update handling of yaml file, add bbsim- and adtran specific yaml file
corrections due to 'flake8' tool run
add mandatory line in variables.py
cosmetical correction (rflint corrections)
move variable (for dm-bbsim) back to dmi-components.yaml
update grpc/kafka libraries version number in requirement.txt
update name of grpc/kafka libraries (now on pypi.org available)
add variables.py, move variables to file
add device manager test to makefile
second update after second review
update after review
new testcases for the device manager
Signed-off-by: uwe ottrembka <uwe.ottrembka@adtran.com>
Change-Id: I1b9a6187446bbf3dd2794e3f69332d2fcab55e2a
diff --git a/libraries/dmi-basics.robot b/libraries/dmi-basics.robot
new file mode 100755
index 0000000..232af98
--- /dev/null
+++ b/libraries/dmi-basics.robot
@@ -0,0 +1,94 @@
+# Copyright 2020 Open Networking Foundation
+# delivered by ADTRAN, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+*** Settings ***
+Documentation Library for basics of the dmi definition
+Library Collections
+Library BuiltIn
+
+*** Variables ***
+
+*** Keywords ***
+Get Managed Devices
+ [Documentation] search and return for known/active devices
+ [Arguments] ${lib_instance}
+ ${name_active_olts}= Create List
+ ${response}= Run Keyword ${lib_instance}.Hw Management Service Get Managed Devices
+ ${size}= Get Length ${response}
+ Return From Keyword If ${size} == ${0} ${name_active_olts}
+ ${devices}= Get From Dictionary ${response} devices
+ FOR ${device} IN @{devices}
+ ${name}= Get From Dictionary ${device} name
+ Append To List ${name_active_olts} ${name}
+ END
+ [Return] ${name_active_olts}
+
+Stop Managing Devices
+ [Documentation] remove given devices from device manager
+ [Arguments] ${lib_instance} ${name_active_olts}
+ FOR ${device_name} IN @{name_active_olts}
+ &{name}= Evaluate {'name':'${device_name}'}
+ Run Keyword ${lib_instance}.Hw Management Service Stop Managing Device ${name}
+ END
+
+Search For Managed Devices And Stop Managing It
+ [Documentation] search for known/active devices and remove it from device manager
+ [Arguments] ${lib_instance}
+ Run Keyword ${lib_instance}.Connection Open ${DEVICEMANAGER_IP} ${DEVICEMANAGER_PORT}
+ ${active_devices}= Get Managed Devices ${lib_instance}
+ ${size}= Get Length ${active_devices}
+ Run Keyword If ${size} != ${0} Stop Managing Devices ${lib_instance} ${active_devices}
+ Run Keyword If ${size} != ${0} Fail test case '${PREV_TEST_NAME}' failed!
+ ${active_devices}= Get Managed Devices ${lib_instance}
+ Should Be Empty ${active_devices}
+ Run Keyword ${lib_instance}.Connection Close
+
+Increment If Equal
+ [Documentation] increment given value if condition 1 and condition 2 is equal
+ [Arguments] ${condition_1} ${condition_2} ${value}
+ ${value}= Set Variable If ${condition_1} == ${condition_2}
+ ... ${value+1} ${value}
+ [Return] ${value}
+
+Increment If Contained
+ [Documentation] increment given value 'string' contained in 'message'
+ [Arguments] ${message} ${string} ${value}
+ ${hit}= Run Keyword And Return Status Should Contain ${message} ${string}
+ ${value}= Increment If Equal ${hit} ${True} ${value}
+ [Return] ${value}
+
+Start Managing Device
+ [Documentation] add a given device to the device manager
+ [Arguments] ${lib_instance} ${olt_ip} ${device_name} ${check_result}=${True}
+ ${dev_name}= Convert To String ${device_name}
+ &{component}= Evaluate {'name':'${dev_name}', 'uri':{'uri':'${olt_ip}'}}
+ ${response}= Run Keyword ${lib_instance}.Hw Management Service Start Managing Device ${component}
+ ${list}= Get From List ${response} 0
+ Run Keyword If ${check_result} == ${True} Should Be Equal ${list}[status] OK_STATUS
+ ${uuid}= Get From Dictionary ${list} device_uuid
+ [Return] ${uuid}
+
+Stop Managing Device
+ [Documentation] remove a given device from the device manager
+ [Arguments] ${lib_instance} ${device_name} ${check_result}=${True}
+ &{name}= Evaluate {'name':'${device_name}'}
+ ${response}= Run Keyword ${lib_instance}.Hw Management Service Stop Managing Device ${name}
+ Run Keyword If ${check_result} == ${True} Should Be Equal ${response}[status] OK_STATUS
+
+Check Dmi Status
+ [Documentation] check if the given state in the given result
+ [Arguments] ${result} ${state}
+ ${state_in_result}= Get From Dictionary ${result} status
+ Should Be Equal ${state} ${state_in_result}
diff --git a/libraries/utility.py b/libraries/utility.py
new file mode 100755
index 0000000..6faec6e
--- /dev/null
+++ b/libraries/utility.py
@@ -0,0 +1,105 @@
+# Copyright 2020 Open Networking Foundation
+# delivered by ADTRAN, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from __future__ import absolute_import
+from __future__ import print_function
+import inspect
+import os
+
+# global definition of keys (find in given 'inventory_data')
+_NAME = 'name'
+_CHILDREN = 'children'
+_SENSOR_DATA = 'sensor_data'
+_ROOT = 'root'
+_INVENTORY = 'inventory'
+_UUID = 'uuid'
+
+
+def test(success):
+ if success is True:
+ return True
+ return False
+
+
+def unique():
+ """Returns the current filename and line number in our program."""
+ trace = str(os.path.basename(__file__) +
+ "[" + str(inspect.currentframe().f_back.f_lineno) + "]:")
+ return trace
+
+
+# check if given paramter exist in inventory data, search recursive
+def check_in_inventory_Component_data(inventory_data, name, element, value):
+ print(unique(), str(inventory_data), str(name), str(element), str(value))
+ if inventory_data.get(_NAME) == name and inventory_data.get(element) == value:
+ return True
+
+ for child in inventory_data[_CHILDREN]:
+ print(unique(), str(child))
+ if child.get(_NAME) == name and child.get(element) == value:
+ return True
+ if _SENSOR_DATA in child:
+ for sensor_data in child[_SENSOR_DATA]:
+ print(unique(), str(sensor_data))
+ if sensor_data.get(element) == value:
+ return True
+ if _CHILDREN in child:
+ result = check_in_inventory_Component_data(child, name, element, value)
+ if result is True:
+ return result
+ return False
+
+
+# get uuid out of inventory data, search recursive
+def get_uuid_from_inventory_Component_data(inventory_data, searchFor):
+ print(unique(), str(inventory_data), ', ', str(searchFor))
+ if inventory_data.get(_NAME) == searchFor:
+ return inventory_data.get(_UUID)
+ for child in inventory_data[_CHILDREN]:
+ print(unique(), str(child))
+ result = None
+ if child.get(_NAME) == searchFor:
+ print(unique(), str(child[_NAME]))
+ result = child.get(_UUID)
+ print(unique(), child.keys())
+ if result is None and _CHILDREN in child:
+ result = get_uuid_from_inventory_Component_data(child, searchFor)
+ if result is not None:
+ return result
+ return None
+
+
+def get_uuid_from_Inventory_Element(inventory, searchFor):
+ for children in inventory[_INVENTORY][_ROOT][_CHILDREN]:
+ return get_uuid_from_inventory_Component_data(children, searchFor)
+ return None
+
+
+def check_Inventory_Element(inventory, name, element, value):
+ for childrens in inventory[_INVENTORY][_ROOT][_CHILDREN]:
+ return check_in_inventory_Component_data(childrens, name, element, value)
+ return False
+
+
+def getWord(line, number):
+ line_in_list = line.split()
+ if len(line_in_list) >= number-1:
+ return line_in_list[number-1]
+ return ""
+
+
+def decode(data):
+ decoded_data = data
+ print(unique(), str(decoded_data))