From c7446ccc434047ac63777703741dbe510d8d7eda Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 1 Jul 2015 17:25:59 +0200 Subject: [PATCH] Cleanup Python 3 changes * Rework BrickException to simplify the code. Revert partially changes done to port os-brick to Python 3, without losing Python 3 compatibility. * tox.ini: run py34 tests using the commands of the default test environent. All os-brick tests now pass on Python 3.4, so testr test runner can be used to run tests in parallel, get the test repository, etc. * tox.ini: exchange order of py27 and py34 in envlist: py34 must be run first to workaround a testrepository bug (see the note below). * README: give advices on tox/testrepository issues with python 2/3 Change-Id: If80e01e802079afea3f2ea8051c76afffa47fa03 --- README.rst | 8 ++++++++ os_brick/exception.py | 10 +--------- tox.ini | 15 +-------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/README.rst b/README.rst index e46362eb9..500af52e1 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,15 @@ Features * Discovery of volumes being attached to a host for many transport protocols. * Removal of volumes from a host. +Hacking +------- +Hacking on brick requires python-gdbm (for Debian derived distributions), +Python 2.7 and Python 3.4. A recent tox is required, as is a recent virtualenv +(13.1.0 or newer). + +If "tox -e py34" fails with the error "db type could not be determined", remove +the .testrepository/ directory and then run "tox -e py34". For any other imformation, refer to the parent project, Cinder: https://github.com/openstack/cinder diff --git a/os_brick/exception.py b/os_brick/exception.py index c4769af5e..dcc0c23f1 100644 --- a/os_brick/exception.py +++ b/os_brick/exception.py @@ -37,7 +37,6 @@ class BrickException(Exception): def __init__(self, message=None, **kwargs): self.kwargs = kwargs - self.kwargs['message'] = message if 'code' not in self.kwargs: try: @@ -45,11 +44,7 @@ class BrickException(Exception): except AttributeError: pass - for k, v in self.kwargs.items(): - if isinstance(v, Exception): - self.kwargs[k] = six.text_type(v) - - if self._should_format(): + if not message: try: message = self.message % kwargs @@ -73,9 +68,6 @@ class BrickException(Exception): def __unicode__(self): return six.text_type(self.msg) - def _should_format(self): - return self.kwargs['message'] is None or '%(message)' in self.message - class NotFound(BrickException): message = _("Resource could not be found.") diff --git a/tox.ini b/tox.ini index bd645da02..b3e4af0a9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 1.6 -envlist = py27,py34,pep8 +envlist = py34,py27,pep8 skipsdist = True [testenv] @@ -28,19 +28,6 @@ commands = python setup.py testr --coverage --testr-args='{posargs}' [testenv:docs] commands = python setup.py build_sphinx -[testenv:py34] -commands = - find . -type f -name "*.pyc" -delete - python -m testtools.run \ - os_brick.tests.test_brick \ - os_brick.tests.test_exception \ - os_brick.tests.test_utils \ - os_brick.tests.initiator.test_connector \ - os_brick.tests.initiator.test_linuxfc \ - os_brick.tests.initiator.test_linuxrbd \ - os_brick.tests.initiator.test_linuxscsi - - [flake8] # H803 skipped on purpose per list discussion. # E123, E125 skipped as they are invalid PEP-8.