From 43c80bef565b62cf6df4761b817fa8c0e4c631a3 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 7 Jun 2020 21:39:06 +0200 Subject: [PATCH 01/17] Change the presentation of elapsed time on st2 execution get to a more user-friendly format #4944 --- CHANGELOG.rst | 8 +++++++ st2client/st2client/commands/action.py | 29 ++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 12e75aa25f..88489f7f06 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,14 @@ Added * Add make command to autogen JSON schema from the models of action, rule, etc. Add check to ensure update to the models require schema to be regenerated. (new feature) +Changed +~~~~~~~ +* Changed the output of elapsed time on `st2 execution get` to a more user-friendly format. + The new format is ``d hms``. Units without a value are omitted. + Old: ``status: succeeded (92342s elapsed)``, ``status: succeeded (113s elapsed)`` + New: ``stauts: succeeded (1d 1h39m2s elapsed)``, ``status: succeeded (1m53s elapsed)`` + This was requested by Sheshagiri (@Sheshagiri) and contributed by Marcel Weinber (@winem). #4944 + Fixed ~~~~~ * Fixed a bug where `type` attribute was missing for netstat action in linux pack. Fixes #4946 diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py index f458303bc0..19b4bb5f4a 100644 --- a/st2client/st2client/commands/action.py +++ b/st2client/st2client/commands/action.py @@ -25,6 +25,8 @@ import six import sys +from dateutil.relativedelta import relativedelta + from os.path import join as pjoin from six.moves import range @@ -167,20 +169,39 @@ def format_execution_status(instance): start_timestamp = parse_isotime(start_timestamp) start_timestamp = calendar.timegm(start_timestamp.timetuple()) now = int(time.time()) - elapsed_seconds = (now - start_timestamp) - instance.status = '%s (%ss elapsed)' % (instance.status, elapsed_seconds) + elapsed_time_string = format_elapsed_time(now - start_timestamp) + instance.status = '%s (%s elapsed)' % (instance.status, elapsed_time_string) elif status in LIVEACTION_COMPLETED_STATES and start_timestamp and end_timestamp: start_timestamp = parse_isotime(start_timestamp) start_timestamp = calendar.timegm(start_timestamp.timetuple()) end_timestamp = parse_isotime(end_timestamp) end_timestamp = calendar.timegm(end_timestamp.timetuple()) - elapsed_seconds = (end_timestamp - start_timestamp) - instance.status = '%s (%ss elapsed)' % (instance.status, elapsed_seconds) + elapsed_time_string = format_elapsed_time(end_timestamp - start_timestamp) + instance.status = '%s (%s elapsed)' % (instance.status, elapsed_time_string) return instance +def format_elapsed_time(delta_in_seconds): + delta = relativedelta(seconds=delta_in_seconds) + days = delta.days + hours = delta.hours + minutes = delta.minutes + seconds = delta.seconds + + if days > 0: + elapsed_time_string = '%sd %sh%sm%ss' % (days, hours, minutes, seconds) + elif hours > 0: + elapsed_time_string = '%sh%sm%ss' % (hours, minutes, seconds) + elif minutes > 0: + elapsed_time_string = '%sm%ss' % (minutes, seconds) + else: + elapsed_time_string = '%ss' % (seconds) + + return elapsed_time_string + + class ActionBranch(resource.ResourceBranch): def __init__(self, description, app, subparsers, parent_parser=None): From 0e76b0ce30cf056ba01926e3e27e98f6c8ff5c9a Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 7 Jun 2020 21:41:37 +0200 Subject: [PATCH 02/17] drop space between days and hours if the elapsed time is > 86400 seconds --- st2client/st2client/commands/action.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py index 19b4bb5f4a..c4d5550a7d 100644 --- a/st2client/st2client/commands/action.py +++ b/st2client/st2client/commands/action.py @@ -191,7 +191,7 @@ def format_elapsed_time(delta_in_seconds): seconds = delta.seconds if days > 0: - elapsed_time_string = '%sd %sh%sm%ss' % (days, hours, minutes, seconds) + elapsed_time_string = '%sd%sh%sm%ss' % (days, hours, minutes, seconds) elif hours > 0: elapsed_time_string = '%sh%sm%ss' % (hours, minutes, seconds) elif minutes > 0: From dc5b830271678691b5fb5551947b22f57dec0e5d Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Mon, 8 Jun 2020 09:32:34 +0200 Subject: [PATCH 03/17] Remove space between days and hours from changelog (more user-friendly elapsed time) --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 88489f7f06..22060b1deb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,7 +14,7 @@ Changed * Changed the output of elapsed time on `st2 execution get` to a more user-friendly format. The new format is ``d hms``. Units without a value are omitted. Old: ``status: succeeded (92342s elapsed)``, ``status: succeeded (113s elapsed)`` - New: ``stauts: succeeded (1d 1h39m2s elapsed)``, ``status: succeeded (1m53s elapsed)`` + New: ``stauts: succeeded (1d1h39m2s elapsed)``, ``status: succeeded (1m53s elapsed)`` This was requested by Sheshagiri (@Sheshagiri) and contributed by Marcel Weinber (@winem). #4944 Fixed From a265346bd80556c06f83ef11bf91387f97767206 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Mon, 8 Jun 2020 20:57:12 +0200 Subject: [PATCH 04/17] remove repeating spaces before operator to pass lint checks --- st2client/st2client/commands/action.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py index c4d5550a7d..851c66d795 100644 --- a/st2client/st2client/commands/action.py +++ b/st2client/st2client/commands/action.py @@ -185,8 +185,8 @@ def format_execution_status(instance): def format_elapsed_time(delta_in_seconds): delta = relativedelta(seconds=delta_in_seconds) - days = delta.days - hours = delta.hours + days = delta.days + hours = delta.hours minutes = delta.minutes seconds = delta.seconds From aafca8b93bc6695bb4348ec69462f033a8d937bb Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sat, 13 Jun 2020 23:45:19 +0200 Subject: [PATCH 05/17] add unit test to parse the elapsed time for the expected format --- st2client/tests/unit/test_action.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/st2client/tests/unit/test_action.py b/st2client/tests/unit/test_action.py index 7e0b15c5dc..98062bf724 100644 --- a/st2client/tests/unit/test_action.py +++ b/st2client/tests/unit/test_action.py @@ -536,3 +536,17 @@ def test_resume_multiple_executions(self): mock.call('/executions/456', expected), mock.call('/executions/789', expected)] httpclient.HTTPClient.put.assert_has_calls(calls) + + @mock.patch.object( + models.ResourceManager, 'get_by_ref_or_id', + mock.MagicMock(side_effect=get_by_ref)) + @mock.patch.object( + models.ResourceManager, 'get_by_name', + mock.MagicMock(side_effect=get_by_name)) + @mock.patch.object( + httpclient.HTTPClient, 'put', + mock.MagicMock(return_value=base.FakeResponse(json.dumps(LIVE_ACTION), 200, 'OK'))) + def test_elapsed_time_string_fast_action(self): + self.shell.run(['run', 'core.pause', 'max_pause=10']) + expected = { 'status': 'succeeded (10s elapsed)'} + httpclient.HTTPClient.put.assert_called_with('/executions', expected) From d4e6bba22b7052308ba599c298bc052adfcb3de9 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 14 Jun 2020 01:35:44 +0200 Subject: [PATCH 06/17] Add unit test for st2client with hours in elapsed time --- ...t_attribute_with_hours_in_elapsed_time.txt | 1 + .../execution_with_hours_in_elapsed_time.json | 29 +++++++++++++++++++ st2client/tests/unit/test_formatters.py | 8 +++++ 3 files changed, 38 insertions(+) create mode 100644 st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt create mode 100644 st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json diff --git a/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt b/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt new file mode 100644 index 0000000000..c792315571 --- /dev/null +++ b/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt @@ -0,0 +1 @@ +status: succeeded (2h1s elapsed) diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json new file mode 100644 index 0000000000..12771065fb --- /dev/null +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -0,0 +1,29 @@ +{ + "id": "547e19561e2e2417d3dde398", + "parameters": { + "cmd": "127.0.0.1 3" + }, + "callback": {}, + "context": { + "user": "stanley" + }, + "result": { + "localhost": { + "failed": false, + "stderr": "", + "return_code": 0, + "succeeded": true, + "stdout": "PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.\n64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.015 ms\n64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.024 ms\n64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.030 ms\n\n--- 127.0.0.1 ping statistics ---\n3 packets transmitted, 3 received, 0% packet loss, time 1998ms\nrtt min/avg/max/mdev = 0.015/0.023/0.030/0.006 ms" + } + }, + "status": "succeeded", + "start_timestamp": "2014-12-02T19:56:06.900000Z", + "end_timestamp": "2014-12-02T21:56:07.000000Z", + "action": { + "ref": "core.ping" + }, + "liveaction": { + "callback": {}, + "id": "1" + } +} \ No newline at end of file diff --git a/st2client/tests/unit/test_formatters.py b/st2client/tests/unit/test_formatters.py index 724444127f..c97842e77d 100644 --- a/st2client/tests/unit/test_formatters.py +++ b/st2client/tests/unit/test_formatters.py @@ -42,6 +42,7 @@ 'execution_result_has_carriage_return.json', 'execution_unicode.json', 'execution_double_backslash.json', + 'execution_with_hours_in_elapsed_time.json', 'execution_with_stack_trace.json', 'execution_with_schema.json'], 'results': ['execution_get_default.txt', @@ -50,6 +51,7 @@ 'execution_result_has_carriage_return.txt', 'execution_result_has_carriage_return_py3.txt', 'execution_get_attributes.txt', + 'execution_get_attribute_with_hours_in_elapsed_time.txt', 'execution_list_attr_start_timestamp.txt', 'execution_list_empty_response_start_timestamp_attr.txt', 'execution_unescape_newline.txt', @@ -66,6 +68,7 @@ OUTPUT_SCHEMA = FIXTURES['executions']['execution_with_schema.json'] NEWLINE = FIXTURES['executions']['execution_with_stack_trace.json'] HAS_CARRIAGE_RETURN = FIXTURES['executions']['execution_result_has_carriage_return.json'] +DURATION_HOURS = FIXTURES['executions']['execution_with_hours_in_elapsed_time.json'] class TestExecutionResultFormatter(unittest2.TestCase): @@ -112,6 +115,11 @@ def test_execution_get_attributes(self): content = self._get_execution(argv) self.assertEqual(content, FIXTURES['results']['execution_get_attributes.txt']) + def test_execution_get_attribute_with_hours_in_elapsed_time(self): + argv = ['execution', 'get', DURATION_HOURS['id'], '--attr', 'status'] + content = self._get_execution(argv) + self.assertEqual(content, FIXTURES['results']['execution_get_attribute_with_hours_in_elapsed_time.txt']) + def test_execution_get_default_in_json(self): argv = ['execution', 'get', EXECUTION['id'], '-j'] content = self._get_execution(argv) From e99819f939e4e23d85500c1f17e017205db7ecfc Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 14 Jun 2020 01:36:13 +0200 Subject: [PATCH 07/17] Revert "add unit test to parse the elapsed time for the expected format" This reverts commit aafca8b93bc6695bb4348ec69462f033a8d937bb. --- st2client/tests/unit/test_action.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/st2client/tests/unit/test_action.py b/st2client/tests/unit/test_action.py index 98062bf724..7e0b15c5dc 100644 --- a/st2client/tests/unit/test_action.py +++ b/st2client/tests/unit/test_action.py @@ -536,17 +536,3 @@ def test_resume_multiple_executions(self): mock.call('/executions/456', expected), mock.call('/executions/789', expected)] httpclient.HTTPClient.put.assert_has_calls(calls) - - @mock.patch.object( - models.ResourceManager, 'get_by_ref_or_id', - mock.MagicMock(side_effect=get_by_ref)) - @mock.patch.object( - models.ResourceManager, 'get_by_name', - mock.MagicMock(side_effect=get_by_name)) - @mock.patch.object( - httpclient.HTTPClient, 'put', - mock.MagicMock(return_value=base.FakeResponse(json.dumps(LIVE_ACTION), 200, 'OK'))) - def test_elapsed_time_string_fast_action(self): - self.shell.run(['run', 'core.pause', 'max_pause=10']) - expected = { 'status': 'succeeded (10s elapsed)'} - httpclient.HTTPClient.put.assert_called_with('/executions', expected) From 3d2af5805cf447d1eb52dd1c07d5111d0c9c1eea Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 14 Jun 2020 02:04:40 +0200 Subject: [PATCH 08/17] try to fix unexpected duration reported --- .../tests/fixtures/execution_with_hours_in_elapsed_time.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index 12771065fb..e97f88ffe7 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-02T21:56:07.000000Z", + "end_timestamp": "2014-12-02T21:56:07.100000Z", "action": { "ref": "core.ping" }, From 98ffc974ea7a8209022a55cd3e2ff4a1783d3d22 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 14 Jun 2020 02:33:21 +0200 Subject: [PATCH 09/17] test with a duration >1 day --- .../tests/fixtures/execution_with_hours_in_elapsed_time.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index e97f88ffe7..1768163328 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-02T21:56:07.100000Z", + "end_timestamp": "2014-12-03T21:56:07.000000Z", "action": { "ref": "core.ping" }, From 7135b762ca43ff8d1f5a39e01354c3c2f24dc90f Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 14 Jun 2020 18:07:00 +0200 Subject: [PATCH 10/17] troubleshooting failing unit test (elapsed time) --- st2client/st2client/commands/action.py | 2 +- .../tests/fixtures/execution_with_hours_in_elapsed_time.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py index 851c66d795..6a4e043fd0 100644 --- a/st2client/st2client/commands/action.py +++ b/st2client/st2client/commands/action.py @@ -178,7 +178,7 @@ def format_execution_status(instance): end_timestamp = calendar.timegm(end_timestamp.timetuple()) elapsed_time_string = format_elapsed_time(end_timestamp - start_timestamp) - instance.status = '%s (%s elapsed)' % (instance.status, elapsed_time_string) + instance.status = '%s (%s elapsed) %s %s' % (instance.status, elapsed_time_string, start_timestamp, end_timestamp) return instance diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index 1768163328..12771065fb 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-03T21:56:07.000000Z", + "end_timestamp": "2014-12-02T21:56:07.000000Z", "action": { "ref": "core.ping" }, From befa79ae54a85dcc787f5102df32c445b22b9810 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 14 Jun 2020 18:34:40 +0200 Subject: [PATCH 11/17] Revert "troubleshooting failing unit test (elapsed time)" This reverts commit 7135b762ca43ff8d1f5a39e01354c3c2f24dc90f. --- st2client/st2client/commands/action.py | 2 +- .../tests/fixtures/execution_with_hours_in_elapsed_time.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/st2client/st2client/commands/action.py b/st2client/st2client/commands/action.py index 6a4e043fd0..851c66d795 100644 --- a/st2client/st2client/commands/action.py +++ b/st2client/st2client/commands/action.py @@ -178,7 +178,7 @@ def format_execution_status(instance): end_timestamp = calendar.timegm(end_timestamp.timetuple()) elapsed_time_string = format_elapsed_time(end_timestamp - start_timestamp) - instance.status = '%s (%s elapsed) %s %s' % (instance.status, elapsed_time_string, start_timestamp, end_timestamp) + instance.status = '%s (%s elapsed)' % (instance.status, elapsed_time_string) return instance diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index 12771065fb..1768163328 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-02T21:56:07.000000Z", + "end_timestamp": "2014-12-03T21:56:07.000000Z", "action": { "ref": "core.ping" }, From 743073224730ffbe0b6a3b3059d7600314e9358c Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sun, 14 Jun 2020 18:35:15 +0200 Subject: [PATCH 12/17] change end timestamp for another test --- .../execution_get_attribute_with_hours_in_elapsed_time.txt | 2 +- .../tests/fixtures/execution_with_hours_in_elapsed_time.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt b/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt index c792315571..09562682f9 100644 --- a/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt +++ b/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt @@ -1 +1 @@ -status: succeeded (2h1s elapsed) +status: succeeded (2h2m1s elapsed) diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index 1768163328..3aa98f9594 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-03T21:56:07.000000Z", + "end_timestamp": "2014-12-03T21:58:07.000000Z", "action": { "ref": "core.ping" }, From c5d8e63eae7ba69f2e39caac598161194c3899e3 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Fri, 19 Jun 2020 23:08:38 +0200 Subject: [PATCH 13/17] use mock.path.object to create DURATION_HOURS response object --- .../execution_with_hours_in_elapsed_time.json | 4 ++-- st2client/tests/unit/test_formatters.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index 3aa98f9594..2b08f68f75 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-03T21:58:07.000000Z", + "end_timestamp": "2014-12-02T21:56:07.000000Z", "action": { "ref": "core.ping" }, @@ -26,4 +26,4 @@ "callback": {}, "id": "1" } -} \ No newline at end of file +} diff --git a/st2client/tests/unit/test_formatters.py b/st2client/tests/unit/test_formatters.py index c97842e77d..d44da89868 100644 --- a/st2client/tests/unit/test_formatters.py +++ b/st2client/tests/unit/test_formatters.py @@ -115,10 +115,6 @@ def test_execution_get_attributes(self): content = self._get_execution(argv) self.assertEqual(content, FIXTURES['results']['execution_get_attributes.txt']) - def test_execution_get_attribute_with_hours_in_elapsed_time(self): - argv = ['execution', 'get', DURATION_HOURS['id'], '--attr', 'status'] - content = self._get_execution(argv) - self.assertEqual(content, FIXTURES['results']['execution_get_attribute_with_hours_in_elapsed_time.txt']) def test_execution_get_default_in_json(self): argv = ['execution', 'get', EXECUTION['id'], '-j'] @@ -138,6 +134,18 @@ def test_execution_with_schema(self): content = self._get_schema_execution(argv) self.assertEqual(content, FIXTURES['results']['execution_get_has_schema.txt']) + @mock.patch.object( + httpclient.HTTPClient, 'get', + mock.MagicMock(return_value=base.FakeResponse(json.dumps(DURATION_HOURS), 200, 'OK', {}))) + def test_execution_get_attribute_with_hours_in_elapsed_time(self): + argv = ['execution', 'get', DURATION_HOURS['id']] + self.assertEqual(self.shell.run(argv), 0) + self._undo_console_redirect() + with open(self.path, 'r') as fd: + content = fd.read() + + self.assertEqual(content, FIXTURES['results']['execution_get_attribute_with_hours_in_elapsed_time.txt']) + @mock.patch.object( httpclient.HTTPClient, 'get', mock.MagicMock(return_value=base.FakeResponse(json.dumps(NEWLINE), 200, 'OK', {}))) From 52bc3d38f63ce4eb9e800aa9f5125bcb12f32ab3 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Fri, 19 Jun 2020 23:20:58 +0200 Subject: [PATCH 14/17] Revert "use mock.path.object to create DURATION_HOURS response object" This reverts commit c5d8e63eae7ba69f2e39caac598161194c3899e3. --- .../execution_with_hours_in_elapsed_time.json | 4 ++-- st2client/tests/unit/test_formatters.py | 16 ++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index 2b08f68f75..3aa98f9594 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-02T21:56:07.000000Z", + "end_timestamp": "2014-12-03T21:58:07.000000Z", "action": { "ref": "core.ping" }, @@ -26,4 +26,4 @@ "callback": {}, "id": "1" } -} +} \ No newline at end of file diff --git a/st2client/tests/unit/test_formatters.py b/st2client/tests/unit/test_formatters.py index d44da89868..c97842e77d 100644 --- a/st2client/tests/unit/test_formatters.py +++ b/st2client/tests/unit/test_formatters.py @@ -115,6 +115,10 @@ def test_execution_get_attributes(self): content = self._get_execution(argv) self.assertEqual(content, FIXTURES['results']['execution_get_attributes.txt']) + def test_execution_get_attribute_with_hours_in_elapsed_time(self): + argv = ['execution', 'get', DURATION_HOURS['id'], '--attr', 'status'] + content = self._get_execution(argv) + self.assertEqual(content, FIXTURES['results']['execution_get_attribute_with_hours_in_elapsed_time.txt']) def test_execution_get_default_in_json(self): argv = ['execution', 'get', EXECUTION['id'], '-j'] @@ -134,18 +138,6 @@ def test_execution_with_schema(self): content = self._get_schema_execution(argv) self.assertEqual(content, FIXTURES['results']['execution_get_has_schema.txt']) - @mock.patch.object( - httpclient.HTTPClient, 'get', - mock.MagicMock(return_value=base.FakeResponse(json.dumps(DURATION_HOURS), 200, 'OK', {}))) - def test_execution_get_attribute_with_hours_in_elapsed_time(self): - argv = ['execution', 'get', DURATION_HOURS['id']] - self.assertEqual(self.shell.run(argv), 0) - self._undo_console_redirect() - with open(self.path, 'r') as fd: - content = fd.read() - - self.assertEqual(content, FIXTURES['results']['execution_get_attribute_with_hours_in_elapsed_time.txt']) - @mock.patch.object( httpclient.HTTPClient, 'get', mock.MagicMock(return_value=base.FakeResponse(json.dumps(NEWLINE), 200, 'OK', {}))) From 41874c782a668180cb85f967f37809fb11f4375b Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Fri, 19 Jun 2020 23:22:07 +0200 Subject: [PATCH 15/17] revert the DURATION_HOURS tests and go back to the initial one --- .../execution_get_attribute_with_hours_in_elapsed_time.txt | 2 +- .../tests/fixtures/execution_with_hours_in_elapsed_time.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt b/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt index 09562682f9..7bbcd96e0f 100644 --- a/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt +++ b/st2client/tests/fixtures/execution_get_attribute_with_hours_in_elapsed_time.txt @@ -1 +1 @@ -status: succeeded (2h2m1s elapsed) +status: succeeded (2h0m1s elapsed) diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index 3aa98f9594..1768163328 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-03T21:58:07.000000Z", + "end_timestamp": "2014-12-03T21:56:07.000000Z", "action": { "ref": "core.ping" }, From 15a4b64cc34cd39e59a0cc6667b1fafd85d69b44 Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sat, 20 Jun 2020 22:48:09 +0200 Subject: [PATCH 16/17] reduce the duration back from 1d2h0m1s ot 2h0m1s --- .../tests/fixtures/execution_with_hours_in_elapsed_time.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json index 1768163328..12771065fb 100644 --- a/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json +++ b/st2client/tests/fixtures/execution_with_hours_in_elapsed_time.json @@ -18,7 +18,7 @@ }, "status": "succeeded", "start_timestamp": "2014-12-02T19:56:06.900000Z", - "end_timestamp": "2014-12-03T21:56:07.000000Z", + "end_timestamp": "2014-12-02T21:56:07.000000Z", "action": { "ref": "core.ping" }, From 25f91d889dbfdb92f85556a655f3a18e2a44817f Mon Sep 17 00:00:00 2001 From: Marcel Weinberg Date: Sat, 20 Jun 2020 23:35:31 +0200 Subject: [PATCH 17/17] break line to fix lint issue --- st2client/tests/unit/test_formatters.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/st2client/tests/unit/test_formatters.py b/st2client/tests/unit/test_formatters.py index c97842e77d..a55f798b9b 100644 --- a/st2client/tests/unit/test_formatters.py +++ b/st2client/tests/unit/test_formatters.py @@ -118,7 +118,8 @@ def test_execution_get_attributes(self): def test_execution_get_attribute_with_hours_in_elapsed_time(self): argv = ['execution', 'get', DURATION_HOURS['id'], '--attr', 'status'] content = self._get_execution(argv) - self.assertEqual(content, FIXTURES['results']['execution_get_attribute_with_hours_in_elapsed_time.txt']) + self.assertEqual( + content, FIXTURES['results']['execution_get_attribute_with_hours_in_elapsed_time.txt']) def test_execution_get_default_in_json(self): argv = ['execution', 'get', EXECUTION['id'], '-j']