summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJui Chandwaskar <jchandwaskar@op5.com>2018-04-11 14:15:08 +0200
committerJui Chandwaskar <jchandwaskar@op5.com>2018-04-11 14:16:27 +0200
commitd396753a839c1317a59fb2867dc2188fc88cf95a (patch)
treeedc4ffb6e0a2bffccd1f80995ded7651a3559d65
parent347049e78ffbffdb6ed5f857e55978b3cad7e86d (diff)
Update pep8 checks
* Set max line length to 100 * Clean up code for pep8 checks Change-Id: Ie00dc204f522fb2112f02f4151ec8a15d5523459 Signed-off-by: Jui Chandwaskar <jchandwaskar@op5.com>
Notes
Notes (review): Code-Review+2: Amir Mofakhar <amofakhar@op5.com> Workflow+1: Amir Mofakhar <amofakhar@op5.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 11 Apr 2018 15:13:36 +0000 Reviewed-on: https://review.openstack.org/560399 Project: openstack/monasca-notification Branch: refs/heads/master
-rw-r--r--monasca_notification/common/repositories/base/base_repo.py19
-rw-r--r--monasca_notification/common/repositories/mysql/mysql_repo.py5
-rw-r--r--monasca_notification/common/repositories/orm/orm_repo.py6
-rw-r--r--monasca_notification/common/repositories/postgres/pgsql_repo.py5
-rw-r--r--monasca_notification/main.py6
-rw-r--r--monasca_notification/plugins/email_notifier.py6
-rw-r--r--monasca_notification/plugins/hipchat_notifier.py30
-rw-r--r--monasca_notification/plugins/jira_notifier.py11
-rw-r--r--monasca_notification/processors/alarm_processor.py9
-rw-r--r--tests/test_alarm_processor.py78
-rw-r--r--tests/test_email_notification.py18
-rw-r--r--tests/test_notification_processor.py18
-rw-r--r--tests/test_webhook_notification.py15
-rw-r--r--tox.ini2
14 files changed, 161 insertions, 67 deletions
diff --git a/monasca_notification/common/repositories/base/base_repo.py b/monasca_notification/common/repositories/base/base_repo.py
index eed94bf..8dc86e5 100644
--- a/monasca_notification/common/repositories/base/base_repo.py
+++ b/monasca_notification/common/repositories/base/base_repo.py
@@ -14,14 +14,17 @@
14 14
15class BaseRepo(object): 15class BaseRepo(object):
16 def __init__(self, config): 16 def __init__(self, config):
17 self._find_alarm_action_sql = """SELECT id, type, name, address, period 17 self._find_alarm_action_sql = \
18 FROM alarm_action as aa 18 """SELECT id, type, name, address, period
19 JOIN notification_method as nm ON aa.action_id = nm.id 19 FROM alarm_action as aa
20 WHERE aa.alarm_definition_id = %s and aa.alarm_state = %s""" 20 JOIN notification_method as nm ON aa.action_id = nm.id
21 self._find_alarm_state_sql = """SELECT state 21 WHERE aa.alarm_definition_id = %s and aa.alarm_state = %s"""
22 FROM alarm 22 self._find_alarm_state_sql = \
23 WHERE alarm.id = %s""" 23 """SELECT state
24 self._insert_notification_types_sql = """INSERT INTO notification_method_type (name) VALUES ( %s)""" 24 FROM alarm
25 WHERE alarm.id = %s"""
26 self._insert_notification_types_sql = \
27 """INSERT INTO notification_method_type (name) VALUES ( %s)"""
25 self._find_all_notification_types_sql = """SELECT name from notification_method_type """ 28 self._find_all_notification_types_sql = """SELECT name from notification_method_type """
26 self._get_notification_sql = """SELECT name, type, address, period 29 self._get_notification_sql = """SELECT name, type, address, period
27 FROM notification_method 30 FROM notification_method
diff --git a/monasca_notification/common/repositories/mysql/mysql_repo.py b/monasca_notification/common/repositories/mysql/mysql_repo.py
index eb4a926..c23ba5d 100644
--- a/monasca_notification/common/repositories/mysql/mysql_repo.py
+++ b/monasca_notification/common/repositories/mysql/mysql_repo.py
@@ -53,7 +53,10 @@ class MysqlRepo(base_repo.BaseRepo):
53 if self._mysql is None: 53 if self._mysql is None:
54 self._connect_to_mysql() 54 self._connect_to_mysql()
55 cur = self._mysql.cursor() 55 cur = self._mysql.cursor()
56 cur.execute(self._find_alarm_action_sql, (alarm['alarmDefinitionId'], alarm['newState'])) 56 cur.execute(
57 self._find_alarm_action_sql,
58 (alarm['alarmDefinitionId'],
59 alarm['newState']))
57 60
58 for row in cur: 61 for row in cur:
59 yield (row[0], row[1].lower(), row[2], row[3], row[4]) 62 yield (row[0], row[1].lower(), row[2], row[3], row[4])
diff --git a/monasca_notification/common/repositories/orm/orm_repo.py b/monasca_notification/common/repositories/orm/orm_repo.py
index cd76d21..697fa3f 100644
--- a/monasca_notification/common/repositories/orm/orm_repo.py
+++ b/monasca_notification/common/repositories/orm/orm_repo.py
@@ -115,7 +115,11 @@ class OrmRepo(object):
115 if notification is None: 115 if notification is None:
116 return None 116 return None
117 else: 117 else:
118 return [notification[0], notification[1].lower(), notification[2], notification[3]] 118 return [
119 notification[0],
120 notification[1].lower(),
121 notification[2],
122 notification[3]]
119 except DatabaseError as e: 123 except DatabaseError as e:
120 LOG.exception("Couldn't fetch the notification method %s", e) 124 LOG.exception("Couldn't fetch the notification method %s", e)
121 raise exc.DatabaseException(e) 125 raise exc.DatabaseException(e)
diff --git a/monasca_notification/common/repositories/postgres/pgsql_repo.py b/monasca_notification/common/repositories/postgres/pgsql_repo.py
index 1ba1e7c..ccc030d 100644
--- a/monasca_notification/common/repositories/postgres/pgsql_repo.py
+++ b/monasca_notification/common/repositories/postgres/pgsql_repo.py
@@ -40,7 +40,10 @@ class PostgresqlRepo(base_repo.BaseRepo):
40 if self._pgsql is None: 40 if self._pgsql is None:
41 self._connect_to_pgsql() 41 self._connect_to_pgsql()
42 cur = self._pgsql.cursor() 42 cur = self._pgsql.cursor()
43 cur.execute(self._find_alarm_action_sql, (alarm['alarmDefinitionId'], alarm['newState'])) 43 cur.execute(
44 self._find_alarm_action_sql,
45 (alarm['alarmDefinitionId'],
46 alarm['newState']))
44 for row in cur: 47 for row in cur:
45 yield (row[0], row[1].lower(), row[2], row[3], row[4]) 48 yield (row[0], row[1].lower(), row[2], row[3], row[4])
46 except psycopg2.Error as e: 49 except psycopg2.Error as e:
diff --git a/monasca_notification/main.py b/monasca_notification/main.py
index 8f091a1..ce0ef32 100644
--- a/monasca_notification/main.py
+++ b/monasca_notification/main.py
@@ -15,7 +15,8 @@
15# limitations under the License. 15# limitations under the License.
16 16
17""" Notification Engine 17""" Notification Engine
18 This engine reads alarms from Kafka and then notifies the customer using their configured notification method. 18 This engine reads alarms from Kafka and then notifies the customer using their configured
19 notification method.
19""" 20"""
20 21
21import multiprocessing 22import multiprocessing
@@ -58,7 +59,8 @@ def clean_exit(signum, frame=None):
58 for process in processors: 59 for process in processors:
59 try: 60 try:
60 if process.is_alive(): 61 if process.is_alive():
61 process.terminate() # Sends sigterm which any processes after a notification is sent attempt to handle 62 # Sends sigterm which any processes after a notification is sent attempt to handle
63 process.terminate()
62 wait_for_exit = True 64 wait_for_exit = True
63 except Exception: # nosec 65 except Exception: # nosec
64 # There is really nothing to do if the kill fails, so just go on. 66 # There is really nothing to do if the kill fails, so just go on.
diff --git a/monasca_notification/plugins/email_notifier.py b/monasca_notification/plugins/email_notifier.py
index 571716f..acb499f 100644
--- a/monasca_notification/plugins/email_notifier.py
+++ b/monasca_notification/plugins/email_notifier.py
@@ -179,9 +179,11 @@ class EmailNotifier(abstract_notifier.AbstractNotifier):
179 179
180 def _create_msg(self, hostname, notification, targethost=None): 180 def _create_msg(self, hostname, notification, targethost=None):
181 """Create two kind of messages: 181 """Create two kind of messages:
182 1. Notifications that include metrics with a hostname as a dimension. There may be more than one hostname. 182 1. Notifications that include metrics with a hostname as a dimension.
183 There may be more than one hostname.
183 We will only report the hostname if there is only one. 184 We will only report the hostname if there is only one.
184 2. Notifications that do not include metrics and therefore no hostname. Example: API initiated changes. 185 2. Notifications that do not include metrics and therefore no hostname.
186 Example: API initiated changes.
185 * A third notification type which include metrics but do not include a hostname will 187 * A third notification type which include metrics but do not include a hostname will
186 be treated as type #2. 188 be treated as type #2.
187 """ 189 """
diff --git a/monasca_notification/plugins/hipchat_notifier.py b/monasca_notification/plugins/hipchat_notifier.py
index d9a2ea4..a901bfb 100644
--- a/monasca_notification/plugins/hipchat_notifier.py
+++ b/monasca_notification/plugins/hipchat_notifier.py
@@ -26,19 +26,19 @@ from monasca_notification.plugins import abstract_notifier
26CONF = cfg.CONF 26CONF = cfg.CONF
27 27
28""" 28"""
29 notification.address = https://hipchat.hpcloud.net/v2/room/<room_id>/notification?auth_token=432432 29notification.address = https://hipchat.hpcloud.net/v2/room/<room_id>/notification?auth_token=432432
30 30
31 How to get access token? 31How to get access token?
32 1) Login to Hipchat with the user account which is used for notification 32 1) Login to Hipchat with the user account which is used for notification
33 2) Go to this page. https://hipchat.hpcloud.net/account/api (Replace your hipchat server name) 33 2) Go to this page. https://hipchat.hpcloud.net/account/api (Replace your hipchat server name)
34 3) You can see option to "Create token". Use the capability "SendNotification" 34 3) You can see option to "Create token". Use the capability "SendNotification"
35 35
36 How to get the Room ID? 36How to get the Room ID?
37 1) Login to Hipchat with the user account which is used for notification 37 1) Login to Hipchat with the user account which is used for notification
38 2) Go to this page. https://hipchat.hpcloud.net/account/api (Replace your hipchat server name) 38 2) Go to this page. https://hipchat.hpcloud.net/account/api (Replace your hipchat server name)
39 3) Click on the Rooms tab 39 3) Click on the Rooms tab
40 4) Click on any Room of your choice. 40 4) Click on any Room of your choice.
41 5) Room ID is the API ID field 41 5) Room ID is the API ID field
42 42
43""" 43"""
44 44
@@ -115,7 +115,10 @@ class HipChatNotifier(abstract_notifier.AbstractNotifier):
115 115
116 query_params = urllib.parse.parse_qs(parsed_url.query) 116 query_params = urllib.parse.parse_qs(parsed_url.query)
117 # URL without query params 117 # URL without query params
118 url = urllib.parse.urljoin(notification.address, urllib.parse.urlparse(notification.address).path) 118 url = urllib.parse.urljoin(
119 notification.address,
120 urllib.parse.urlparse(
121 notification.address).path)
119 122
120 # Default option is to do cert verification 123 # Default option is to do cert verification
121 verify = not CONF.hipchat_notifier.insecure 124 verify = not CONF.hipchat_notifier.insecure
@@ -143,7 +146,8 @@ class HipChatNotifier(abstract_notifier.AbstractNotifier):
143 self._log.info("Notification successfully posted.") 146 self._log.info("Notification successfully posted.")
144 return True 147 return True
145 else: 148 else:
146 msg = "Received an HTTP code {} when trying to send to hipchat on URL {} with response {}." 149 msg = ("Received an HTTP code {} when trying to send to hipchat on URL {}"
150 " with response {}.")
147 self._log.error(msg.format(result.status_code, url, result.text)) 151 self._log.error(msg.format(result.status_code, url, result.text))
148 return False 152 return False
149 except Exception: 153 except Exception:
diff --git a/monasca_notification/plugins/jira_notifier.py b/monasca_notification/plugins/jira_notifier.py
index 86c2341..0152368 100644
--- a/monasca_notification/plugins/jira_notifier.py
+++ b/monasca_notification/plugins/jira_notifier.py
@@ -147,7 +147,8 @@ class JiraNotifier(AbstractNotifier):
147 'metrics': notification.metrics} 147 'metrics': notification.metrics}
148 148
149 jira_fields = {} 149 jira_fields = {}
150 summary_format_string = "Monasca alarm for alarm_defintion {0} status changed to {1} for the alarm_id {2}" 150 summary_format_string = ("Monasca alarm for alarm_defintion {0} status changed to {1} "
151 "for the alarm_id {2}")
151 jira_fields["summary"] = summary_format_string.format(notification.alarm_name, 152 jira_fields["summary"] = summary_format_string.format(notification.alarm_name,
152 notification.state, 153 notification.state,
153 notification.alarm_id) 154 notification.alarm_id)
@@ -173,7 +174,10 @@ class JiraNotifier(AbstractNotifier):
173 parsed_url = urllib.parse.urlsplit(notification.address) 174 parsed_url = urllib.parse.urlsplit(notification.address)
174 query_params = urllib.parse.parse_qs(parsed_url.query) 175 query_params = urllib.parse.parse_qs(parsed_url.query)
175 # URL without query params 176 # URL without query params
176 url = urllib.parse.urljoin(notification.address, urllib.parse.urlparse(notification.address).path) 177 url = urllib.parse.urljoin(
178 notification.address,
179 urllib.parse.urlparse(
180 notification.address).path)
177 181
178 jira_fields["project"] = query_params["project"][0] 182 jira_fields["project"] = query_params["project"][0]
179 if query_params.get("component"): 183 if query_params.get("component"):
@@ -229,7 +233,8 @@ class JiraNotifier(AbstractNotifier):
229 if current_state.lower() in ["resolved", "closed"]: 233 if current_state.lower() in ["resolved", "closed"]:
230 # Open the the issue 234 # Open the the issue
231 transitions = jira_obj.transitions(issue) 235 transitions = jira_obj.transitions(issue)
232 allowed_transistions = [(t['id'], t['name']) for t in transitions if "reopen" in t['name'].lower()] 236 allowed_transistions = [(t['id'], t['name'])
237 for t in transitions if "reopen" in t['name'].lower()]
233 if allowed_transistions: 238 if allowed_transistions:
234 # Reopen the issue 239 # Reopen the issue
235 jira_obj.transition_issue(issue, allowed_transistions[0][0]) 240 jira_obj.transition_issue(issue, allowed_transistions[0][0])
diff --git a/monasca_notification/processors/alarm_processor.py b/monasca_notification/processors/alarm_processor.py
index 20ac84a..bb58108 100644
--- a/monasca_notification/processors/alarm_processor.py
+++ b/monasca_notification/processors/alarm_processor.py
@@ -113,7 +113,9 @@ class AlarmProcessor(object):
113 alarm = self._parse_alarm(raw_alarm[1].message.value) 113 alarm = self._parse_alarm(raw_alarm[1].message.value)
114 except Exception as e: # This is general because of a lack of json exception base class 114 except Exception as e: # This is general because of a lack of json exception base class
115 failed_parse_count += 1 115 failed_parse_count += 1
116 log.exception("Invalid Alarm format skipping partition %d, offset %d\nError%s" % (partition, offset, e)) 116 log.exception(
117 "Invalid Alarm format skipping partition %d, offset %d\nError%s" %
118 (partition, offset, e))
117 return [], partition, offset 119 return [], partition, offset
118 120
119 log.debug("Read alarm from alarms sent_queue. Partition %d, Offset %d, alarm data %s" 121 log.debug("Read alarm from alarms sent_queue. Partition %d, Offset %d, alarm data %s"
@@ -131,8 +133,9 @@ class AlarmProcessor(object):
131 133
132 if len(notifications) == 0: 134 if len(notifications) == 0:
133 no_notification_count += 1 135 no_notification_count += 1
134 log.debug('No notifications found for this alarm, partition %d, offset %d, alarm data %s' 136 log.debug(
135 % (partition, offset, alarm)) 137 'No notifications found for this alarm, partition %d, offset %d, alarm data %s' %
138 (partition, offset, alarm))
136 return [], partition, offset 139 return [], partition, offset
137 else: 140 else:
138 log.debug('Found %d notifications: [%s]', len(notifications), notifications) 141 log.debug('Found %d notifications: [%s]', len(notifications), notifications)
diff --git a/tests/test_alarm_processor.py b/tests/test_alarm_processor.py
index c05691b..dba5f17 100644
--- a/tests/test_alarm_processor.py
+++ b/tests/test_alarm_processor.py
@@ -45,9 +45,11 @@ class TestAlarmProcessor(base.BaseTestCase):
45 @mock.patch('pymysql.connect') 45 @mock.patch('pymysql.connect')
46 @mock.patch('monasca_notification.processors.alarm_processor.log') 46 @mock.patch('monasca_notification.processors.alarm_processor.log')
47 def _run_alarm_processor(self, alarm, sql_response, mock_log, mock_mysql): 47 def _run_alarm_processor(self, alarm, sql_response, mock_log, mock_mysql):
48 """Runs a mocked alarm processor reading from queue while running, returns (queue_message, log_message) 48 """Runs a mocked alarm processor reading from queue while running,
49 returns (queue_message, log_message)
49 """ 50 """
50 # Since the log runs in another thread I can mock it directly, instead change the methods to put to a queue 51 # Since the log runs in another thread I can mock it directly, instead
52 # change the methods to put to a queue
51 mock_log.warn = self.trap.append 53 mock_log.warn = self.trap.append
52 mock_log.error = self.trap.append 54 mock_log.error = self.trap.append
53 mock_log.exception = self.trap.append 55 mock_log.exception = self.trap.append
@@ -84,10 +86,20 @@ class TestAlarmProcessor(base.BaseTestCase):
84 def test_old_timestamp(self): 86 def test_old_timestamp(self):
85 """Should cause the alarm_ttl to fire log a warning and push to finished queue.""" 87 """Should cause the alarm_ttl to fire log a warning and push to finished queue."""
86 timestamp = 1375346830042 88 timestamp = 1375346830042
87 alarm_dict = {"tenantId": "0", "alarmDefinitionId": "0", "alarmId": "1", "alarmName": "test Alarm", 89 alarm_dict = {
88 "oldState": "OK", "newState": "ALARM", "stateChangeReason": "I am alarming!", 90 "tenantId": "0",
89 "timestamp": timestamp, "actionsEnabled": 1, "metrics": "cpu_util", 91 "alarmDefinitionId": "0",
90 "severity": "LOW", "link": "http://some-place.com", "lifecycleState": "OPEN"} 92 "alarmId": "1",
93 "alarmName": "test Alarm",
94 "oldState": "OK",
95 "newState": "ALARM",
96 "stateChangeReason": "I am alarming!",
97 "timestamp": timestamp,
98 "actionsEnabled": 1,
99 "metrics": "cpu_util",
100 "severity": "LOW",
101 "link": "http://some-place.com",
102 "lifecycleState": "OPEN"}
91 alarm = self._create_raw_alarm(0, 2, alarm_dict) 103 alarm = self._create_raw_alarm(0, 2, alarm_dict)
92 expected_datetime = time.ctime(timestamp / 1000) 104 expected_datetime = time.ctime(timestamp / 1000)
93 105
@@ -105,10 +117,20 @@ class TestAlarmProcessor(base.BaseTestCase):
105 def test_no_notifications(self): 117 def test_no_notifications(self):
106 """Test an alarm with no defined notifications 118 """Test an alarm with no defined notifications
107 """ 119 """
108 alarm_dict = {"tenantId": "0", "alarmDefinitionId": "0", "alarmId": "1", "alarmName": "test Alarm", 120 alarm_dict = {
109 "oldState": "OK", "newState": "ALARM", "stateChangeReason": "I am alarming!", 121 "tenantId": "0",
110 "timestamp": time.time() * 1000, "actionsEnabled": 1, "metrics": "cpu_util", 122 "alarmDefinitionId": "0",
111 "severity": "LOW", "link": "http://some-place.com", "lifecycleState": "OPEN"} 123 "alarmId": "1",
124 "alarmName": "test Alarm",
125 "oldState": "OK",
126 "newState": "ALARM",
127 "stateChangeReason": "I am alarming!",
128 "timestamp": time.time() * 1000,
129 "actionsEnabled": 1,
130 "metrics": "cpu_util",
131 "severity": "LOW",
132 "link": "http://some-place.com",
133 "lifecycleState": "OPEN"}
112 alarm = self._create_raw_alarm(0, 3, alarm_dict) 134 alarm = self._create_raw_alarm(0, 3, alarm_dict)
113 135
114 notifications, partition, offset = self._run_alarm_processor(alarm, None) 136 notifications, partition, offset = self._run_alarm_processor(alarm, None)
@@ -120,10 +142,20 @@ class TestAlarmProcessor(base.BaseTestCase):
120 def test_valid_notification(self): 142 def test_valid_notification(self):
121 """Test a valid notification, being put onto the notification_queue 143 """Test a valid notification, being put onto the notification_queue
122 """ 144 """
123 alarm_dict = {"tenantId": "0", "alarmDefinitionId": "0", "alarmId": "1", "alarmName": "test Alarm", 145 alarm_dict = {
124 "oldState": "OK", "newState": "ALARM", "stateChangeReason": "I am alarming!", 146 "tenantId": "0",
125 "timestamp": time.time() * 1000, "actionsEnabled": 1, "metrics": "cpu_util", 147 "alarmDefinitionId": "0",
126 "severity": "LOW", "link": "http://some-place.com", "lifecycleState": "OPEN"} 148 "alarmId": "1",
149 "alarmName": "test Alarm",
150 "oldState": "OK",
151 "newState": "ALARM",
152 "stateChangeReason": "I am alarming!",
153 "timestamp": time.time() * 1000,
154 "actionsEnabled": 1,
155 "metrics": "cpu_util",
156 "severity": "LOW",
157 "link": "http://some-place.com",
158 "lifecycleState": "OPEN"}
127 alarm = self._create_raw_alarm(0, 4, alarm_dict) 159 alarm = self._create_raw_alarm(0, 4, alarm_dict)
128 160
129 sql_response = [[1, 'EMAIL', 'test notification', 'me@here.com', 0]] 161 sql_response = [[1, 'EMAIL', 'test notification', 'me@here.com', 0]]
@@ -137,10 +169,20 @@ class TestAlarmProcessor(base.BaseTestCase):
137 self.assertEqual(offset, 4) 169 self.assertEqual(offset, 4)
138 170
139 def test_two_valid_notifications(self): 171 def test_two_valid_notifications(self):
140 alarm_dict = {"tenantId": "0", "alarmDefinitionId": "0", "alarmId": "1", "alarmName": "test Alarm", 172 alarm_dict = {
141 "oldState": "OK", "newState": "ALARM", "stateChangeReason": "I am alarming!", 173 "tenantId": "0",
142 "timestamp": time.time() * 1000, "actionsEnabled": 1, "metrics": "cpu_util", 174 "alarmDefinitionId": "0",
143 "severity": "LOW", "link": "http://some-place.com", "lifecycleState": "OPEN"} 175 "alarmId": "1",
176 "alarmName": "test Alarm",
177 "oldState": "OK",
178 "newState": "ALARM",
179 "stateChangeReason": "I am alarming!",
180 "timestamp": time.time() * 1000,
181 "actionsEnabled": 1,
182 "metrics": "cpu_util",
183 "severity": "LOW",
184 "link": "http://some-place.com",
185 "lifecycleState": "OPEN"}
144 186
145 alarm = self._create_raw_alarm(0, 5, alarm_dict) 187 alarm = self._create_raw_alarm(0, 5, alarm_dict)
146 188
diff --git a/tests/test_email_notification.py b/tests/test_email_notification.py
index 6833693..f108a8b 100644
--- a/tests/test_email_notification.py
+++ b/tests/test_email_notification.py
@@ -143,7 +143,8 @@ class TestEmail(base.PluginTestCase):
143 143
144 alarm_dict = alarm(metric) 144 alarm_dict = alarm(metric)
145 145
146 notification = Notification(0, 'email', 'email notification', 'me@here.com', 0, 0, alarm_dict) 146 notification = Notification(0, 'email', 'email notification',
147 'me@here.com', 0, 0, alarm_dict)
147 148
148 self.trap.append(email.send_notification(notification)) 149 self.trap.append(email.send_notification(notification))
149 150
@@ -267,7 +268,8 @@ class TestEmail(base.PluginTestCase):
267 268
268 alarm_dict = alarm(metrics) 269 alarm_dict = alarm(metrics)
269 270
270 notification = Notification(0, 'email', 'email notification', 'me@here.com', 0, 0, alarm_dict) 271 notification = Notification(0, 'email', 'email notification',
272 'me@here.com', 0, 0, alarm_dict)
271 273
272 self.trap.append(email.send_notification(notification)) 274 self.trap.append(email.send_notification(notification))
273 275
@@ -313,7 +315,8 @@ class TestEmail(base.PluginTestCase):
313 315
314 alarm_dict = alarm(metrics) 316 alarm_dict = alarm(metrics)
315 317
316 notification = Notification(0, 'email', 'email notification', 'me@here.com', 0, 0, alarm_dict) 318 notification = Notification(0, 'email', 'email notification',
319 'me@here.com', 0, 0, alarm_dict)
317 320
318 email_result = email.send_notification(notification) 321 email_result = email.send_notification(notification)
319 322
@@ -355,7 +358,8 @@ class TestEmail(base.PluginTestCase):
355 358
356 alarm_dict = alarm(metrics) 359 alarm_dict = alarm(metrics)
357 360
358 notification = Notification(0, 'email', 'email notification', 'me@here.com', 0, 0, alarm_dict) 361 notification = Notification(0, 'email', 'email notification',
362 'me@here.com', 0, 0, alarm_dict)
359 363
360 self.trap.append(email.send_notification(notification)) 364 self.trap.append(email.send_notification(notification))
361 365
@@ -395,7 +399,8 @@ class TestEmail(base.PluginTestCase):
395 399
396 alarm_dict = alarm(metrics) 400 alarm_dict = alarm(metrics)
397 401
398 notification = Notification(0, 'email', 'email notification', 'me@here.com', 0, 0, alarm_dict) 402 notification = Notification(0, 'email', 'email notification',
403 'me@here.com', 0, 0, alarm_dict)
399 404
400 self.trap.append(email.send_notification(notification)) 405 self.trap.append(email.send_notification(notification))
401 406
@@ -435,7 +440,8 @@ class TestEmail(base.PluginTestCase):
435 440
436 alarm_dict = alarm(metrics) 441 alarm_dict = alarm(metrics)
437 442
438 notification = Notification(0, 'email', 'email notification', 'me@here.com', 0, 0, alarm_dict) 443 notification = Notification(0, 'email', 'email notification',
444 'me@here.com', 0, 0, alarm_dict)
439 445
440 self.trap.append(email.send_notification(notification)) 446 self.trap.append(email.send_notification(notification))
441 447
diff --git a/tests/test_notification_processor.py b/tests/test_notification_processor.py
index 92fd009..8765bc6 100644
--- a/tests/test_notification_processor.py
+++ b/tests/test_notification_processor.py
@@ -93,7 +93,8 @@ class TestNotificationProcessor(base.BaseTestCase):
93 "timestamp": time.time(), 93 "timestamp": time.time(),
94 "metrics": metric} 94 "metrics": metric}
95 95
96 notification = m_notification.Notification(0, 'email', 'email notification', 'me@here.com', 0, 0, alarm_dict) 96 notification = m_notification.Notification(
97 0, 'email', 'email notification', 'me@here.com', 0, 0, alarm_dict)
97 98
98 self._start_processor([notification]) 99 self._start_processor([notification])
99 100
@@ -104,9 +105,18 @@ class TestNotificationProcessor(base.BaseTestCase):
104 def test_invalid_notification(self): 105 def test_invalid_notification(self):
105 """Verify invalid notification type is rejected. 106 """Verify invalid notification type is rejected.
106 """ 107 """
107 alarm_dict = {"tenantId": "0", "alarmId": "0", "alarmName": "test Alarm", "oldState": "OK", "newState": "ALARM", 108 alarm_dict = {
108 "stateChangeReason": "I am alarming!", "timestamp": time.time(), "metrics": "cpu_util", 109 "tenantId": "0",
109 "severity": "LOW", "link": "http://some-place.com", "lifecycleState": "OPEN"} 110 "alarmId": "0",
111 "alarmName": "test Alarm",
112 "oldState": "OK",
113 "newState": "ALARM",
114 "stateChangeReason": "I am alarming!",
115 "timestamp": time.time(),
116 "metrics": "cpu_util",
117 "severity": "LOW",
118 "link": "http://some-place.com",
119 "lifecycleState": "OPEN"}
110 invalid_notification = m_notification.Notification(0, 'invalid', 'test notification', 120 invalid_notification = m_notification.Notification(0, 'invalid', 'test notification',
111 'me@here.com', 0, 0, alarm_dict) 121 'me@here.com', 0, 0, alarm_dict)
112 122
diff --git a/tests/test_webhook_notification.py b/tests/test_webhook_notification.py
index cd386d1..d43f0ab 100644
--- a/tests/test_webhook_notification.py
+++ b/tests/test_webhook_notification.py
@@ -111,10 +111,17 @@ class TestWebhook(base.PluginTestCase):
111 self.maxDiff = None 111 self.maxDiff = None
112 # timestamp is in milliseconds while alarm_timestamp is in seconds 112 # timestamp is in milliseconds while alarm_timestamp is in seconds
113 self.assertEqual(json.loads(data), 113 self.assertEqual(json.loads(data),
114 {"metrics": [{"dimensions": {"hostname": "foo1", "service": "bar1"}}], "alarm_id": "0", 114 {"metrics": [{"dimensions": {"hostname": "foo1",
115 "state": "ALARM", "alarm_timestamp": 1429023453, "tenant_id": "0", 115 "service": "bar1"}}],
116 "old_state": "OK", "alarm_description": "test Alarm description", 116 "alarm_id": "0",
117 "message": "I am alarming!", "alarm_definition_id": 0, "alarm_name": "test Alarm"}) 117 "state": "ALARM",
118 "alarm_timestamp": 1429023453,
119 "tenant_id": "0",
120 "old_state": "OK",
121 "alarm_description": "test Alarm description",
122 "message": "I am alarming!",
123 "alarm_definition_id": 0,
124 "alarm_name": "test Alarm"})
118 self.assertEqual(headers, {'content-type': 'application/json'}) 125 self.assertEqual(headers, {'content-type': 'application/json'})
119 126
120 return_value = self.trap.get() 127 return_value = self.trap.get()
diff --git a/tox.ini b/tox.ini
index 85dc6ee..80792df 100644
--- a/tox.ini
+++ b/tox.ini
@@ -78,7 +78,7 @@ description = Generates an example of monasca-notification configuration file
78commands = oslo-config-generator --config-file={toxinidir}/config-generator/notification.conf 78commands = oslo-config-generator --config-file={toxinidir}/config-generator/notification.conf
79 79
80[flake8] 80[flake8]
81max-line-length = 120 81max-line-length = 100
82# TODO: ignored checks should be enabled in the future 82# TODO: ignored checks should be enabled in the future
83# H201 no 'except:' at least use 'except Exception:' 83# H201 no 'except:' at least use 'except Exception:'
84# H202: assertRaises Exception too broad 84# H202: assertRaises Exception too broad