mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
parent
2c57d8ba6a
commit
b46e18c4be
@ -859,11 +859,14 @@ class LocalClient(object):
|
||||
|
||||
found = set()
|
||||
# Check to see if the jid is real, if not return the empty dict
|
||||
if self.returners['{0}.get_load'.format(self.opts['master_job_cache'])](jid) == {}:
|
||||
log.warning('jid does not exist')
|
||||
yield {}
|
||||
# stop the iteration, since the jid is invalid
|
||||
raise StopIteration()
|
||||
try:
|
||||
if self.returners['{0}.get_load'.format(self.opts['master_job_cache'])](jid) == {}:
|
||||
log.warning('jid does not exist')
|
||||
yield {}
|
||||
# stop the iteration, since the jid is invalid
|
||||
raise StopIteration()
|
||||
except salt.exceptions.SaltMasterError as exc:
|
||||
log.warning('Returner unavailable: {exc}'.format(exc=exc))
|
||||
# Wait for the hosts to check in
|
||||
syndic_wait = 0
|
||||
last_time = False
|
||||
|
@ -122,12 +122,18 @@ def _fetch_option(cfg, ret_config, virtualname, attr_name):
|
||||
"""
|
||||
# c_cfg is a dictionary returned from config.option for
|
||||
# any options configured for this returner.
|
||||
c_cfg = cfg('{0}'.format(virtualname), {})
|
||||
if isinstance(cfg, dict):
|
||||
c_cfg = cfg
|
||||
else:
|
||||
c_cfg = cfg('{0}'.format(virtualname), {})
|
||||
|
||||
default_cfg_key = '{0}.{1}'.format(virtualname, attr_name)
|
||||
if not ret_config:
|
||||
# Using the default configuration key
|
||||
return c_cfg.get(attr_name, cfg(default_cfg_key))
|
||||
if isinstance(cfg, dict):
|
||||
return c_cfg.get(attr_name, cfg.get(default_cfg_key))
|
||||
else:
|
||||
return c_cfg.get(attr_name, cfg(default_cfg_key))
|
||||
|
||||
# Using ret_config to override the default configuration key
|
||||
ret_cfg = cfg('{0}.{1}'.format(ret_config, virtualname), {})
|
||||
|
@ -101,6 +101,7 @@ import logging
|
||||
# Import salt libs
|
||||
import salt.returners
|
||||
import salt.utils.jid
|
||||
import salt.exceptions
|
||||
|
||||
# Import third party libs
|
||||
try:
|
||||
@ -155,11 +156,14 @@ def _get_serv(ret=None, commit=False):
|
||||
Return a mysql cursor
|
||||
'''
|
||||
_options = _get_options(ret)
|
||||
conn = MySQLdb.connect(host=_options.get('host'),
|
||||
user=_options.get('user'),
|
||||
passwd=_options.get('pass'),
|
||||
db=_options.get('db'),
|
||||
port=_options.get('port'))
|
||||
try:
|
||||
conn = MySQLdb.connect(host=_options.get('host'),
|
||||
user=_options.get('user'),
|
||||
passwd=_options.get('pass'),
|
||||
db=_options.get('db'),
|
||||
port=_options.get('port'))
|
||||
except MySQLdb.connections.OperationalError as exc:
|
||||
raise salt.exceptions.SaltMasterError('MySQL returner could not connect to database: {exc}'.format(exc=exc))
|
||||
cursor = conn.cursor()
|
||||
try:
|
||||
yield cursor
|
||||
@ -181,16 +185,19 @@ def returner(ret):
|
||||
'''
|
||||
Return data to a mysql server
|
||||
'''
|
||||
with _get_serv(ret, commit=True) as cur:
|
||||
sql = '''INSERT INTO `salt_returns`
|
||||
(`fun`, `jid`, `return`, `id`, `success`, `full_ret` )
|
||||
VALUES (%s, %s, %s, %s, %s, %s)'''
|
||||
try:
|
||||
with _get_serv(ret, commit=True) as cur:
|
||||
sql = '''INSERT INTO `salt_returns`
|
||||
(`fun`, `jid`, `return`, `id`, `success`, `full_ret` )
|
||||
VALUES (%s, %s, %s, %s, %s, %s)'''
|
||||
|
||||
cur.execute(sql, (ret['fun'], ret['jid'],
|
||||
json.dumps(ret['return']),
|
||||
ret['id'],
|
||||
ret['success'],
|
||||
json.dumps(ret)))
|
||||
cur.execute(sql, (ret['fun'], ret['jid'],
|
||||
json.dumps(ret['return']),
|
||||
ret['id'],
|
||||
ret['success'],
|
||||
json.dumps(ret)))
|
||||
except salt.exceptions.SaltMasterError:
|
||||
log.critical('Could not store return with MySQL returner. MySQL server unavailable.')
|
||||
|
||||
|
||||
def event_return(events):
|
||||
|
Loading…
Reference in New Issue
Block a user