def validate_parameters( self, parameters, parameters_type="stonith", allow_invalid=False, update=False ): report_list = super(StonithAgent, self).validate_parameters( parameters, parameters_type=parameters_type, allow_invalid=allow_invalid, update=update ) if parameters.get("action", ""): report_list.append(reports.deprecated_option( "action", _STONITH_ACTION_REPLACED_BY, parameters_type, severity=( ReportItemSeverity.ERROR if not allow_invalid else ReportItemSeverity.WARNING ), forceable=( report_codes.FORCE_OPTIONS if not allow_invalid else None ) )) return report_list
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( reports.deprecated_option("masters", ["promoted-max"], "container", severity=ReportItemSeverity.WARNING)) return (validate.ValidatorAll(validators).validate(container_options) + deprecation_reports)
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))
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_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))
def _validate_action_is_deprecated(self, parameters, force=False): if parameters.get("action", ""): forcible, severity = self._validate_report_forcible_severity(force) return [ reports.deprecated_option("action", _STONITH_ACTION_REPLACED_BY, self._agent_type_label, severity=severity, forceable=forcible) ] return []
def _validate_action_is_deprecated(self, parameters, force=False): if parameters.get("action", ""): forcible, severity = self._validate_report_forcible_severity(force) return [reports.deprecated_option( "action", _STONITH_ACTION_REPLACED_BY, self._agent_type_label, severity=severity, forceable=forcible )] return []
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))