def test_good_notifications_create_subcommand_webhook(self): self._script_keystone_client() resp = fakes.FakeHTTPResponse( 201, 'Created', {'location': 'http://no.where/v2.0/notification-methods'}, None) http.HTTPClient.json_request('POST', '/notification-methods', data={ 'name': 'mypost', 'type': 'WEBHOOK', 'address': 'http://localhost:8080' }, headers={ 'X-Auth-Key': 'password', 'X-Auth-User': '******' }).AndReturn((resp, 'id')) self.m.ReplayAll() argstrings = [ 'notification-create mypost WEBHOOK http://localhost:8080', ] for argstr in argstrings: retvalue = self.shell(argstr) self.assertRegexpMatches(retvalue, "id")
def test_good_metrics_create_subcommand(self): self._script_keystone_client() resp = fakes.FakeHTTPResponse( 204, 'Created', {'location': 'http://no.where/v2.0/metrics'}, None) http.HTTPClient.json_request('POST', '/metrics', data={ 'timestamp': 1395691090, 'name': 'metric1', 'value': 123.0 }, headers={ 'X-Auth-Key': 'password', 'X-Auth-User': '******' }).AndReturn((resp, None)) self.m.ReplayAll() argstrings = [ 'metric-create metric1 123 --time 1395691090', ] for argstr in argstrings: retvalue = self.shell(argstr) self.assertRegexpMatches(retvalue, "^Success")
def test_good_notifications_update(self): self._script_keystone_client() id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96491' resp = fakes.FakeHTTPResponse( 201, 'Created', {'location': 'http://no.where/v2.0/notification-methods'}, None) http.HTTPClient.json_request('PUT', '/notification-methods/' + id_str, data={ 'name': 'notification_updated_name', 'type': 'EMAIL', 'address': '*****@*****.**', 'period': 0 }, headers={ 'X-Auth-Key': 'password', 'X-Auth-User': '******' }).AndReturn((resp, 'id')) self.m.ReplayAll() argstring = 'notification-update {0} notification_updated_name ' \ 'EMAIL [email protected] 0'.format(id_str) retvalue = self.shell(argstring) self.assertRegexpMatches(retvalue, "id")
def test_good_alarm_definition_update(self): self._script_keystone_client() cmd = 'alarm-definition-update' id = '0495340b-58fd-4e1c-932b-5e6f9cc96490' name = 'alarm_name' description = 'test_alarm_definition' expression = 'avg(Test_Metric_1)>=10' notif_id = '16012650-0b62-4692-9103-2d04fe81cc93' enabled = 'True' match_by = 'hostname' severity = 'CRITICAL' resp = fakes.FakeHTTPResponse( 201, 'Created', {'location': 'http://no.where/v2.0/notification-methods'}, None) http.HTTPClient.json_request('PUT', '/alarm-definitions/' + id, data={ 'name': name, 'description': description, 'expression': expression, 'alarm_actions': [notif_id], 'undetermined_actions': [notif_id], 'ok_actions': [notif_id], 'match_by': [match_by], 'actions_enabled': bool(enabled), 'severity': severity }, headers={ 'X-Auth-Key': 'password', 'X-Auth-User': '******' }).AndReturn((resp, 'id')) self.m.ReplayAll() args = [ cmd, id, name, description, expression, notif_id, notif_id, notif_id, enabled, match_by, severity ] argstring = " ".join(args) retvalue = self.shell(argstring) self.assertRegexpMatches(retvalue, "id")
def test_notifications_types_list(self): self._script_keystone_client() resp_body = [{ "type": "WEBHOOK" }, { "type": "EMAIL" }, { "type": "PAGERDUTY" }] resp = fakes.FakeHTTPResponse(status_code=200, content=resp_body) http.HTTPClient.json_request('GET', '/notification-methods/types', headers={ 'X-Auth-Key': 'password', 'X-Auth-User': '******' }).AndReturn(((resp, resp_body))) self.m.ReplayAll() argstrings = ["notification-type-list"] retvalue = self.shell("".join(argstrings)) self.assertRegexpMatches(retvalue, "types")