Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user field to re_run method #4785

Merged
merged 4 commits into from Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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