From 20abc47e6d445fa4252c5a11b0db9d4e0227dd33 Mon Sep 17 00:00:00 2001 From: Mark McClain Date: Wed, 9 Aug 2017 18:32:57 +0000 Subject: [PATCH] fix text conversion for python2/3 Change-Id: I53f2a006670e7afda575f4c403939e8b152b455a --- networking_arista/ml2/rpc/arista_eapi.py | 7 ++++--- networking_arista/ml2/rpc/arista_json.py | 5 +++-- networking_arista/ml2/rpc/base.py | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/networking_arista/ml2/rpc/arista_eapi.py b/networking_arista/ml2/rpc/arista_eapi.py index 7ac4996e..b40d91fe 100644 --- a/networking_arista/ml2/rpc/arista_eapi.py +++ b/networking_arista/ml2/rpc/arista_eapi.py @@ -21,6 +21,7 @@ from neutron_lib import constants as n_const from oslo_config import cfg from oslo_log import log as logging import requests +import six from networking_arista._i18n import _, _LI, _LW, _LE from networking_arista.common import constants as const @@ -91,8 +92,8 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase): for data in response.json()['error']['data']: if type(data) == dict and 'errors' in data: if const.ERR_CVX_NOT_LEADER in data['errors'][0]: - msg = unicode("%s is not the master" % ( - self._server_ip)) + msg = six.text_type("%s is not the master" % ( + self._server_ip)) LOG.info(msg) return None @@ -123,7 +124,7 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase): LOG.info("Ignoring invalid JSON response") return None except Exception as error: - msg = unicode(error) + msg = six.text_type(error) LOG.warning(msg) raise diff --git a/networking_arista/ml2/rpc/arista_json.py b/networking_arista/ml2/rpc/arista_json.py index 4a417d51..29d137cb 100644 --- a/networking_arista/ml2/rpc/arista_json.py +++ b/networking_arista/ml2/rpc/arista_json.py @@ -20,6 +20,7 @@ from neutron_lib import constants as n_const from oslo_log import log as logging from oslo_utils import excutils import requests +import six from networking_arista._i18n import _, _LI, _LW, _LE from networking_arista.common import constants as const @@ -96,7 +97,7 @@ class AristaRPCWrapperJSON(AristaRPCWrapperBase): except ValueError: LOG.warning(_LW("Ignoring invalid JSON response: %s"), resp.text) except Exception as error: - msg = unicode(error) + msg = six.text_type(error) LOG.warning(msg) # reraise the exception with excutils.save_and_reraise_exception() as ctxt: @@ -117,7 +118,7 @@ class AristaRPCWrapperJSON(AristaRPCWrapperBase): def _send_api_request(self, path, method, data=None, sanitized_data=None): host = self._get_eos_master() if not host: - msg = unicode("Could not find CVX leader") + msg = six.text_type("Could not find CVX leader") LOG.info(msg) self.set_cvx_unavailable() raise arista_exc.AristaRpcError(msg=msg) diff --git a/networking_arista/ml2/rpc/base.py b/networking_arista/ml2/rpc/base.py index 476e2cda..a08a60fb 100644 --- a/networking_arista/ml2/rpc/base.py +++ b/networking_arista/ml2/rpc/base.py @@ -20,7 +20,7 @@ import os from neutron_lib.db import api as db_api from oslo_config import cfg from oslo_log import log as logging -from six import add_metaclass +import six from neutron.db.models.plugins.ml2 import vlanallocation @@ -31,7 +31,7 @@ from networking_arista.ml2 import arista_sec_gp LOG = logging.getLogger(__name__) -@add_metaclass(abc.ABCMeta) +@six.add_metaclass(abc.ABCMeta) class AristaRPCWrapperBase(object): """Wraps Arista JSON RPC. @@ -89,7 +89,9 @@ class AristaRPCWrapperBase(object): def _get_random_name(self, length=10): """Returns a base64 encoded name.""" - return base64.b64encode(os.urandom(10)).translate(None, '=+/') + result = base64.b64encode(os.urandom(10)).translate(None, b'=+/') + + return result if six.PY2 else result.decode('utf-8') def _get_cvx_hosts(self): cvx = []