mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2015.8' into '2016.3'
Conflicts: - doc/conf.py - tests/runtests.py
This commit is contained in:
commit
c305d8d99b
5 changed files with 196 additions and 32 deletions
|
@ -12,6 +12,7 @@ from __future__ import absolute_import
|
|||
# Import 3rd-party libs
|
||||
# pylint: disable=import-error,no-name-in-module,redefined-builtin
|
||||
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin
|
||||
import salt.ext.six
|
||||
import salt.ext.six.moves.http_client
|
||||
# pylint: enable=import-error,no-name-in-module
|
||||
|
||||
|
@ -973,48 +974,62 @@ def agent_service_register(consul_url=None, **kwargs):
|
|||
ret['res'] = False
|
||||
return ret
|
||||
|
||||
if 'name' in kwargs:
|
||||
data['Name'] = kwargs['name']
|
||||
lc_kwargs = dict()
|
||||
for k, v in salt.ext.six.iteritems(kwargs):
|
||||
lc_kwargs[k.lower()] = v
|
||||
|
||||
if 'name' in lc_kwargs:
|
||||
data['Name'] = lc_kwargs['name']
|
||||
else:
|
||||
raise SaltInvocationError('Required argument "name" is missing.')
|
||||
|
||||
if 'address' in kwargs:
|
||||
data['Address'] = kwargs['address']
|
||||
if 'address' in lc_kwargs:
|
||||
data['Address'] = lc_kwargs['address']
|
||||
|
||||
if 'port' in kwargs:
|
||||
data['Port'] = kwargs['port']
|
||||
if 'port' in lc_kwargs:
|
||||
data['Port'] = lc_kwargs['port']
|
||||
|
||||
if 'id' in kwargs:
|
||||
data['ID'] = kwargs['id']
|
||||
if 'id' in lc_kwargs:
|
||||
data['ID'] = lc_kwargs['id']
|
||||
|
||||
if 'tags' in kwargs:
|
||||
_tags = kwargs['tags']
|
||||
if 'tags' in lc_kwargs:
|
||||
_tags = lc_kwargs['tags']
|
||||
if not isinstance(_tags, list):
|
||||
_tags = [_tags]
|
||||
data['Tags'] = _tags
|
||||
|
||||
check_elements = ('check_script', 'check_http', 'check_ttl')
|
||||
if True in [True for item in check_elements if item in kwargs]:
|
||||
data['Check'] = {}
|
||||
if 'enabletagoverride' in lc_kwargs:
|
||||
data['EnableTagOverride'] = lc_kwargs['enabletagoverride']
|
||||
|
||||
if 'check_script' in kwargs:
|
||||
if 'interval' not in kwargs:
|
||||
if 'check' in lc_kwargs:
|
||||
dd = dict()
|
||||
for k, v in salt.ext.six.iteritems(lc_kwargs['check']):
|
||||
dd[k.lower()] = v
|
||||
interval_required = False
|
||||
check_dd = dict()
|
||||
|
||||
if 'script' in dd:
|
||||
interval_required = True
|
||||
check_dd['Script'] = dd['script']
|
||||
if 'http' in dd:
|
||||
interval_required = True
|
||||
check_dd['HTTP'] = dd['http']
|
||||
if 'ttl' in dd:
|
||||
check_dd['TTL'] = dd['ttl']
|
||||
if 'interval' in dd:
|
||||
check_dd['Interval'] = dd['interval']
|
||||
|
||||
if interval_required:
|
||||
if 'Interval' not in check_dd:
|
||||
ret['message'] = 'Required parameter "interval" is missing.'
|
||||
ret['res'] = False
|
||||
return ret
|
||||
data['Check']['Script'] = kwargs['check_script']
|
||||
data['Check']['Interval'] = kwargs['check_interval']
|
||||
else:
|
||||
if 'Interval' in check_dd:
|
||||
del check_dd['Interval'] # not required, so ignore it
|
||||
|
||||
if 'check_ttl' in kwargs:
|
||||
data['Check']['TTL'] = kwargs['check_ttl']
|
||||
|
||||
if 'check_http' in kwargs:
|
||||
if 'interval' not in kwargs:
|
||||
ret['message'] = 'Required parameter "interval" is missing.'
|
||||
ret['res'] = False
|
||||
return ret
|
||||
data['Check']['HTTP'] = kwargs['check_http']
|
||||
data['Check']['Interval'] = kwargs['check_interval']
|
||||
if len(check_dd) > 0:
|
||||
data['Check'] = check_dd # if empty, ignore it
|
||||
|
||||
function = 'agent/service/register'
|
||||
res = _query(consul_url=consul_url,
|
||||
|
|
|
@ -1391,7 +1391,7 @@ def diff(cwd,
|
|||
cached=False,
|
||||
paths=None):
|
||||
'''
|
||||
.. versionadded:: 2015.8.12,2016.3.3
|
||||
.. versionadded:: 2015.8.12,2016.3.3,Carbon
|
||||
|
||||
Interface to `git-diff(1)`_
|
||||
|
||||
|
|
1
tests/integration/returners/__init__.py
Normal file
1
tests/integration/returners/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
129
tests/integration/returners/local_cache.py
Normal file
129
tests/integration/returners/local_cache.py
Normal file
|
@ -0,0 +1,129 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Tests for the local_cache returner
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import os
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import salt libs
|
||||
import integration
|
||||
from integration import TMP
|
||||
import salt.utils.job
|
||||
from salt.returners import local_cache
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# JOBS DIR and FILES
|
||||
TMP_CACHE_DIR = os.path.join(TMP, 'master-minion-root', 'cache')
|
||||
JOBS_DIR = os.path.join(TMP_CACHE_DIR, 'jobs')
|
||||
JID_DIR = os.path.join(JOBS_DIR, 'b1', '4dac7bc743c928d7fac908823af1ab')
|
||||
JID_FILE = os.path.join(JID_DIR, 'jid')
|
||||
JID_MINION_DIR = os.path.join(JID_DIR, 'minion', 'return.p')
|
||||
JOB_CACHE_DIR_FILES = [JID_FILE, JID_MINION_DIR]
|
||||
KEEP_JOBS = 0.0000000010
|
||||
EMPTY_JID_DIR = []
|
||||
|
||||
local_cache.__opts__ = {'cachedir': TMP_CACHE_DIR,
|
||||
'keep_jobs': KEEP_JOBS}
|
||||
|
||||
|
||||
class Local_CacheTest(integration.ShellCase):
|
||||
'''
|
||||
Test the local cache returner
|
||||
'''
|
||||
def _check_dir_files(self, msg, contents, status='None'):
|
||||
'''
|
||||
helper method to ensure files or dirs
|
||||
are either present or removed
|
||||
'''
|
||||
for content in contents:
|
||||
log.debug('CONTENT {0}'.format(content))
|
||||
if status == 'present':
|
||||
check_job_dir = os.path.exists(content)
|
||||
elif status == 'removed':
|
||||
if os.path.exists(content):
|
||||
check_job_dir = False
|
||||
else:
|
||||
check_job_dir = True
|
||||
self.assertTrue(check_job_dir,
|
||||
msg=msg + content)
|
||||
|
||||
def _add_job(self):
|
||||
'''
|
||||
helper method to add job.
|
||||
'''
|
||||
# add the job.
|
||||
opts = {}
|
||||
opts.update(self.get_config('master'))
|
||||
load = {'fun_args': [], 'jid': '20160603132323715452',
|
||||
'return': True, 'retcode': 0, 'success': True,
|
||||
'cmd': '_return', 'fun': 'test.ping', 'id': 'minion'}
|
||||
|
||||
add_job = salt.utils.job.store_job(opts, load)
|
||||
self.assertEqual(add_job, None)
|
||||
self._check_dir_files('Dir/file does not exist: ',
|
||||
JOB_CACHE_DIR_FILES,
|
||||
status='present')
|
||||
|
||||
def test_clean_old_jobs(self):
|
||||
'''
|
||||
test to ensure jobs are removed from job cache
|
||||
'''
|
||||
self._add_job()
|
||||
|
||||
# remove job
|
||||
self.assertEqual(local_cache.clean_old_jobs(), None)
|
||||
|
||||
self._check_dir_files('job cache was not removed: ',
|
||||
JOB_CACHE_DIR_FILES,
|
||||
status='removed')
|
||||
|
||||
def test_not_clean_new_jobs(self):
|
||||
'''
|
||||
test to ensure jobs are not removed when
|
||||
jobs dir is new
|
||||
'''
|
||||
self._add_job()
|
||||
|
||||
local_cache.__opts__['keep_jobs'] = 24
|
||||
self.assertEqual(local_cache.clean_old_jobs(), None)
|
||||
|
||||
self._check_dir_files('job cache was removed: ',
|
||||
JOB_CACHE_DIR_FILES,
|
||||
status='present')
|
||||
|
||||
# need to set back to initial KEEP_JOBS
|
||||
local_cache.__opts__['keep_jobs'] = KEEP_JOBS
|
||||
|
||||
def test_empty_jid_dir(self):
|
||||
'''
|
||||
test to ensure removal of empty jid dir
|
||||
'''
|
||||
# add empty jid dir
|
||||
new_jid_dir = os.path.join(JOBS_DIR, 'z0')
|
||||
EMPTY_JID_DIR.append(new_jid_dir)
|
||||
os.makedirs(new_jid_dir)
|
||||
|
||||
# check dir exists
|
||||
self._check_dir_files('new_jid_dir was not created',
|
||||
EMPTY_JID_DIR,
|
||||
status='present')
|
||||
|
||||
# remove job
|
||||
self.assertEqual(local_cache.clean_old_jobs(), None)
|
||||
|
||||
# check jid dir is removed
|
||||
self._check_dir_files('new_jid_dir was not removed',
|
||||
EMPTY_JID_DIR,
|
||||
status='removed')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(Local_CacheTest)
|
|
@ -155,6 +155,13 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
action='store_true',
|
||||
help='Run tests for minion'
|
||||
)
|
||||
self.test_selection_group.add_option(
|
||||
'--returners',
|
||||
dest='returners',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Run salt/returners/*.py tests'
|
||||
)
|
||||
self.test_selection_group.add_option(
|
||||
'-l',
|
||||
'--loader',
|
||||
|
@ -239,6 +246,7 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
self.options.state,
|
||||
self.options.runners,
|
||||
self.options.renderers,
|
||||
self.options.returners,
|
||||
self.options.loader,
|
||||
self.options.name,
|
||||
self.options.outputter,
|
||||
|
@ -261,8 +269,12 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
self.options.state, self.options.runners,
|
||||
self.options.loader, self.options.name,
|
||||
self.options.outputter, self.options.cloud_provider_tests,
|
||||
self.options.fileserver, self.options.wheel, self.options.api,
|
||||
self.options.minion, self.options.renderers)):
|
||||
self.options.fileserver,
|
||||
self.options.wheel,
|
||||
self.options.api,
|
||||
self.options.minion,
|
||||
self.options.returners,
|
||||
self.options.renderers)):
|
||||
self.options.module = True
|
||||
self.options.cli = True
|
||||
self.options.client = True
|
||||
|
@ -271,6 +283,7 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
self.options.unit = True
|
||||
self.options.runners = True
|
||||
self.options.renderers = True
|
||||
self.options.returners = True
|
||||
self.options.state = True
|
||||
self.options.loader = True
|
||||
self.options.outputter = True
|
||||
|
@ -410,6 +423,7 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
if (self.options.unit or named_unit_test) and not \
|
||||
(self.options.runners or
|
||||
self.options.renderers or
|
||||
self.options.returners or
|
||||
self.options.state or
|
||||
self.options.module or
|
||||
self.options.cli or
|
||||
|
@ -445,8 +459,11 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
self.options.shell, self.options.state,
|
||||
self.options.loader, self.options.outputter,
|
||||
self.options.name, self.options.cloud_provider_tests,
|
||||
self.options.api, self.options.renderers,
|
||||
self.options.fileserver, self.options.wheel,
|
||||
self.options.api,
|
||||
self.options.renderers,
|
||||
self.options.returners,
|
||||
self.options.fileserver,
|
||||
self.options.wheel,
|
||||
self.options.minion]):
|
||||
return status
|
||||
|
||||
|
@ -484,6 +501,8 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
status.append(self.run_integration_suite('cloud/providers', 'Cloud Provider'))
|
||||
if self.options.api:
|
||||
status.append(self.run_integration_suite('netapi', 'NetAPI'))
|
||||
if self.options.returners:
|
||||
status.append(self.run_integration_suite('returners', 'Returners'))
|
||||
if self.options.renderers:
|
||||
status.append(self.run_integration_suite('renderers', 'Renderers'))
|
||||
if self.options.minion:
|
||||
|
|
Loading…
Add table
Reference in a new issue