def get_failcounts(env, resource=None, node=None, operation=None, interval=None): # pylint: disable=redefined-outer-name """ List resources failcounts, optionally filtered by a resource, node or op LibraryEnvironment env string resource -- show failcounts for the specified resource only string node -- show failcounts for the specified node only string operation -- show failcounts for the specified operation only string interval -- show failcounts for the specified operation interval only """ report_items = [] if interval is not None and operation is None: report_items.append( reports.prerequisite_option_is_missing("interval", "operation")) if interval is not None: report_items.extend( ValueTimeInterval("interval").validate({"interval": interval})) if report_items: raise LibraryError(*report_items) interval_ms = (None if interval is None else timeout_to_seconds(interval) * 1000) all_failcounts = cib_status.get_resources_failcounts( get_status(env.get_cib())) return cib_status.filter_resources_failcounts(all_failcounts, resource=resource, node=node, operation=operation, interval=interval_ms)
def validate_different_intervals(operation_list): """ Check that the same operations (e.g. monitor) have different interval. list operation_list contains dictionaries with attributes of operation return see resource operation in pcs/lib/exchange_formats.md """ duplication_map = defaultdict(lambda: defaultdict(list)) for operation in operation_list: interval = operation.get( "interval", get_default_interval(operation["name"]) ) seconds = timeout_to_seconds(interval) duplication_map[operation["name"]][seconds].append(interval) duplications = defaultdict(list) for name, interval_map in duplication_map.items(): for timeout in sorted(interval_map.values()): if len(timeout) > 1: duplications[name].append(timeout) if duplications: return [reports.resource_operation_interval_duplication( dict(duplications) )] return []
def validate_different_intervals(operation_list): """ Check that the same operations (e.g. monitor) have different interval. list operation_list contains dictionaries with attributes of operation return see resource operation in pcs/lib/exchange_formats.md """ duplication_map = defaultdict(lambda: defaultdict(list)) for operation in operation_list: interval = operation.get("interval", get_default_interval(operation["name"])) seconds = timeout_to_seconds(interval) duplication_map[operation["name"]][seconds].append(interval) duplications = defaultdict(list) for name, interval_map in duplication_map.items(): for timeout in sorted(interval_map.values()): if len(timeout) > 1: duplications[name].append(timeout) if duplications: return [ ReportItem.error( reports.messages.ResourceOperationIntervalDuplication( dict(duplications))) ] return []
def test_valid(self): self.assertEqual(10, lib.timeout_to_seconds(10)) self.assertEqual(10, lib.timeout_to_seconds("10")) self.assertEqual(10, lib.timeout_to_seconds("10s")) self.assertEqual(10, lib.timeout_to_seconds("10sec")) self.assertEqual(600, lib.timeout_to_seconds("10m")) self.assertEqual(600, lib.timeout_to_seconds("10min")) self.assertEqual(36000, lib.timeout_to_seconds("10h")) self.assertEqual(36000, lib.timeout_to_seconds("10hr"))
def value_time_interval(option_name, option_name_for_report=None): return value_cond( option_name, lambda normalized_value: timeout_to_seconds(normalized_value) is not None, "time interval (e.g. 1, 2s, 3m, 4h, ...)", option_name_for_report=option_name_for_report, )
def value_time_interval(option_name, option_name_for_report=None): return value_cond( option_name, lambda normalized_value: timeout_to_seconds(normalized_value) is not None , "time interval (e.g. 1, 2s, 3m, 4h, ...)", option_name_for_report=option_name_for_report, )
def get_uniq_interval(name, initial_interval): """ Return unique interval for name based on initial_interval if initial_interval is valid or return initial_interval otherwise. string name is the operation name for searching interval initial_interval is starting point for finding free value """ used_intervals = used_intervals_map[name] normalized_interval = timeout_to_seconds(initial_interval) if normalized_interval is None: return initial_interval if normalized_interval not in used_intervals: used_intervals.add(normalized_interval) return initial_interval while normalized_interval in used_intervals: normalized_interval += 1 used_intervals.add(normalized_interval) return str(normalized_interval)
def get_failcounts( env, resource=None, node=None, operation=None, interval=None ): # pylint: disable=redefined-outer-name """ List resources failcounts, optionally filtered by a resource, node or op LibraryEnvironment env string resource -- show failcounts for the specified resource only string node -- show failcounts for the specified node only string operation -- show failcounts for the specified operation only string interval -- show failcounts for the specified operation interval only """ report_items = [] if interval is not None and operation is None: report_items.append( reports.prerequisite_option_is_missing("interval", "operation") ) if interval is not None: report_items.extend( value_time_interval("interval")({"interval": interval}) ) if report_items: raise LibraryError(*report_items) interval_ms = ( None if interval is None else timeout_to_seconds(interval) * 1000 ) all_failcounts = cib_status.get_resources_failcounts( get_status(env.get_cib()) ) return cib_status.filter_resources_failcounts( all_failcounts, resource=resource, node=node, operation=operation, interval=interval_ms )
def test_invalid(self): self.assertEqual(None, lib.timeout_to_seconds(-10)) self.assertEqual(None, lib.timeout_to_seconds("1a1s")) self.assertEqual(None, lib.timeout_to_seconds("10mm")) self.assertEqual(None, lib.timeout_to_seconds("10mim")) self.assertEqual(None, lib.timeout_to_seconds("aaa")) self.assertEqual(None, lib.timeout_to_seconds("")) self.assertEqual(-10, lib.timeout_to_seconds(-10, True)) self.assertEqual("1a1s", lib.timeout_to_seconds("1a1s", True)) self.assertEqual("10mm", lib.timeout_to_seconds("10mm", True)) self.assertEqual("10mim", lib.timeout_to_seconds("10mim", True)) self.assertEqual("aaa", lib.timeout_to_seconds("aaa", True)) self.assertEqual("", lib.timeout_to_seconds("", True))
def _is_valid(self, value): return timeout_to_seconds(value) is not None
def _is_valid(self, value: TypeOptionValue) -> bool: return timeout_to_seconds(value) is not None