示例#1
0
def _validate_network_options_update(bundle_el, network_el, options,
                                     force_options):
    report_list = []
    inner_primitive = get_inner_resource(bundle_el)
    if (inner_primitive is not None and
            not _is_pcmk_remote_acccessible_after_update(network_el, options)):
        report_list.append(
            reports.get_problem_creator(
                report_codes.FORCE_OPTIONS,
                force_options)(reports.resource_in_bundle_not_accessible,
                               bundle_el.get("id"), inner_primitive.get("id")))
    validators = [
        # TODO add validators for other keys (ip-range-start - IPv4)
        validate.value_empty_or_valid(
            "control-port",
            validate.value_port_number("control-port"),
        ),
        validate.value_empty_or_valid(
            "host-netmask",
            _value_host_netmask("host-netmask", force_options),
        ),
    ]
    return (report_list +
            validate.run_collection_of_option_validators(options, validators) +
            validate.names_in(
                # allow to remove options even if they are not allowed
                _network_options | _options_to_remove(options),
                options.keys(),
                "network",
                report_codes.FORCE_OPTIONS,
                force_options))
示例#2
0
def _validate_container_docker_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(
            "replicas",
            validate.value_positive_integer("replicas")
        ),
        validate.value_empty_or_valid(
            "replicas-per-host",
            validate.value_positive_integer("replicas-per-host")
        ),
    ]
    return (
        validate.run_collection_of_option_validators(options, validators)
        +
        validate.names_in(
            # allow to remove options even if they are not allowed
            _docker_options | _options_to_remove(options),
            options.keys(),
            "container",
            report_codes.FORCE_OPTIONS,
            force_options
        )
    )
示例#3
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))
示例#4
0
 def __get_heuristics_options_validators(
     self, allow_empty_values=False, force_options=False
 ):
     validators = {
         "mode": validate.value_in(
             "mode",
             ("off", "on", "sync"),
             code_to_allow_extra_values=report_codes.FORCE_OPTIONS,
             allow_extra_values=force_options
         ),
         "interval": validate.value_positive_integer(
             "interval",
             code_to_allow_extra_values=report_codes.FORCE_OPTIONS,
             allow_extra_values=force_options
         ),
         "sync_timeout": validate.value_positive_integer(
             "sync_timeout",
             code_to_allow_extra_values=report_codes.FORCE_OPTIONS,
             allow_extra_values=force_options
         ),
         "timeout": validate.value_positive_integer(
             "timeout",
             code_to_allow_extra_values=report_codes.FORCE_OPTIONS,
             allow_extra_values=force_options
         ),
     }
     if not allow_empty_values:
         # make sure to return a list even in python3 so we can call append
         # on it
         return list(validators.values())
     return [
         validate.value_empty_or_valid(option_name, validator)
         for option_name, validator in validators.items()
     ]
示例#5
0
def _get_quorum_options_validators(allow_empty_values=False):
    allowed_bool = ("0", "1")
    validators = {
        "auto_tie_breaker": validate.value_in(
            "auto_tie_breaker",
            allowed_bool
        ),
        "last_man_standing": validate.value_in(
            "last_man_standing",
            allowed_bool
        ),
        "last_man_standing_window": validate.value_positive_integer(
            "last_man_standing_window"
        ),
        "wait_for_all": validate.value_in(
            "wait_for_all",
            allowed_bool
        ),
    }
    if not allow_empty_values:
        # make sure to return a list even in python3 so we can call append
        # on it
        return list(validators.values())
    return [
        validate.value_empty_or_valid(option_name, validator)
        for option_name, validator in validators.items()
    ]
示例#6
0
def _get_qdevice_model_net_options_validators(node_ids,
                                              allow_empty_values=False,
                                              force_options=False):
    allow_extra_values = validate.allow_extra_values(
        report_codes.FORCE_OPTIONS, force_options)
    validators = {
        "connect_timeout":
        validate.value_integer_in_range("connect_timeout", 1000, 2 * 60 * 1000,
                                        **allow_extra_values),
        "force_ip_version":
        validate.value_in("force_ip_version", ("0", "4", "6"),
                          **allow_extra_values),
        "port":
        validate.value_port_number("port", **allow_extra_values),
        "tie_breaker":
        validate.value_in("tie_breaker", ["lowest", "highest"] + node_ids,
                          **allow_extra_values),
    }
    if not allow_empty_values:
        return ([
            validate.value_not_empty("host", "a qdevice host address"),
            _validate_qdevice_net_algorithm(**allow_extra_values)
        ] +
                # explicitely convert to a list for python 3
                list(validators.values()))
    return ([
        validate.value_not_empty("host", "a qdevice host address"),
        _validate_qdevice_net_algorithm(**allow_extra_values)
    ] + [
        validate.value_empty_or_valid(option_name, validator)
        for option_name, validator in validators.items()
    ])
示例#7
0
 def test_not_valid(self):
     assert_report_item_list_equal(
         validate.value_empty_or_valid("a", self.validator)({
             "a": "c"
         }), [
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "a",
                 "option_value": "c",
                 "allowed_values": "test",
             }, None),
         ])
示例#8
0
文件: bundle.py 项目: cwjenkins/pcs
def _validate_network_options_update(network_el, options, force_options):
    validators = [
        # TODO add validators for other keys (ip-range-start - IPv4)
        validate.value_empty_or_valid(
            "control-port",
            validate.value_port_number("control-port"),
        ),
        validate.value_empty_or_valid(
            "host-netmask",
            _value_host_netmask("host-netmask", force_options),
        ),
    ]
    return (validate.run_collection_of_option_validators(options, validators) +
            validate.names_in(
                # allow to remove options even if they are not allowed
                _network_options | _options_to_remove(options),
                options.keys(),
                "network",
                report_codes.FORCE_OPTIONS,
                force_options))
示例#9
0
 def test_not_valid(self):
     assert_report_item_list_equal(
         validate.value_empty_or_valid("a", self.validator)({"a": "c"}),
         [
             (
                 severities.ERROR,
                 report_codes.INVALID_OPTION_VALUE,
                 {
                     "option_name": "a",
                     "option_value": "c",
                     "allowed_values": "test",
                 },
                 None
             ),
         ]
     )
示例#10
0
def _get_qdevice_generic_options_validators(allow_empty_values=False,
                                            force_options=False):
    allow_extra_values = validate.allow_extra_values(
        report_codes.FORCE_OPTIONS, force_options)
    validators = {
        "sync_timeout":
        validate.value_positive_integer("sync_timeout", **allow_extra_values),
        "timeout":
        validate.value_positive_integer("timeout", **allow_extra_values),
    }
    if not allow_empty_values:
        # make sure to return a list even in python3 so we can call append
        # on it
        return list(validators.values())
    return [
        validate.value_empty_or_valid(option_name, validator)
        for option_name, validator in validators.items()
    ]
示例#11
0
 def test_valid(self):
     assert_report_item_list_equal(
         validate.value_empty_or_valid("a", self.validator)({
             "a": "b"
         }), [])
示例#12
0
 def test_valid(self):
     assert_report_item_list_equal(
         validate.value_empty_or_valid("a", self.validator)({"a": "b"}),
         [
         ]
     )