def _validate_port_map_list(options_list, id_provider, force_options): kwargs = validate.set_warning(report_codes.FORCE_OPTIONS, force_options) option_type = "port-map" validators = [ validate.NamesIn(PORT_MAP_OPTIONS, option_type=option_type, **kwargs), validate.ValueId("id", option_name_for_report="port-map id", id_provider=id_provider), validate.DependsOnOption( ["internal-port"], "port", option_type=option_type, prerequisite_type=option_type, ), validate.IsRequiredSome(["port", "range"], option_type=option_type), validate.MutuallyExclusive(["port", "range"], option_type=option_type), validate.ValuePortNumber("port"), validate.ValuePortNumber("internal-port"), validate.ValuePortRange("range", **kwargs), ] validator_all = validate.ValidatorAll(validators) report_list = [] for options in options_list: report_list.extend(validator_all.validate(options)) return report_list
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"))) kwargs = validate.set_warning(report_codes.FORCE_OPTIONS, force_options) validators_optional_options = [ # TODO add validators for other keys (ip-range-start - IPv4) validate.ValuePortNumber("control-port"), # Leaving a possibility to force this validation for the case pacemaker # starts supporting IPv6 or other format of the netmask. ValueHostNetmask("host-netmask", **kwargs), ] for val in validators_optional_options: val.empty_string_valid = True validators = [ validate.NamesIn( # allow to remove options even if they are not allowed NETWORK_OPTIONS | _options_to_remove(options), option_type="network", **kwargs) ] + validators_optional_options return (report_list + validate.ValidatorAll(validators).validate(options))
def _validate_network_options_new(options, force_options): kwargs = validate.set_warning(report_codes.FORCE_OPTIONS, force_options) validators = [ # TODO add validators for other keys (ip-range-start - IPv4) validate.NamesIn(NETWORK_OPTIONS, option_type="network", **kwargs), validate.ValuePortNumber("control-port"), # Leaving a possibility to force this validation for the case pacemaker # starts supporting IPv6 or other format of the netmask. ValueHostNetmask("host-netmask", **kwargs), ] return validate.ValidatorAll(validators).validate(options)
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))
def test_report_invalid_value(self): assert_report_item_list_equal( validate.ValuePortNumber("key").validate({"key": "65536"}), [ fixture.error( report_codes.INVALID_OPTION_VALUE, option_name="key", option_value="65536", allowed_values="a port number (1..65535)", cannot_be_empty=False, forbidden_characters=None, ), ])
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_accessible_after_update(network_el, options) ): report_list.append( ReportItem( severity=reports.item.get_severity( reports.codes.FORCE, force_options, ), message=reports.messages.ResourceInBundleNotAccessible( bundle_el.get("id"), inner_primitive.get("id"), ), ) ) severity = reports.item.get_severity(reports.codes.FORCE, force_options) validators_optional_options = [ # TODO add validators for other keys (ip-range-start - IPv4) validate.ValuePortNumber("control-port"), # Leaving a possibility to force this validation for the case pacemaker # starts supporting IPv6 or other format of the netmask. ValueHostNetmask("host-netmask", severity=severity), ] for val in validators_optional_options: val.empty_string_valid = True validators = [ validate.NamesIn( # allow to remove options even if they are not allowed NETWORK_OPTIONS | _options_to_remove(options), option_type="network", severity=severity, ) ] + validators_optional_options return report_list + validate.ValidatorAll(validators).validate(options)
def test_empty_report_on_valid_option(self): assert_report_item_list_equal( validate.ValuePortNumber("key").validate({"key": "54321"}), [])