mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2019.2' into merge-2019.2
This commit is contained in:
commit
54ea40a265
9 changed files with 103 additions and 15 deletions
|
@ -8,7 +8,7 @@ Python 2.7 Deprecation
|
|||
======================
|
||||
|
||||
In light of Python 2.7 reaching its End of Life (EOL) on Jan 1st 2020,
|
||||
Python 2 will be deprecated from SaltStack no earlier then the Sodium
|
||||
Python 2 will be deprecated from SaltStack no earlier than the Sodium
|
||||
release, that is either the Sodium release or a later release.
|
||||
This decision is pending further community discussion.
|
||||
|
||||
|
|
|
@ -1828,7 +1828,7 @@ def create_disk(kwargs=None, call=None):
|
|||
)
|
||||
return False
|
||||
|
||||
if 'size' is None and 'image' is None and 'snapshot' is None:
|
||||
if size is None and image is None and snapshot is None:
|
||||
log.error(
|
||||
'Must specify image, snapshot, or size.'
|
||||
)
|
||||
|
|
|
@ -1256,9 +1256,9 @@ def edit_team(name,
|
|||
parameters = {}
|
||||
if name is not None:
|
||||
parameters['name'] = name
|
||||
if 'description' is not None:
|
||||
if description is not None:
|
||||
parameters['description'] = description
|
||||
if 'privacy' is not None:
|
||||
if privacy is not None:
|
||||
parameters['privacy'] = privacy
|
||||
if permission is not None:
|
||||
parameters['permission'] = permission
|
||||
|
|
|
@ -163,15 +163,17 @@ def _render_template(config_file):
|
|||
return template.render(__grains__)
|
||||
|
||||
|
||||
def _config(name, conf):
|
||||
def _config(name, conf, default=None):
|
||||
'''
|
||||
Return a value for 'name' from the config file options.
|
||||
Return a value for 'name' from the config file options. If the 'name' is
|
||||
not in the config, the 'default' value is returned. This method converts
|
||||
unicode values to str type under python 2.
|
||||
'''
|
||||
try:
|
||||
value = salt.utils.data.decode(conf[name], to_str=True)
|
||||
value = conf[name]
|
||||
except KeyError:
|
||||
value = None
|
||||
return value
|
||||
value = default
|
||||
return salt.utils.data.decode(value, to_str=True)
|
||||
|
||||
|
||||
def _result_to_dict(data, result, conf, source):
|
||||
|
@ -285,7 +287,7 @@ def _do_search(conf):
|
|||
scope = _config('scope', conf)
|
||||
_lists = _config('lists', conf) or []
|
||||
_attrs = _config('attrs', conf) or []
|
||||
_dict_key_attr = _config('dict_key_attr', conf) or 'dn'
|
||||
_dict_key_attr = _config('dict_key_attr', conf, 'dn')
|
||||
attrs = _lists + _attrs + [_dict_key_attr]
|
||||
if not attrs:
|
||||
attrs = None
|
||||
|
|
|
@ -240,7 +240,7 @@ class Schedule(object):
|
|||
)
|
||||
data['_skip_reason'] = 'maxrunning'
|
||||
data['_skipped'] = True
|
||||
data['_skip_time'] = now
|
||||
data['_skipped_time'] = now
|
||||
data['run'] = False
|
||||
return data
|
||||
return data
|
||||
|
@ -1378,8 +1378,10 @@ class Schedule(object):
|
|||
# Clear these out between runs
|
||||
for item in ['_continue',
|
||||
'_error',
|
||||
'_enabled',
|
||||
'_skipped',
|
||||
'_skip_reason']:
|
||||
'_skip_reason',
|
||||
'_skipped_time']:
|
||||
if item in data:
|
||||
del data[item]
|
||||
run = False
|
||||
|
@ -1600,10 +1602,20 @@ class Schedule(object):
|
|||
if 'enabled' not in data:
|
||||
data['enabled'] = self.enabled
|
||||
|
||||
# If globally disabled, disable the job
|
||||
if not self.enabled:
|
||||
data['enabled'] = self.enabled
|
||||
data['_skip_reason'] = 'disabled'
|
||||
data['_skipped_time'] = now
|
||||
data['_skipped'] = True
|
||||
run = False
|
||||
|
||||
# Job is disabled, set run to False
|
||||
if 'enabled' in data and not data['enabled']:
|
||||
log.debug('Job: %s is disabled', job_name)
|
||||
data['_enabled'] = False
|
||||
data['_skip_reason'] = 'disabled'
|
||||
data['_skipped_time'] = now
|
||||
data['_skipped'] = True
|
||||
run = False
|
||||
|
||||
miss_msg = ''
|
||||
|
|
|
@ -6,6 +6,7 @@ Contains systemd related help files
|
|||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
# Import Salt libs
|
||||
|
@ -65,8 +66,8 @@ def version(context=None):
|
|||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
|
||||
outstr = salt.utils.stringutils.to_str(stdout)
|
||||
try:
|
||||
ret = int(outstr.splitlines()[0].split()[-1])
|
||||
except (IndexError, ValueError):
|
||||
ret = int(re.search(r'\w+ ([0-9]+)', outstr.splitlines()[0]).group(1))
|
||||
except (AttributeError, IndexError, ValueError):
|
||||
log.error(
|
||||
'Unable to determine systemd version from systemctl '
|
||||
'--version, output follows:\n%s', outstr
|
||||
|
|
|
@ -506,6 +506,32 @@ class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertNotIn('_last_run', ret)
|
||||
self.assertEqual(ret['_skip_reason'], 'disabled')
|
||||
|
||||
def test_eval_global_disabled_job_enabled(self):
|
||||
'''
|
||||
verify that scheduled job does not run
|
||||
'''
|
||||
job_name = 'test_eval_global_disabled'
|
||||
job = {
|
||||
'schedule': {
|
||||
'enabled': False,
|
||||
job_name: {
|
||||
'function': 'test.ping',
|
||||
'when': '11/29/2017 4:00pm',
|
||||
'enabled': True,
|
||||
}
|
||||
}
|
||||
}
|
||||
run_time1 = dateutil_parser.parse('11/29/2017 4:00pm')
|
||||
|
||||
# Add the job to the scheduler
|
||||
self.schedule.opts.update(job)
|
||||
|
||||
# Evaluate 1 second at the run time
|
||||
self.schedule.eval(now=run_time1)
|
||||
ret = self.schedule.job_status(job_name)
|
||||
self.assertNotIn('_last_run', ret)
|
||||
self.assertEqual(ret['_skip_reason'], 'disabled')
|
||||
|
||||
def test_eval_run_on_start(self):
|
||||
'''
|
||||
verify that scheduled job is run when minion starts
|
||||
|
|
26
tests/unit/pillar/test_pillar_ldap.py
Normal file
26
tests/unit/pillar/test_pillar_ldap.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
from tests.support.unit import TestCase
|
||||
import salt.utils.stringutils
|
||||
|
||||
|
||||
from salt.pillar.pillar_ldap import _config
|
||||
|
||||
|
||||
class LdapPillarTestCase(TestCase):
|
||||
|
||||
def test__config_returns_str(self):
|
||||
conf = {'foo': 'bar'}
|
||||
assert _config('foo', conf) == salt.utils.stringutils.to_str('bar')
|
||||
|
||||
def test__conf_defaults_to_none(self):
|
||||
conf = {'foo': 'bar'}
|
||||
assert _config('bang', conf) is None
|
||||
|
||||
def test__conf_returns_str_from_unicode_default(self):
|
||||
conf = {'foo': 'bar'}
|
||||
default = salt.utils.stringutils.to_unicode('bam')
|
||||
assert _config('bang', conf, default) == salt.utils.stringutils.to_str('bam')
|
|
@ -100,6 +100,27 @@ class SystemdTestCase(TestCase):
|
|||
self.assertTrue(_systemd.version(context))
|
||||
self.assertEqual(context, {'salt.utils.systemd.version': _version})
|
||||
|
||||
def test_version_generated_from_git_describe(self):
|
||||
'''
|
||||
Test with version string matching versions generated by git describe
|
||||
in systemd. This feature is used in systemd>=241.
|
||||
'''
|
||||
with patch('subprocess.Popen') as popen_mock:
|
||||
_version = 241
|
||||
output = 'systemd {0} ({0}.0-0-dist)\n-SYSVINIT'.format(_version)
|
||||
popen_mock.return_value = Mock(
|
||||
communicate=lambda *args, **kwargs: (output, None),
|
||||
pid=lambda: 12345,
|
||||
retcode=0
|
||||
)
|
||||
|
||||
# Test without context dict passed
|
||||
self.assertEqual(_systemd.version(), _version)
|
||||
# Test that context key is set when context dict is passed
|
||||
context = {}
|
||||
self.assertTrue(_systemd.version(context))
|
||||
self.assertEqual(context, {'salt.utils.systemd.version': _version})
|
||||
|
||||
def test_version_return_from_context(self):
|
||||
'''
|
||||
Test that the context data is returned when present. To ensure we're
|
||||
|
|
Loading…
Add table
Reference in a new issue