Browse Source

fix text conversion for python2/3

Change-Id: I53f2a006670e7afda575f4c403939e8b152b455a
changes/41/474341/4
Mark McClain 5 years ago
parent
commit
20abc47e6d
  1. 7
      networking_arista/ml2/rpc/arista_eapi.py
  2. 5
      networking_arista/ml2/rpc/arista_json.py
  3. 8
      networking_arista/ml2/rpc/base.py

7
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

5
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)

8
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 = []

Loading…
Cancel
Save