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:
parent
20479d1c1d
commit
1ee321bb05
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2015 FUJITSU LIMITED
|
# Copyright 2015-2017 FUJITSU LIMITED
|
||||||
# (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP
|
# (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
|
# 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.base import base_repo
|
||||||
from monasca_notification.common.repositories import exceptions as exc
|
from monasca_notification.common.repositories import exceptions as exc
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -52,7 +50,7 @@ class MysqlRepo(base_repo.BaseRepo):
|
||||||
self._mysql = pymysql.connect(host=self._mysql_host,
|
self._mysql = pymysql.connect(host=self._mysql_host,
|
||||||
port=self._mysql_port,
|
port=self._mysql_port,
|
||||||
user=self._mysql_user,
|
user=self._mysql_user,
|
||||||
passwd=six.text_type(self._mysql_passwd).encode('utf-8'),
|
passwd=self._mysql_passwd,
|
||||||
db=self._mysql_dbname,
|
db=self._mysql_dbname,
|
||||||
ssl=self._mysql_ssl,
|
ssl=self._mysql_ssl,
|
||||||
use_unicode=True,
|
use_unicode=True,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
|
||||||
|
# Copyright 2017 FUJITSU LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -99,7 +100,7 @@ def main(argv=None):
|
||||||
else:
|
else:
|
||||||
config_file = '/etc/monasca/notification.yaml'
|
config_file = '/etc/monasca/notification.yaml'
|
||||||
|
|
||||||
config = yaml.safe_load(open(config_file, 'r'))
|
config = yaml.safe_load(open(config_file, 'rb'))
|
||||||
|
|
||||||
# Setup logging
|
# Setup logging
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
|
||||||
|
# Copyright 2017 FUJITSU LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with 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
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
|
import six
|
||||||
import time
|
import time
|
||||||
|
import ujson as json
|
||||||
|
|
||||||
from monasca_notification.common.repositories import exceptions as exc
|
from monasca_notification.common.repositories import exceptions as exc
|
||||||
from monasca_notification.common.utils import get_db_repo
|
from monasca_notification.common.utils import get_db_repo
|
||||||
|
@ -51,6 +53,10 @@ class AlarmProcessor(object):
|
||||||
'tenantId',
|
'tenantId',
|
||||||
'timestamp'
|
'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)
|
json_alarm = json.loads(alarm_data)
|
||||||
alarm = json_alarm['alarm-transitioned']
|
alarm = json_alarm['alarm-transitioned']
|
||||||
for field in expected_fields:
|
for field in expected_fields:
|
||||||
|
|
Loading…
Reference in New Issue