From 70e451dce3b1a572d0542feb763e879623b2deb2 Mon Sep 17 00:00:00 2001 From: Bryan Strassner Date: Mon, 9 Jul 2018 14:16:48 -0500 Subject: [PATCH] Add step info and timestamp to get actions command Adds an execution start time and a summary of steps that have succeeded, failed, or otherwise. Change-Id: I8aaaa45b9c3e00aaf3ae428911dc522509dec694 --- .../shipyard_client/cli/cli_format_common.py | 31 ++++++++++++++++--- .../unit/cli/create/test_create_actions.py | 1 + .../tests/unit/cli/get/test_get_actions.py | 1 + 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/bin/shipyard_client/shipyard_client/cli/cli_format_common.py b/src/bin/shipyard_client/shipyard_client/cli/cli_format_common.py index 126f16a0..98ff7a8e 100644 --- a/src/bin/shipyard_client/shipyard_client/cli/cli_format_common.py +++ b/src/bin/shipyard_client/shipyard_client/cli/cli_format_common.py @@ -122,20 +122,43 @@ def gen_action_table(action_list): 'action_lifecycle' """ actions = format_utils.table_factory( - field_names=['Name', 'Action', 'Lifecycle']) + field_names=['Name', 'Action', 'Lifecycle', 'Execution Time', + 'Step Succ/Fail/Oth']) if action_list: # sort by id, which is ULID - chronological. for action in sorted(action_list, key=lambda k: k['id']): actions.add_row([ - action.get('name'), 'action/{}'.format(action.get('id')), - action.get('action_lifecycle') + action.get('name'), + 'action/{}'.format(action.get('id')), + action.get('action_lifecycle'), + action.get('dag_execution_date'), + _step_summary(action.get('steps', [])) ]) else: - actions.add_row(['None', '', '']) + actions.add_row(['None', '', '', '', '']) return format_utils.table_get_string(actions) +def _step_summary(step_list): + """Creates a single string representation of the step status + + Success/Failed/Other counts in each position + """ + successes = 0 + failures = 0 + other = 0 + for s in step_list: + state = s.get('state') + if state in ['success']: + successes += 1 + elif state in ['failed']: + failures += 1 + else: + other += 1 + return "{}/{}/{}".format(successes, failures, other) + + def gen_collection_table(collection_list): """Generates a list of collections and their status diff --git a/src/bin/shipyard_client/tests/unit/cli/create/test_create_actions.py b/src/bin/shipyard_client/tests/unit/cli/create/test_create_actions.py index 198aea9c..813ef848 100644 --- a/src/bin/shipyard_client/tests/unit/cli/create/test_create_actions.py +++ b/src/bin/shipyard_client/tests/unit/cli/create/test_create_actions.py @@ -55,6 +55,7 @@ def test_create_action(*args): assert 'Lifecycle' in response assert 'action/01BTTMFVDKZFRJM80FGD7J1AKN' in response assert 'Error:' not in response + assert '0/0/0' in response @responses.activate diff --git a/src/bin/shipyard_client/tests/unit/cli/get/test_get_actions.py b/src/bin/shipyard_client/tests/unit/cli/get/test_get_actions.py index 18af9beb..3f8d1877 100644 --- a/src/bin/shipyard_client/tests/unit/cli/get/test_get_actions.py +++ b/src/bin/shipyard_client/tests/unit/cli/get/test_get_actions.py @@ -77,6 +77,7 @@ def test_get_actions(*args): assert 'deploy_site' in response assert 'action/01BTP9T2WCE1PAJR2DWYXG805V' in response assert 'Lifecycle' in response + assert '2/1/0' in response @responses.activate