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
This commit is contained in:
Artur Basiak 2017-07-19 13:53:04 +02:00
parent 20479d1c1d
commit 1ee321bb05
3 changed files with 11 additions and 6 deletions

View File

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

View File

@ -1,4 +1,5 @@
# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
# Copyright 2017 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -99,7 +100,7 @@ def main(argv=None):
else:
config_file = '/etc/monasca/notification.yaml'
config = yaml.safe_load(open(config_file, 'r'))
config = yaml.safe_load(open(config_file, 'rb'))
# Setup logging
try:

View File

@ -1,4 +1,5 @@
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
# Copyright 2017 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -13,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import logging
import six
import time
import ujson as json
from monasca_notification.common.repositories import exceptions as exc
from monasca_notification.common.utils import get_db_repo
@ -51,6 +53,10 @@ class AlarmProcessor(object):
'tenantId',
'timestamp'
]
# check if alarm_data is <class 'bytes'>
# if yes convert it to standard string
if isinstance(alarm_data, six.binary_type):
alarm_data = alarm_data.decode("utf-8")
json_alarm = json.loads(alarm_data)
alarm = json_alarm['alarm-transitioned']
for field in expected_fields: