Strip json and html from error messages

Error messages were being passed with either JSON or HTML formatting
leading to an unpleasant user experience. This strips the JSON or HTML
tags and presents the clean error message to the user.

Rewrote the lispy function to be more pythonic, added test cases
and cleaned up some pep8 violations.

Removed commented out cruft from a previous version of this
patch.

Changed the HTML details from a set to a list in order to ensure
the ordering of the exception details.

Added code to eliminate the duplicate detail messages from the list
and reordered the assertion string to match actual output.

Refactored duplicate elimination code to be more readable and
reliable.

Some reworking of the duplication elimination loop to make it
more readable.

Removed unneeded conditional to filter out empty elements.

Change-Id: I79985b3e305cb30328a3c16b025315a8e969243d
Closes-Bug: 1398838
This commit is contained in:
d34dh0r53
2015-01-19 18:02:08 -06:00
parent aebbcff100
commit 01caf4e734
3 changed files with 82 additions and 14 deletions
+14 -12
View File
@@ -477,14 +477,16 @@ class OpenStackImagesShell(object):
"or prompted response"))
# Validate password flow auth
project_info = (args.os_tenant_name or
args.os_tenant_id or
(args.os_project_name and
(args.os_project_domain_name or
args.os_project_domain_id)) or
args.os_project_id)
project_info = (
args.os_tenant_name or args.os_tenant_id or (
args.os_project_name and (
args.os_project_domain_name or
args.os_project_domain_id
)
) or args.os_project_id
)
if (not project_info):
if not project_info:
# tenant is deprecated in Keystone v3. Use the latest
# terminology instead.
raise exc.CommandError(
@@ -571,14 +573,14 @@ class OpenStackImagesShell(object):
with open(schema_file_path, 'w') as f:
f.write(json.dumps(schema.raw()))
except Exception:
#NOTE(esheffield) do nothing here, we'll get a message
#later if the schema is missing
# NOTE(esheffield) do nothing here, we'll get a message
# later if the schema is missing
pass
def main(self, argv):
# Parse args once to find version
#NOTE(flepied) Under Python3, parsed arguments are removed
# NOTE(flepied) Under Python3, parsed arguments are removed
# from the list so make a copy for the first parsing
base_argv = copy.deepcopy(argv)
parser = self.get_base_parser()
@@ -642,8 +644,8 @@ class OpenStackImagesShell(object):
except exc.Unauthorized:
raise exc.CommandError("Invalid OpenStack Identity credentials.")
except Exception:
#NOTE(kragniz) Print any exceptions raised to stderr if the --debug
# flag is set
# NOTE(kragniz) Print any exceptions raised to stderr if the
# --debug flag is set
if args.debug:
traceback.print_exc()
raise