2015-04-22 10:45:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
2015-04-22 10:45:54 +00:00
|
|
|
'''
|
|
|
|
# Import Python libs
|
2018-01-17 23:05:08 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2015-04-22 10:45:54 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-19 22:28:46 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import (
|
2015-04-22 10:45:54 +00:00
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON,
|
|
|
|
MagicMock,
|
|
|
|
patch)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.states.boto_cloudwatch_alarm as boto_cloudwatch_alarm
|
2015-04-22 10:45:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-02-19 22:28:46 +00:00
|
|
|
class BotoCloudwatchAlarmTestCase(TestCase, LoaderModuleMockMixin):
|
2015-04-22 10:45:54 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.states.boto_cloudwatch_alarm
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {boto_cloudwatch_alarm: {}}
|
2017-02-19 22:28:46 +00:00
|
|
|
|
2015-04-22 10:45:54 +00:00
|
|
|
# 'present' function tests: 1
|
|
|
|
|
|
|
|
def test_present(self):
|
|
|
|
'''
|
|
|
|
Test to ensure the cloudwatch alarm exists.
|
|
|
|
'''
|
|
|
|
name = 'my test alarm'
|
|
|
|
attributes = {'metric': 'ApproximateNumberOfMessagesVisible',
|
|
|
|
'namespace': 'AWS/SQS'}
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': None,
|
|
|
|
'changes': {},
|
|
|
|
'comment': ''}
|
|
|
|
|
|
|
|
mock = MagicMock(side_effect=[['ok_actions'], [], []])
|
|
|
|
mock_bool = MagicMock(return_value=True)
|
|
|
|
with patch.dict(boto_cloudwatch_alarm.__salt__,
|
|
|
|
{'boto_cloudwatch.get_alarm': mock,
|
|
|
|
'boto_cloudwatch.create_or_update_alarm': mock_bool}):
|
|
|
|
with patch.dict(boto_cloudwatch_alarm.__opts__, {'test': True}):
|
|
|
|
comt = ('alarm my test alarm is to be created/updated.')
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(boto_cloudwatch_alarm.present(name,
|
|
|
|
attributes),
|
|
|
|
ret)
|
|
|
|
|
|
|
|
comt = ('alarm my test alarm is to be created/updated.')
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(boto_cloudwatch_alarm.present(name,
|
|
|
|
attributes),
|
|
|
|
ret)
|
|
|
|
|
|
|
|
with patch.dict(boto_cloudwatch_alarm.__opts__, {'test': False}):
|
|
|
|
changes = {'new':
|
|
|
|
{'metric': 'ApproximateNumberOfMessagesVisible',
|
|
|
|
'namespace': 'AWS/SQS'}}
|
|
|
|
comt = ('alarm my test alarm is to be created/updated.')
|
|
|
|
ret.update({'changes': changes, 'comment': '', 'result': True})
|
|
|
|
self.assertDictEqual(boto_cloudwatch_alarm.present(name,
|
|
|
|
attributes),
|
|
|
|
ret)
|
|
|
|
|
|
|
|
# 'absent' function tests: 1
|
|
|
|
|
|
|
|
def test_absent(self):
|
|
|
|
'''
|
|
|
|
Test to ensure the named cloudwatch alarm is deleted.
|
|
|
|
'''
|
|
|
|
name = 'my test alarm'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': None,
|
|
|
|
'changes': {},
|
|
|
|
'comment': ''}
|
|
|
|
|
|
|
|
mock = MagicMock(side_effect=[True, False])
|
|
|
|
with patch.dict(boto_cloudwatch_alarm.__salt__,
|
|
|
|
{'boto_cloudwatch.get_alarm': mock}):
|
|
|
|
with patch.dict(boto_cloudwatch_alarm.__opts__, {'test': True}):
|
|
|
|
comt = ('alarm {0} is set to be removed.'.format(name))
|
|
|
|
ret.update({'comment': comt})
|
|
|
|
self.assertDictEqual(boto_cloudwatch_alarm.absent(name), ret)
|
|
|
|
|
|
|
|
comt = ('my test alarm does not exist in None.')
|
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(boto_cloudwatch_alarm.absent(name), ret)
|