示例#1
0
def validate_operation_list(operation_list,
                            allowed_operation_name_list,
                            allow_invalid=False):
    options_validators = [
        validate.is_required("name", "resource operation"),
        validate.value_in("role", ROLE_VALUES),
        validate.value_in("requires", REQUIRES_VALUES),
        validate.value_in("on-fail", ON_FAIL_VALUES),
        validate.value_in("record-pending", BOOLEAN_VALUES),
        validate.value_in("enabled", BOOLEAN_VALUES),
        validate.mutually_exclusive(["interval-origin", "start-delay"],
                                    "resource operation"),
        validate.value_in(
            "name",
            allowed_operation_name_list,
            option_name_for_report="operation name",
            code_to_allow_extra_values=report_codes.FORCE_OPTIONS,
            allow_extra_values=allow_invalid,
        ),
        validate.value_id("id", option_name_for_report="operation id"),
    ]
    report_list = []
    for operation in operation_list:
        report_list.extend(validate_operation(operation, options_validators))
    return report_list
示例#2
0
def _qdevice_add_model_net_options(options, node_ids, force_options=False):
    """
    Validate quorum device model options when adding a quorum device

    dict options -- model options
    list node_ids -- list of existing node ids
    bool force_options -- turn forceable errors into warnings
    """
    allowed_options = (
        _QDEVICE_NET_REQUIRED_OPTIONS + _QDEVICE_NET_OPTIONAL_OPTIONS
    )
    option_type = "quorum device model"
    validators = (
        [
            validate.is_required(option_name, option_type)
            for option_name in _QDEVICE_NET_REQUIRED_OPTIONS
        ]
        +
        _get_qdevice_model_net_options_validators(
            node_ids,
            force_options=force_options
        )
    )
    return (
        validate.run_collection_of_option_validators(options, validators)
        +
        validate.names_in(
            allowed_options,
            options.keys(),
            option_type,
            **validate.allow_extra_names(
                report_codes.FORCE_OPTIONS, force_options
            )
        )
    )
示例#3
0
def _validate_storage_map_list(options_list, id_provider, force_options):
    allowed_options = [
        "id",
        "options",
        "source-dir",
        "source-dir-root",
        "target-dir",
    ]
    source_dir_options = ["source-dir", "source-dir-root"]
    validators = [
        validate.value_id("id", "storage-map id", id_provider),
        validate.is_required_some_of(source_dir_options, "storage-map"),
        validate.mutually_exclusive(source_dir_options, "storage-map"),
        validate.is_required("target-dir", "storage-map"),
    ]
    report_list = []
    for options in options_list:
        report_list.extend(
            validate.run_collection_of_option_validators(options, validators)
            +
            validate.names_in(
                allowed_options,
                options.keys(),
                "storage-map",
                report_codes.FORCE_OPTIONS,
                force_options
            )
        )
    return report_list
示例#4
0
文件: bundle.py 项目: wuyeliang/pcs
def _validate_container(container_type,
                        container_options,
                        force_options=False):
    if not container_type in GENERIC_CONTAINER_TYPES:
        return [
            reports.invalid_option_value(
                "container type",
                container_type,
                GENERIC_CONTAINER_TYPES,
            )
        ]

    validators = [
        validate.is_required("image", "container"),
        validate.value_not_empty("image", "image name"),
        validate.value_nonnegative_integer("masters"),
        validate.value_nonnegative_integer("promoted-max"),
        validate.mutually_exclusive(["masters", "promoted-max"], "container"),
        validate.value_positive_integer("replicas"),
        validate.value_positive_integer("replicas-per-host"),
    ]
    deprecation_reports = []
    if "masters" in container_options:
        deprecation_reports.append(
            reports.deprecated_option("masters", ["promoted-max"],
                                      "container",
                                      severity=ReportItemSeverity.WARNING))
    return (validate.run_collection_of_option_validators(
        container_options, validators) + deprecation_reports +
            validate.names_in(GENERIC_CONTAINER_OPTIONS,
                              container_options.keys(), "container",
                              report_codes.FORCE_OPTIONS, force_options))
示例#5
0
 def test_returns_report_when_required_is_missing(self):
     assert_report_item_list_equal(
         validate.is_required("name", "some type")({}), [
             (severities.ERROR, report_codes.REQUIRED_OPTION_IS_MISSING, {
                 "option_names": ["name"],
                 "option_type": "some type",
             }, None),
         ])
示例#6
0
def _get_node_name_validators(node_index):
    return [
        validate.is_required("name", f"node {node_index}"),
        validate.value_not_empty(
            "name",
            "a non-empty string",
            option_name_for_report=f"node {node_index} name")
    ]
示例#7
0
文件: bundle.py 项目: cwjenkins/pcs
def _validate_container_docker_options_new(options, force_options):
    validators = [
        validate.is_required("image", "container"),
        validate.value_not_empty("image", "image name"),
        validate.value_nonnegative_integer("masters"),
        validate.value_positive_integer("replicas"),
        validate.value_positive_integer("replicas-per-host"),
    ]
    return (validate.run_collection_of_option_validators(options, validators) +
            validate.names_in(_docker_options, options.keys(), "container",
                              report_codes.FORCE_OPTIONS, force_options))
示例#8
0
 def test_returns_report_when_required_is_missing(self):
     assert_report_item_list_equal(
         validate.is_required("name", "some type")({}),
         [
             (
                 severities.ERROR,
                 report_codes.REQUIRED_OPTION_IS_MISSING,
                 {
                     "option_names": ["name"],
                     "option_type": "some type",
                 },
                 None
             ),
         ]
     )
示例#9
0
文件: bundle.py 项目: gmelikov/pcs
def _validate_generic_container_options_new(options, force_options):
    validators = [
        validate.is_required("image", "container"),
        validate.value_not_empty("image", "image name"),
        validate.value_nonnegative_integer("masters"),
        validate.value_nonnegative_integer("promoted-max"),
        validate.mutually_exclusive(["masters", "promoted-max"], "container"),
        validate.value_positive_integer("replicas"),
        validate.value_positive_integer("replicas-per-host"),
    ]
    deprecation_reports = []
    if "masters" in options:
        deprecation_reports.append(
            reports.deprecated_option("masters", ["promoted-max"],
                                      "container",
                                      severity=ReportItemSeverity.WARNING))
    return (validate.run_collection_of_option_validators(options, validators) +
            deprecation_reports + validate.names_in(
                _generic_container_options, options.keys(), "container",
                report_codes.FORCE_OPTIONS, force_options))
示例#10
0
 def test_returns_no_report_when_required_is_present(self):
     assert_report_item_list_equal(
         validate.is_required("name", "some type")({
             "name": "monitor"
         }), [])
示例#11
0
 def test_returns_no_report_when_required_is_present(self):
     assert_report_item_list_equal(
         validate.is_required("name", "some type")({"name": "monitor"}),
         []
     )
示例#12
0
    "1",
    "true",
    "false",
]

#normalize(key, value) -> normalized_value
normalize = validate.option_value_normalization({
    "role": lambda value: value.lower().capitalize(),
    "requires": lambda value: value.lower(),
    "on-fail": lambda value: value.lower(),
    "record-pending": lambda value: value.lower(),
    "enabled": lambda value: value.lower(),
})

OPERATION_OPTIONS_VALIDATORS = [
    validate.is_required("name", "resource operation"),
    validate.value_in("role", ROLE_VALUES),
    validate.value_in("requires", REQUIRES_VALUES),
    validate.value_in("on-fail", ON_FAIL_VALUES),
    validate.value_in("record-pending", BOOLEAN_VALUES),
    validate.value_in("enabled", BOOLEAN_VALUES),
    validate.mutually_exclusive(
        ["interval-origin", "start-delay"],
        "resource operation"
    )
]

def prepare(
    report_processor, raw_operation_list, default_operation_list,
    allowed_operation_name_list, allow_invalid=False
):