Skip to content

Commit

Permalink
Merge pull request #54542 from garethgreenaway/2019_2_1_port_50306
Browse files Browse the repository at this point in the history
[master] Porting #50306 to master
  • Loading branch information
dwoz authored Nov 12, 2019
2 parents 4a5aa4d + 9756be6 commit c400411
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions salt/modules/opkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ def refresh_db(failhard=False, **kwargs): # pylint: disable=unused-argument
return ret


def _append_noaction_if_testmode(cmd, **kwargs):
'''
Adds the --noaction flag to the command if it's running in the test mode.
'''
if bool(kwargs.get('test') or __opts__.get('test')):
cmd.append('--noaction')


def install(name=None,
refresh=False,
pkgs=None,
Expand Down Expand Up @@ -366,6 +374,7 @@ def install(name=None,
to_reinstall = []
to_downgrade = []

_append_noaction_if_testmode(cmd_prefix, **kwargs)
if pkg_params is None or len(pkg_params) == 0:
return {}
elif pkg_type == 'file':
Expand Down Expand Up @@ -540,6 +549,7 @@ def remove(name=None, pkgs=None, **kwargs): # pylint: disable=unused-argument
if not targets:
return {}
cmd = ['opkg', 'remove']
_append_noaction_if_testmode(cmd, **kwargs)
if kwargs.get('remove_dependencies', False):
cmd.append('--force-removal-of-dependent-packages')
if kwargs.get('auto_remove_deps', False):
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/modules/test_opkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ def test_install(self):
with patch.multiple(opkg, **patch_kwargs):
self.assertEqual(opkg.install('vim:7.4'), INSTALLED)

def test_install_noaction(self):
'''
Test - Install packages.
'''
with patch('salt.modules.opkg.list_pkgs', MagicMock(return_value=({}))):
ret_value = {'retcode': 0}
mock = MagicMock(return_value=ret_value)
patch_kwargs = {
'__salt__': {
'cmd.run_all': mock,
'pkg_resource.parse_targets': MagicMock(return_value=({'vim': '7.4'}, 'repository')),
'restartcheck.restartcheck': MagicMock(return_value='No packages seem to need to be restarted')
}
}
with patch.multiple(opkg, **patch_kwargs):
self.assertEqual(opkg.install('vim:7.4', test=True), {})

def test_remove(self):
'''
Test - Remove packages.
Expand All @@ -160,6 +177,23 @@ def test_remove(self):
with patch.multiple(opkg, **patch_kwargs):
self.assertEqual(opkg.remove('vim'), REMOVED)

def test_remove_noaction(self):
'''
Test - Remove packages.
'''
with patch('salt.modules.opkg.list_pkgs', MagicMock(return_value=({}))):
ret_value = {'retcode': 0}
mock = MagicMock(return_value=ret_value)
patch_kwargs = {
'__salt__': {
'cmd.run_all': mock,
'pkg_resource.parse_targets': MagicMock(return_value=({'vim': '7.4'}, 'repository')),
'restartcheck.restartcheck': MagicMock(return_value='No packages seem to need to be restarted')
}
}
with patch.multiple(opkg, **patch_kwargs):
self.assertEqual(opkg.remove('vim:7.4', test=True), {})

def test_info_installed(self):
'''
Test - Return the information of the named package(s) installed on the system.
Expand Down

0 comments on commit c400411

Please sign in to comment.