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 ~~~~~~~ diff --git a/st2client/st2client/models/core.py b/st2client/st2client/models/core.py index 42e7fb7b72..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, 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 +392,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) 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)))