Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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_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_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)])
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)
print("Storage-schemas configuration '%s' is valid" % SCHEMAS_FILE)
Returns True or False
"""
if not archiveList:
raise InvalidConfiguration("You must specify at least one archive configuration!")
archiveList.sort(key=lambda a: a[0]) #sort by precision (secondsPerPoint)
for i,archive in enumerate(archiveList):
if i == len(archiveList) - 1:
break
nextArchive = archiveList[i+1]
if not archive[0] < nextArchive[0]:
raise InvalidConfiguration("A Whisper database may not configured having"
"two archives with the same precision (archive%d: %s, archive%d: %s)" %
(i, archive, i + 1, nextArchive))
if nextArchive[0] % archive[0] != 0:
raise InvalidConfiguration("Higher precision archives' precision "
"must evenly divide all lower precision archives' precision "
"(archive%d: %s, archive%d: %s)" %
(i, archive[0], i + 1, nextArchive[0]))
retention = archive[0] * archive[1]
nextRetention = nextArchive[0] * nextArchive[1]
if not nextRetention > retention:
raise InvalidConfiguration("Lower precision archives must cover "
"larger time intervals than higher precision archives "
"(archive%d: %s seconds, archive%d: %s seconds)" %
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))
schemaList.append(defaultSchema)
return schemaList
def validateArchiveList(archiveList):
""" Validates an archiveList.
An ArchiveList must:
1. Have at least one archive config. Example: (60, 86400)
2. No archive may be a duplicate of another.
3. Higher precision archives' precision must evenly divide all lower precision archives' precision.
4. Lower precision archives must cover larger time intervals than higher precision archives.
5. Each archive must have at least enough points to consolidate to the next archive
Returns True or False
"""
if not archiveList:
raise InvalidConfiguration("You must specify at least one archive configuration!")
archiveList.sort(key=lambda a: a[0]) #sort by precision (secondsPerPoint)
for i,archive in enumerate(archiveList):
if i == len(archiveList) - 1:
break
nextArchive = archiveList[i+1]
if not archive[0] < nextArchive[0]:
raise InvalidConfiguration("A Whisper database may not configured having"
"two archives with the same precision (archive%d: %s, archive%d: %s)" %
(i, archive, i + 1, nextArchive))
if nextArchive[0] % archive[0] != 0:
raise InvalidConfiguration("Higher precision archives' precision "
"must evenly divide all lower precision archives' precision "
def validateArchiveList(self, archiveList):
try:
whisper.validateArchiveList(archiveList)
except whisper.InvalidConfiguration as e:
raise ValueError("%s" % e)