[Python3] Fix python3 bugs in code

- The BaseException class no longer has a "message"
  attribute in python 3 [1]. On the contrary, the
  string representation of an Exception object will
  print all the exception args in all supported
  python versions, so use that instead.
- Functional tests were run with a specific locale,
  remove those annotations so we can handle unicode
  encoding and decoding in python3 envs.
- Cleanup errors were not being handled correctly,
  cleanup the code so we don't have spurious failures.
- In python3, dict.keys() gives you a view for lazy
  loading, so convert occurrences to lists as expected
  in our functional tests.
- Start capturing STDOUT and STDERR in tox envs to
  enable troubleshooting.

Co-Authored-By: Goutham Pacha Ravi <gouthampravi@gmail.com>
Closes-Bug: #1811627
Closes-Bug: #1811516
Change-Id: Idaa2fb9b60451b3fbd298e19574195f2d663c6f4
[1] https://www.python.org/dev/peps/pep-0352/#transition-plan
(cherry picked from commit b955ac9064)
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
This commit is contained in:
Goutham Pacha Ravi 2019-01-16 16:31:21 -08:00
parent 1ca51195c3
commit c0ce858da6
6 changed files with 17 additions and 21 deletions

View File

@ -705,10 +705,7 @@ def main():
sys.exit(130)
except Exception as e:
logger.debug(e, exc_info=1)
message = e.message
if not isinstance(message, six.string_types):
message = str(message)
print("ERROR: %s" % encodeutils.safe_encode(message), file=sys.stderr)
print("ERROR: %s" % six.text_type(e), file=sys.stderr)
sys.exit(1)

View File

@ -41,14 +41,12 @@ class handle_cleanup_exceptions(object):
return self
def __exit__(self, exc_type, exc_value, exc_traceback):
if not (isinstance(exc_value,
(lib_exc.NotFound, lib_exc.Forbidden)) or
CONF.suppress_errors_in_cleanup):
return False # Do not suppress error if any
if exc_traceback:
LOG.error("Suppressed cleanup error: "
"\n%s", traceback.format_exc())
return True # Suppress error if any
if isinstance(exc_value, (lib_exc.NotFound, lib_exc.Forbidden)):
return True
elif CONF.suppress_errors_in_cleanup:
LOG.error("Suppressed cleanup error: \n%s", traceback.format_exc())
return True
return False # Don't suppress cleanup errors
class BaseTestCase(base.ClientTestBase):

View File

@ -44,7 +44,7 @@ def not_found_wrapper(f):
return f(self, *args, **kwargs)
except tempest_lib_exc.CommandFailed as e:
for regexp in ('No (\w+) with a name or ID', 'not(.*){0,5}found'):
if re.search(regexp, e.stderr):
if re.search(regexp, six.text_type(e.stderr)):
# Raise appropriate 'NotFound' error
raise tempest_lib_exc.NotFound()
raise
@ -58,7 +58,7 @@ def forbidden_wrapper(f):
try:
return f(self, *args, **kwargs)
except tempest_lib_exc.CommandFailed as e:
if re.search('HTTP 403', e.stderr):
if re.search('HTTP 403', six.text_type(e.stderr)):
# Raise appropriate 'Forbidden' error.
raise tempest_lib_exc.Forbidden()
raise

View File

@ -74,7 +74,7 @@ class SharesMetadataReadWriteTest(base.BaseTestCase):
self.user_client.set_share_metadata(share["id"], md)
# Unset share metadata
self.user_client.unset_share_metadata(share["id"], md.keys())
self.user_client.unset_share_metadata(share["id"], list(md.keys()))
# Verify deletion of share metadata
metadata = self.user_client.get_share_metadata(share["id"])

View File

@ -0,0 +1,5 @@
---
fixes:
- |
The shell utility has been fixed to report errors correctly on
python3 environments.

View File

@ -7,9 +7,8 @@ skipsdist = True
[testenv]
install_command = pip install {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=C
OS_STDOUT_CAPTURE=1
OS_STDERR_CAPTURE=1
whitelist_externals = find
deps =
@ -67,9 +66,6 @@ commands =
-b html releasenotes/source releasenotes/build/html
[testenv:functional]
# TODO(gouthamr): Remove this when https://review.opendev.org/757651/
# merges
basepython = python2.7
setenv =
{[testenv]setenv}
OS_TEST_PATH = ./manilaclient/tests/functional