def test_create_alarm(self):
        runner_create = CLIRunner(AlarmCreate())

        alarm_name = 'my-alarm' + CLITest.random_string(6)
        trigger_interval = 300000

        create = runner_create.get_output([
            '-n', alarm_name, '-m', 'CPU', '-g', 'max', '-o', 'gt', '-v',
            '0.50', '-r',
            str(trigger_interval)
        ])
        alarm = json.loads(create)
        self.assertEqual(trigger_interval, int(alarm['triggerInterval']))
        self.assertEqual([], alarm['actions'])
        self.assertEqual(1, int(alarm['familyId']))
        self.assertFalse(alarm['isDisabled'])
        self.assertEqual('CPU', alarm['metric'])
        self.assertEqual(alarm_name, alarm['name'])
        self.assertTrue(alarm['perHostNotify'])
        self.assertTrue(alarm['notifyClear'])
        self.assertTrue(alarm['notifySet'])
        self.assertEqual('max', alarm['triggerPredicate']['agg'])
        self.assertEqual('gt', alarm['triggerPredicate']['op'])
        self.assertEqual(0.5, alarm['triggerPredicate']['val'])
        self.assertEqual(3, int(alarm['typeId']))

        self.api.alarm_delete(id=alarm['id'])
class TestCommand(unittest.TestCase):

    def setUp(self):
        self.alarm_create = AlarmCreate()
        pass

    def test_cli_description(self):
        self.assertEqual('Creates a alarm definition in an Boundary account',
                         self.alarm_create.getDescription(), 'Check AlarmCreate description')
Ejemplo n.º 3
0
    def test_update_alarm(self):
        alarm_name = 'my-alarm-' + CLITest.random_string(6)
        metric_name = 'CPU'
        note = CLITest.random_string(50)
        aggregate = 'max'
        op = 'gt'
        value = 0.75
        trigger_interval = 900000
        is_disabled = True
        runner_create = CLIRunner(AlarmCreate())
        create = runner_create.get_output([
            '-n', alarm_name, '-m', metric_name, '-d', note, '-g', aggregate,
            '-o', op, '-v',
            str(value), '-r',
            str(trigger_interval), '-x',
            str(is_disabled).lower()
        ])
        alarm_create = json.loads(create)

        note = CLITest.random_string(50)
        aggregate = 'max'
        op = 'gt'
        value = 0.75
        trigger_interval = 300000
        is_disabled = False

        runner_update = CLIRunner(AlarmUpdate())
        update = runner_update.get_output([
            '-i',
            str(int(alarm_create['id'])), '-n', alarm_name, '-m', metric_name,
            '-d', note, '-g', aggregate, '-o', op, '-v',
            str(value), '-r',
            str(trigger_interval), '-x',
            str(is_disabled).lower()
        ])
        alarm = json.loads(update)

        self.assertEqual(trigger_interval, alarm['triggerInterval'])
        self.assertEqual(1, alarm['familyId'])
        self.assertFalse(is_disabled, alarm['isDisabled'])
        self.assertEqual(metric_name, alarm['metric'])
        self.assertEqual(alarm_name, alarm['name'])
        self.assertEqual(aggregate, alarm['triggerPredicate']['agg'])
        self.assertEqual(op, alarm['triggerPredicate']['op'])
        self.assertEqual(value, alarm['triggerPredicate']['val'])
        self.assertEqual(3, int(alarm['typeId']))
        self.assertEqual(note, alarm['note'])

        runner_delete = CLIRunner(AlarmDelete())
        delete = runner_delete.get_output(['-i', str(alarm['id'])])
    def test_delete_alarm(self):
        name = 'ALARM_DELETE_TEST' + CLITest.random_string(6)
        metric = 'CPU'
        trigger_interval = 60000
        aggregate = 'sum'
        operation = 'gt'
        threshold = '0.80'
        note = CLITest.random_string(20)

        runner_create = CLIRunner(AlarmCreate())
        create = runner_create.get_output([
            '-n', name, '-m', metric, '-g', aggregate, '-o', operation, '-v',
            str(threshold), '-r',
            str(trigger_interval), '-d', note
        ])
        alarm = json.loads(create)
        runner_delete = CLIRunner(AlarmDelete())
        delete = runner_delete.get_output(['-i', str(alarm['id'])])
Ejemplo n.º 5
0
    def test_get_alarm(self):
        runner_create = CLIRunner(AlarmCreate())

        name = 'my-alarm'
        metric = 'CPU'
        aggregate = 'max'
        operation = 'gt'
        threshold = 0.50
        trigger_interval = 300000

        create = runner_create.get_output([
            '-n', name, '-m', metric, '-g', aggregate, '-o', operation, '-v',
            str(threshold), '-r',
            str(trigger_interval)
        ])
        alarm_create = json.loads(create)

        runner_get = CLIRunner(AlarmGet())
        get = runner_get.get_output(['-i', str(alarm_create['id'])])
        alarm_get = json.loads(get)['result']

        self.assertEqual(int(alarm_create['triggerInterval']),
                         alarm_get['triggerInterval'])
        self.assertEqual(alarm_create['actions'], alarm_get['actions'])
        self.assertEqual(int(alarm_create['familyId']),
                         int(alarm_get['familyId']))
        self.assertFalse(alarm_create['isDisabled'], alarm_get['isDisabled'])
        self.assertEqual(alarm_create['metric'], alarm_get['metric'])
        self.assertEqual(alarm_create['name'], alarm_get['name'])
        self.assertTrue(alarm_get['perHostNotify'])
        self.assertEqual(alarm_create['triggerPredicate']['agg'],
                         alarm_get['triggerPredicate']['agg'])
        self.assertEqual(alarm_create['triggerPredicate']['op'],
                         alarm_get['triggerPredicate']['op'])
        self.assertEqual(alarm_create['triggerPredicate']['val'],
                         alarm_get['triggerPredicate']['val'])
        self.assertEqual(int(alarm_create['typeId']), int(alarm_get['typeId']))

        runner_delete = CLIRunner(AlarmDelete())
        delete = runner_delete.get_output(['-i', str(alarm_get['id'])])
Ejemplo n.º 6
0
    def test_search_alarm(self):
        alarm_name = 'alarm_test' + CLITest.random_string(6)
        metric_name = 'CPU'
        aggregate = 'max'
        op = 'gt'
        value = 0.50
        trigger_interval = 300000
        note = CLITest.random_string(20)
        enabled = True
        runner_create = CLIRunner(AlarmCreate())

        create = runner_create.get_output([
            '-n', alarm_name, '-m', metric_name, '-g', aggregate, '-o', op,
            '-v',
            str(value), '-r',
            str(trigger_interval), '-d', note, '-x',
            str(enabled).lower()
        ])

        runner_search = CLIRunner(AlarmSearch())
        search = runner_search.get_output(['-n', alarm_name])
        result_search = json.loads(search)
        alarm = result_search['result'][0]
        self.assertEqual(trigger_interval, alarm['interval'])
        self.assertItemsEqual([], alarm['actions'])
        self.assertEqual(1, int(alarm['familyId']))
        self.assertFalse(False, alarm['isDisabled'])
        self.assertEqual(metric_name, alarm['metric'])
        self.assertEqual(alarm_name, alarm['name'])
        self.assertTrue(alarm['perHostNotify'])
        self.assertEqual(aggregate, alarm['triggerPredicate']['agg'])
        self.assertEqual(op, alarm['triggerPredicate']['op'])
        self.assertEqual(value, alarm['triggerPredicate']['val'])
        self.assertEqual(3, int(alarm['typeId']))

        runner_delete = CLIRunner(AlarmDelete())
        delete = runner_delete.get_output(['-i', str(alarm['id'])])
Ejemplo n.º 7
0
 def alarm_create(self, **kwargs):
     api = AlarmCreate()
     api._kwargs = kwargs
     return api.api_call()
 def setUp(self):
     self.cli = AlarmCreate()
     self.api = API()
Ejemplo n.º 9
0
 def setUp(self):
     self.alarm_create = AlarmCreate()
     pass
Ejemplo n.º 10
0
 def alarm_create(self, **kwargs):
     api = AlarmCreate()
     api._kwargs = kwargs
     return api.api_call()
 def setUp(self):
     self.alarm_create = AlarmCreate()
     pass