Fix: others issues for Python 2/3 compatible code.

Fix: "reduce" issue in
   service-mgmt-api/sm-api/sm_api/openstack/common/rpc/impl_zmq.py
     - from functools import reduce to support python 3
Fix: "long" issue in
   service-mgmt-api/sm-api/sm_api/openstack/common/jsonutils.py
     -  remove long type if for python 3
     -  change to six.integer_types
Fix: "funcattrs" issue in
   service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/session.py
     - change f.func_name to f.__name__
Fix: "zip" and "methodattrs" issues in
   service-mgmt-api/sm-api/sm_api/common/safe_utils.py
     - change zip() to list(zip())
     - change function.im_self to function.__self__
Fix: "itertools" issue in
   service-mgmt-api/sm-api/sm_api/openstack/common/log.py
     - from six import moves and use moves.filter

Story: 2003430
Task: 26523

Change-Id: I37b47a12a24ef05fb4d57823b2a91086b6ca537f
Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
Sun Austin 2018-10-16 10:12:39 +08:00
parent 6753274b28
commit ec02214db7
5 changed files with 7 additions and 6 deletions

View File

@ -43,12 +43,12 @@ def getcallargs(function, *args, **kwargs):
# The function may not actually be a method or have im_self.
# Typically seen when it's stubbed with mox.
if inspect.ismethod(function) and hasattr(function, 'im_self'):
keyed_args[argnames[0]] = function.im_self
keyed_args[argnames[0]] = function.__self__
else:
keyed_args[argnames[0]] = None
remaining_argnames = [x for x in argnames if x not in keyed_args]
keyed_args.update(dict(zip(remaining_argnames, args)))
keyed_args.update(dict(list(zip(remaining_argnames, args))))
if defaults:
num_defaults = len(defaults)

View File

@ -489,7 +489,7 @@ def _wrap_db_error(f):
except Exception as e:
LOG.exception(_('DB exception wrapped.'))
raise exception.DBError(e)
_wrap.func_name = f.func_name
_wrap.__name__ = f.__name__
return _wrap

View File

@ -54,8 +54,7 @@ _nasty_type_tests = [inspect.ismodule, inspect.isclass, inspect.ismethod,
inspect.isgenerator, inspect.istraceback, inspect.isframe,
inspect.iscode, inspect.isbuiltin, inspect.isroutine,
inspect.isabstract]
_simple_types = (type(None), int, six.string_types, bool, float, long)
_simple_types = (type(None), six.integer_types, six.string_types, bool, float)
def to_primitive(value, convert_instances=False, convert_datetime=True,

View File

@ -44,6 +44,7 @@ import os
import sys
import traceback
from six import moves
from oslo_config import cfg
from sm_api.openstack.common.gettextutils import _
@ -289,7 +290,7 @@ class JSONFormatter(logging.Formatter):
def formatException(self, ei, strip_newlines=True):
lines = traceback.format_exception(*ei)
if strip_newlines:
lines = [itertools.ifilter(
lines = [moves.filter(
lambda x: x,
line.rstrip().splitlines()) for line in lines]
lines = list(itertools.chain(*lines))

View File

@ -36,6 +36,7 @@ from sm_api.openstack.common import importutils
from sm_api.openstack.common import jsonutils
from sm_api.openstack.common import processutils as utils
from sm_api.openstack.common.rpc import common as rpc_common
from functools import reduce
zmq = importutils.try_import('eventlet.green.zmq')