Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15:Update
salt.15448
fix-for-return-value-ret-vs-return-in-batch-mod...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fix-for-return-value-ret-vs-return-in-batch-mode.patch of Package salt.15448
From f8eeddc8461a66d34b11e3677729d733b3deb804 Mon Sep 17 00:00:00 2001 From: Jochen Breuer <jbreuer@suse.de> Date: Thu, 9 Apr 2020 17:12:54 +0200 Subject: [PATCH] Fix for return value ret vs return in batch mode The least intrusive fix for ret vs return in batch mode. --- salt/cli/batch.py | 16 ++++++---- tests/unit/cli/test_batch.py | 62 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/salt/cli/batch.py b/salt/cli/batch.py index 10fc81a5f4..d5b8754ad7 100644 --- a/salt/cli/batch.py +++ b/salt/cli/batch.py @@ -234,14 +234,16 @@ class Batch(object): if not self.quiet: salt.utils.stringutils.print_cli('\nExecuting run on {0}\n'.format(sorted(next_))) # create a new iterator for this batch of minions + return_value = self.opts.get("return", self.opts.get("ret", "")) new_iter = self.local.cmd_iter_no_block( - *args, - raw=self.opts.get('raw', False), - ret=self.opts.get('return', ''), - show_jid=show_jid, - verbose=show_verbose, - gather_job_timeout=self.opts['gather_job_timeout'], - **self.eauth) + *args, + raw=self.opts.get("raw", False), + ret=return_value, + show_jid=show_jid, + verbose=show_verbose, + gather_job_timeout=self.opts["gather_job_timeout"], + **self.eauth + ) # add it to our iterators and to the minion_tracker iters.append(new_iter) minion_tracker[new_iter] = {} diff --git a/tests/unit/cli/test_batch.py b/tests/unit/cli/test_batch.py index acabbe51f5..d7411e8039 100644 --- a/tests/unit/cli/test_batch.py +++ b/tests/unit/cli/test_batch.py @@ -72,3 +72,65 @@ class BatchTestCase(TestCase): ''' ret = Batch.get_bnum(self.batch) self.assertEqual(ret, None) + + def test_return_value_in_run_for_ret(self): + """ + cmd_iter_no_block should have been called with a return no matter if + the return value was in ret or return. + """ + self.batch.opts = { + "batch": "100%", + "timeout": 5, + "fun": "test", + "arg": "foo", + "gather_job_timeout": 5, + "ret": "my_return", + } + self.batch.minions = ["foo", "bar", "baz"] + self.batch.local.cmd_iter_no_block = MagicMock(return_value=iter([])) + ret = Batch.run(self.batch) + # We need to fetch at least one object to trigger the relevant code path. + x = next(ret) + self.batch.local.cmd_iter_no_block.assert_called_with( + ["baz", "bar", "foo"], + "test", + "foo", + 5, + "list", + raw=False, + ret="my_return", + show_jid=False, + verbose=False, + gather_job_timeout=5, + ) + + def test_return_value_in_run_for_return(self): + """ + cmd_iter_no_block should have been called with a return no matter if + the return value was in ret or return. + """ + self.batch.opts = { + "batch": "100%", + "timeout": 5, + "fun": "test", + "arg": "foo", + "gather_job_timeout": 5, + "return": "my_return", + } + self.batch.minions = ["foo", "bar", "baz"] + self.batch.local.cmd_iter_no_block = MagicMock(return_value=iter([])) + ret = Batch.run(self.batch) + # We need to fetch at least one object to trigger the relevant code path. + x = next(ret) + self.batch.local.cmd_iter_no_block.assert_called_with( + ["baz", "bar", "foo"], + "test", + "foo", + 5, + "list", + raw=False, + ret="my_return", + show_jid=False, + verbose=False, + gather_job_timeout=5, + ) -- 2.26.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor