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

[master] Porting #53080 to master #54566

Merged
merged 4 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions salt/modules/win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,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'
pkg = next(iter(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)
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]))