コード例 #1
0
ファイル: test_validate.py プロジェクト: bgistone/pcs
 def test_returns_empty_report_when_valid(self):
     assert_report_item_list_equal(
         validate.mutually_exclusive(["a", "b"])({
             "a": "A"
         }),
         [],
     )
コード例 #2
0
ファイル: bundle.py プロジェクト: cwjenkins/pcs
def _validate_port_map_list(options_list, id_provider, force_options):
    allowed_options = [
        "id",
        "port",
        "internal-port",
        "range",
    ]
    validators = [
        validate.value_id("id", "port-map id", id_provider),
        validate.depends_on_option("internal-port", "port", "port-map",
                                   "port-map"),
        validate.is_required_some_of(["port", "range"], "port-map"),
        validate.mutually_exclusive(["port", "range"], "port-map"),
        validate.value_port_number("port"),
        validate.value_port_number("internal-port"),
        validate.value_port_range(
            "range",
            code_to_allow_extra_values=report_codes.FORCE_OPTIONS,
            allow_extra_values=force_options),
    ]
    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(), "port-map",
                              report_codes.FORCE_OPTIONS, force_options))
    return report_list
コード例 #3
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
コード例 #4
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
コード例 #5
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))
コード例 #6
0
ファイル: bundle.py プロジェクト: gmelikov/pcs
def _validate_generic_container_options_update(docker_el, options,
                                               force_options):
    validators = [
        # image is a mandatory attribute and cannot be removed
        validate.value_not_empty("image", "image name"),
        validate.value_empty_or_valid(
            "masters", validate.value_nonnegative_integer("masters")),
        validate.value_empty_or_valid(
            "promoted-max",
            validate.value_nonnegative_integer("promoted-max")),
        validate.value_empty_or_valid(
            "replicas", validate.value_positive_integer("replicas")),
        validate.value_empty_or_valid(
            "replicas-per-host",
            validate.value_positive_integer("replicas-per-host")),
    ]
    # CIB does not allow both to be set. Deleting both is not a problem,
    # though. Deleting one while setting another also works and is further
    # checked bellow.
    if not (options.get("masters", "") == ""
            or options.get("promoted-max", "") == ""):
        validators.append(
            validate.mutually_exclusive(["masters", "promoted-max"],
                                        "container"))

    deprecation_reports = []
    if options.get("masters"):
        # If the user wants to delete the masters option, do not report it is
        # deprecated. They may be removing it because they just found out it is
        # deprecated.
        deprecation_reports.append(
            reports.deprecated_option("masters", ["promoted-max"],
                                      "container",
                                      severity=ReportItemSeverity.WARNING))
    # Do not allow to set masters if promoted-max is set unless promoted-max is
    # going to be removed now. Do the same check also the other way around. CIB
    # only allows one of them to be set.
    if (options.get("masters") and docker_el.get("promoted-max")
            and options.get("promoted-max") != ""):
        deprecation_reports.append(
            reports.prerequisite_option_must_not_be_set(
                "masters", "promoted-max", "container", "container"))
    if (options.get("promoted-max") and docker_el.get("masters")
            and options.get("masters") != ""):
        deprecation_reports.append(
            reports.prerequisite_option_must_not_be_set(
                "promoted-max", "masters", "container", "container"))

    return (validate.run_collection_of_option_validators(options, validators) +
            deprecation_reports + validate.names_in(
                # allow to remove options even if they are not allowed
                _generic_container_options | _options_to_remove(options),
                options.keys(),
                "container",
                report_codes.FORCE_OPTIONS,
                force_options))
コード例 #7
0
ファイル: test_validate.py プロジェクト: bgistone/pcs
 def test_returns_mutually_exclusive_report_on_2_names_conflict(self):
     assert_report_item_list_equal(
         validate.mutually_exclusive(["a", "b", "c"])({
             "a": "A",
             "b": "B",
             "d": "D",
         }),
         [
             (severities.ERROR, report_codes.MUTUALLY_EXCLUSIVE_OPTIONS, {
                 "option_type": "option",
                 "option_names": ["a", "b"],
             }, None),
         ],
     )
コード例 #8
0
ファイル: test_validate.py プロジェクト: HideoYamauchi/pcs
 def test_returns_mutually_exclusive_report_on_2_names_conflict(self):
     assert_report_item_list_equal(
         validate.mutually_exclusive(["a", "b", "c"])({
             "a": "A",
             "b": "B",
             "d": "D",
         }),
         [
             (
                 severities.ERROR,
                 report_codes.MUTUALLY_EXCLUSIVE_OPTIONS,
                 {
                     "option_type": "option",
                     "option_names": ["a", "b"],
                 },
                 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
ファイル: test_validate.py プロジェクト: HideoYamauchi/pcs
 def test_returns_empty_report_when_valid(self):
     assert_report_item_list_equal(
         validate.mutually_exclusive(["a", "b"])({"a": "A"}),
         [],
     )
コード例 #11
0
ファイル: operations.py プロジェクト: HideoYamauchi/pcs
    "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
):
    """
    Return operation_list prepared from raw_operation_list and
    default_operation_list.

    report_processor is tool for warning/info/error reporting
    list of dicts raw_operation_list are entered operations that require
        follow-up care
    list of dicts default_operation_list are operations defined as default by