From 686d298bc96cea641421e0b45c76b40e39111b89 Mon Sep 17 00:00:00 2001 From: Tristan Struthers Date: Tue, 3 Sep 2019 13:14:34 -0700 Subject: [PATCH 1/4] Add user field to re_run method --- st2client/st2client/models/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/st2client/st2client/models/core.py b/st2client/st2client/models/core.py index 42e7fb7b72..f85009facc 100644 --- a/st2client/st2client/models/core.py +++ b/st2client/st2client/models/core.py @@ -378,7 +378,7 @@ def match_and_execute(self, instance, **kwargs): class ExecutionResourceManager(ResourceManager): @add_auth_token_to_kwargs_from_env - def re_run(self, execution_id, parameters=None, tasks=None, no_reset=None, delay=0, **kwargs): + def re_run(self, execution_id, parameters=None, tasks=None, no_reset=None, user=None, delay=0, **kwargs): url = '/%s/%s/re_run' % (self.resource.get_url_path_name(), execution_id) tasks = tasks or [] @@ -391,7 +391,8 @@ def re_run(self, execution_id, parameters=None, tasks=None, no_reset=None, delay 'parameters': parameters or {}, 'tasks': tasks, 'reset': list(set(tasks) - set(no_reset)), - 'delay': delay + 'delay': delay, + 'user': user } response = self.client.post(url, data, **kwargs) From 7ae5582d8aafef9c5c418a25d362a957c2607357 Mon Sep 17 00:00:00 2001 From: Tristan Struthers Date: Wed, 4 Sep 2019 15:10:45 -0700 Subject: [PATCH 2/4] Update failing unit tests and add a new test for user param --- .../tests/unit/test_client_executions.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/st2client/tests/unit/test_client_executions.py b/st2client/tests/unit/test_client_executions.py index b3e6c98b1e..65ab972361 100644 --- a/st2client/tests/unit/test_client_executions.py +++ b/st2client/tests/unit/test_client_executions.py @@ -86,6 +86,7 @@ def test_rerun_with_no_params(self): 'tasks': ['foobar'], 'reset': ['foobar'], 'parameters': {}, + 'user': None, 'delay': 0 } @@ -120,6 +121,7 @@ def test_rerun_with_params(self): 'tasks': ['foobar'], 'reset': ['foobar'], 'parameters': params, + 'user': None, 'delay': 0 } @@ -146,11 +148,39 @@ def test_rerun_with_delay(self): 'tasks': ['foobar'], 'reset': ['foobar'], 'parameters': {}, + 'user': None, 'delay': 100 } httpclient.HTTPClient.post.assert_called_with(endpoint, data) + @mock.patch.object( + models.ResourceManager, 'get_by_id', + mock.MagicMock(return_value=models.Execution(**EXECUTION))) + @mock.patch.object( + models.ResourceManager, 'get_by_ref_or_id', + mock.MagicMock(return_value=models.Action(**ACTION))) + @mock.patch.object( + models.ResourceManager, 'get_by_name', + mock.MagicMock(return_value=models.RunnerType(**RUNNER))) + @mock.patch.object( + httpclient.HTTPClient, 'post', + mock.MagicMock(return_value=base.FakeResponse(json.dumps(EXECUTION), 200, 'OK'))) + def test_rerun_with_user(self): + self.client.executions.re_run(EXECUTION['id'], tasks=['foobar'], user='stanley') + + endpoint = '/executions/%s/re_run' % EXECUTION['id'] + + data = { + 'tasks': ['foobar'], + 'reset': ['foobar'], + 'parameters': {}, + 'user': 'stanley', + 'delay': 0 + } + + httpclient.HTTPClient.post.assert_called_with(endpoint, data) + @mock.patch.object( models.ResourceManager, 'get_by_id', mock.MagicMock(return_value=models.Execution(**EXECUTION))) From 0021d7fa013026f93f732dbc5b0c097055d6ca54 Mon Sep 17 00:00:00 2001 From: Tristan Struthers Date: Wed, 4 Sep 2019 15:13:28 -0700 Subject: [PATCH 3/4] Wrap a line to pacify the linter --- st2client/st2client/models/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/st2client/st2client/models/core.py b/st2client/st2client/models/core.py index f85009facc..f9d2a86838 100644 --- a/st2client/st2client/models/core.py +++ b/st2client/st2client/models/core.py @@ -378,7 +378,8 @@ def match_and_execute(self, instance, **kwargs): class ExecutionResourceManager(ResourceManager): @add_auth_token_to_kwargs_from_env - def re_run(self, execution_id, parameters=None, tasks=None, no_reset=None, user=None, delay=0, **kwargs): + def re_run(self, execution_id, parameters=None, tasks=None, no_reset=None, user=None, delay=0, + **kwargs): url = '/%s/%s/re_run' % (self.resource.get_url_path_name(), execution_id) tasks = tasks or [] From d55e5b0f91c9917a842f89047829f5255a99f258 Mon Sep 17 00:00:00 2001 From: Tristan Struthers Date: Wed, 4 Sep 2019 15:50:24 -0700 Subject: [PATCH 4/4] Add corresponding entry to CHANGELOG --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 010c57e370..1aa027c819 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,7 @@ Added * Add support for blacklisting / whitelisting hosts to the HTTP runner by adding new ``url_hosts_blacklist`` and ``url_hosts_whitelist`` runner attribute. (new feature) #4757 +* Add ``user`` parameter to ``re_run`` method of st2client. #4785 Changed ~~~~~~~