Skip to content

Commit

Permalink
Add CloudWatch Alarm TreatMissingData validator (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
marinpurgar authored and markpeek committed Jan 7, 2020
1 parent c19dee1 commit d902ec6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/test_cloudwatch.py
@@ -1,4 +1,5 @@
import unittest
import troposphere.cloudwatch as cloudwatch
from troposphere.cloudwatch import Dashboard


Expand Down Expand Up @@ -36,5 +37,21 @@ def test_dashboard(self):
)


class TestCloudWatchValidators(unittest.TestCase):
def test_validate_units(self):
for unit in cloudwatch.VALID_UNITS:
cloudwatch.validate_unit(unit)
for bad_unit in ['Minutes', 'Bytes/Minute', 'Bits/Hour', '']:
with self.assertRaisesRegexp(ValueError, "must be one of"):
cloudwatch.validate_unit(bad_unit)

def test_validate_treat_missing_data(self):
for value in cloudwatch.VALID_TREAT_MISSING_DATA_TYPES:
cloudwatch.validate_treat_missing_data(value)
for bad_value in ['exists', 'notMissing', '']:
with self.assertRaisesRegexp(ValueError, "must be one of"):
cloudwatch.validate_treat_missing_data(bad_value)


if __name__ == '__main__':
unittest.main()
14 changes: 13 additions & 1 deletion troposphere/cloudwatch.py
Expand Up @@ -16,6 +16,9 @@
'Kilobits/Second', 'Megabits/Second', 'Gigabits/Second',
'Terabits/Second', 'Count/Second', 'None')

VALID_TREAT_MISSING_DATA_TYPES = ('breaching', 'notBreaching', 'ignore',
'missing')


def validate_unit(unit):
"""Validate Units"""
Expand All @@ -26,6 +29,15 @@ def validate_unit(unit):
return unit


def validate_treat_missing_data(value):
"""Validate TreatMissingData"""

if value not in VALID_TREAT_MISSING_DATA_TYPES:
raise ValueError("Alarm TreatMissingData must be one of: %s" %
", ".join(VALID_TREAT_MISSING_DATA_TYPES))
return value


class MetricDimension(AWSProperty):
props = {
'Name': (basestring, True),
Expand Down Expand Up @@ -83,7 +95,7 @@ class Alarm(AWSObject):
'Statistic': (basestring, False),
'Threshold': (double, False),
'ThresholdMetricId': (basestring, False),
'TreatMissingData': (basestring, False),
'TreatMissingData': (validate_treat_missing_data, False),
'Unit': (basestring, False),
}

Expand Down

0 comments on commit d902ec6

Please sign in to comment.