python3 patch (including zuul config)

Fix points are extracted in following methods.

1st: check with sixer:
    change unicode function to use sixer lib.
2nd: check & fix manually.
    2-1: as_dict() function
         fix as_dict() to work in py3 env.
    2-2: delete unnecessary as_dict() call in response to the change in as_dict()
    2-3: fix all_pfs_have_vf() to be able to treat both list and iterator,
         because filter() function returns list in py2, iterator in py3.
    2-4: To treats map() in same way in py2/3 env , wrap map() with list()  in P6,P7
    2-5: add python3.7 to setup.cfg
    2-6: add py3 tests, as voting

Change-Id: Ibfdec7258c731ee45ce1b9bdba4b2024cea78a12
Story: #2003219
Task: #23418
This commit is contained in:
Shogo Saito 2019-08-22 17:00:11 +09:00 committed by Sundar Nadathur
parent 2c50b9fd50
commit 38119f675e
8 changed files with 25 additions and 10 deletions

View File

@ -3,6 +3,7 @@
- openstack-python-jobs
- check-requirements
- release-notes-jobs-python3
- openstack-python3-train-jobs
- publish-openstack-docs-pti
check:
jobs:

View File

@ -69,6 +69,8 @@ def link_real_path(p):
os.path.join(os.path.dirname(p), os.readlink(p)))
# TODO(s_shogo) This function name should be reconsidered in py3
# env( filter() in py3 returns iterator, not list)
def find_fpgas_by_know_list():
return filter(
lambda p: (
@ -99,8 +101,8 @@ def all_vf_fpgas():
def all_pfs_have_vf():
return filter(lambda p: glob.glob(os.path.join(p, "virtfn0")),
all_fpgas())
return list(filter(lambda p: glob.glob(os.path.join(p, "virtfn0")),
all_fpgas()))
def target_symbolic_map():

View File

@ -58,9 +58,20 @@ class CyborgObject(object_base.VersionedObject):
}
def as_dict(self):
return dict((k, getattr(self, k))
"""Return the object represented as a dict.
The returned object is JSON-serialisable.
"""
def _attr_as_dict(field):
"""Return an attribute as a dict, handling nested objects."""
attr = getattr(self, field)
if isinstance(attr, CyborgObject):
attr = attr.as_dict()
return attr
return dict((k, _attr_as_dict(k))
for k in self.fields
if hasattr(self, k))
if self.obj_attr_is_set(k))
@staticmethod
def _from_db_object(obj, db_obj):

View File

@ -114,7 +114,7 @@ class TestIntelFPGADriver(base.TestCase):
fpga_dep_list[0].as_dict()['attach_handle_list']
self.assertEqual(expected[i]['vendor'], fpga_dict['vendor'])
self.assertEqual(expected[i]['controlpath_id'],
fpga_dict['controlpath_id'].as_dict())
fpga_dict['controlpath_id'])
self.assertEqual(expected[i]['deployable_list'][0]
['num_accelerators'],
fpga_dep_list[0].as_dict()['num_accelerators'])

View File

@ -93,7 +93,7 @@ class TestGPUDriverUtils(base.TestCase):
gpu_dep_list[0].as_dict()['attach_handle_list']
self.assertEqual(expected['vendor'], gpu_dict['vendor'])
self.assertEqual(expected['controlpath_id'],
gpu_dict['controlpath_id'].as_dict())
gpu_dict['controlpath_id'])
self.assertEqual(expected['std_board_info'],
jsonutils.loads(gpu_dict['std_board_info']))
self.assertEqual(expected['deployable_list'][0]['num_accelerators'],

View File

@ -74,14 +74,14 @@ def _drop_uuid(dp_dict):
def get_obj_devprofs():
dp_list = _get_device_profiles_as_dict()
obj_devprofs = map(_convert_to_obj, dp_list)
obj_devprofs = list(map(_convert_to_obj, dp_list))
return obj_devprofs
def get_api_devprofs(drop_uuid=False):
dp_list = _get_device_profiles_as_dict()
if drop_uuid:
api_devprofs = map(_drop_uuid, dp_list)
api_devprofs = list(map(_drop_uuid, dp_list))
else:
api_devprofs = dp_list
return api_devprofs
@ -89,5 +89,5 @@ def get_api_devprofs(drop_uuid=False):
def get_db_devprofs():
dp_list = _get_device_profiles_as_dict()
db_devprofs = map(_convert_to_db_devprof, dp_list)
db_devprofs = list(map(_convert_to_db_devprof, dp_list))
return db_devprofs

View File

@ -64,7 +64,7 @@ def _convert_from_dict_to_obj(arq_dict):
def get_fake_extarq_objs():
arq_list = _get_arqs_as_dict()
obj_extarqs = map(_convert_from_dict_to_obj, arq_list)
obj_extarqs = list(map(_convert_from_dict_to_obj, arq_list))
return obj_extarqs

View File

@ -17,6 +17,7 @@ classifier =
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
[files]
packages =