mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2018.3' into 50542_mysql_ensure_verify_login_uses_connection_host
This commit is contained in:
commit
db89b27ff2
6 changed files with 235 additions and 15 deletions
|
@ -909,7 +909,7 @@ def _virtual(osdata):
|
|||
# Tested on CentOS 5.4 / 2.6.18-164.15.1.el5xen
|
||||
grains['virtual_subtype'] = 'Xen Dom0'
|
||||
else:
|
||||
if grains.get('productname', '') == 'HVM domU':
|
||||
if osdata.get('productname', '') == 'HVM domU':
|
||||
# Requires dmidecode!
|
||||
grains['virtual_subtype'] = 'Xen HVM DomU'
|
||||
elif os.path.isfile('/proc/xen/capabilities') and \
|
||||
|
@ -926,9 +926,8 @@ def _virtual(osdata):
|
|||
elif isdir('/sys/bus/xen'):
|
||||
if 'xen:' in __salt__['cmd.run']('dmesg').lower():
|
||||
grains['virtual_subtype'] = 'Xen PV DomU'
|
||||
elif os.listdir('/sys/bus/xen/drivers'):
|
||||
# An actual DomU will have several drivers
|
||||
# whereas a paravirt ops kernel will not.
|
||||
elif os.path.isfile('/sys/bus/xen/drivers/xenconsole'):
|
||||
# An actual DomU will have the xenconsole driver
|
||||
grains['virtual_subtype'] = 'Xen PV DomU'
|
||||
# If a Dom0 or DomU was detected, obviously this is xen
|
||||
if 'dom' in grains.get('virtual_subtype', '').lower():
|
||||
|
|
93
salt/modules/win_wusa.py
Normal file
93
salt/modules/win_wusa.py
Normal file
|
@ -0,0 +1,93 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Microsoft Update files management via wusa.exe
|
||||
|
||||
:maintainer: Thomas Lemarchand
|
||||
:platform: Windows
|
||||
:depends: PowerShell
|
||||
|
||||
.. versionadded:: Neon
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.platform
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'win_wusa'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Load only on Windows
|
||||
'''
|
||||
if not salt.utils.platform.is_windows():
|
||||
return False, 'Only available on Windows systems'
|
||||
|
||||
powershell_info = __salt__['cmd.shell_info'](shell='powershell', list_modules=False)
|
||||
if not powershell_info['installed']:
|
||||
return False, 'PowerShell not available'
|
||||
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def is_installed(kb):
|
||||
'''
|
||||
Check if a specific KB is installed.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' win_wusa.is_installed KB123456
|
||||
'''
|
||||
get_hotfix_result = __salt__['cmd.powershell_all']('Get-HotFix -Id {0}'.format(kb), ignore_retcode=True)
|
||||
|
||||
return get_hotfix_result['retcode'] == 0
|
||||
|
||||
|
||||
def install(path):
|
||||
'''
|
||||
Install a KB from a .msu file.
|
||||
Some KBs will need a reboot, but this function does not manage it.
|
||||
You may have to manage reboot yourself after installation.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' win_wusa.install C:/temp/KB123456.msu
|
||||
'''
|
||||
return __salt__['cmd.run_all']('wusa.exe {0} /quiet /norestart'.format(path), ignore_retcode=True)
|
||||
|
||||
|
||||
def uninstall(kb):
|
||||
'''
|
||||
Uninstall a specific KB.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' win_wusa.uninstall KB123456
|
||||
'''
|
||||
return __salt__['cmd.run_all']('wusa.exe /uninstall /kb:{0} /quiet /norestart'.format(kb[2:]), ignore_retcode=True)
|
||||
|
||||
|
||||
def list_kbs():
|
||||
'''
|
||||
Return a list of dictionaries, one dictionary for each installed KB.
|
||||
The HotFixID key contains the ID of the KB.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' win_wusa.list_kbs
|
||||
'''
|
||||
return __salt__['cmd.powershell']('Get-HotFix')
|
115
salt/states/win_wusa.py
Normal file
115
salt/states/win_wusa.py
Normal file
|
@ -0,0 +1,115 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Microsoft Updates (KB) Management
|
||||
|
||||
This module provides the ability to enforce KB installations
|
||||
from files (.msu), without WSUS.
|
||||
|
||||
.. versionadded:: Neon
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.platform
|
||||
import salt.exceptions
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'win_wusa'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Load only on Windows
|
||||
'''
|
||||
if not salt.utils.platform.is_windows():
|
||||
return False, 'Only available on Windows systems'
|
||||
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def installed(name, source):
|
||||
'''
|
||||
Enforce the installed state of a KB
|
||||
|
||||
name
|
||||
Name of the Windows KB ("KB123456")
|
||||
source
|
||||
Source of .msu file corresponding to the KB
|
||||
|
||||
'''
|
||||
ret = {
|
||||
'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': '',
|
||||
}
|
||||
|
||||
# Start with basic error-checking. Do all the passed parameters make sense
|
||||
# and agree with each-other?
|
||||
if not name or not source:
|
||||
raise salt.exceptions.SaltInvocationError(
|
||||
'Arguments "name" and "source" are mandatory.')
|
||||
|
||||
# Check the current state of the system. Does anything need to change?
|
||||
current_state = __salt__['win_wusa.is_installed'](name)
|
||||
|
||||
if current_state:
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'KB already installed'
|
||||
return ret
|
||||
|
||||
# The state of the system does need to be changed. Check if we're running
|
||||
# in ``test=true`` mode.
|
||||
if __opts__['test'] is True:
|
||||
ret['comment'] = 'The KB "{0}" will be installed.'.format(name)
|
||||
ret['changes'] = {
|
||||
'old': current_state,
|
||||
'new': True,
|
||||
}
|
||||
|
||||
# Return ``None`` when running with ``test=true``.
|
||||
ret['result'] = None
|
||||
|
||||
return ret
|
||||
|
||||
try:
|
||||
result = __states__['file.cached'](source,
|
||||
skip_verify=True,
|
||||
saltenv=__env__)
|
||||
except Exception as exc:
|
||||
msg = 'Failed to cache {0}: {1}'.format(
|
||||
salt.utils.url.redact_http_basic_auth(source),
|
||||
exc.__str__())
|
||||
log.exception(msg)
|
||||
ret['comment'] = msg
|
||||
return ret
|
||||
|
||||
if result['result']:
|
||||
# Get the path of the file in the minion cache
|
||||
cached = __salt__['cp.is_cached'](source, saltenv=__env__)
|
||||
else:
|
||||
log.debug(
|
||||
'failed to download %s',
|
||||
salt.utils.url.redact_http_basic_auth(source)
|
||||
)
|
||||
return result
|
||||
|
||||
# Finally, make the actual change and return the result.
|
||||
new_state = __salt__['win_wusa.install'](cached)
|
||||
|
||||
ret['comment'] = 'The KB "{0}" was installed!'.format(name)
|
||||
|
||||
ret['changes'] = {
|
||||
'old': current_state,
|
||||
'new': new_state,
|
||||
}
|
||||
|
||||
ret['result'] = True
|
||||
|
||||
return ret
|
|
@ -1598,6 +1598,10 @@ class Pygit2(GitProvider):
|
|||
will let the calling function know whether or not a new repo was
|
||||
initialized by this function.
|
||||
'''
|
||||
# https://github.com/libgit2/pygit2/issues/339
|
||||
# https://github.com/libgit2/libgit2/issues/2122
|
||||
home = os.path.expanduser('~')
|
||||
pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = home
|
||||
new = False
|
||||
if not os.listdir(self.cachedir):
|
||||
# Repo cachedir is empty, initialize a new repo there
|
||||
|
@ -1606,17 +1610,7 @@ class Pygit2(GitProvider):
|
|||
else:
|
||||
# Repo cachedir exists, try to attach
|
||||
try:
|
||||
try:
|
||||
self.repo = pygit2.Repository(self.cachedir)
|
||||
except GitError as exc:
|
||||
import pwd
|
||||
# https://github.com/libgit2/pygit2/issues/339
|
||||
# https://github.com/libgit2/libgit2/issues/2122
|
||||
if "Error stat'ing config file" not in six.text_type(exc):
|
||||
raise
|
||||
home = pwd.getpwnam(salt.utils.user.get_user()).pw_dir
|
||||
pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = home
|
||||
self.repo = pygit2.Repository(self.cachedir)
|
||||
self.repo = pygit2.Repository(self.cachedir)
|
||||
except KeyError:
|
||||
log.error(_INVALID_REPO, self.cachedir, self.url, self.role)
|
||||
return new
|
||||
|
|
|
@ -4,6 +4,7 @@ ec2-test:
|
|||
size: c5.large
|
||||
sh_username: centos
|
||||
script_args: '-P'
|
||||
tag: {'created-by': 'cloud-tests'}
|
||||
ec2-win2012r2-test:
|
||||
provider: ec2-config
|
||||
size: c5.large
|
||||
|
@ -17,6 +18,7 @@ ec2-win2012r2-test:
|
|||
use_winrm: True
|
||||
winrm_verify_ssl: False
|
||||
deploy: True
|
||||
tag: {'created-by': 'cloud-tests'}
|
||||
ec2-win2016-test:
|
||||
provider: ec2-config
|
||||
size: c5.large
|
||||
|
@ -30,3 +32,4 @@ ec2-win2016-test:
|
|||
use_winrm: True
|
||||
winrm_verify_ssl: False
|
||||
deploy: True
|
||||
tag: {'created-by': 'cloud-tests'}
|
||||
|
|
|
@ -685,6 +685,22 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'Docker'
|
||||
)
|
||||
|
||||
@skipIf(salt.utils.platform.is_windows(), 'System is Windows')
|
||||
def test_xen_virtual(self):
|
||||
'''
|
||||
Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
|
||||
'''
|
||||
with patch.object(os.path, 'isfile', MagicMock(return_value=False)):
|
||||
with patch.dict(core.__salt__, {'cmd.run': MagicMock(return_value='')}), \
|
||||
patch.object(os.path,
|
||||
'isfile',
|
||||
MagicMock(side_effect=lambda x: True if x == '/sys/bus/xen/drivers/xenconsole' else False)):
|
||||
log.debug('Testing Xen')
|
||||
self.assertEqual(
|
||||
core._virtual({'kernel': 'Linux'}).get('virtual_subtype'),
|
||||
'Xen PV DomU'
|
||||
)
|
||||
|
||||
def _check_ipaddress(self, value, ip_v):
|
||||
'''
|
||||
check if ip address in a list is valid
|
||||
|
|
Loading…
Add table
Reference in a new issue