def test_parse_interface_list_data(stc):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug('start.test_parse_interface_list_data')
    input_string = '''{
        "ParentTagName": "ttIpv4If",
        "ClassName": "Ipv4If",
        "PropertyValueDict": {
            "PrefixLength": ["22", "11"],
            "IfCountPerLowerIf": ["2", "1"]
        },
        "StmPropertyModifierDict": {
            "Address": {
                "Start": ["2.2.2.2", "0.0.0.0"],
                "Step": ["0.0.0.1", "0.0.0.0"]
            },
            "Gateway": {
                "Start": ["2.2.2.1", "0.0.0.0"],
                "Step": "0.0.1.0"
            }
        }
    }'''

    expected_prop_val = {}
    expected_prop_val["className"] = "Ipv4If"
    expected_prop_val["tagName"] = "ttIpv4If"
    expected_prop_val["propertyValueList"] = {}
    expected_prop_val["propertyValueList"]["PrefixLength"] = "22"
    expected_prop_val["propertyValueList"]["IfCountPerLowerIf"] = "2"

    expected_prop_mod1 = {}
    expected_prop_mod1["className"] = "Ipv4If"
    expected_prop_mod1["tagName"] = "ttIpv4If.Address"
    expected_prop_mod1["parentTagName"] = "ttIpv4If"
    expected_prop_mod1["propertyName"] = "Address"
    expected_prop_mod1["propertyValueList"] = {}
    expected_prop_mod1["propertyValueList"]["Start"] = "2.2.2.2"
    expected_prop_mod1["propertyValueList"]["Step"] = "0.0.0.1"

    expected_prop_mod2 = {}
    expected_prop_mod2["className"] = "Ipv4If"
    expected_prop_mod2["tagName"] = "ttIpv4If.Gateway"
    expected_prop_mod2["parentTagName"] = "ttIpv4If"
    expected_prop_mod2["propertyName"] = "Gateway"
    expected_prop_mod2["propertyValueList"] = {}
    expected_prop_mod2["propertyValueList"]["Start"] = "2.2.2.1"
    expected_prop_mod2["propertyValueList"]["Step"] = "0.0.1.0"

    err_str, input_table_data = json_utils.load_json(input_string)
    assert err_str == ""
    # Call parse on the first row
    res = process_util.parse_interface_data(input_table_data, 0)

    assert len(res["propertyValueList"]) == 1
    assert cmp(res["propertyValueList"][0], expected_prop_val) == 0

    assert len(res["stmPropertyModifierList"]) == 2
    assert expected_prop_mod1 in res["stmPropertyModifierList"]
    assert expected_prop_mod2 in res["stmPropertyModifierList"]
def config_table_data(input_dict):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug('begin.txml_processing_functions.config_table_data')

    output_dict = {}
    err_msg = ""
    json_data_list = []

    plLogger.LogDebug('input_dict: ' + str(input_dict))

    # Validate the input_dict
    res = validate_input_dict(input_dict)
    if res != "":
        return output_dict, res

    # Loop through each row in the txml table
    weight_list = input_dict["input"]["customDict"]["Weight"]

    for row_idx, weight in enumerate(weight_list):
        json_data = {}
        json_data["weight"] = float(weight)

        enable_vlan = input_dict["input"]["customDict"]["EnableVlan"][row_idx]
        if ast.literal_eval(enable_vlan):
            json_data["baseTemplateFile"] = "Dual_Vlan.xml"
        else:
            json_data["baseTemplateFile"] = "Dual_NoVlan.xml"

        json_data["protocolTemplateFile"] = "AllRouters.xml"
        json_data["deviceTag"] = "ttEmulatedDevice"
        json_data["useBlock"] = False
        enable_bfd = False
        bfd_protocol = {}
        json_data["interfaceList"] = []
        json_data["protocolList"] = []

        # Loop through the interfaceDict in the input_dict and
        # add each interface to the interfaceList in the output_dict
        for interface in input_dict["input"]["interfaceDict"]:
            # Don't add the VlanIf if EnableVlan is False
            if interface["ClassName"] == "VlanIf" and \
               ast.literal_eval(enable_vlan) is False:
                continue
            else:
                json_data["interfaceList"].append(
                    process_util.parse_interface_data(interface, row_idx))

        # Loop through the protocolDict in the input_dict and
        # add each protocol to the protocolList in the output_dict
        for protocol in input_dict["input"]["protocolDict"]:
            # Add the protocol to the protocolList if it is enabled
            if "EnableProperty" in protocol.keys():
                if ast.literal_eval(protocol["EnableProperty"][row_idx]):
                    if "EnableBfd" in protocol["PropertyValueDict"].keys():
                        enable_bfd |= ast.literal_eval(
                            protocol["PropertyValueDict"]["EnableBfd"][row_idx])
                    json_data["protocolList"].append(
                        process_util.parse_protocol_data(protocol, row_idx))

            # BfdRouterConfig will be handled after all other protocols are parsed
            if protocol["ClassName"] == "BfdRouterConfig":
                bfd_protocol = protocol

        # Bfd is added to the protocolList if bfd is enabled in at least one protocol and
        # the BfdRouterConfig information is defined in input_dict
        if enable_bfd is True and len(bfd_protocol) != 0:
            json_data["protocolList"].append(
                process_util.parse_protocol_data(bfd_protocol, row_idx))

        json_data_list.append(json_data)

    # f = open('out.txt', 'w')
    # f.write(json.dumps(json_data_list))
    # f.write(str(json_data_list))

    output_dict["TableData"] = json.dumps(json_data_list)
    plLogger.LogDebug('output_dict: ' + str(output_dict))
    plLogger.LogDebug('end.txml_processing_functions.config_table_data')
    return output_dict, err_msg