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

Adds the possibility to also use downloadonly in kwargs #55448

Merged
merged 6 commits into from
Dec 2, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions salt/modules/aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,9 @@ def upgrade(refresh=True, dist_upgrade=False, **kwargs):
Skip refreshing the package database if refresh has already occurred within
<value> 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

Expand Down Expand Up @@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a deprecation warning here too log.warning('download_only will be deprecated in a future release') as described in #54790

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Akm0d Do we want to deprecate it?

cmd.append('--download-only')

cmd.append('dist-upgrade' if dist_upgrade else 'upgrade')
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/modules/test_aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,39 @@ 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()
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[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[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))

def test_show(self):
'''
Test that the pkg.show function properly parses apt-cache show output.
Expand Down