Commit 0016c72e authored by douomo's avatar douomo
Browse files

fixed counters in the hw inventory check

parent d8c2ee01
Loading
Loading
Loading
Loading
+781 −232

File changed.

Preview size limit exceeded, changes collapsed.

+14 −10
Original line number Original line Diff line number Diff line
@@ -10,32 +10,36 @@ from robot.libraries.BuiltIn import BuiltIn


def check_hardware_inventory(xml_reply):
def check_hardware_inventory(xml_reply):
    tree = ET.fromstring(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"})
    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:
    for comp in value:
        name = comp.findall(".//ns0:name", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"})
        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"})
        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"})
        parent_rel_pos = comp.findall(".//ns0:parent-rel-pos", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"})
        expected_params = expected_params + 4
        expected_params = expected_params + 3
        actual_params = actual_params + 4
        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:
        if len(name)==0:
            actual_params = actual_params - 1
            actual_params = actual_params - 1
            #return "name not found"
            #return "name not found"
        if len(cls)==0:
        if len(cls)==0:
            actual_params = actual_params - 1
            actual_params = actual_params - 1
            #return "Component class not found"
            #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:
        if len(parent_rel_pos)==0:
            actual_params = actual_params - 1
            actual_params = actual_params - 1
            #return "component parent rel pos not found"
            #return "component parent rel pos not found"
        
        parent = comp.findall(".//ns0:parent", namespaces={"ns0" :"urn:ietf:params:xml:ns:yang:ietf-hardware"})
        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"})
        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 "port" in cls[0].text:
            if len(parent) == 0 or len(contains_child)>0:
            if len(parent) == 0 or len(contains_child)>0:
                return "tree not consistent"
                return "tree not consistent"