def test_validate_property_tuple(stc):
    class_name = "BfdRouterConfig"
    good_list = [("ScaleMode", "NORMAL"), ("DetectMultiplier", "3"), ("BfdCcChannelType", "34")]
    res, ret_list = dm_utils.validate_property_tuple(class_name, good_list)
    assert res == ""
    lower_list = [("scalemode", "NORMAL"), ("detectmultiplier", "3"), ("bfdccchanneltype", "34")]
    res, ret_list = dm_utils.validate_property_tuple(class_name, lower_list)
    assert res == ""
    assert lower_list != ret_list
    low_name_orig = [o[0].lower() for o in lower_list]
    low_name_res = [o[0].lower() for o in ret_list]
    assert low_name_orig == low_name_res

    # Test validating a list property
    class_name = "Ipv4NetworkBlock"
    non_list = [("StartIpList", "1.1.1.1")]
    res, ret_list = dm_utils.validate_property_tuple(class_name, non_list)
    assert res == ""
    real_list = [("StartIpList", ["1.1.1.1"])]
    res, ret_list = dm_utils.validate_property_tuple(class_name, real_list)
    assert res == ""
Example #2
0
def parse_prop_and_val_list(PropertyList, ValueList):
    plLogger = PLLogger.GetLogger("methodology")
    attr_dict = {}
    attr_dict["obj_list"] = []
    # Check the length of the PropertyList and ValueList
    # They MUST be the same length.
    if len(PropertyList) != len(ValueList):
        msg = "PropertyList and ValueList must have " + \
              "the same number of elements."
        plLogger.LogError(msg)
        return None, msg

    for prop_id, val in zip(PropertyList, ValueList):
        # Break down the property name
        split_name = prop_id.split(".")
        if len(split_name) < 2:
            msg = "Format of PropertyList item " + str(prop_id) + \
                  " is invalid.  Item should be in the form " + \
                  "Object.Property."
            plLogger.LogError(msg)
            return None, msg
        classname = ".".join(split_name[0:-1])
        prop_name = split_name[-1]
        plLogger.LogDebug("checking class: " + classname + " for prop " +
                          prop_name + " with value " + str(val))

        # Check the class name
        res, classname = dm_utils.validate_classname(classname)
        if res is False:
            return None, "Invalid classname: " + classname + \
                " specified in PropertyList."

        # Check the property and value
        prop_val = (prop_name, val)
        msg, tuple_list = dm_utils.validate_property_tuple(classname,
                                                           [prop_val])
        if msg != "":
            plLogger.LogError(msg)
            return None, msg
        else:
            prop_name = tuple_list[0][0]
            val = tuple_list[0][1]

        attr_dict[classname + "." + prop_name] = val
        if classname not in attr_dict["obj_list"]:
            attr_dict["obj_list"].append(classname)
            attr_dict[classname] = []
        if prop_name not in attr_dict[classname]:
            attr_dict[classname].append(prop_name)
    return attr_dict, ""
Example #3
0
def parse_property_value_list(prop_val_list):
    attr_dict = {}
    attr_dict["obj_list"] = []
    for item in prop_val_list:
        parsed_pattern = re.findall("(.*?)\.(.*?)=(.*)", item)

        # FIXME:
        # Check for three things
        # Use Barry's functions to test obj, param, and val

        obj = parsed_pattern[0][0]
        param = parsed_pattern[0][1]
        val = parsed_pattern[0][2]

        # Check the class name (obj)
        res, classname = dm_utils.validate_classname(obj)
        if res is False:
            return None, "Invalid classname: " + classname + \
                " specified in property value list."
        else:
            obj = classname

        # Check the property and value
        param_val = (param, val)
        msg, tuple_list = dm_utils.validate_property_tuple(obj,
                                                           [param_val])
        if msg != "":
            return None, msg
        else:
            param = tuple_list[0][0]
            val = tuple_list[0][1]

        attr_dict[obj + "." + param] = val
        if obj not in attr_dict["obj_list"]:
            attr_dict["obj_list"].append(obj)
            attr_dict[obj] = []
        if param not in attr_dict[obj]:
            attr_dict[obj].append(param)
    return attr_dict, ""
def test_validate_property_tuple_big_int(stc):
    class_name = "BfdRouterConfig"
    big_int_list = [("ScaleMode", "NORMAL"), ("DetectMultiplier", "512"), ("BfdCcChannelType", "34")]
    res, ret_list = dm_utils.validate_property_tuple(class_name, big_int_list)
    assert res != ""
    assert "should be between" in res
def test_validate_property_tuple_bad_int(stc):
    class_name = "BfdRouterConfig"
    not_int_list = [("ScaleMode", "NORMAL"), ("DetectMultiplier", "3"), ("BfdCcChannelType", "INVALID")]
    res, ret_list = dm_utils.validate_property_tuple(class_name, not_int_list)
    assert res != ""
    assert "Invalid uint16" in res
def test_validate_property_tuple_bad_enum(stc):
    class_name = "BfdRouterConfig"
    bad_enum_list = [("ScaleMode", "NOMRAL"), ("DetectMultiplier", "3"), ("BfdCcChannelType", "34")]
    res, ret_list = dm_utils.validate_property_tuple(class_name, bad_enum_list)
    assert res != ""
    assert "Invalid value" in res