Skip to content

Commit

Permalink
Merge pull request #55448 from brejoc/master-download-only-fix
Browse files Browse the repository at this point in the history
Adds the possibility to also use downloadonly in kwargs
  • Loading branch information
dwoz authored Dec 2, 2019
2 parents e5fcd07 + a37c2e1 commit bc0f924
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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):
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

0 comments on commit bc0f924

Please sign in to comment.