def validate_ticket_options(report_processor, options, allow_unknown_options): reports = [] for key in sorted(options): if key in GLOBAL_KEYS: reports.append( common_reports.invalid_option( [key], TICKET_KEYS, "booth ticket", )) elif key not in TICKET_KEYS: reports.append( common_reports.invalid_option( [key], TICKET_KEYS, "booth ticket", severity=(severities.WARNING if allow_unknown_options else severities.ERROR), forceable=(None if allow_unknown_options else report_codes.FORCE_OPTIONS), )) if not options[key].strip(): reports.append( common_reports.invalid_option_value( key, options[key], "no-empty", )) report_processor.process_list(reports)
def validate_ticket_options(report_processor, options, allow_unknown_options): reports = [] for key in sorted(options): if key in GLOBAL_KEYS: reports.append(common_reports.invalid_option( [key], TICKET_KEYS, "booth ticket", )) elif key not in TICKET_KEYS: reports.append( common_reports.invalid_option( [key], TICKET_KEYS, "booth ticket", severity=( severities.WARNING if allow_unknown_options else severities.ERROR ), forceable=( None if allow_unknown_options else report_codes.FORCE_OPTIONS ), ) ) if not options[key].strip(): reports.append(common_reports.invalid_option_value( key, options[key], "no-empty", )) report_processor.process_list(reports)
def _validate_sbd_options(sbd_config, allow_unknown_opts=False): """ Validate user SBD configuration. Options 'SBD_WATCHDOG_DEV' and 'SBD_OPTS' are restricted. Returns list of ReportItem sbd_config -- dictionary in format: <SBD config option>: <value> allow_unknown_opts -- if True, accept also unknown options. """ report_item_list = [] unsupported_sbd_option_list = ["SBD_WATCHDOG_DEV", "SBD_OPTS"] allowed_sbd_options = [ "SBD_DELAY_START", "SBD_STARTMODE", "SBD_WATCHDOG_TIMEOUT" ] for sbd_opt in sbd_config: if sbd_opt in unsupported_sbd_option_list: report_item_list.append(reports.invalid_option( sbd_opt, allowed_sbd_options, None )) elif sbd_opt not in allowed_sbd_options: report_item_list.append(reports.invalid_option( sbd_opt, allowed_sbd_options, None, Severities.WARNING if allow_unknown_opts else Severities.ERROR, None if allow_unknown_opts else report_codes.FORCE_OPTIONS )) return report_item_list
def __validate_quorum_options(self, options): report_items = [] for name, value in sorted(options.items()): allowed_names = self.__class__.QUORUM_OPTIONS if name not in allowed_names: report_items.append( reports.invalid_option(name, allowed_names, "quorum") ) continue if value == "": continue if name == "last_man_standing_window": if not value.isdigit(): report_items.append(reports.invalid_option_value( name, value, "positive integer" )) else: allowed_values = ("0", "1") if value not in allowed_values: report_items.append(reports.invalid_option_value( name, value, allowed_values )) return report_items
def validate_parameters(self, parameters, parameters_type="resource", allow_invalid=False, update=False): forceable = report_codes.FORCE_OPTIONS if not allow_invalid else None severity = (ReportItemSeverity.ERROR if not allow_invalid else ReportItemSeverity.WARNING) report_list = [] bad_opts, missing_req_opts = self.validate_parameters_values( parameters) if bad_opts: report_list.append( reports.invalid_option( bad_opts, sorted([attr["name"] for attr in self.get_parameters()]), parameters_type, severity=severity, forceable=forceable, )) if not update and missing_req_opts: report_list.append( reports.required_option_is_missing( missing_req_opts, parameters_type, severity=severity, forceable=forceable, )) return report_list
def validate_parameters( self, parameters, parameters_type="resource agent parameter", allow_invalid=False ): forceable = report_codes.FORCE_OPTIONS if not allow_invalid else None severity = ( ReportItemSeverity.ERROR if not allow_invalid else ReportItemSeverity.WARNING ) report_list = [] bad_opts, missing_req_opts = self.validate_parameters_values( parameters ) if bad_opts: report_list.append(reports.invalid_option( bad_opts, sorted([attr["name"] for attr in self.get_parameters()]), parameters_type, severity=severity, forceable=forceable, )) if missing_req_opts: report_list.append(reports.required_option_is_missing( missing_req_opts, parameters_type, severity=severity, forceable=forceable, )) return report_list
def _validate_attrib_names(attrib_names, options): invalid_names = [ name for name in options.keys() if name not in attrib_names ] if invalid_names: raise LibraryError( reports.invalid_option(invalid_names, attrib_names, None))
def __validate_quorum_device_generic_options(self, generic_options, force=False): optional_options = frozenset([ "sync_timeout", "timeout", ]) allowed_options = optional_options report_items = [] severity = (ReportItemSeverity.WARNING if force else ReportItemSeverity.ERROR) forceable = None if force else report_codes.FORCE_OPTIONS for name, value in sorted(generic_options.items()): if name not in allowed_options: # model is never allowed in generic options, it is passed # in its own argument report_items.append( reports.invalid_option( [name], allowed_options, "quorum device", severity if name != "model" else ReportItemSeverity.ERROR, forceable if name != "model" else None)) continue if value == "": continue if not value.isdigit(): report_items.append( reports.invalid_option_value(name, value, "positive integer", severity, forceable)) return report_items
def validate_options(options): # Pacemaker does not care currently about meaningfulness for concrete # constraint, so we use all attribs. for name, value in options.items(): if name not in ATTRIB: raise LibraryError(reports.invalid_option(name, list(ATTRIB.keys()), None)) if value not in ATTRIB[name]: raise LibraryError(reports.invalid_option_value(name, value, ATTRIB[name]))
def _validate_attrib_names(attrib_names, options): invalid_names = [ name for name in options.keys() if name not in attrib_names ] if invalid_names: raise LibraryError( reports.invalid_option(invalid_names, attrib_names, None) )
def _validate_sbd_options(sbd_config, allow_unknown_opts=False): """ Validate user SBD configuration. Options 'SBD_WATCHDOG_DEV' and 'SBD_OPTS' are restricted. Returns list of ReportItem sbd_config -- dictionary in format: <SBD config option>: <value> allow_unknown_opts -- if True, accept also unknown options. """ report_item_list = [] unsupported_sbd_option_list = [ "SBD_WATCHDOG_DEV", "SBD_OPTS", "SBD_PACEMAKER" ] allowed_sbd_options = [ "SBD_DELAY_START", "SBD_STARTMODE", "SBD_WATCHDOG_TIMEOUT" ] for sbd_opt in sbd_config: if sbd_opt in unsupported_sbd_option_list: report_item_list.append(reports.invalid_option( [sbd_opt], allowed_sbd_options, None )) elif sbd_opt not in allowed_sbd_options: report_item_list.append(reports.invalid_option( [sbd_opt], allowed_sbd_options, None, Severities.WARNING if allow_unknown_opts else Severities.ERROR, None if allow_unknown_opts else report_codes.FORCE_OPTIONS )) if "SBD_WATCHDOG_TIMEOUT" in sbd_config: report_item = reports.invalid_option_value( "SBD_WATCHDOG_TIMEOUT", sbd_config["SBD_WATCHDOG_TIMEOUT"], "nonnegative integer" ) try: if int(sbd_config["SBD_WATCHDOG_TIMEOUT"]) < 0: report_item_list.append(report_item) except (ValueError, TypeError): report_item_list.append(report_item) return report_item_list
def validate_options(options): #Pacemaker does not care currently about meaningfulness for concrete #constraint, so we use all attribs. for name, value in options.items(): if name not in ATTRIB: raise LibraryError( reports.invalid_option([name], list(ATTRIB.keys()), None)) if value not in ATTRIB[name]: raise LibraryError( reports.invalid_option_value(name, value, ATTRIB[name]))
def _validate_server_not_used(agent, option_dict): if "server" in option_dict: return [ reports.invalid_option( ["server"], sorted([ attr["name"] for attr in agent.get_parameters() if attr["name"] != "server" ]), "resource", ) ] return []
def __validate_quorum_options(self, options): report_items = [] has_qdevice = self.has_quorum_device() qdevice_incompatible_options = [] for name, value in sorted(options.items()): allowed_names = self.__class__.QUORUM_OPTIONS if name not in allowed_names: report_items.append( reports.invalid_option([name], allowed_names, "quorum") ) continue if value == "": continue if ( has_qdevice and name in self.__class__.QUORUM_OPTIONS_INCOMPATIBLE_WITH_QDEVICE ): qdevice_incompatible_options.append(name) if name == "last_man_standing_window": if not value.isdigit(): report_items.append(reports.invalid_option_value( name, value, "positive integer" )) else: allowed_values = ("0", "1") if value not in allowed_values: report_items.append(reports.invalid_option_value( name, value, allowed_values )) if qdevice_incompatible_options: report_items.append( reports.corosync_options_incompatible_with_qdevice( qdevice_incompatible_options ) ) return report_items
def __validate_quorum_options(self, options): report_items = [] has_qdevice = self.has_quorum_device() qdevice_incompatible_options = [] for name, value in sorted(options.items()): allowed_names = self.__class__.QUORUM_OPTIONS if name not in allowed_names: report_items.append( reports.invalid_option(name, allowed_names, "quorum") ) continue if value == "": continue if ( has_qdevice and name in self.__class__.QUORUM_OPTIONS_INCOMPATIBLE_WITH_QDEVICE ): qdevice_incompatible_options.append(name) if name == "last_man_standing_window": if not value.isdigit(): report_items.append(reports.invalid_option_value( name, value, "positive integer" )) else: allowed_values = ("0", "1") if value not in allowed_values: report_items.append(reports.invalid_option_value( name, value, allowed_values )) if qdevice_incompatible_options: report_items.append( reports.corosync_options_incompatible_with_qdevice( qdevice_incompatible_options ) ) return report_items
def __validate_quorum_device_generic_options( self, generic_options, force=False ): optional_options = frozenset([ "sync_timeout", "timeout", ]) allowed_options = optional_options report_items = [] severity = ( ReportItemSeverity.WARNING if force else ReportItemSeverity.ERROR ) forceable = None if force else report_codes.FORCE_OPTIONS for name, value in sorted(generic_options.items()): if name not in allowed_options: # model is never allowed in generic options, it is passed # in its own argument report_items.append(reports.invalid_option( [name], allowed_options, "quorum device", severity if name != "model" else ReportItemSeverity.ERROR, forceable if name != "model" else None )) continue if value == "": continue if not value.isdigit(): report_items.append(reports.invalid_option_value( name, value, "positive integer", severity, forceable )) return report_items
def __validate_quorum_device_model_net_options( self, model_options, need_required, force=False ): required_options = frozenset(["host", "algorithm"]) optional_options = frozenset([ "connect_timeout", "force_ip_version", "port", "tie_breaker", ]) allowed_options = required_options | optional_options model_options_names = frozenset(model_options.keys()) missing_options = [] report_items = [] severity = ( ReportItemSeverity.WARNING if force else ReportItemSeverity.ERROR ) forceable = None if force else report_codes.FORCE_OPTIONS if need_required: missing_options += required_options - model_options_names for name, value in sorted(model_options.items()): if name not in allowed_options: report_items.append(reports.invalid_option( [name], allowed_options, "quorum device model", severity, forceable )) continue if value == "": # do not allow to remove required options if name in required_options: missing_options.append(name) else: continue if name == "algorithm": allowed_values = ("ffsplit", "lms") if value not in allowed_values: report_items.append(reports.invalid_option_value( name, value, allowed_values, severity, forceable )) if name == "connect_timeout": minimum, maximum = 1000, 2*60*1000 if not (value.isdigit() and minimum <= int(value) <= maximum): min_max = "{min}-{max}".format(min=minimum, max=maximum) report_items.append(reports.invalid_option_value( name, value, min_max, severity, forceable )) if name == "force_ip_version": allowed_values = ("0", "4", "6") if value not in allowed_values: report_items.append(reports.invalid_option_value( name, value, allowed_values, severity, forceable )) if name == "port": minimum, maximum = 1, 65535 if not (value.isdigit() and minimum <= int(value) <= maximum): min_max = "{min}-{max}".format(min=minimum, max=maximum) report_items.append(reports.invalid_option_value( name, value, min_max, severity, forceable )) if name == "tie_breaker": node_ids = [node.id for node in self.get_nodes()] allowed_nonid = ["lowest", "highest"] if value not in allowed_nonid + node_ids: allowed_values = allowed_nonid + ["valid node id"] report_items.append(reports.invalid_option_value( name, value, allowed_values, severity, forceable )) if missing_options: report_items.append( reports.required_option_is_missing(sorted(missing_options)) ) return report_items
def _validate_attrib_names(attrib_names, options): for option_name in options.keys(): if option_name not in attrib_names: raise LibraryError( reports.invalid_option(option_name, attrib_names, None) )
def __validate_quorum_device_model_net_options( self, model_options, need_required, force=False ): required_options = frozenset(["host", "algorithm"]) optional_options = frozenset([ "connect_timeout", "force_ip_version", "port", "tie_breaker", ]) allowed_options = required_options | optional_options model_options_names = frozenset(model_options.keys()) report_items = [] severity = ( ReportItemSeverity.WARNING if force else ReportItemSeverity.ERROR ) forceable = None if force else report_codes.FORCE_OPTIONS if need_required: for missing in sorted(required_options - model_options_names): report_items.append(reports.required_option_is_missing(missing)) for name, value in sorted(model_options.items()): if name not in allowed_options: report_items.append(reports.invalid_option( name, allowed_options, "quorum device model", severity, forceable )) continue if value == "": # do not allow to remove required options if name in required_options: report_items.append( reports.required_option_is_missing(name) ) else: continue if name == "algorithm": allowed_values = ("ffsplit", "lms") if value not in allowed_values: report_items.append(reports.invalid_option_value( name, value, allowed_values, severity, forceable )) if name == "connect_timeout": minimum, maximum = 1000, 2*60*1000 if not (value.isdigit() and minimum <= int(value) <= maximum): min_max = "{min}-{max}".format(min=minimum, max=maximum) report_items.append(reports.invalid_option_value( name, value, min_max, severity, forceable )) if name == "force_ip_version": allowed_values = ("0", "4", "6") if value not in allowed_values: report_items.append(reports.invalid_option_value( name, value, allowed_values, severity, forceable )) if name == "port": minimum, maximum = 1, 65535 if not (value.isdigit() and minimum <= int(value) <= maximum): min_max = "{min}-{max}".format(min=minimum, max=maximum) report_items.append(reports.invalid_option_value( name, value, min_max, severity, forceable )) if name == "tie_breaker": node_ids = [node.id for node in self.get_nodes()] allowed_nonid = ["lowest", "highest"] if value not in allowed_nonid + node_ids: allowed_values = allowed_nonid + ["valid node id"] report_items.append(reports.invalid_option_value( name, value, allowed_values, severity, forceable )) return report_items