From 90e2b8afa062b3125b74f58ff570837b52af34c1467379fd8e4ad9c1c82ebd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= Date: Wed, 3 Jul 2019 09:10:11 +0000 Subject: [PATCH] osc copypac from project:systemsmanagement:saltstack:testing package:salt revision:278 OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=147 --- _lastrevision | 2 +- ...args-to-pkg.list_downloaded-bsc-1140.patch | 68 ++++++ ...iblegate-to-crash-on-python3-minions.patch | 219 ++++++++++++++++++ salt.changes | 16 ++ salt.spec | 6 + 5 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 allow-passing-kwargs-to-pkg.list_downloaded-bsc-1140.patch create mode 100644 do-not-make-ansiblegate-to-crash-on-python3-minions.patch diff --git a/_lastrevision b/_lastrevision index 7f4553a..7aac985 100644 --- a/_lastrevision +++ b/_lastrevision @@ -1 +1 @@ -9254ebb1efeefa8f3a97e0c301de5f7376f14669 \ No newline at end of file +0ae10b837a49c10246690aabc972d2cb02bb75de \ No newline at end of file diff --git a/allow-passing-kwargs-to-pkg.list_downloaded-bsc-1140.patch b/allow-passing-kwargs-to-pkg.list_downloaded-bsc-1140.patch new file mode 100644 index 0000000..4aeeed8 --- /dev/null +++ b/allow-passing-kwargs-to-pkg.list_downloaded-bsc-1140.patch @@ -0,0 +1,68 @@ +From 9e2139213bc2eeb8afbf10fdff663ebe7ed23887 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= + +Date: Wed, 3 Jul 2019 09:34:50 +0100 +Subject: [PATCH] Allow passing kwargs to pkg.list_downloaded + (bsc#1140193) + +Add unit test for pkg.list_downloaded with kwargs +--- + salt/modules/zypperpkg.py | 2 +- + tests/unit/modules/test_zypperpkg.py | 27 +++++++++++++++++++++++++++ + 2 files changed, 28 insertions(+), 1 deletion(-) + +diff --git a/salt/modules/zypperpkg.py b/salt/modules/zypperpkg.py +index 9d0407e674..6bc7211f59 100644 +--- a/salt/modules/zypperpkg.py ++++ b/salt/modules/zypperpkg.py +@@ -2553,7 +2553,7 @@ def download(*packages, **kwargs): + ) + + +-def list_downloaded(root=None): ++def list_downloaded(root=None, **kwargs): + ''' + .. versionadded:: 2017.7.0 + +diff --git a/tests/unit/modules/test_zypperpkg.py b/tests/unit/modules/test_zypperpkg.py +index d2ae06a98e..0a3053680f 100644 +--- a/tests/unit/modules/test_zypperpkg.py ++++ b/tests/unit/modules/test_zypperpkg.py +@@ -766,6 +766,33 @@ Repository 'DUMMY' not found by its alias, number, or URI. + self.assertEqual(len(list_patches), 3) + self.assertDictEqual(list_patches, PATCHES_RET) + ++ @patch('salt.utils.path.os_walk', MagicMock(return_value=[('test', 'test', 'test')])) ++ @patch('os.path.getsize', MagicMock(return_value=123456)) ++ @patch('os.path.getctime', MagicMock(return_value=1234567890.123456)) ++ @patch('fnmatch.filter', MagicMock(return_value=['/var/cache/zypper/packages/foo/bar/test_package.rpm'])) ++ def test_list_downloaded_with_kwargs(self): ++ ''' ++ Test downloaded packages listing. ++ ++ :return: ++ ''' ++ DOWNLOADED_RET = { ++ 'test-package': { ++ '1.0': { ++ 'path': '/var/cache/zypper/packages/foo/bar/test_package.rpm', ++ 'size': 123456, ++ 'creation_date_time_t': 1234567890, ++ 'creation_date_time': '2009-02-13T23:31:30', ++ } ++ } ++ } ++ ++ with patch.dict(zypper.__salt__, {'lowpkg.bin_pkg_info': MagicMock(return_value={'name': 'test-package', ++ 'version': '1.0'})}): ++ list_downloaded = zypper.list_downloaded(kw1=True, kw2=False) ++ self.assertEqual(len(list_downloaded), 1) ++ self.assertDictEqual(list_downloaded, DOWNLOADED_RET) ++ + @patch('salt.utils.path.os_walk', MagicMock(return_value=[('test', 'test', 'test')])) + @patch('os.path.getsize', MagicMock(return_value=123456)) + @patch('os.path.getctime', MagicMock(return_value=1234567890.123456)) +-- +2.21.0 + + diff --git a/do-not-make-ansiblegate-to-crash-on-python3-minions.patch b/do-not-make-ansiblegate-to-crash-on-python3-minions.patch new file mode 100644 index 0000000..1249f63 --- /dev/null +++ b/do-not-make-ansiblegate-to-crash-on-python3-minions.patch @@ -0,0 +1,219 @@ +From 189a19b6e8d28cc49e5ad5f2a683e1dfdce66a86 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= + +Date: Fri, 28 Jun 2019 15:17:56 +0100 +Subject: [PATCH] Do not make ansiblegate to crash on Python3 minions + +Fix pylint issues + +Move MockTimedProc implementation to tests.support.mock + +Add unit test for ansible caller +--- + salt/modules/ansiblegate.py | 14 +++++++-- + tests/support/mock.py | 31 +++++++++++++++++++ + tests/unit/modules/test_ansiblegate.py | 41 ++++++++++++++++++++++++++ + tests/unit/modules/test_cmdmod.py | 34 +-------------------- + 4 files changed, 84 insertions(+), 36 deletions(-) + +diff --git a/salt/modules/ansiblegate.py b/salt/modules/ansiblegate.py +index 771db6d6aa..88e8147573 100644 +--- a/salt/modules/ansiblegate.py ++++ b/salt/modules/ansiblegate.py +@@ -147,6 +147,10 @@ class AnsibleModuleCaller(object): + :param kwargs: keywords to the module + :return: + ''' ++ if six.PY3: ++ python_exec = 'python3' ++ else: ++ python_exec = 'python' + + module = self._resolver.load_module(module) + if not hasattr(module, 'main'): +@@ -162,9 +166,13 @@ class AnsibleModuleCaller(object): + ["echo", "{0}".format(js_args)], + stdout=subprocess.PIPE, timeout=self.timeout) + proc_out.run() ++ if six.PY3: ++ proc_out_stdout = proc_out.stdout.decode() ++ else: ++ proc_out_stdout = proc_out.stdout + proc_exc = salt.utils.timed_subprocess.TimedProc( +- ['python', module.__file__], +- stdin=proc_out.stdout, stdout=subprocess.PIPE, timeout=self.timeout) ++ [python_exec, module.__file__], ++ stdin=proc_out_stdout, stdout=subprocess.PIPE, timeout=self.timeout) + proc_exc.run() + + try: +@@ -263,7 +271,7 @@ def help(module=None, *args): + description = doc.get('description') or '' + del doc['description'] + ret['Description'] = description +- ret['Available sections on module "{}"'.format(module.__name__.replace('ansible.modules.', ''))] = doc.keys() ++ ret['Available sections on module "{}"'.format(module.__name__.replace('ansible.modules.', ''))] = [i for i in doc.keys()] + else: + for arg in args: + info = doc.get(arg) +diff --git a/tests/support/mock.py b/tests/support/mock.py +index 38b68bd5c4..4b44c112ee 100644 +--- a/tests/support/mock.py ++++ b/tests/support/mock.py +@@ -510,6 +510,37 @@ class MockOpen(object): + ret.extend(fh_.writelines_calls) + return ret + ++class MockTimedProc(object): ++ ''' ++ Class used as a stand-in for salt.utils.timed_subprocess.TimedProc ++ ''' ++ class _Process(object): ++ ''' ++ Used to provide a dummy "process" attribute ++ ''' ++ def __init__(self, returncode=0, pid=12345): ++ self.returncode = returncode ++ self.pid = pid ++ ++ def __init__(self, stdout=None, stderr=None, returncode=0, pid=12345): ++ if stdout is not None and not isinstance(stdout, bytes): ++ raise TypeError('Must pass stdout to MockTimedProc as bytes') ++ if stderr is not None and not isinstance(stderr, bytes): ++ raise TypeError('Must pass stderr to MockTimedProc as bytes') ++ self._stdout = stdout ++ self._stderr = stderr ++ self.process = self._Process(returncode=returncode, pid=pid) ++ ++ def run(self): ++ pass ++ ++ @property ++ def stdout(self): ++ return self._stdout ++ ++ @property ++ def stderr(self): ++ return self._stderr + + # reimplement mock_open to support multiple filehandles + mock_open = MockOpen +diff --git a/tests/unit/modules/test_ansiblegate.py b/tests/unit/modules/test_ansiblegate.py +index 1fbb083eb7..70b47f8bc2 100644 +--- a/tests/unit/modules/test_ansiblegate.py ++++ b/tests/unit/modules/test_ansiblegate.py +@@ -29,6 +29,7 @@ from tests.support.unit import TestCase, skipIf + from tests.support.mock import ( + patch, + MagicMock, ++ MockTimedProc, + NO_MOCK, + NO_MOCK_REASON + ) +@@ -36,6 +37,7 @@ from tests.support.mock import ( + import salt.modules.ansiblegate as ansible + import salt.utils.platform + from salt.exceptions import LoaderError ++from salt.ext import six + + + @skipIf(NO_MOCK, NO_MOCK_REASON) +@@ -137,3 +139,42 @@ description: + ''' + with patch('salt.modules.ansiblegate.ansible', None): + assert ansible.__virtual__() == 'ansible' ++ ++ def test_ansible_module_call(self): ++ ''' ++ Test Ansible module call from ansible gate module ++ ++ :return: ++ ''' ++ ++ class Module(object): ++ ''' ++ An ansible module mock. ++ ''' ++ __name__ = 'one.two.three' ++ __file__ = 'foofile' ++ ++ def main(): ++ pass ++ ++ ANSIBLE_MODULE_ARGS = '{"ANSIBLE_MODULE_ARGS": ["arg_1", {"kwarg1": "foobar"}]}' ++ ++ proc = MagicMock(side_effect=[ ++ MockTimedProc( ++ stdout=ANSIBLE_MODULE_ARGS.encode(), ++ stderr=None), ++ MockTimedProc(stdout='{"completed": true}'.encode(), stderr=None) ++ ]) ++ ++ with patch.object(ansible, '_resolver', self.resolver), \ ++ patch.object(ansible._resolver, 'load_module', MagicMock(return_value=Module())): ++ _ansible_module_caller = ansible.AnsibleModuleCaller(ansible._resolver) ++ with patch('salt.utils.timed_subprocess.TimedProc', proc): ++ ret = _ansible_module_caller.call("one.two.three", "arg_1", kwarg1="foobar") ++ if six.PY3: ++ proc.assert_any_call(['echo', '{"ANSIBLE_MODULE_ARGS": {"kwarg1": "foobar", "_raw_params": "arg_1"}}'], stdout=-1, timeout=1200) ++ proc.assert_any_call(['python3', 'foofile'], stdin=ANSIBLE_MODULE_ARGS, stdout=-1, timeout=1200) ++ else: ++ proc.assert_any_call(['echo', '{"ANSIBLE_MODULE_ARGS": {"_raw_params": "arg_1", "kwarg1": "foobar"}}'], stdout=-1, timeout=1200) ++ proc.assert_any_call(['python', 'foofile'], stdin=ANSIBLE_MODULE_ARGS, stdout=-1, timeout=1200) ++ assert ret == {"completed": True, "timeout": 1200} +diff --git a/tests/unit/modules/test_cmdmod.py b/tests/unit/modules/test_cmdmod.py +index 8da672dd22..a20afaca0f 100644 +--- a/tests/unit/modules/test_cmdmod.py ++++ b/tests/unit/modules/test_cmdmod.py +@@ -24,6 +24,7 @@ from tests.support.paths import FILES + from tests.support.mock import ( + mock_open, + Mock, ++ MockTimedProc, + MagicMock, + NO_MOCK, + NO_MOCK_REASON, +@@ -36,39 +37,6 @@ MOCK_SHELL_FILE = '# List of acceptable shells\n' \ + '/bin/bash\n' + + +-class MockTimedProc(object): +- ''' +- Class used as a stand-in for salt.utils.timed_subprocess.TimedProc +- ''' +- class _Process(object): +- ''' +- Used to provide a dummy "process" attribute +- ''' +- def __init__(self, returncode=0, pid=12345): +- self.returncode = returncode +- self.pid = pid +- +- def __init__(self, stdout=None, stderr=None, returncode=0, pid=12345): +- if stdout is not None and not isinstance(stdout, bytes): +- raise TypeError('Must pass stdout to MockTimedProc as bytes') +- if stderr is not None and not isinstance(stderr, bytes): +- raise TypeError('Must pass stderr to MockTimedProc as bytes') +- self._stdout = stdout +- self._stderr = stderr +- self.process = self._Process(returncode=returncode, pid=pid) +- +- def run(self): +- pass +- +- @property +- def stdout(self): +- return self._stdout +- +- @property +- def stderr(self): +- return self._stderr +- +- + @skipIf(NO_MOCK, NO_MOCK_REASON) + class CMDMODTestCase(TestCase, LoaderModuleMockMixin): + ''' +-- +2.21.0 + + diff --git a/salt.changes b/salt.changes index 54a34da..eca3c0b 100644 --- a/salt.changes +++ b/salt.changes @@ -1,3 +1,19 @@ +------------------------------------------------------------------- +Wed Jul 3 08:53:13 UTC 2019 - Pablo Suárez Hernández + +- Allow passing kwargs to pkg.list_downloaded for Zypper (bsc#1140193) + +- Added: + * allow-passing-kwargs-to-pkg.list_downloaded-bsc-1140.patch + +------------------------------------------------------------------- +Fri Jun 28 15:26:59 UTC 2019 - Pablo Suárez Hernández + +- Do not make "ansiblegate" module to crash on Python3 minions (bsc#1139761) + +- Added: + * do-not-make-ansiblegate-to-crash-on-python3-minions.patch + ------------------------------------------------------------------- Thu Jun 20 12:32:04 UTC 2019 - Pablo Suárez Hernández diff --git a/salt.spec b/salt.spec index 33d7e8a..6e171f8 100644 --- a/salt.spec +++ b/salt.spec @@ -198,6 +198,10 @@ Patch64: virt.pool_running-fix-pool-start.patch Patch65: virt.volume_infos-fix-for-single-vm.patch # PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/161 Patch66: provide-the-missing-features-required-for-yomi-yet-o.patch +# PATCH_FIX_UPSTREAM: https://github.com/saltstack/salt/pull/53661 +Patch67: do-not-make-ansiblegate-to-crash-on-python3-minions.patch +# PATCH_FIX_UPSTREAM: https://github.com/saltstack/salt/pull/53693 +Patch68: allow-passing-kwargs-to-pkg.list_downloaded-bsc-1140.patch # BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -734,6 +738,8 @@ cp %{S:5} ./.travis.yml %patch64 -p1 %patch65 -p1 %patch66 -p1 +%patch67 -p1 +%patch68 -p1 %build %if 0%{?build_py2}