Beispiel #1
0
def _validate_generic_container_options(container_options,
                                        force_options=False):
    validators = [
        validate.NamesIn(
            GENERIC_CONTAINER_OPTIONS,
            option_type="container",
            **validate.set_warning(report_codes.FORCE_OPTIONS, force_options),
        ),
        validate.IsRequiredAll(["image"], option_type="container"),
        validate.ValueNotEmpty("image", "image name"),
        validate.ValueNonnegativeInteger("masters"),
        validate.ValueNonnegativeInteger("promoted-max"),
        validate.MutuallyExclusive(
            ["masters", "promoted-max"],
            option_type="container",
        ),
        validate.ValuePositiveInteger("replicas"),
        validate.ValuePositiveInteger("replicas-per-host"),
    ]

    deprecation_reports = []
    if "masters" in container_options:
        deprecation_reports.append(
            ReportItem.warning(
                reports.messages.DeprecatedOption(
                    "masters",
                    ["promoted-max"],
                    "container",
                )))

    return (validate.ValidatorAll(validators).validate(container_options) +
            deprecation_reports)
Beispiel #2
0
 def test_empty_report_on_not_empty_value(self):
     assert_report_item_list_equal(
         validate.ValueNotEmpty("key", "description").validate(
             {"key": "abc"}
         ),
         [],
     )
Beispiel #3
0
def validate_resource_instance_attributes_create(
    resource_agent: ResourceAgentFacade,
    instance_attributes: Mapping[str, str],
    resources_section: _Element,
    force: bool = False,
) -> reports.ReportItemList:
    report_items: reports.ReportItemList = []
    report_items += validate.ValidatorAll([
        validate.ValueNotEmpty(name, None) for name in instance_attributes
    ]).validate(instance_attributes)
    if resource_agent.metadata.agent_exists:
        report_items += validate.ValidatorAll(
            resource_agent.get_validators_allowed_parameters(force) +
            resource_agent.get_validators_required_parameters(force)).validate(
                instance_attributes)
        report_items += validate.ValidatorAll(
            resource_agent.get_validators_deprecated_parameters()).validate({
                name: value
                for name, value in instance_attributes.items()
                # we create a custom report for stonith parameter "action"
                if not (resource_agent.metadata.name.is_stonith
                        and name == "action")
            })

    if resource_agent.metadata.name.is_stonith:
        report_items += _validate_stonith_action(instance_attributes, force)

    if resource_agent.metadata.agent_exists:
        report_items += _validate_unique_instance_attributes(
            resource_agent.metadata,
            instance_attributes,
            resources_section,
            force=force,
        )
    return report_items
Beispiel #4
0
def _validate_generic_container_options_update(container_el, options,
                                               force_options):
    validators_optional_options = [
        validate.ValueNonnegativeInteger("masters"),
        validate.ValueNonnegativeInteger("promoted-max"),
        validate.ValuePositiveInteger("replicas"),
        validate.ValuePositiveInteger("replicas-per-host"),
    ]
    for val in validators_optional_options:
        val.empty_string_valid = True
    validators = [
        validate.NamesIn(
            # allow to remove options even if they are not allowed
            GENERIC_CONTAINER_OPTIONS | _options_to_remove(options),
            option_type="container",
            **validate.set_warning(report_codes.FORCE_OPTIONS, force_options)),
        # image is a mandatory attribute and cannot be removed
        validate.ValueNotEmpty("image", "image name")
    ] + validators_optional_options

    # 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.MutuallyExclusive(
                ["masters", "promoted-max"],
                option_type="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 container_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 container_el.get("masters")
            and options.get("masters") != ""):
        deprecation_reports.append(
            reports.prerequisite_option_must_not_be_set(
                "promoted-max", "masters", "container", "container"))

    return (validate.ValidatorAll(validators).validate(options) +
            deprecation_reports)
def _validate_ticket_options(options, allow_unknown_options):
    validator_list = ([
        validate.NamesIn(constants.TICKET_KEYS,
                         option_type="booth ticket",
                         banned_name_list=constants.GLOBAL_KEYS,
                         **validate.set_warning(report_codes.FORCE_OPTIONS,
                                                allow_unknown_options)),
    ] + [validate.ValueNotEmpty(option, None) for option in options])
    normalized_options = validate.values_to_pairs(
        options, lambda key, value: value.strip())
    return validate.ValidatorAll(validator_list).validate(normalized_options)
Beispiel #6
0
def validate_set_as_guest(tree, existing_nodes_names, existing_nodes_addrs,
                          node_name, options):
    validator_list = [
        validate.NamesIn(GUEST_OPTIONS, option_type="guest"),
        validate.ValueTimeInterval("remote-connect-timeout"),
        validate.ValuePortNumber("remote-port"),
    ]
    return (validate.ValidatorAll(validator_list).validate(options) +
            validate.ValueNotEmpty("node name", None).validate(
                {"node name": node_name.strip()}) +
            validate_conflicts(tree, existing_nodes_names,
                               existing_nodes_addrs, node_name, options))
Beispiel #7
0
 def test_report_on_empty_string(self):
     assert_report_item_list_equal(
         validate.ValueNotEmpty("key", "description").validate({"key": ""}),
         [
             fixture.error(
                 report_codes.INVALID_OPTION_VALUE,
                 option_name="key",
                 option_value="",
                 allowed_values="description",
                 cannot_be_empty=True,
                 forbidden_characters=None,
             ),
         ])
Beispiel #8
0
def _validate_ticket_options(options, allow_unknown_options):
    validator_list = [
        validate.NamesIn(
            constants.TICKET_KEYS,
            option_type="booth ticket",
            banned_name_list=constants.GLOBAL_KEYS,
            severity=report.item.get_severity(
                report_codes.FORCE, allow_unknown_options
            ),
        ),
    ] + [validate.ValueNotEmpty(option, None) for option in options]
    normalized_options = validate.values_to_pairs(
        options, lambda key, value: value.strip()
    )
    return validate.ValidatorAll(validator_list).validate(normalized_options)
Beispiel #9
0
def _validate_ticket_options(options, allow_unknown_options):
    severity = reports.item.get_severity(reports.codes.FORCE,
                                         allow_unknown_options)
    validator_list = ([
        validate.NamesIn(
            constants.TICKET_KEYS,
            option_type="booth ticket",
            banned_name_list=constants.GLOBAL_KEYS,
            severity=severity,
        ),
    ] + [
        validate.ValueNotEmpty(option, None)
        for option in options if option != "mode"
    ] + [validate.ValueIn("mode", ["auto", "manual"], severity=severity)])
    normalized_options = validate.values_to_pairs(
        options, lambda key, value: value.strip())
    return validate.ValidatorAll(validator_list).validate(normalized_options)
Beispiel #10
0
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.NamesIn(
            GENERIC_CONTAINER_OPTIONS,
            option_type="container",
            **validate.set_warning(report_codes.FORCE_OPTIONS, force_options)
        ),
        validate.IsRequiredAll(["image"], option_type="container"),
        validate.ValueNotEmpty("image", "image name"),
        validate.ValueNonnegativeInteger("masters"),
        validate.ValueNonnegativeInteger("promoted-max"),
        validate.MutuallyExclusive(
            ["masters", "promoted-max"],
            option_type="container",
        ),
        validate.ValuePositiveInteger("replicas"),
        validate.ValuePositiveInteger("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.ValidatorAll(validators).validate(container_options)
        +
        deprecation_reports
    )
Beispiel #11
0
 def test_empty_report_on_zero_int_value(self):
     assert_report_item_list_equal(
         validate.ValueNotEmpty("key", "description").validate({"key": 0}),
         [])