From e69ea37845ec991b5856a518114783e53a1e4f3c Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 5 Mar 2017 16:48:14 -0600 Subject: [PATCH] Return the exit code of the executed command On the container exec command, return the same exit code of the command being executed in the container. This would be useful for users to retrieve the exit code as they did in Docker CLI. Change-Id: I2aa0b4d9e7994a125f54e93d36efc854db66fe25 Depends-On: I20cc48da20bdc3784ec8fce4e38a98baf388a0ca Closes-Bug: #1645044 --- zunclient/osc/v1/containers.py | 5 ++++- zunclient/shell.py | 8 ++++---- zunclient/v1/containers_shell.py | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/zunclient/osc/v1/containers.py b/zunclient/osc/v1/containers.py index 442f2a45..37f823e6 100644 --- a/zunclient/osc/v1/containers.py +++ b/zunclient/osc/v1/containers.py @@ -386,8 +386,11 @@ class ExecContainer(command.Command): client = _get_client(self, parsed_args) container = parsed_args.container command = ' '.join(parsed_args.command) - output = client.containers.execute(container, command) + response = client.containers.execute(container, command) + output = response['output'] + exit_code = response['exit_code'] print(output) + return exit_code class LogsContainer(command.Command): diff --git a/zunclient/shell.py b/zunclient/shell.py index a5b4ea4e..38a2fb10 100644 --- a/zunclient/shell.py +++ b/zunclient/shell.py @@ -573,7 +573,7 @@ class OpenStackZunShell(object): endpoint_type=endpoint_type, insecure=insecure) - args.func(self.cs, args) + return args.func(self.cs, args) def _dump_timings(self, timings): class Tyme(object): @@ -631,8 +631,8 @@ class OpenStackHelpFormatter(argparse.HelpFormatter): def main(): try: - OpenStackZunShell().main(map(encodeutils.safe_decode, sys.argv[1:])) - + return OpenStackZunShell().main( + map(encodeutils.safe_decode, sys.argv[1:])) except Exception as e: logger.debug(e, exc_info=1) print("ERROR: %s" % encodeutils.safe_encode(six.text_type(e)), @@ -641,4 +641,4 @@ def main(): if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py index 38bd0944..2d111931 100644 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -359,8 +359,11 @@ def do_logs(cs, args): help='The command to execute in a container') def do_exec(cs, args): """Execute command in a container.""" - output = cs.containers.execute(args.container, ' '.join(args.command)) + response = cs.containers.execute(args.container, ' '.join(args.command)) + output = response['output'] + exit_code = response['exit_code'] print(output) + return exit_code @utils.arg('containers',