def test_return_normalized_value_if_normalization_for_key_specified(self): normalize = validate.option_value_normalization( {"first": lambda value: value.upper()}) self.assertEqual("ONE", normalize("first", "one"))
def test_return_value_if_normalization_for_key_unspecified(self): normalize = validate.option_value_normalization({}) self.assertEqual("one", normalize("first", "one"))
def test_return_normalized_value_if_normalization_for_key_specified(self): normalize = validate.option_value_normalization({ "first": lambda value: value.upper() }) self.assertEqual("ONE", normalize("first", "one"))
] BOOLEAN_VALUES = [ "0", "1", "true", "false", ] #normalize(key, value) -> normalized_value normalize = validate.option_value_normalization({ "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(), }) 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.
"fence", "restart-container", ] BOOLEAN_VALUES = [ "0", "1", "true", "false", ] #normalize(key, value) -> normalized_value normalize = validate.option_value_normalization({ "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_options_plain( cib: _Element, report_processor: reports.ReportProcessor, options, ticket: str, resource_id, ): options = options.copy() report_processor.report_list(_validate_options_common(options)) if not ticket: report_processor.report( ReportItem.error( reports.messages.RequiredOptionsAreMissing(["ticket"]))) else: report_processor.report_list(validate_ticket_name(ticket)) options["ticket"] = ticket if not resource_id: report_processor.report( ReportItem.error( reports.messages.RequiredOptionsAreMissing(["rsc"]))) options["rsc"] = resource_id role_value_validator = validate.ValueIn("rsc-role", const.PCMK_ROLES, option_name_for_report="role") role_value_validator.empty_string_valid = True validators = [ role_value_validator, validate.ValueDeprecated( "rsc-role", { const.PCMK_ROLE_PROMOTED_LEGACY: const.PCMK_ROLE_PROMOTED, const.PCMK_ROLE_UNPROMOTED_LEGACY: const.PCMK_ROLE_UNPROMOTED, }, reports.ReportItemSeverity.deprecation(), option_name_for_report="role", ), ] report_processor.report_list( validate.ValidatorAll(validators).validate( validate.values_to_pairs( options, validate.option_value_normalization( {"rsc-role": lambda value: value.capitalize()}), ))) if report_processor.has_errors: raise LibraryError() if "rsc-role" in options: if options["rsc-role"]: options["rsc-role"] = pacemaker.role.get_value_for_cib( options["rsc-role"].capitalize(), tools.are_new_role_names_supported(cib), ) else: del options["rsc-role"] return constraint.prepare_options( tuple(list(ATTRIB) + list(ATTRIB_PLAIN)), options, partial( _create_id, cib, options["ticket"], resource_id, options.get("rsc-role", ""), ), partial(tools.check_new_id_applicable, cib, DESCRIPTION), )