Exemplo n.º 1
0
def _validate_generic_container_options(container_options,
                                        force_options=False):
    validators = [
        validate.NamesIn(
            GENERIC_CONTAINER_OPTIONS,
            option_type="container",
            severity=reports.item.get_severity(reports.codes.FORCE,
                                               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.deprecation(
                reports.messages.DeprecatedOption(
                    "masters",
                    ["promoted-max"],
                    "container",
                )))

    return (validate.ValidatorAll(validators).validate(container_options) +
            deprecation_reports)
Exemplo n.º 2
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",
            severity=reports.item.get_severity(
                reports.codes.FORCE, 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(
            ReportItem.deprecation(
                reports.messages.DeprecatedOption(
                    "masters",
                    ["promoted-max"],
                    "container",
                )
            )
        )
    # 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(
            ReportItem.error(
                reports.messages.PrerequisiteOptionMustNotBeSet(
                    "masters", "promoted-max", "container", "container"
                )
            )
        )
    if (
        options.get("promoted-max")
        and container_el.get("masters")
        and options.get("masters") != ""
    ):
        deprecation_reports.append(
            ReportItem.error(
                reports.messages.PrerequisiteOptionMustNotBeSet(
                    "promoted-max", "masters", "container", "container"
                )
            )
        )

    return (
        validate.ValidatorAll(validators).validate(options)
        + deprecation_reports
    )