summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Basiak <artur.basiak@ts.fujitsu.com>2017-07-19 13:53:04 +0200
committerArtur Basiak <artur.basiak@ts.fujitsu.com>2017-08-10 07:12:26 +0200
commit1ee321bb05debbfeebc3c3d9d2ed66a09d822026 (patch)
tree9887a0240399ad79aa09b9440cb29c9eecb525bc
parent20479d1c1d88153722d91b3d4d228647940b4665 (diff)
Make code compatible with Python3.5
Add adjustments: - read configuration file in binary mode - remove extra encoding - check if string is binary class and convert it to standard string Change-Id: I5f73b6b0e8b5592539e07fe66debf917540ce24c Story: 2001124 Task: 4816
Notes
Notes (review): Code-Review+1: Yushiro FURUKAWA <y.furukawa_2@jp.fujitsu.com> Code-Review+1: Roland Hochmuth <roland.hochmuth@hpe.com> Code-Review+2: Tomasz Trębski <tomasz.trebski@ts.fujitsu.com> Workflow+1: Tomasz Trębski <tomasz.trebski@ts.fujitsu.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 11 Aug 2017 06:42:07 +0000 Reviewed-on: https://review.openstack.org/485173 Project: openstack/monasca-notification Branch: refs/heads/master
-rw-r--r--monasca_notification/common/repositories/mysql/mysql_repo.py6
-rw-r--r--monasca_notification/main.py3
-rw-r--r--monasca_notification/processors/alarm_processor.py8
3 files changed, 11 insertions, 6 deletions
diff --git a/monasca_notification/common/repositories/mysql/mysql_repo.py b/monasca_notification/common/repositories/mysql/mysql_repo.py
index 379e857..2209ee0 100644
--- a/monasca_notification/common/repositories/mysql/mysql_repo.py
+++ b/monasca_notification/common/repositories/mysql/mysql_repo.py
@@ -1,4 +1,4 @@
1# Copyright 2015 FUJITSU LIMITED 1# Copyright 2015-2017 FUJITSU LIMITED
2# (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP 2# (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP
3# 3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 4# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
@@ -17,8 +17,6 @@ import pymysql
17from monasca_notification.common.repositories.base import base_repo 17from monasca_notification.common.repositories.base import base_repo
18from monasca_notification.common.repositories import exceptions as exc 18from monasca_notification.common.repositories import exceptions as exc
19 19
20import six
21
22 20
23log = logging.getLogger(__name__) 21log = logging.getLogger(__name__)
24 22
@@ -52,7 +50,7 @@ class MysqlRepo(base_repo.BaseRepo):
52 self._mysql = pymysql.connect(host=self._mysql_host, 50 self._mysql = pymysql.connect(host=self._mysql_host,
53 port=self._mysql_port, 51 port=self._mysql_port,
54 user=self._mysql_user, 52 user=self._mysql_user,
55 passwd=six.text_type(self._mysql_passwd).encode('utf-8'), 53 passwd=self._mysql_passwd,
56 db=self._mysql_dbname, 54 db=self._mysql_dbname,
57 ssl=self._mysql_ssl, 55 ssl=self._mysql_ssl,
58 use_unicode=True, 56 use_unicode=True,
diff --git a/monasca_notification/main.py b/monasca_notification/main.py
index 1ffecea..8023ff4 100644
--- a/monasca_notification/main.py
+++ b/monasca_notification/main.py
@@ -1,4 +1,5 @@
1# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP 1# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
2# Copyright 2017 FUJITSU LIMITED
2# 3#
3# Licensed under the Apache License, Version 2.0 (the "License"); 4# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License. 5# you may not use this file except in compliance with the License.
@@ -99,7 +100,7 @@ def main(argv=None):
99 else: 100 else:
100 config_file = '/etc/monasca/notification.yaml' 101 config_file = '/etc/monasca/notification.yaml'
101 102
102 config = yaml.safe_load(open(config_file, 'r')) 103 config = yaml.safe_load(open(config_file, 'rb'))
103 104
104 # Setup logging 105 # Setup logging
105 try: 106 try:
diff --git a/monasca_notification/processors/alarm_processor.py b/monasca_notification/processors/alarm_processor.py
index c06e223..ae2b754 100644
--- a/monasca_notification/processors/alarm_processor.py
+++ b/monasca_notification/processors/alarm_processor.py
@@ -1,4 +1,5 @@
1# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP 1# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
2# Copyright 2017 FUJITSU LIMITED
2# 3#
3# Licensed under the Apache License, Version 2.0 (the "License"); 4# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License. 5# you may not use this file except in compliance with the License.
@@ -13,9 +14,10 @@
13# See the License for the specific language governing permissions and 14# See the License for the specific language governing permissions and
14# limitations under the License. 15# limitations under the License.
15 16
16import json
17import logging 17import logging
18import six
18import time 19import time
20import ujson as json
19 21
20from monasca_notification.common.repositories import exceptions as exc 22from monasca_notification.common.repositories import exceptions as exc
21from monasca_notification.common.utils import get_db_repo 23from monasca_notification.common.utils import get_db_repo
@@ -51,6 +53,10 @@ class AlarmProcessor(object):
51 'tenantId', 53 'tenantId',
52 'timestamp' 54 'timestamp'
53 ] 55 ]
56 # check if alarm_data is <class 'bytes'>
57 # if yes convert it to standard string
58 if isinstance(alarm_data, six.binary_type):
59 alarm_data = alarm_data.decode("utf-8")
54 json_alarm = json.loads(alarm_data) 60 json_alarm = json.loads(alarm_data)
55 alarm = json_alarm['alarm-transitioned'] 61 alarm = json_alarm['alarm-transitioned']
56 for field in expected_fields: 62 for field in expected_fields: