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

Pkg installed flag fix #53080

Merged
merged 13 commits into from
May 21, 2019
5 changes: 5 additions & 0 deletions salt/modules/win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,11 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
'extra_install_flags': kwargs.get('extra_install_flags')
}
}
elif len(pkg_params) == 1:
# A dict of packages was passed, but it contains only 1 key, so we need
# to add the 'extra_install_flags'
for pkg in pkg_params:
cmcmarrow marked this conversation as resolved.
Show resolved Hide resolved
pkg_params[pkg]['extra_install_flags'] = kwargs.get('extra_install_flags')

# Get a list of currently installed software for comparison at the end
old = list_pkgs(saltenv=saltenv, refresh=refresh, versions_as_list=True)
Expand Down
69 changes: 68 additions & 1 deletion tests/unit/modules/test_win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, patch
from tests.support.unit import TestCase
from tests.support.unit import TestCase, skipIf

# Import Salt Libs
import salt.modules.pkg_resource as pkg_resource
import salt.modules.win_pkg as win_pkg
import salt.utils.data
import salt.utils.platform


@skipIf(not salt.utils.platform.is_windows(), "Must be on Windows")
class WinPkgInstallTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.win_pkg
Expand Down Expand Up @@ -151,3 +154,67 @@ def test_pkg_install_existing_with_version(self):
expected = {}
result = win_pkg.install(name='nsis', version='3.03')
self.assertDictEqual(expected, result)

def test_pkg_install_name(self):
'''
test pkg.install name extra_install_flags
'''

ret__get_package_info = {'3.03': {'uninstaller': '%program.exe', 'reboot': False,
'msiexec': False,
'installer': 'runme.exe',
'uninstall_flags': '/S', 'locale': 'en_US', 'install_flags': '/s',
'full_name': 'Firebox 3.03 (x86 en-US)'}}

mock_cmd_run_all = MagicMock(return_value={'retcode': 0})
with patch.object(salt.utils.data, 'is_true', MagicMock(return_value=True)),\
patch.object(win_pkg, '_get_package_info', MagicMock(return_value=ret__get_package_info)),\
patch.dict(win_pkg.__salt__, {'pkg_resource.parse_targets':
MagicMock(return_value=[{'firebox': '3.03'}, None]),
'cp.is_cached':
MagicMock(return_value='C:\\fake\\path.exe'),
'cmd.run_all': mock_cmd_run_all}):
ret = win_pkg.install(name='firebox', version='3.03', extra_install_flags='-e True -test_flag True')
self.assertTrue('-e True -test_flag True' in str(mock_cmd_run_all.call_args[0]))

def test_pkg_install_single_pkg(self):
'''
test pkg.install pkg with extra_install_flags
'''
ret__get_package_info = {'3.03': {'uninstaller': '%program.exe', 'reboot': False,
'msiexec': False,
'installer': 'runme.exe',
'uninstall_flags': '/S', 'locale': 'en_US', 'install_flags': '/s',
'full_name': 'Firebox 3.03 (x86 en-US)'}}

mock_cmd_run_all = MagicMock(return_value={'retcode': 0})
with patch.object(salt.utils.data, 'is_true', MagicMock(return_value=True)), \
patch.object(win_pkg, '_get_package_info', MagicMock(return_value=ret__get_package_info)), \
patch.dict(win_pkg.__salt__, {'pkg_resource.parse_targets':
MagicMock(return_value=[{'firebox': '3.03'}, None]),
'cp.is_cached':
MagicMock(return_value='C:\\fake\\path.exe'),
'cmd.run_all': mock_cmd_run_all}):
ret = win_pkg.install(pkgs=['firebox'], version='3.03', extra_install_flags='-e True -test_flag True')
self.assertTrue('-e True -test_flag True' in str(mock_cmd_run_all.call_args[0]))

def test_pkg_install_multiple_pkgs(self):
'''
test pkg.install pkg with extra_install_flags
'''
ret__get_package_info = {'3.03': {'uninstaller': '%program.exe', 'reboot': False,
'msiexec': False,
'installer': 'runme.exe',
'uninstall_flags': '/S', 'locale': 'en_US', 'install_flags': '/s',
'full_name': 'Firebox 3.03 (x86 en-US)'}}

mock_cmd_run_all = MagicMock(return_value={'retcode': 0})
with patch.object(salt.utils.data, 'is_true', MagicMock(return_value=True)), \
patch.object(win_pkg, '_get_package_info', MagicMock(return_value=ret__get_package_info)), \
patch.dict(win_pkg.__salt__, {'pkg_resource.parse_targets':
MagicMock(return_value=[{'firebox': '3.03', 'got': '3.03'}, None]),
'cp.is_cached':
MagicMock(return_value='C:\\fake\\path.exe'),
'cmd.run_all': mock_cmd_run_all}):
ret = win_pkg.install(pkgs=['firebox', 'got'], extra_install_flags='-e True -test_flag True')
self.assertFalse('-e True -test_flag True' in str(mock_cmd_run_all.call_args[0]))