[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
This commit is contained in:

committed by
Tom Barron

parent
9cf7d50561
commit
b955ac9064
@@ -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)
|
||||
|
||||
|
||||
|
@@ -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):
|
||||
|
@@ -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
|
||||
|
@@ -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"])
|
||||
|
@@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
The shell utility has been fixed to report errors correctly on
|
||||
python3 environments.
|
Reference in New Issue
Block a user