mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge forward #52065
This commit is contained in:
parent
491bfa8c4d
commit
b71b655bdb
2 changed files with 58 additions and 35 deletions
|
@ -8,8 +8,9 @@ Windows 10.
|
|||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
|
||||
# Import Python libs
|
||||
import re
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.platform
|
||||
|
@ -21,6 +22,27 @@ from salt.ext import six
|
|||
log = logging.getLogger(__name__)
|
||||
__virtualname__ = "dism"
|
||||
|
||||
# We always want to use the version of dism that matches the architecture of the
|
||||
# host machine. On 32bit boxes that will always be System32. On 64bit boxes that
|
||||
# are running 64bit salt that will always be System32. On 64bit boxes that are
|
||||
# running 32bit salt the 64bit dism will be found in SysNative
|
||||
# Sysnative is a virtual folder, a special alias, that can be used to access the
|
||||
# 64-bit System32 folder from a 32-bit application
|
||||
try:
|
||||
# This does not apply to Non-Windows platforms
|
||||
if not salt.utils.platform.is_windows():
|
||||
raise OSError
|
||||
|
||||
if os.path.exists(os.path.join(os.environ.get('SystemRoot'), 'SysNative')):
|
||||
bin_path = os.path.join(os.environ.get('SystemRoot'), 'SysNative')
|
||||
else:
|
||||
bin_path = os.path.join(os.environ.get('SystemRoot'), 'System32')
|
||||
bin_dism = os.path.join(bin_path, 'dism.exe')
|
||||
|
||||
except OSError:
|
||||
log.trace('win_dism: Non-Windows system')
|
||||
bin_dism = 'dism.exe'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
|
@ -33,7 +55,7 @@ def __virtual__():
|
|||
|
||||
|
||||
def _get_components(type_regex, plural_type, install_value, image=None):
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/English',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Get-{0}'.format(plural_type)]
|
||||
|
@ -82,7 +104,7 @@ def add_capability(capability,
|
|||
'`install_capability` is not available on this version of Windows: '
|
||||
'{0}'.format(__grains__['osversion']))
|
||||
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/Quiet',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Add-Capability',
|
||||
|
@ -127,7 +149,7 @@ def remove_capability(capability, image=None, restart=False):
|
|||
'`uninstall_capability` is not available on this version of '
|
||||
'Windows: {0}'.format(__grains__['osversion']))
|
||||
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/Quiet',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Remove-Capability',
|
||||
|
@ -166,7 +188,7 @@ def get_capabilities(image=None):
|
|||
'`installed_capabilities` is not available on this version of '
|
||||
'Windows: {0}'.format(__grains__['osversion']))
|
||||
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/English',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Get-Capabilities']
|
||||
|
@ -272,7 +294,7 @@ def add_feature(feature,
|
|||
|
||||
salt '*' dism.add_feature NetFx3
|
||||
'''
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/Quiet',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Enable-Feature',
|
||||
|
@ -313,7 +335,7 @@ def remove_feature(feature, remove_payload=False, image=None, restart=False):
|
|||
|
||||
salt '*' dism.remove_feature NetFx3
|
||||
'''
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/Quiet',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Disable-Feature',
|
||||
|
@ -359,7 +381,7 @@ def get_features(package=None, image=None):
|
|||
# Return all features in the calc package
|
||||
salt '*' dism.get_features Microsoft.Windows.Calc.Demo~6595b6144ccf1df~x86~en~1.0.0.0
|
||||
'''
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/English',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Get-Features']
|
||||
|
@ -461,7 +483,7 @@ def add_package(package,
|
|||
|
||||
salt '*' dism.add_package C:\\Packages\\package.cab
|
||||
'''
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/Quiet',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Add-Package',
|
||||
|
@ -504,7 +526,7 @@ def remove_package(package, image=None, restart=False):
|
|||
# Remove the package.cab (does not remove C:\\packages\\package.cab)
|
||||
salt '*' dism.remove_package C:\\packages\\package.cab
|
||||
'''
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/Quiet',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Remove-Package']
|
||||
|
@ -563,7 +585,7 @@ def package_info(package, image=None):
|
|||
|
||||
salt '*' dism. package_info C:\\packages\\package.cab
|
||||
'''
|
||||
cmd = ['DISM',
|
||||
cmd = [bin_dism,
|
||||
'/English',
|
||||
'/Image:{0}'.format(image) if image else '/Online',
|
||||
'/Get-PackageInfo']
|
||||
|
|
|
@ -9,10 +9,7 @@ import salt.modules.win_dism as dism
|
|||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.unit import TestCase
|
||||
from tests.support.mock import (
|
||||
MagicMock,
|
||||
patch
|
||||
)
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
||||
class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
@ -29,7 +26,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__grains__, {'osversion': 10}):
|
||||
dism.add_capability("test")
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Add-Capability',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Add-Capability',
|
||||
'/CapabilityName:test', '/NoRestart'])
|
||||
|
||||
def test_add_capability_with_extras(self):
|
||||
|
@ -41,7 +38,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__grains__, {'osversion': 10}):
|
||||
dism.add_capability("test", "life", True)
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Add-Capability',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Add-Capability',
|
||||
'/CapabilityName:test', '/Source:life', '/LimitAccess',
|
||||
'/NoRestart'])
|
||||
|
||||
|
@ -54,7 +51,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__grains__, {'osversion': 10}):
|
||||
dism.remove_capability("test")
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Remove-Capability',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Remove-Capability',
|
||||
'/CapabilityName:test', '/NoRestart'])
|
||||
|
||||
def test_get_capabilities(self):
|
||||
|
@ -69,7 +66,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__grains__, {'osversion': 10}):
|
||||
out = dism.get_capabilities()
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/English', '/Online', '/Get-Capabilities'])
|
||||
[dism.bin_dism, '/English', '/Online', '/Get-Capabilities'])
|
||||
self.assertEqual(out, ['Capa1', 'Capa2'])
|
||||
|
||||
def test_installed_capabilities(self):
|
||||
|
@ -84,7 +81,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__grains__, {'osversion': 10}):
|
||||
out = dism.installed_capabilities()
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/English', '/Online', '/Get-Capabilities'])
|
||||
[dism.bin_dism, '/English', '/Online', '/Get-Capabilities'])
|
||||
self.assertEqual(out, ["Capa1"])
|
||||
|
||||
def test_available_capabilities(self):
|
||||
|
@ -99,7 +96,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__grains__, {'osversion': 10}):
|
||||
out = dism.available_capabilities()
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/English', '/Online', '/Get-Capabilities'])
|
||||
[dism.bin_dism, '/English', '/Online', '/Get-Capabilities'])
|
||||
self.assertEqual(out, ["Capa2"])
|
||||
|
||||
def test_add_feature(self):
|
||||
|
@ -110,7 +107,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.add_feature("test")
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Enable-Feature',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Enable-Feature',
|
||||
'/FeatureName:test', '/NoRestart'])
|
||||
|
||||
def test_add_feature_with_extras(self):
|
||||
|
@ -121,7 +118,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.add_feature('sponge', 'bob', 'C:\\temp', True, True)
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Enable-Feature',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Enable-Feature',
|
||||
'/FeatureName:sponge', '/PackageName:bob', '/Source:C:\\temp',
|
||||
'/LimitAccess', '/All', '/NoRestart'])
|
||||
|
||||
|
@ -133,7 +130,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.remove_feature("test")
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Disable-Feature',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Disable-Feature',
|
||||
'/FeatureName:test', '/NoRestart'])
|
||||
|
||||
def test_remove_feature_with_extras(self):
|
||||
|
@ -144,7 +141,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.remove_feature('sponge', True)
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Disable-Feature',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Disable-Feature',
|
||||
'/FeatureName:sponge', '/Remove', '/NoRestart'])
|
||||
|
||||
def test_get_features(self):
|
||||
|
@ -152,12 +149,13 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
Test getting all the features
|
||||
'''
|
||||
features = "Feature Name : Capa1\r\n State : Enabled\r\n" \
|
||||
"Feature Name : Capa2\r\n State : Disabled\r\n"
|
||||
"Feature Name : Capa2\r\n State : Disabled\r\n"
|
||||
|
||||
mock = MagicMock(return_value=features)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
out = dism.get_features()
|
||||
mock.assert_called_once_with(['DISM', '/English', '/Online', '/Get-Features'])
|
||||
mock.assert_called_once_with(
|
||||
[dism.bin_dism, '/English', '/Online', '/Get-Features'])
|
||||
self.assertEqual(out, ['Capa1', 'Capa2'])
|
||||
|
||||
def test_installed_features(self):
|
||||
|
@ -165,12 +163,13 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
Test getting all the installed features
|
||||
'''
|
||||
features = "Feature Name : Capa1\r\n State : Enabled\r\n" \
|
||||
"Feature Name : Capa2\r\n State : Disabled\r\n"
|
||||
"Feature Name : Capa2\r\n State : Disabled\r\n"
|
||||
|
||||
mock = MagicMock(return_value=features)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
out = dism.installed_features()
|
||||
mock.assert_called_once_with(['DISM', '/English', '/Online', '/Get-Features'])
|
||||
mock.assert_called_once_with(
|
||||
[dism.bin_dism, '/English', '/Online', '/Get-Features'])
|
||||
self.assertEqual(out, ["Capa1"])
|
||||
|
||||
def test_available_features(self):
|
||||
|
@ -183,7 +182,8 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value=features)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
out = dism.available_features()
|
||||
mock.assert_called_once_with(['DISM', '/English', '/Online', '/Get-Features'])
|
||||
mock.assert_called_once_with(
|
||||
[dism.bin_dism, '/English', '/Online', '/Get-Features'])
|
||||
self.assertEqual(out, ["Capa2"])
|
||||
|
||||
def test_add_package(self):
|
||||
|
@ -194,7 +194,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.add_package("test")
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Add-Package',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Add-Package',
|
||||
'/PackagePath:test', '/NoRestart'])
|
||||
|
||||
def test_add_package_with_extras(self):
|
||||
|
@ -205,7 +205,7 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.add_package('sponge', True, True)
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Add-Package',
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Add-Package',
|
||||
'/PackagePath:sponge', '/IgnoreCheck', '/PreventPending',
|
||||
'/NoRestart'])
|
||||
|
||||
|
@ -217,8 +217,8 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.remove_package("test")
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Remove-Package', '/NoRestart',
|
||||
'/PackagePath:test'])
|
||||
[dism.bin_dism, '/Quiet', '/Online', '/Remove-Package',
|
||||
'/NoRestart', '/PackagePath:test'])
|
||||
|
||||
def test_installed_packages(self):
|
||||
'''
|
||||
|
@ -230,5 +230,6 @@ class WinDismTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value=features)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
out = dism.installed_packages()
|
||||
mock.assert_called_once_with(['DISM', '/English', '/Online', '/Get-Packages'])
|
||||
mock.assert_called_once_with(
|
||||
[dism.bin_dism, '/English', '/Online', '/Get-Packages'])
|
||||
self.assertEqual(out, ['Capa1', 'Capa2'])
|
||||
|
|
Loading…
Add table
Reference in a new issue