class AlarmDeleteTest(TestCase): def setUp(self): self.cli = AlarmDelete() self.api = API() def test_cli_description(self): CLITest.check_description(self, self.cli) def test_cli_help(self): CLITest.check_cli_help(self, self.cli) def test_create_curl(self): runner = CLIRunner(self.cli) alarm_id = 1024 curl = runner.get_output(['-i', str(alarm_id), '-z']) CLITest.check_curl(self, self.cli, curl) def test_api_call(self): api = API() name = 'ALARM_DELETE_API_TEST' + CLITest.random_string(6) metric = 'CPU' trigger_interval = 60000 aggregate = 'sum' operation = 'gt' threshold = '0.80' note = CLITest.random_string(20) alarm = api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold, note=note) self.api.alarm_delete(id=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'])])
def test_api_call(self): self.api = API() name = 'ALARM_GET_TEST' metric = 'CPU' trigger_interval = 60000 aggregate = 'sum' operation = 'gt' threshold = '0.80' alarm_create = self.api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold) alarm_get = self.api.alarm_get(id=alarm_create.id) self.assertEqual(alarm_create.id, alarm_get.id) self.assertEqual(alarm_create.name, alarm_get.name) self.assertEqual(alarm_create.metric, alarm_get.metric) self.assertEqual(alarm_create.trigger_interval, alarm_get.trigger_interval) self.assertEqual(alarm_create.aggregate, alarm_get.aggregate) self.assertEqual(alarm_create.operation, alarm_get.operation) self.assertEqual(alarm_create.threshold, alarm_get.threshold) self.api.alarm_delete(id=alarm_get.id)
def test_credentials(self): parameters = CLITestParameters(filename='credentials.json') api_host = parameters.get_value('api-host', 'value') email = parameters.get_value('email', 'value') api_token = parameters.get_value('api-token', 'value') api = API(api_host=api_host, email=email, api_token=api_token) name = 'ALARM_CREDS_TEST' + CLITest.random_string(6) metric = 'CPU' trigger_interval = 900000 aggregate = 'sum' operation = 'gt' threshold = 0.80 alarm = api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold) self.assertEqual(name, alarm.name) self.assertEqual(metric, alarm.metric) self.assertEqual(trigger_interval, alarm.trigger_interval) self.assertEqual(aggregate, alarm.aggregate) self.assertEqual(operation, alarm.operation) self.assertEqual(threshold, alarm.threshold) api.alarm_delete(id=alarm.id)
class AlarmDeleteTest(TestCase): def setUp(self): self.cli = AlarmDelete() self.api = API() def test_cli_description(self): CLITest.check_description(self, self.cli) def test_cli_help(self): CLITest.check_cli_help(self, self.cli) def test_create_curl(self): runner = CLIRunner(self.cli) alarm_id = 1024 curl = runner.get_output(['-i', str(alarm_id), '-z']) CLITest.check_curl(self, self.cli, curl) def test_api_call(self): api = API() name = 'ALARM_DELETE_API_TEST' + CLITest.random_string(6) metric = 'CPU' trigger_interval = 60000 aggregate = 'sum' operation = 'gt' threshold = '0.80' note = CLITest.random_string(20) alarm = api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold, note=note) self.api.alarm_delete(id=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'])])
class AlarmListTest(TestCase): def setUp(self): self.cli = AlarmList() self.api = API() def test_cli_description(self): CLITest.check_description(self, self.cli) def test_cli_help(self): CLITest.check_cli_help(self, self.cli) def test_create_curl(self): runner = CLIRunner(self.cli) curl = runner.get_output(['-z']) CLITest.check_curl(self, self.cli, curl) def test_api_call(self): alarm_list = self.api.alarm_list() self.assertGreaterEqual(len(alarm_list), 1) for alarm in alarm_list: print(alarm) def test_list_alarm(self): runner_list = CLIRunner(AlarmList()) create = runner_list.get_output([]) result_list = json.loads(create) alarm_list = result_list['result'] self.assertGreaterEqual(len(alarm_list), 1)
def test_api_call(self): api = API() name = 'ALARM_DELETE_API_TEST' + CLITest.random_string(6) metric = 'CPU' trigger_interval = 60000 aggregate = 'sum' operation = 'gt' threshold = '0.80' note = CLITest.random_string(20) alarm = api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold, note=note) self.api.alarm_delete(id=alarm.id)
def setUp(self): self.cli = AlarmCreate() self.api = API()
def setUp(self): self.cli = AlarmDelete() self.api = API()
class AlarmGetTest(TestCase): def setUp(self): self.cli = AlarmGet() self.api = API() def test_cli_description(self): CLITest.check_description(self, self.cli) def test_cli_help(self): CLITest.check_cli_help(self, self.cli) def test_create_curl(self): runner = CLIRunner(self.cli) alarm_id = 1024 curl = runner.get_output(['-i', str(alarm_id), '-z']) CLITest.check_curl(self, self.cli, curl) def test_api_call(self): self.api = API() name = 'ALARM_GET_TEST' metric = 'CPU' trigger_interval = 60000 aggregate = 'sum' operation = 'gt' threshold = '0.80' alarm_create = self.api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold) alarm_get = self.api.alarm_get(id=alarm_create.id) self.assertEqual(alarm_create.id, alarm_get.id) self.assertEqual(alarm_create.name, alarm_get.name) self.assertEqual(alarm_create.metric, alarm_get.metric) self.assertEqual(alarm_create.trigger_interval, alarm_get.trigger_interval) self.assertEqual(alarm_create.aggregate, alarm_get.aggregate) self.assertEqual(alarm_create.operation, alarm_get.operation) self.assertEqual(alarm_create.threshold, alarm_get.threshold) self.api.alarm_delete(id=alarm_get.id) 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'])])
class AlarmGetTest(TestCase): def setUp(self): self.cli = AlarmGet() self.api = API() def test_cli_description(self): CLITest.check_description(self, self.cli) def test_cli_help(self): CLITest.check_cli_help(self, self.cli) def test_create_curl(self): runner = CLIRunner(self.cli) alarm_id = 1024 curl = runner.get_output(['-i', str(alarm_id), '-z']) CLITest.check_curl(self, self.cli, curl) def test_api_call(self): self.api = API() name = 'ALARM_GET_TEST' metric = 'CPU' trigger_interval = 60000 aggregate = 'sum' operation = 'gt' threshold = '0.80' alarm_create = self.api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold) alarm_get = self.api.alarm_get(id=alarm_create.id) self.assertEqual(alarm_create.id, alarm_get.id) self.assertEqual(alarm_create.name, alarm_get.name) self.assertEqual(alarm_create.metric, alarm_get.metric) self.assertEqual(alarm_create.trigger_interval, alarm_get.trigger_interval) self.assertEqual(alarm_create.aggregate, alarm_get.aggregate) self.assertEqual(alarm_create.operation, alarm_get.operation) self.assertEqual(alarm_create.threshold, alarm_get.threshold) self.api.alarm_delete(id=alarm_get.id) 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'])])
def setUp(self): self.cli = AlarmUpdate() self.api = API()
class AlarmUpdateTest(TestCase): def setUp(self): self.cli = AlarmUpdate() self.api = API() def test_cli_description(self): CLITest.check_description(self, self.cli) def test_cli_help(self): CLITest.check_cli_help(self, self.cli) def test_create_curl(self): runner = CLIRunner(self.cli) alarm_id = 1024 alarm_name = 'my-curl' metric_name = 'CPU' aggregate = 'min' operation = 'lt' value = 0.5 trigger_interval = 300000 enabled = False curl = runner.get_output(['-i', str(alarm_id), '-n', alarm_name, '-m', metric_name, '-g', aggregate, '-o', operation, '-v', str(value), '-r', str(trigger_interval), '-x', str(enabled).lower(), '-z']) CLITest.check_curl(self, self.cli, curl) def test_api_call(self): aggregate = 'sum' trigger_interval = 60 is_disabled = True metric_name = 'CPU' note = 'This is a note' alarm_name = 'ALARM_CREATE_TEST' + CLITest.random_string(4) operation = 'gt' per_host_modify = True threshold = '0.80' alarm_create = self.api.alarm_create(aggregate=aggregate, trigger_interval=trigger_interval, is_disabled=is_disabled, metric_name=metric_name, name=alarm_name, note=note, operation=operation, per_host_modify=per_host_modify, threshold=threshold) aggregate = 'avg' trigger_interval = 3600000 is_disabled = False metric_name = 'CPU' note = 'This is a updated note' operation = 'lt' per_host_modify = True threshold = '0.50' alarm_update = self.api.alarm_update(id=alarm_create.id, aggregate=aggregate, trigger_interval=trigger_interval, is_disabled=is_disabled, metric_name=metric_name, name=alarm_name, note=note, operation=operation, per_host_modify=per_host_modify, threshold=threshold) self.assertEqual(aggregate, alarm_update.aggregate) self.assertEqual(trigger_interval, alarm_update.trigger_interval) self.assertEqual(is_disabled, alarm_update.is_disabled) self.assertEqual(metric_name, alarm_update.metric_name) self.assertEqual(alarm_name, alarm_update.name) self.assertEqual(note, alarm_update.note) self.assertEqual(operation, alarm_update.operation) self.assertEqual(per_host_modify, alarm_update.per_host_modify) self.assertEqual(threshold, alarm_update.threshold) self.api.alarm_delete(id=alarm_create.id) 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 setUp(self): self.cli = AlarmGet() self.api = API()
class AlarmCreateTest(TestCase): def setUp(self): self.cli = AlarmCreate() self.api = API() def test_cli_description(self): CLITest.check_description(self, self.cli) def test_cli_help(self): CLITest.check_cli_help(self, self.cli) def test_create_curl(self): runner = CLIRunner(self.cli) alarm_name = 'my-curl' metric = 'CPU' aggregate = 'min' operation = 'lt' value = 0.5 trigger_interval = 300000 enabled = False curl = runner.get_output([ '-n', alarm_name, '-m', metric, '-g', aggregate, '-o', operation, '-v', str(value), '-r', str(trigger_interval), '-x', str(enabled).lower(), '-z' ]) CLITest.check_curl(self, self.cli, curl) def test_api_call(self): name = 'ALARM_CREATE_TEST' + CLITest.random_string(6) metric = 'CPU' trigger_interval = 60000 aggregate = 'sum' operation = 'gt' threshold = 0.80 alarm = self.api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold) self.assertEqual(name, alarm.name) self.assertEqual(metric, alarm.metric) self.assertEqual(trigger_interval, alarm.trigger_interval) self.assertEqual(aggregate, alarm.aggregate) self.assertEqual(operation, alarm.operation) self.assertEqual(threshold, alarm.threshold) self.api.alarm_delete(id=alarm.id) def test_credentials(self): parameters = CLITestParameters(filename='credentials.json') api_host = parameters.get_value('api-host', 'value') email = parameters.get_value('email', 'value') api_token = parameters.get_value('api-token', 'value') api = API(api_host=api_host, email=email, api_token=api_token) name = 'ALARM_CREDS_TEST' + CLITest.random_string(6) metric = 'CPU' trigger_interval = 900000 aggregate = 'sum' operation = 'gt' threshold = 0.80 alarm = api.alarm_create(name=name, metric=metric, trigger_interval=trigger_interval, aggregate=aggregate, operation=operation, threshold=threshold) self.assertEqual(name, alarm.name) self.assertEqual(metric, alarm.metric) self.assertEqual(trigger_interval, alarm.trigger_interval) self.assertEqual(aggregate, alarm.aggregate) self.assertEqual(operation, alarm.operation) self.assertEqual(threshold, alarm.threshold) api.alarm_delete(id=alarm.id) 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'])
def setUp(self): self.cli = AlarmList() self.api = API()
class AlarmUpdateTest(TestCase): def setUp(self): self.cli = AlarmUpdate() self.api = API() def test_cli_description(self): CLITest.check_description(self, self.cli) def test_cli_help(self): CLITest.check_cli_help(self, self.cli) def test_create_curl(self): runner = CLIRunner(self.cli) alarm_id = 1024 alarm_name = 'my-curl' metric_name = 'CPU' aggregate = 'min' operation = 'lt' value = 0.5 trigger_interval = 300000 enabled = False curl = runner.get_output([ '-i', str(alarm_id), '-n', alarm_name, '-m', metric_name, '-g', aggregate, '-o', operation, '-v', str(value), '-r', str(trigger_interval), '-x', str(enabled).lower(), '-z' ]) CLITest.check_curl(self, self.cli, curl) def test_api_call(self): aggregate = 'sum' trigger_interval = 60 is_disabled = True metric_name = 'CPU' note = 'This is a note' alarm_name = 'ALARM_CREATE_TEST' + CLITest.random_string(4) operation = 'gt' per_host_modify = True threshold = '0.80' alarm_create = self.api.alarm_create(aggregate=aggregate, trigger_interval=trigger_interval, is_disabled=is_disabled, metric_name=metric_name, name=alarm_name, note=note, operation=operation, per_host_modify=per_host_modify, threshold=threshold) aggregate = 'avg' trigger_interval = 3600000 is_disabled = False metric_name = 'CPU' note = 'This is a updated note' operation = 'lt' per_host_modify = True threshold = '0.50' alarm_update = self.api.alarm_update(id=alarm_create.id, aggregate=aggregate, trigger_interval=trigger_interval, is_disabled=is_disabled, metric_name=metric_name, name=alarm_name, note=note, operation=operation, per_host_modify=per_host_modify, threshold=threshold) self.assertEqual(aggregate, alarm_update.aggregate) self.assertEqual(trigger_interval, alarm_update.trigger_interval) self.assertEqual(is_disabled, alarm_update.is_disabled) self.assertEqual(metric_name, alarm_update.metric_name) self.assertEqual(alarm_name, alarm_update.name) self.assertEqual(note, alarm_update.note) self.assertEqual(operation, alarm_update.operation) self.assertEqual(per_host_modify, alarm_update.per_host_modify) self.assertEqual(threshold, alarm_update.threshold) self.api.alarm_delete(id=alarm_create.id) 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'])])