- more py3k fixes

This commit is contained in:
L.C. Rees 2012-06-04 16:40:34 -06:00
parent 46041df022
commit cc8a921311
6 changed files with 154 additions and 106 deletions

View file

@ -79,8 +79,8 @@ on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
# -- General configuration -----------------------------------------------------
project = u'Salt'
copyright = u'2012, Thomas S. Hatch'
project = 'Salt'
copyright = '2012, Thomas S. Hatch'
version = __version__
release = version
@ -152,8 +152,7 @@ html_show_copyright = True
### Latex options
latex_documents = [
('contents', 'Salt.tex', u'Salt Documentation',
u'Thomas Hatch', 'manual'),
('contents', 'Salt.tex', 'Salt Documentation', 'Thomas Hatch', 'manual'),
]
latex_logo = '_static/salt-vert.png'
@ -163,27 +162,27 @@ latex_logo = '_static/salt-vert.png'
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
authors = [
u'Thomas S. Hatch <thatch@gmail.com> and many others, please see the Authors file',
'Thomas S. Hatch <thatch@gmail.com> and many others, please see the Authors file',
]
man_pages = [
('ref/cli/salt', 'salt', u'salt', authors, 1),
('contents', 'salt', u'Salt Documentation', authors, 7),
('ref/cli/salt-master', 'salt-master', u'salt-master Documentation', authors, 1),
('ref/cli/salt-minion', 'salt-minion', u'salt-minion Documentation', authors, 1),
('ref/cli/salt-key', 'salt-key', u'salt-key Documentation', authors, 1),
('ref/cli/salt-cp', 'salt-cp', u'salt-cp Documentation', authors, 1),
('ref/cli/salt-call', 'salt-call', u'salt-call Documentation', authors, 1),
('ref/cli/salt-syndic', 'salt-syndic', u'salt-syndic Documentation', authors, 1),
('ref/cli/salt-run', 'salt-run', u'salt-run Documentation', authors, 1),
('ref/cli/salt', 'salt', 'salt', authors, 1),
('contents', 'salt', 'Salt Documentation', authors, 7),
('ref/cli/salt-master', 'salt-master', 'salt-master Documentation', authors, 1),
('ref/cli/salt-minion', 'salt-minion', 'salt-minion Documentation', authors, 1),
('ref/cli/salt-key', 'salt-key', 'salt-key Documentation', authors, 1),
('ref/cli/salt-cp', 'salt-cp', 'salt-cp Documentation', authors, 1),
('ref/cli/salt-call', 'salt-call', 'salt-call Documentation', authors, 1),
('ref/cli/salt-syndic', 'salt-syndic', 'salt-syndic Documentation', authors, 1),
('ref/cli/salt-run', 'salt-run', 'salt-run Documentation', authors, 1),
]
### epub options
epub_title = u'Salt Documentation'
epub_author = u'Thomas S. Hatch'
epub_title = 'Salt Documentation'
epub_author = 'Thomas S. Hatch'
epub_publisher = epub_author
epub_copyright = u'2012, Thomas S. Hatch'
epub_copyright = '2012, Thomas S. Hatch'
epub_scheme = 'URL'
epub_identifier = 'http://saltstack.org/'

View file

@ -72,16 +72,17 @@ from salt._compat import string_types, url_open
__opts__ = {'solr.cores': [],
'solr.host': 'localhost',
'solr.port': '8983',
'solr.baseurl':'/solr',
'solr.type':'master',
'solr.baseurl': '/solr',
'solr.type': 'master',
'solr.request_timeout': None,
'solr.init_script': '/etc/rc.d/solr',
'solr.dih.import_options': {'clean':False, 'optimize':True,
'commit':True, 'verbose':False},
'solr.dih.import_options': {'clean': False, 'optimize': True,
'commit': True, 'verbose': False},
'solr.backup_path': None,
'solr.num_backups':1
'solr.num_backups': 1
}
########################## PRIVATE METHODS ##############################
def __virtual__():
@ -97,6 +98,7 @@ def __virtual__():
return 'solr'
return False
def _get_none_or_value(value):
'''
PRIVATE METHOD
@ -122,6 +124,7 @@ def _get_none_or_value(value):
else:
return None
def _check_for_cores():
'''
PRIVATE METHOD
@ -134,7 +137,8 @@ def _check_for_cores():
'''
return len(__opts__['solr.cores']) > 0
def _get_return_dict(success=True, data={}, errors=[], warnings=[]):
def _get_return_dict(success=True, data=None, errors=None, warnings=None):
'''
PRIVATE METHOD
Creates a new return dict with default values. Defaults may be overwritten.
@ -152,14 +156,18 @@ def _get_return_dict(success=True, data={}, errors=[], warnings=[]):
{'success':boolean, 'data':dict, 'errors':list, 'warnings':list}
'''
ret = {'success':success,
'data':data,
'errors':errors,
'warnings':warnings}
data = {} if data is None else data
errors = [] if errors is None else errors
warnings = [] if warnings is None else warnings
ret = {'success': success,
'data': data,
'errors': errors,
'warnings': warnings}
return ret
def _update_return_dict(ret, success, data, errors=[], warnings=[]):
def _update_return_dict(ret, success, data, errors=None, warnings=None):
'''
PRIVATE METHOD
Updates the return dictionary and returns it.
@ -180,6 +188,8 @@ def _update_return_dict(ret, success, data, errors=[], warnings=[]):
{'success':boolean, 'data':dict, 'errors':list, 'warnings':list}
'''
errors = [] if errors is None else errors
warnings = [] if warnings is None else warnings
ret['success'] = success
ret['data'].update(data)
ret['errors'] = ret['errors'] + errors
@ -187,7 +197,7 @@ def _update_return_dict(ret, success, data, errors=[], warnings=[]):
return ret
def _format_url(handler, host=None, core_name=None, extra=[]):
def _format_url(handler, host=None, core_name=None, extra=None):
'''
PRIVATE METHOD
Formats the url based on parameters, and if cores are used or not
@ -204,8 +214,9 @@ def _format_url(handler, host=None, core_name=None, extra=[]):
Return: str::
A fullly formatted url (http://<host>:<port>/solr/<handler>?wt=json&<extra>
Fully formatted url (http://<host>:<port>/solr/<handler>?wt=json&<extra>
'''
extra = [] if extra is None else extra
if _get_none_or_value(host) is None or host == 'None':
host = __opts__['solr.host']
port = __opts__['solr.port']
@ -216,14 +227,15 @@ def _format_url(handler, host=None, core_name=None, extra=[]):
host, port, baseurl, handler)
else:
return "http://{0}:{1}{2}/{3}?wt=json&{4}".format(
host, port, baseurl, handler,"&".join(extra))
host, port, baseurl, handler, "&".join(extra))
else:
if extra is None or len(extra) == 0:
return "http://{0}:{1}{2}/{3}/{4}?wt=json".format(
host,port,baseurl,core_name,handler)
host, port, baseurl, core_name, handler)
else:
return "http://{0}:{1}{2}/{3}/{4}?wt=json&{5}".format(
host,port,baseurl,core_name,handler,"&".join(extra))
host, port, baseurl, core_name, handler, "&".join(extra))
def _http_request(url, request_timeout=None):
'''
@ -233,8 +245,8 @@ def _http_request(url, request_timeout=None):
url : str
a complete url that can be passed to urllib.open
request_timeout : int (None)
The number of seconds before the timeout should fail. Leave blank/None to
use the default. __opts__['solr.request_timeout']
The number of seconds before the timeout should fail. Leave blank/None
to use the default. __opts__['solr.request_timeout']
Return: dict<str,obj>::
@ -252,7 +264,7 @@ def _http_request(url, request_timeout=None):
return _get_return_dict(False, {}, ["{0} : {1}".format(url, e)])
def _replication_request(command, host=None, core_name=None, params=[]):
def _replication_request(command, host=None, core_name=None, params=None):
'''
PRIVATE METHOD
Performs the requested replication command and returns a dictionary with
@ -274,11 +286,13 @@ def _replication_request(command, host=None, core_name=None, params=[]):
{'success':boolean, 'data':dict, 'errors':list, 'warnings':list}
'''
params = [] if params is None else params
extra = ["command={0}".format(command)] + params
url = _format_url('replication', host=host, core_name=core_name,
extra=extra)
return _http_request(url)
def _get_admin_info(command, host=None, core_name=None):
'''
PRIVATE METHOD
@ -300,9 +314,10 @@ def _get_admin_info(command, host=None, core_name=None):
{'success':boolean, 'data':dict, 'errors':list, 'warnings':list}
'''
url = _format_url("admin/{0}".format(command), host, core_name=core_name)
resp = _http_request(url)
resp = _http_request(url)
return resp
def _is_master():
'''
PRIVATE METHOD
@ -313,6 +328,7 @@ def _is_master():
'''
return __opts__['solr.type'] == 'master'
def _merge_options(options):
'''
PRIVATE METHOD
@ -331,11 +347,12 @@ def _merge_options(options):
defaults = __opts__['solr.dih.import_options']
if isinstance(options, dict):
defaults.update(options)
for (k, v) in defaults.items():
for k, v in defaults.items():
if isinstance(v, bool):
defaults[k] = str(v).lower()
return defaults
def _pre_index_check(handler, host=None, core_name=None):
'''
PRIVATE METHOD - MASTER CALL
@ -357,7 +374,8 @@ def _pre_index_check(handler, host=None, core_name=None):
'''
#make sure that it's a master minion
if _get_none_or_value(host) is None and not _is_master():
err = ['solr.pre_indexing_check can only be called by "master" minions']
err = [
'solr.pre_indexing_check can only be called by "master" minions']
return _get_return_dict(False, err)
'''
solr can run out of memory quickly if the dih is processing multiple
@ -383,14 +401,15 @@ def _pre_index_check(handler, host=None, core_name=None):
return resp
def _find_value(ret_dict, key, path=None):
'''
PRIVATE METHOD
Traverses a dictionary of dictionaries/lists to find key
and return the value stored.
TODO:// this method doesn't really work very well, and it's not really very
useful in it's current state. The purpose for this method is to
simplify parsing the json output so you can just pass the key
TODO:// this method doesn't really work very well, and it's not really
very useful in it's current state. The purpose for this method is
to simplify parsing the json output so you can just pass the key
you want to find and have it return the value.
ret : dict<str,obj>
The dictionary to search through. Typically this will be a dict
@ -408,9 +427,9 @@ def _find_value(ret_dict, key, path=None):
path = "{0}:{1}".format(path, key)
ret = []
for (k, v) in ret_dict.items():
for k, v in ret_dict.items():
if k == key:
ret.append({path:v})
ret.append({path: v})
if isinstance(v, list):
for x in v:
if isinstance(x, dict):
@ -419,6 +438,7 @@ def _find_value(ret_dict, key, path=None):
ret = ret + _find_value(v, key, path)
return ret
########################## PUBLIC METHODS ##############################
def lucene_version(core_name=None):
@ -444,12 +464,12 @@ def lucene_version(core_name=None):
if _get_none_or_value(core_name) is None and _check_for_cores():
success = True
for name in __opts__['solr.cores']:
resp = _get_admin_info('system', core_name=name )
resp = _get_admin_info('system', core_name=name)
if resp['success']:
version = resp['data']['lucene']['lucene-spec-version']
data = {name: {'lucene_version':version}}
else:#generally this means that an exception happened.
data = {name:{'lucene_version':None}}
data = {name: {'lucene_version': version}}
else: # generally this means that an exception happened.
data = {name: {'lucene_version': None}}
success = False
ret = _update_return_dict(ret, success, data, resp['errors'])
return ret
@ -457,10 +477,11 @@ def lucene_version(core_name=None):
resp = _get_admin_info('system', core_name=core_name)
if resp['success']:
version = resp['data']['lucene']['lucene-spec-version']
return _get_return_dict(True, {'version':version}, resp['errors'])
return _get_return_dict(True, {'version': version}, resp['errors'])
else:
return resp
def version(core_name=None):
'''
Gets the solr version for the core specified. You should specify a core
@ -484,13 +505,13 @@ def version(core_name=None):
if _get_none_or_value(core_name) is None and _check_for_cores():
success = True
for name in __opts__['solr.cores']:
resp = _get_admin_info('system', core_name=name )
resp = _get_admin_info('system', core_name=name)
if resp['success']:
lucene = resp['data']['lucene']
data = {name:{'version':lucene['solr-spec-version']}}
data = {name: {'version': lucene['solr-spec-version']}}
else:
success = False
data = {name:{'version':None}}
data = {name: {'version': None}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
return ret
@ -498,11 +519,12 @@ def version(core_name=None):
resp = _get_admin_info('system', core_name=core_name)
if resp['success']:
version = resp['data']['lucene']['solr-spec-version']
return _get_return_dict(True, {'version':version},
return _get_return_dict(True, {'version': version},
resp['errors'], resp['warnings'])
else:
return resp
def optimize(host=None, core_name=None):
'''
Search queries fast, but it is a very expensive operation. The ideal
@ -537,13 +559,13 @@ def optimize(host=None, core_name=None):
extra=["optimize=true"])
resp = _http_request(url)
if resp['success']:
data = {name : {'data':resp['data']}}
ret = _update_return_dict(ret, success, data,
data = {name: {'data': resp['data']}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
else:
success = False
data = {name : {'data':resp['data']}}
ret = _update_return_dict(ret, success, data,
data = {name: {'data': resp['data']}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
return ret
else:
@ -551,6 +573,7 @@ def optimize(host=None, core_name=None):
extra=["optimize=true"])
return _http_request(url)
def ping(host=None, core_name=None):
'''
Does a health check on solr, makes sure solr can talk to the indexes.
@ -575,16 +598,17 @@ def ping(host=None, core_name=None):
for name in __opts__['solr.cores']:
resp = _get_admin_info('ping', host=host, core_name=name)
if resp['success']:
data = {name:{'status':resp['data']['status']}}
data = {name: {'status': resp['data']['status']}}
else:
success = False
data = {name:{'status':None}}
data = {name: {'status': None}}
ret = _update_return_dict(ret, success, data, resp['errors'])
return ret
else:
resp = _get_admin_info('ping', host=host, core_name=core_name)
return resp
def is_replication_enabled(host=None, core_name=None):
'''
SLAVE CALL
@ -609,14 +633,15 @@ def is_replication_enabled(host=None, core_name=None):
# since only slaves can call this let's check the config:
if self._is_master() and is_none(host) is None:
errors = ['Only "slave" minions can run "is_replication_enabled"']
return ret.update({'success':False, 'errors':errors})
return ret.update({'success': False, 'errors': errors})
#define a convenience method so we don't duplicate code
def _checks(ret, success, resp, core):
if response['success']:
slave = resp['data']['details']['slave']
# we need to initialize this to false in case there is an error
# on the master and we can't get this info.
replication_enabled = 'false'
replication_enabled = 'false'
master_url = slave['masterUrl']
#check for errors on the slave
if 'ERROR' in slave:
@ -624,9 +649,10 @@ def is_replication_enabled(host=None, core_name=None):
err = "{0}: {1} - {2}".format(name, slave['ERROR'], master_url)
resp['errors'].append(err)
#if there is an error return everything
data = slave if core is None else {core : {'data':slave}}
data = slave if core is None else {core: {'data': slave}}
else:
enabled = slave['masterDetails']['master']['replicationEnabled']
enabled = slave['masterDetails']['master'][
'replicationEnabled']
'''
if replication is turned off on the master, or polling is
disabled we need to return false. These may not not errors,
@ -656,6 +682,7 @@ def is_replication_enabled(host=None, core_name=None):
return ret
def match_index_versions(host=None, core_name=None):
'''
SLAVE CALL
@ -684,8 +711,8 @@ def match_index_versions(host=None, core_name=None):
success = True
if _is_master() and _get_none_or_value(host) is None:
e = ['solr.match_index_versions can only be called by "slave" minions']
return ret.update({'success':False, 'errors':e})
#get the default return dict
return ret.update({'success': False, 'errors': e})
# get the default return dict
def _match(ret, success, resp, core):
if response['success']:
@ -698,21 +725,24 @@ def match_index_versions(host=None, core_name=None):
resp['errors'].append(err)
#if there was an error return the entire response so the
#alterer can get what it wants
data = slave if core is None else {core : {'data': slave}}
data = slave if core is None else {core: {'data': slave}}
else:
versions = {'master':slave['masterDetails']['master']['replicatableIndexVersion'],
'slave' : resp['data']['details']['indexVersion'],
'next_replication' : slave['nextExecutionAt'],
'failed_list': []
}
versions = {
'master': slave['masterDetails']['master'][
'replicatableIndexVersion'],
'slave': resp['data']['details']['indexVersion'],
'next_replication': slave['nextExecutionAt'],
'failed_list': []
}
if 'replicationFailedAtList' in slave:
versions.update({'failed_list' : slave['replicationFailedAtList']})
versions.update({'failed_list': slave[
'replicationFailedAtList']})
#check the index versions
if versions['master'] != versions['slave']:
success = False
err = "Master and Slave index versions do not match."
resp['errors'].append(err)
data = versions if core is None else {core:{'data':versions}}
data = versions if core is None else {core: {'data': versions}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
else:
@ -732,10 +762,11 @@ def match_index_versions(host=None, core_name=None):
else:
response = _replication_request('details', host=host,
core_name=core_name)
ret, success = _match(ret , success, response, core_name)
ret, success = _match(ret, success, response, core_name)
return ret
def replication_details(host=None, core_name=None):
'''
Get the full replication details.
@ -759,18 +790,19 @@ def replication_details(host=None, core_name=None):
success = True
for name in __opts__['solr.cores']:
resp = _replication_request('details', host=host, core_name=name)
data = {name : {'data':resp['data']}}
data = {name: {'data': resp['data']}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
else:
resp = _replication_request('details', host=host, core_name=core_name)
if resp['success']:
ret = _update_return_dict(ret, success, resp['data'],
ret = _update_return_dict(ret, success, resp['data'],
resp['errors'], resp['warnings'])
else:
return resp
return ret
def backup(host=None, core_name=None, append_core_to_path=False):
'''
Tell solr make a backup. This method can be mis-leading since it uses the
@ -814,7 +846,7 @@ def backup(host=None, core_name=None, append_core_to_path=False):
params=params)
if not resp['success']:
success = False
data = {name : {'data': resp['data']}}
data = {name: {'data': resp['data']}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
return ret
@ -829,6 +861,7 @@ def backup(host=None, core_name=None, append_core_to_path=False):
params=params)
return resp
def set_is_polling(polling, host=None, core_name=None):
'''
SLAVE CALL
@ -855,7 +888,7 @@ def set_is_polling(polling, host=None, core_name=None):
# since only slaves can call this let's check the config:
if _is_master() and _get_none_or_value(host) is None:
err = ['solr.set_is_polling can only be called by "slave" minions']
return ret.update({'success':False, 'errors':err})
return ret.update({'success': False, 'errors': err})
cmd = "enablepoll" if polling else "disapblepoll"
if _get_none_or_value(core_name) is None and _check_for_cores():
@ -864,7 +897,7 @@ def set_is_polling(polling, host=None, core_name=None):
resp = set_is_polling(cmd, host=host, core_name=name)
if not resp['success']:
success = False
data = {name : {'data' : resp['data']}}
data = {name: {'data': resp['data']}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
return ret
@ -872,6 +905,7 @@ def set_is_polling(polling, host=None, core_name=None):
resp = _replication_request(cmd, host=host, core_name=name)
return resp
def set_replication_enabled(status, host=None, core_name=None):
'''
MASTER ONLY
@ -907,7 +941,7 @@ def set_replication_enabled(status, host=None, core_name=None):
resp = set_replication_enabled(status, host, name)
if not resp['success']:
success = False
data = {name : {'data' : resp['data']}}
data = {name: {'data': resp['data']}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
return ret
@ -917,6 +951,7 @@ def set_replication_enabled(status, host=None, core_name=None):
else:
return _replication_request(cmd, host=host, core_name=core_name)
def signal(signal=None):
'''
Signals Apache Solr to start, stop, or restart. Obviously this is only
@ -939,11 +974,13 @@ def signal(signal=None):
# TODO: Fix this logic to be reusable and used by apache.signal
if signal not in valid_signals:
msg = valid_signals[:-1] + ('or {0}'.format(valid_signals[-1]),)
return '{0} is an invalid signal. Try: one of: {1}'.format(signal, ', '.join(msg))
return '{0} is an invalid signal. Try: one of: {1}'.format(
signal, ', '.join(msg))
cmd = "{0} {1}".format(__opts__['solr.init_script'], signal)
out = __salt__['cmd.run'](cmd)
def reload_core(host=None, core_name=None):
'''
MULTI-CORE HOSTS ONLY
@ -970,7 +1007,7 @@ def reload_core(host=None, core_name=None):
ret = _get_return_dict()
if not _check_for_cores():
err = ['solr.reload_core can only be called by "multi-core" minions']
return ret.update({'success':False, 'errors':err})
return ret.update({'success': False, 'errors': err})
if _get_none_or_value(core_name) is None and _check_for_cores():
success = True
@ -978,7 +1015,7 @@ def reload_core(host=None, core_name=None):
resp = reload_core(host, name)
if not resp['success']:
success = False
data = {name : {'data' : resp['data']}}
data = {name: {'data': resp['data']}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
return ret
@ -986,6 +1023,7 @@ def reload_core(host=None, core_name=None):
url = _format_url('admin/cores', host=host, core_name=None, extra=extra)
return _http_request(url)
def core_status(host=None, core_name=None):
'''
MULTI-CORE HOSTS ONLY
@ -1007,7 +1045,7 @@ def core_status(host=None, core_name=None):
ret = _get_return_dict()
if not _check_for_cores():
err = ['solr.reload_core can only be called by "multi-core" minions']
return ret.update({'success':False, 'errors':err})
return ret.update({'success': False, 'errors': err})
if _get_none_or_value(core_name) is None and _check_for_cores():
success = True
@ -1015,7 +1053,7 @@ def core_status(host=None, core_name=None):
resp = reload_core(host, name)
if not resp['success']:
success = False
data = {name : {'data' : resp['data']}}
data = {name: {'data': resp['data']}}
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
return ret
@ -1023,6 +1061,7 @@ def core_status(host=None, core_name=None):
url = _format_url('admin/cores', host=host, core_name=None, extra=extra)
return _http_request(url)
################### DIH (Direct Import Handler) COMMANDS #####################
def reload_import_config(handler, host=None, core_name=None, verbose=False):
@ -1051,7 +1090,8 @@ def reload_import_config(handler, host=None, core_name=None, verbose=False):
#make sure that it's a master minion
if not _is_master() and _get_none_or_value(host) is None:
err = ['solr.pre_indexing_check can only be called by "master" minions']
err = [
'solr.pre_indexing_check can only be called by "master" minions']
return _get_return_dict(False, err)
if _get_none_or_value(core_name) is None and _check_for_cores():
@ -1064,6 +1104,7 @@ def reload_import_config(handler, host=None, core_name=None, verbose=False):
url = _format_url(handler, host=host, core_name=core_name, extra=params)
return _http_request(url)
def abort_import(handler, host=None, core_name=None, verbose=False):
'''
MASTER ONLY
@ -1102,7 +1143,8 @@ def abort_import(handler, host=None, core_name=None, verbose=False):
url = _format_url(handler, host=host, core_name=core_name, extra=params)
return _http_request(url)
def full_import(handler, host=None, core_name=None, options={}, extra=[]):
def full_import(handler, host=None, core_name=None, options=None, extra=None):
'''
MASTER ONLY
Submits an import command to the specified handler using specified options.
@ -1130,6 +1172,8 @@ def full_import(handler, host=None, core_name=None, options={}, extra=[]):
salt '*' solr.full_import dataimport None music {'clean':True}
'''
options = {} if options is None else options
extra = [] if extra is None else extra
if not _is_master():
err = ['solr.full_import can only be called on "master" minions']
return _get_return_dict(False, errors=err)
@ -1148,13 +1192,14 @@ def full_import(handler, host=None, core_name=None, options={}, extra=[]):
errors = ['Failed to set the replication status on the master.']
return _get_return_dict(False, errors=errors)
params = ['command=full-import']
for (k, v) in options.items():
for k, v in options.items():
params.append("&{0}={1}".format(k, v))
url = _format_url(handler, host=host, core_name=core_name,
extra=params + extra)
return _http_request(url)
def delta_import(handler, host=None, core_name=None, options={}, extra=[]):
def delta_import(handler, host=None, core_name=None, options=None, extra=None):
'''
Submits an import command to the specified handler using specified options.
This command can only be run if the minion is is configured with
@ -1182,6 +1227,8 @@ def delta_import(handler, host=None, core_name=None, options={}, extra=[]):
salt '*' solr.delta_import dataimport None music {'clean':True}
'''
options = {} if options is None else options
extra = [] if extra is None else extra
if not _is_master() and _get_none_or_value(host) is None:
err = ['solr.delta_import can only be called on "master" minions']
return _get_return_dict(False, errors=err)
@ -1197,12 +1244,13 @@ def delta_import(handler, host=None, core_name=None, options={}, extra=[]):
errors = ['Failed to set the replication status on the master.']
return _get_return_dict(False, errors=errors)
params = ['command=delta-import']
for (k, v) in options.items():
for k, v in options.items():
params.append("{0}={1}".format(k, v))
url = _format_url(handler, host=host, core_name=core_name,
extra=params + extra)
return _http_request(url)
def import_status(handler, host=None, core_name=None, verbose=False):
'''
Submits an import command to the specified handler using specified options.

View file

@ -45,6 +45,7 @@ class CMDModuleTest(integration.ModuleCase):
'''
cmd.run_all
'''
from salt._compat import string_types
ret = self.run_function('cmd.run_all', ['echo "cheese" 1>&2'])
self.assertTrue('pid' in ret)
self.assertTrue('retcode' in ret)
@ -52,8 +53,8 @@ class CMDModuleTest(integration.ModuleCase):
self.assertTrue('stderr' in ret)
self.assertTrue(isinstance(ret.get('pid'), int))
self.assertTrue(isinstance(ret.get('retcode'), int))
self.assertTrue(isinstance(ret.get('stdout'), basestring))
self.assertTrue(isinstance(ret.get('stderr'), basestring))
self.assertTrue(isinstance(ret.get('stdout'), string_types))
self.assertTrue(isinstance(ret.get('stderr'), string_types))
self.assertEqual(ret.get('stderr').rstrip(), 'cheese')
def test_retcode(self):

View file

@ -38,8 +38,8 @@ class SSHModuleTest(integration.ModuleCase):
os.path.join(integration.FILES, 'ssh', 'authorized_keys'),
AUTHORIZED_KEYS)
ret = self.run_function('ssh.auth_keys', ['root', AUTHORIZED_KEYS])
self.assertEqual(len(ret.items()), 1) # exactply one key is found
key_data = ret.items()[0][1]
self.assertEqual(len(list(ret.items())), 1) # exactply one key is found
key_data = list(ret.items())[0][1]
self.assertEqual(key_data['comment'], 'github.com')
self.assertEqual(key_data['enc'], 'ssh-rsa')
self.assertEqual(key_data['options'], [])

View file

@ -223,7 +223,7 @@ class FileTest(integration.ModuleCase):
with open(name, 'r') as fp_:
self.assertTrue(fp_.read().startswith('#comment'))
# result is positive
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertTrue(ret['result'], ret)
# comment twice
_ret = self.run_state('file.comment', name=name, regex='^comment')
@ -231,7 +231,7 @@ class FileTest(integration.ModuleCase):
with open(name, 'r') as fp_:
self.assertTrue(fp_.read().startswith('#comment'))
# result is still positive
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertTrue(ret['result'], ret)
def test_test_comment(self):

View file

@ -31,25 +31,25 @@ class SSHKnownHostsStateTest(integration.ModuleCase):
}
# test first
_ret = self.run_state('ssh_known_hosts.present', test=True, **kwargs)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['result'], None, ret)
# save once, new key appears
_ret = self.run_state('ssh_known_hosts.present', **kwargs)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['changes']['new']['fingerprint'],
GITHUB_FINGERPRINT, ret)
# save twice, no changes
_ret = self.run_state('ssh_known_hosts.present', **kwargs)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['changes'], {}, ret)
# test again, nothing is about to be changed
_ret = self.run_state('ssh_known_hosts.present', test=True, **kwargs)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['result'], None, ret)
# then add a record for IP address
_ret = self.run_state('ssh_known_hosts.present',
**dict(kwargs, name=GITHUB_IP))
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['changes']['new']['fingerprint'],
GITHUB_FINGERPRINT, ret)
# record for every host must be available
@ -67,7 +67,7 @@ class SSHKnownHostsStateTest(integration.ModuleCase):
user='root',
fingerprint='aa:bb:cc:dd',
config=KNOWN_HOSTS)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertFalse(ret['result'], ret)
def test_absent(self):
@ -82,20 +82,20 @@ class SSHKnownHostsStateTest(integration.ModuleCase):
'config': KNOWN_HOSTS}
# test first
_ret = self.run_state('ssh_known_hosts.absent', test=True, **kwargs)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['result'], None, ret)
# remove once, the key is gone
_ret = self.run_state('ssh_known_hosts.absent', **kwargs)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['changes']['old']['fingerprint'],
GITHUB_FINGERPRINT, ret)
# remove twice, nothing has changed
_ret = self.run_state('ssh_known_hosts.absent', **kwargs)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['changes'], {}, ret)
# test again
_ret = self.run_state('ssh_known_hosts.absent', test=True, **kwargs)
ret = _ret.values()[0]
ret = list(_ret.values())[0]
self.assertEqual(ret['result'], None, ret)