From 95056d1ef49730d98eda1fc246b7e4bb1070a311 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Mon, 20 Oct 2014 10:41:34 +0100 Subject: Make swift post output an error message when failing swiftclient.shell.st_post was ignoring the result dict returned from SwiftService.post and therefore giving no indication when posts failed e.g. due to invalid auth credentials. This patch ensures that SwiftService always returns a result_dict from post() and then checks the result dict. On failure the shell now outputs the ClientException message and exits with error code 1. Also adds unit tests and cleans up some unnecessary mocked return values in existing tests. Closes-Bug: 1383243 Change-Id: I111150eb3d026c8d01c2cac13d3613ca7304e5b9 --- swiftclient/shell.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'swiftclient/shell.py') diff --git a/swiftclient/shell.py b/swiftclient/shell.py index 07a7e52..d58ce3a 100755 --- a/swiftclient/shell.py +++ b/swiftclient/shell.py @@ -543,8 +543,7 @@ If the container is not found, it will be created automatically. Positional arguments: [container] Name of container to post to. - [object] Name of object to post. Specify multiple times - for multiple objects. + [object] Name of object to post. Optional arguments: --read-acl Read ACL for containers. Quick summary of ACL syntax: @@ -596,7 +595,7 @@ def st_post(parser, args, output_manager): with SwiftService(options=_opts) as swift: try: if not args: - swift.post() + result = swift.post() else: container = args[0] if '/' in container: @@ -612,15 +611,16 @@ def st_post(parser, args, output_manager): results_iterator = swift.post( container=container, objects=objects ) - for result in results_iterator: # only 1 result - if not result["success"]: - raise(result["error"]) + result = next(results_iterator) else: output_manager.error( 'Usage: %s post %s\n%s', BASENAME, st_post_options, st_post_help) + return else: - swift.post(container=container) + result = swift.post(container=container) + if not result["success"]: + raise(result["error"]) except SwiftError as e: output_manager.error(e.value) -- cgit v1.2.1