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
Prev Previous commit
Next Next commit
Refactor _append_noaction_if_testmode to make codeclimate happy
Signed-off-by: Rares POP <rares.pop@ni.com>
  • Loading branch information
Rares POP committed Oct 31, 2018
commit dcaeb9ef288d7eff19f004c4d82c1bfa23b90a1f
15 changes: 10 additions & 5 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):
Copy link
Contributor

Choose a reason for hiding this comment

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

You can call it just _noaction 😉 but this is also OK.

'''
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,9 +374,7 @@ def install(name=None,
to_reinstall = []
to_downgrade = []

if bool(kwargs.get('test') or __opts__.get('test')):
cmd_prefix.append('--noaction')

_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 @@ -543,8 +549,7 @@ def remove(name=None, pkgs=None, **kwargs): # pylint: disable=unused-argument
if not targets:
return {}
cmd = ['opkg', 'remove']
if bool(kwargs.get('test') or __opts__.get('test')):
cmd.append('--noaction')
_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