Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CloudWatch Alarm TreatMissingData validator #1536

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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