Skip to content

Commit

Permalink
Porting PR saltstack#53080 to 2019.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgreenaway committed Sep 18, 2019
1 parent 8d4d5ea commit a36cfd8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
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'
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)
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]))

0 comments on commit a36cfd8

Please sign in to comment.