Skip to content

Commit

Permalink
Merge pull request #4785 from trstruth/trstruth/st2client-user-re-run
Browse files Browse the repository at this point in the history
Add user field to re_run method
  • Loading branch information
armab committed Sep 11, 2019
2 parents f6efff6 + d55e5b0 commit 3cfc71d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -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
~~~~~~~
Expand Down
6 changes: 4 additions & 2 deletions st2client/st2client/models/core.py
Expand Up @@ -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 []
Expand All @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions st2client/tests/unit/test_client_executions.py
Expand Up @@ -86,6 +86,7 @@ def test_rerun_with_no_params(self):
'tasks': ['foobar'],
'reset': ['foobar'],
'parameters': {},
'user': None,
'delay': 0
}

Expand Down Expand Up @@ -120,6 +121,7 @@ def test_rerun_with_params(self):
'tasks': ['foobar'],
'reset': ['foobar'],
'parameters': params,
'user': None,
'delay': 0
}

Expand All @@ -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)))
Expand Down

0 comments on commit 3cfc71d

Please sign in to comment.