diff --git a/salt/modules/win_pkg.py b/salt/modules/win_pkg.py index 8ef4bae6ceb3..0cbc16237a75 100644 --- a/salt/modules/win_pkg.py +++ b/salt/modules/win_pkg.py @@ -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: + 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) diff --git a/tests/unit/modules/test_win_pkg.py b/tests/unit/modules/test_win_pkg.py index 50881a634845..50cd3a8e1106 100644 --- a/tests/unit/modules/test_win_pkg.py +++ b/tests/unit/modules/test_win_pkg.py @@ -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 @@ -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]))