Loading __pycache__/validateInventory.cpython-312.pyc +685 B (18 KiB) File changed.No diff preview for this file type. View original file View changed file tmp.py +781 −232 File changed.Preview size limit exceeded, changes collapsed. Show changes validateInventory.py +14 −10 Original line number Diff line number Diff line Loading @@ -10,32 +10,36 @@ from robot.libraries.BuiltIn import BuiltIn def check_hardware_inventory(xml_reply): tree = ET.fromstring(xml_reply) expected_params = 2 value = tree.findall(".//ns1:component", namespaces={"ns0" :"urn:ietf:params:xml:ns:netconf:base:1.0","ns1": "urn:ietf:params:xml:ns:yang:ietf-hardware"}) expected_params = 0 actual_params = 0 hw_rev = tree.findall(".//ns0:hardware-rev", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) sw_rev = tree.findall(".//ns0:software-rev", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) actual_params = min([1,len(hw_rev)]) + min([1,len(sw_rev)]) #at least one occurrence is needed for comp in value: name = comp.findall(".//ns0:name", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) cls = comp.findall(".//ns0:class", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) hw_rev = comp.findall(".//ns0:hardware-rev", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) parent_rel_pos = comp.findall(".//ns0:parent-rel-pos", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) expected_params = expected_params + 4 actual_params = actual_params + 4 expected_params = expected_params + 3 actual_params = actual_params + 3 serial_num = comp.findall(".//ns0:serial-num", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) if len(name)==0: actual_params = actual_params - 1 #return "name not found" if len(cls)==0: actual_params = actual_params - 1 #return "Component class not found" if len(hw_rev)==0: actual_params = actual_params - 1 #return "hw rev not found" if len(parent_rel_pos)==0: actual_params = actual_params - 1 #return "component parent rel pos not found" parent = comp.findall(".//ns0:parent", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) contains_child = comp.findall(".//ns0:contains-child", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) if "chassis" in cls[0].text or "module" in cls[0].text: expected_params = expected_params + 1 actual_params = actual_params + min([1,len(serial_num)]) if len(serial_num)==0: print("not found serial num for component ",cls[0].text," with name ",name[0].text) if "port" in cls[0].text: if len(parent) == 0 or len(contains_child)>0: return "tree not consistent" Loading Loading
__pycache__/validateInventory.cpython-312.pyc +685 B (18 KiB) File changed.No diff preview for this file type. View original file View changed file
validateInventory.py +14 −10 Original line number Diff line number Diff line Loading @@ -10,32 +10,36 @@ from robot.libraries.BuiltIn import BuiltIn def check_hardware_inventory(xml_reply): tree = ET.fromstring(xml_reply) expected_params = 2 value = tree.findall(".//ns1:component", namespaces={"ns0" :"urn:ietf:params:xml:ns:netconf:base:1.0","ns1": "urn:ietf:params:xml:ns:yang:ietf-hardware"}) expected_params = 0 actual_params = 0 hw_rev = tree.findall(".//ns0:hardware-rev", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) sw_rev = tree.findall(".//ns0:software-rev", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) actual_params = min([1,len(hw_rev)]) + min([1,len(sw_rev)]) #at least one occurrence is needed for comp in value: name = comp.findall(".//ns0:name", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) cls = comp.findall(".//ns0:class", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) hw_rev = comp.findall(".//ns0:hardware-rev", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) parent_rel_pos = comp.findall(".//ns0:parent-rel-pos", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) expected_params = expected_params + 4 actual_params = actual_params + 4 expected_params = expected_params + 3 actual_params = actual_params + 3 serial_num = comp.findall(".//ns0:serial-num", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) if len(name)==0: actual_params = actual_params - 1 #return "name not found" if len(cls)==0: actual_params = actual_params - 1 #return "Component class not found" if len(hw_rev)==0: actual_params = actual_params - 1 #return "hw rev not found" if len(parent_rel_pos)==0: actual_params = actual_params - 1 #return "component parent rel pos not found" parent = comp.findall(".//ns0:parent", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) contains_child = comp.findall(".//ns0:contains-child", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"}) if "chassis" in cls[0].text or "module" in cls[0].text: expected_params = expected_params + 1 actual_params = actual_params + min([1,len(serial_num)]) if len(serial_num)==0: print("not found serial num for component ",cls[0].text," with name ",name[0].text) if "port" in cls[0].text: if len(parent) == 0 or len(contains_child)>0: return "tree not consistent" Loading