Browse Source

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
Artur Basiak 1 year ago
parent
commit
1ee321bb05

+ 2
- 4
monasca_notification/common/repositories/mysql/mysql_repo.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2015 FUJITSU LIMITED
1
+# Copyright 2015-2017 FUJITSU LIMITED
2 2
 # (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP
3 3
 #
4 4
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
@@ -17,8 +17,6 @@ import pymysql
17 17
 from monasca_notification.common.repositories.base import base_repo
18 18
 from monasca_notification.common.repositories import exceptions as exc
19 19
 
20
-import six
21
-
22 20
 
23 21
 log = logging.getLogger(__name__)
24 22
 
@@ -52,7 +50,7 @@ class MysqlRepo(base_repo.BaseRepo):
52 50
             self._mysql = pymysql.connect(host=self._mysql_host,
53 51
                                           port=self._mysql_port,
54 52
                                           user=self._mysql_user,
55
-                                          passwd=six.text_type(self._mysql_passwd).encode('utf-8'),
53
+                                          passwd=self._mysql_passwd,
56 54
                                           db=self._mysql_dbname,
57 55
                                           ssl=self._mysql_ssl,
58 56
                                           use_unicode=True,

+ 2
- 1
monasca_notification/main.py View File

@@ -1,4 +1,5 @@
1 1
 # (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
2
+# Copyright 2017 FUJITSU LIMITED
2 3
 #
3 4
 # Licensed under the Apache License, Version 2.0 (the "License");
4 5
 # you may not use this file except in compliance with the License.
@@ -99,7 +100,7 @@ def main(argv=None):
99 100
     else:
100 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 105
     # Setup logging
105 106
     try:

+ 7
- 1
monasca_notification/processors/alarm_processor.py View File

@@ -1,4 +1,5 @@
1 1
 # (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
2
+# Copyright 2017 FUJITSU LIMITED
2 3
 #
3 4
 # Licensed under the Apache License, Version 2.0 (the "License");
4 5
 # you may not use this file except in compliance with the License.
@@ -13,9 +14,10 @@
13 14
 # See the License for the specific language governing permissions and
14 15
 # limitations under the License.
15 16
 
16
-import json
17 17
 import logging
18
+import six
18 19
 import time
20
+import ujson as json
19 21
 
20 22
 from monasca_notification.common.repositories import exceptions as exc
21 23
 from monasca_notification.common.utils import get_db_repo
@@ -51,6 +53,10 @@ class AlarmProcessor(object):
51 53
             'tenantId',
52 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 60
         json_alarm = json.loads(alarm_data)
55 61
         alarm = json_alarm['alarm-transitioned']
56 62
         for field in expected_fields:

Loading…
Cancel
Save