def test_number_of_points(self): """ number of points """ whisper.validateArchiveList(self.retention) with AssertRaisesException(whisper.InvalidConfiguration("Each archive must have at least enough points to consolidate to the next archive (archive1 consolidates 60 of archive0's points but it has only 30 total points)")): whisper.validateArchiveList([(1, 30), (60, 60)])
def loadStorageSchemas(): schemaList = [] config = OrderedConfigParser() config.read(STORAGE_SCHEMAS_CONFIG) for section in config.sections(): options = dict( config.items(section) ) pattern = options.get('pattern') retentions = options['retentions'].split(',') archives = [ Archive.fromString(s) for s in retentions ] if pattern: mySchema = PatternSchema(section, pattern, archives) else: log.err("Section missing 'pattern': %s" % section) continue archiveList = [a.getTuple() for a in archives] try: whisper.validateArchiveList(archiveList) schemaList.append(mySchema) except whisper.InvalidConfiguration, e: log.msg("Invalid schemas found in %s: %s" % (section, e) )
def test_even_precision_division(self): """ even precision division """ whisper.validateArchiveList([(60, 60), (6, 60)]) with AssertRaisesException(whisper.InvalidConfiguration("Higher precision archives' precision must evenly divide all lower precision archives' precision (archive0: 7, archive1: 60)")): whisper.validateArchiveList([(60, 60), (7, 60)])
def test_timespan_coverage(self): """ timespan coverage """ whisper.validateArchiveList(self.retention) with AssertRaisesException(whisper.InvalidConfiguration('Lower precision archives must cover larger time intervals than higher precision archives (archive0: 60 seconds, archive1: 10 seconds)')): whisper.validateArchiveList([(1, 60), (10, 1)])
def loadStorageSchemas(): schemaList = [] config = OrderedConfigParser() config.read(STORAGE_SCHEMAS_CONFIG) for section in config.sections(): options = dict(config.items(section)) matchAll = options.get('match-all') pattern = options.get('pattern') listName = options.get('list') retentions = options['retentions'].split(',') archives = [Archive.fromString(s) for s in retentions] if matchAll: mySchema = DefaultSchema(section, archives) elif pattern: mySchema = PatternSchema(section, pattern, archives) elif listName: mySchema = ListSchema(section, listName, archives) archiveList = [a.getTuple() for a in archives] try: whisper.validateArchiveList(archiveList) schemaList.append(mySchema) except whisper.InvalidConfiguration, e: log.msg("Invalid schemas found in %s: %s" % (section, e))
def test_validate_archive_list(self): """ blank archive config """ with AssertRaisesException( whisper.InvalidConfiguration( 'You must specify at least one archive configuration!')): whisper.validateArchiveList([])
def test_duplicate(self): """ Checking duplicates """ # TODO: Fix the lies with whisper.validateArchiveList() saying it returns True/False self.assertIsNone(whisper.validateArchiveList(self.retention)) with AssertRaisesException(whisper.InvalidConfiguration('A Whisper database may not be configured having two archives with the same precision (archive0: (1, 60), archive1: (1, 60))')): whisper.validateArchiveList([(1, 60), (60, 60), (1, 60)])
def test_timespan_coverage(self): """ timespan coverage """ whisper.validateArchiveList(self.retention) with AssertRaisesException( whisper.InvalidConfiguration( 'Lower precision archives must cover larger time intervals than higher precision archives (archive0: 60 seconds, archive1: 10 seconds)' )): whisper.validateArchiveList([(1, 60), (10, 1)])
def test_number_of_points(self): """ number of points """ whisper.validateArchiveList(self.retention) with AssertRaisesException( whisper.InvalidConfiguration( "Each archive must have at least enough points to consolidate to the next archive (archive1 consolidates 60 of archive0's points but it has only 30 total points)" )): whisper.validateArchiveList([(1, 30), (60, 60)])
def test_even_precision_division(self): """ even precision division """ whisper.validateArchiveList([(60, 60), (6, 60)]) with AssertRaisesException( whisper.InvalidConfiguration( "Higher precision archives' precision must evenly divide all lower precision archives' precision (archive0: 7, archive1: 60)" )): whisper.validateArchiveList([(60, 60), (7, 60)])
def test_duplicate(self): """ Checking duplicates """ # TODO: Fix the lies with whisper.validateArchiveList() saying it returns True/False self.assertIsNone(whisper.validateArchiveList(self.retention)) with AssertRaisesException( whisper.InvalidConfiguration( 'A Whisper database may not be configured having two archives with the same precision (archive0: (1, 60), archive1: (1, 60))' )): whisper.validateArchiveList([(1, 60), (60, 60), (1, 60)])
def loadStorageSchemas(): schemaList = [] config = OrderedConfigParser() config.read(STORAGE_SCHEMAS_CONFIG) for section in config.sections(): options = dict(config.items(section)) matchAll = options.get('match-all') pattern = options.get('pattern') listName = options.get('list') retentions = options['retentions'].split(',') archives = [Archive.fromString(s) for s in retentions] if matchAll: mySchema = DefaultSchema(section, archives) elif pattern: mySchema = PatternSchema(section, pattern, archives) elif listName: mySchema = ListSchema(section, listName, archives) archiveList = [a.getTuple() for a in archives] validSchema = whisper.validateArchiveList(archiveList) if validSchema: schemaList.append(mySchema) else: log.msg("Invalid schemas found in %s." % section) schemaList.append(defaultSchema) return schemaList
def test_duplicate(self): """Checking duplicates""" whisper.validateArchiveList([(1, 60), (60, 60)]) with self.assertRaises(whisper.InvalidConfiguration): whisper.validateArchiveList([(1, 60), (60, 60), (1, 60)])
def validateArchiveList(self, archiveList): try: whisper.validateArchiveList(archiveList) except whisper.InvalidConfiguration, e: raise ValueError("%s" % e)
def test_validate_archive_list(self): """blank archive config""" with self.assertRaises(whisper.InvalidConfiguration): whisper.validateArchiveList([])
def test_even_precision_division(self): """even precision division""" whisper.validateArchiveList([(60, 60), (6, 60)]) with self.assertRaises(whisper.InvalidConfiguration): whisper.validateArchiveList([(60, 60), (7, 60)])
def test_timespan_coverage(self): """timespan coverage""" whisper.validateArchiveList([(1, 60), (60, 60)]) with self.assertRaises(whisper.InvalidConfiguration): whisper.validateArchiveList([(1, 60), (10, 1)])
def test_number_of_points(self): """number of points""" whisper.validateArchiveList([(1, 60), (60, 60)]) with self.assertRaises(whisper.InvalidConfiguration): whisper.validateArchiveList([(1, 30), (60, 60)])
archives = [] section_failed = False for retention in retentions: try: archives.append(whisper.parseRetentionDef(retention)) except ValueError as e: print( " - Error: Section '%s' contains an invalid item in its retention definition ('%s')" % (section, retention) ) print(" %s" % e) section_failed = True if not section_failed: try: whisper.validateArchiveList(archives) except whisper.InvalidConfiguration as e: print( " - Error: Section '%s' contains an invalid retention definition ('%s')" % (section, ','.join(retentions)) ) print(" %s" % e) if section_failed: errors_found += 1 else: print(" OK") if errors_found: raise SystemExit("Storage-schemas configuration '%s' failed validation" % SCHEMAS_FILE)
def test_validate_archive_list(self): """ blank archive config """ with AssertRaisesException(whisper.InvalidConfiguration('You must specify at least one archive configuration!')): whisper.validateArchiveList([])