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

Add 'noaction' flag for install/remove in the opkg execution module #50306

Merged
merged 10 commits into from
Oct 31, 2018
4 changes: 4 additions & 0 deletions salt/modules/opkg.py
Original file line number Diff line number Diff line change
@@ -366,6 +366,8 @@ def install(name=None,
to_reinstall = []
to_downgrade = []

if kwargs.get('noaction', False):
cmd_prefix.append('--noaction')
if pkg_params is None or len(pkg_params) == 0:
return {}
elif pkg_type == 'file':
@@ -540,6 +542,8 @@ def remove(name=None, pkgs=None, **kwargs): # pylint: disable=unused-argument
if not targets:
return {}
cmd = ['opkg', 'remove']
if kwargs.get('noaction', False):
cmd.append('--noaction')
if kwargs.get('remove_dependencies', False):
cmd.append('--force-removal-of-dependent-packages')
if kwargs.get('auto_remove_deps', False):
34 changes: 34 additions & 0 deletions tests/unit/modules/test_opkg.py
Original file line number Diff line number Diff line change
@@ -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', noaction=True), {})

def test_remove(self):
'''
Test - Remove packages.
@@ -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', noaction=True), {})

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