From 3cf381cd7c5e644326194c08c979efd4f42c66dd Mon Sep 17 00:00:00 2001 From: Jochen Breuer Date: Fri, 27 Sep 2019 11:33:47 +0200 Subject: [PATCH 1/6] Adds the possibility to also use downloadonly in kwargs The download_only parameter in the apt module is not in line with the yum and zypper modules. Both of them use downloadonly without the underline. With this change apt now additionally supports the downloadonly parameter. Fixes #54790 --- salt/modules/aptpkg.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/salt/modules/aptpkg.py b/salt/modules/aptpkg.py index a8a33dbe74c3..a88dd6aa30c0 100644 --- a/salt/modules/aptpkg.py +++ b/salt/modules/aptpkg.py @@ -1016,8 +1016,9 @@ def upgrade(refresh=True, dist_upgrade=False, **kwargs): Skip refreshing the package database if refresh has already occurred within seconds - download_only - Only download the packages, don't unpack or install them + download_only (or downloadonly) + Only download the packages, don't unpack or install them. Use + downloadonly to be in line with yum and zypper module. .. versionadded:: 2018.3.0 @@ -1048,7 +1049,7 @@ def upgrade(refresh=True, dist_upgrade=False, **kwargs): cmd.append('--force-yes') if kwargs.get('skip_verify', False): cmd.append('--allow-unauthenticated') - if kwargs.get('download_only', False): + if kwargs.get('download_only', False) or kwargs.get('downloadonly', False): cmd.append('--download-only') cmd.append('dist-upgrade' if dist_upgrade else 'upgrade') From bc62a187b2c2379f45ff25d2ca39c83d940360f9 Mon Sep 17 00:00:00 2001 From: Jochen Breuer Date: Fri, 27 Sep 2019 16:44:29 +0200 Subject: [PATCH 2/6] Add tests for download_only option in upgrade method --- tests/unit/modules/test_aptpkg.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/unit/modules/test_aptpkg.py b/tests/unit/modules/test_aptpkg.py index 1e963ee5dbd0..648422f68904 100644 --- a/tests/unit/modules/test_aptpkg.py +++ b/tests/unit/modules/test_aptpkg.py @@ -348,6 +348,37 @@ def test_upgrade(self): with patch.multiple(aptpkg, **patch_kwargs): self.assertEqual(aptpkg.upgrade(), dict()) + def test_upgrade_downloadonly(self): + ''' + Tests the download-only options for upgrade. + ''' + with patch('salt.utils.pkg.clear_rtag', MagicMock()): + with patch('salt.modules.aptpkg.list_pkgs', + MagicMock(return_value=UNINSTALL)): + mock_cmd = MagicMock(return_value={ + 'retcode': 0, + 'stdout': UPGRADE + }) + patch_kwargs = { + '__salt__': { + 'config.get': MagicMock(return_value=True), + 'cmd.run_all': mock_cmd + }, + } + with patch.multiple(aptpkg, **patch_kwargs): + aptpkg.upgrade() + self.assertTrue("--download-only" not in \ + patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + aptpkg.upgrade(downloadonly=False) + self.assertTrue("--download-only" not in \ + patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + aptpkg.upgrade(downloadonly=True) + self.assertTrue("--download-only" in \ + patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + aptpkg.upgrade(download_only=True) + self.assertTrue("--download-only" in \ + patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + def test_show(self): ''' Test that the pkg.show function properly parses apt-cache show output. From 4a4f02c4972cd754179a380a42fbd914d6feac15 Mon Sep 17 00:00:00 2001 From: Jochen Breuer Date: Fri, 27 Sep 2019 17:04:10 +0200 Subject: [PATCH 3/6] Fixes linter error --- tests/unit/modules/test_aptpkg.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/unit/modules/test_aptpkg.py b/tests/unit/modules/test_aptpkg.py index 648422f68904..8de4ad93155f 100644 --- a/tests/unit/modules/test_aptpkg.py +++ b/tests/unit/modules/test_aptpkg.py @@ -367,17 +367,13 @@ def test_upgrade_downloadonly(self): } with patch.multiple(aptpkg, **patch_kwargs): aptpkg.upgrade() - self.assertTrue("--download-only" not in \ - patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + self.assertTrue("--download-only" not in patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) aptpkg.upgrade(downloadonly=False) - self.assertTrue("--download-only" not in \ - patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + self.assertTrue("--download-only" not in patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) aptpkg.upgrade(downloadonly=True) - self.assertTrue("--download-only" in \ - patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + self.assertTrue("--download-only" in patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) aptpkg.upgrade(download_only=True) - self.assertTrue("--download-only" in \ - patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + self.assertTrue("--download-only" in patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) def test_show(self): ''' From c22919ed9a3d64d0107bf98f08676a764ee4cfe3 Mon Sep 17 00:00:00 2001 From: Jochen Breuer Date: Mon, 30 Sep 2019 09:31:39 +0200 Subject: [PATCH 4/6] Tests are no longer only picking first args --- tests/unit/modules/test_aptpkg.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/unit/modules/test_aptpkg.py b/tests/unit/modules/test_aptpkg.py index 8de4ad93155f..c1c534bb074a 100644 --- a/tests/unit/modules/test_aptpkg.py +++ b/tests/unit/modules/test_aptpkg.py @@ -367,13 +367,16 @@ def test_upgrade_downloadonly(self): } with patch.multiple(aptpkg, **patch_kwargs): aptpkg.upgrade() - self.assertTrue("--download-only" not in patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) - aptpkg.upgrade(downloadonly=False) - self.assertTrue("--download-only" not in patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] + self.assertFalse(any(args_matching)) + aptpkg.upgrade(downloadonly=True) - self.assertTrue("--download-only" in patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] + self.assertTrue(any(args_matching)) + aptpkg.upgrade(download_only=True) - self.assertTrue("--download-only" in patch_kwargs['__salt__']['cmd.run_all'].call_args.args[0]) + args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] + self.assertTrue(any(args_matching)) def test_show(self): ''' From 8cd6c231184c0b4b1bca11135eb6ce374be777f7 Mon Sep 17 00:00:00 2001 From: Jochen Breuer Date: Tue, 1 Oct 2019 15:30:09 +0200 Subject: [PATCH 5/6] I need some debug output from the test suite This will be cleaned up later. --- tests/unit/modules/test_aptpkg.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit/modules/test_aptpkg.py b/tests/unit/modules/test_aptpkg.py index c1c534bb074a..58a919880428 100644 --- a/tests/unit/modules/test_aptpkg.py +++ b/tests/unit/modules/test_aptpkg.py @@ -368,14 +368,23 @@ def test_upgrade_downloadonly(self): with patch.multiple(aptpkg, **patch_kwargs): aptpkg.upgrade() args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] + print("=============================================================") + [print(args) for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args] + # Here we shouldn't see the parameter and args_matching should be empty. self.assertFalse(any(args_matching)) aptpkg.upgrade(downloadonly=True) args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] + print("=============================================================") + [print(args) for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args] + # --download-only should be in the args list and we should have at least on True in the list. self.assertTrue(any(args_matching)) aptpkg.upgrade(download_only=True) args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] + print("=============================================================") + [print(args) for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args] + # --download-only should be in the args list and we should have at least on True in the list. self.assertTrue(any(args_matching)) def test_show(self): From a37c2e159094e0cbb5135efa9ed60705e6ba8ab5 Mon Sep 17 00:00:00 2001 From: Jochen Breuer Date: Mon, 28 Oct 2019 08:57:56 +0100 Subject: [PATCH 6/6] Fix for aptpkg test with older mock modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and removal of debug prints --- tests/unit/modules/test_aptpkg.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/unit/modules/test_aptpkg.py b/tests/unit/modules/test_aptpkg.py index 58a919880428..09d496284919 100644 --- a/tests/unit/modules/test_aptpkg.py +++ b/tests/unit/modules/test_aptpkg.py @@ -367,23 +367,17 @@ def test_upgrade_downloadonly(self): } with patch.multiple(aptpkg, **patch_kwargs): aptpkg.upgrade() - args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] - print("=============================================================") - [print(args) for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args] + args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args[0] if "--download-only" in args] # Here we shouldn't see the parameter and args_matching should be empty. self.assertFalse(any(args_matching)) aptpkg.upgrade(downloadonly=True) - args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] - print("=============================================================") - [print(args) for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args] + args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args[0] if "--download-only" in args] # --download-only should be in the args list and we should have at least on True in the list. self.assertTrue(any(args_matching)) aptpkg.upgrade(download_only=True) - args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args if "--download-only" in args] - print("=============================================================") - [print(args) for args in patch_kwargs['__salt__']['cmd.run_all'].call_args.args] + args_matching = [True for args in patch_kwargs['__salt__']['cmd.run_all'].call_args[0] if "--download-only" in args] # --download-only should be in the args list and we should have at least on True in the list. self.assertTrue(any(args_matching))