def test_invalid_retentions(self): retention_map = ( # From getUnitString ('10x:10', ValueError("Invalid unit 'x'")), ('60:10x', ValueError("Invalid unit 'x'")), # From parseRetentionDef ('10X:10', ValueError("Invalid precision specification '10X'")), ('10:10$', ValueError("Invalid retention specification '10$'")), ('60:10', (60, 10)), ) for retention, expected_exc in retention_map: try: results = parseRetentionDef(retention) except expected_exc.__class__ as exc: self.assertEqual( str(expected_exc), str(exc), ) self.assertEqual( expected_exc.__class__, exc.__class__, ) else: # When there isn't an exception raised self.assertEqual(results, expected_exc)
def test_valid_retentions(self): retention_map = ( ('60:10', (60, 10)), ('10:60', (10, 60)), ('10s:10h', (10, 3600)), ) for retention, expected in retention_map: results = parseRetentionDef(retention) self.assertEqual(results, expected)
def _get_retentions_from_storage_schemas(self, opts): """Parse storage-schemas.conf and returns all retentions.""" ret = [] config_parser = ConfigParser() if not config_parser.read(opts.storage_schemas): raise SystemExit("Error: Couldn't read config file: %s" % opts.storage_schemas) for section in config_parser.sections(): options = dict(config_parser.items(section)) retentions = options['retentions'].split(',') archives = [carbon_util.parseRetentionDef(s) for s in retentions] ret.append(bg_accessor.Retention.from_carbon(archives)) return ret
def _get_retentions_from_storage_schemas(self, opts): """Parse storage-schemas.conf and returns all retentions.""" ret = [] config_parser = ConfigParser() if not config_parser.read(opts.storage_schemas): raise SystemExit( "Error: Couldn't read config file: %s" % opts.storage_schemas ) for section in config_parser.sections(): options = dict(config_parser.items(section)) retentions = options["retentions"].split(",") archives = [carbon_util.parseRetentionDef(s) for s in retentions] ret.append(bg_metric.Retention.from_carbon(archives)) return ret
def fromString(retentionDef): (secondsPerPoint, points) = parseRetentionDef(retentionDef) return Archive(secondsPerPoint, points)