Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write lists of minions targeted by syndic masters to job cache #31670

Merged
merged 29 commits into from
Mar 7, 2016
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2ad8cef
Add salt.utils.split_input()
terminalmage Mar 4, 2016
978b6cb
Add missing RST file for slsutil module
terminalmage Mar 4, 2016
1e6b43e
Add a contextmanager for file locking
terminalmage Mar 4, 2016
3f527be
Add an exception class for errors encountered while locking files.
terminalmage Mar 4, 2016
214fedc
Simplify jobs.get_jobs logic, generally improve jobs runner docs
terminalmage Mar 4, 2016
0b4616a
Separate writing of serialized minion list into its own function
terminalmage Mar 4, 2016
504f7df
Add utils function to invoke a returner's save_minions() func
terminalmage Mar 4, 2016
f731dc5
Update a job's minion list to include minion lists forwarded by syndic
terminalmage Mar 4, 2016
084a784
salt.returners.couchbase_return: move minion list updates to new save…
terminalmage Mar 4, 2016
44538df
salt.returners.cassandra_cql_return: add no-op save_minions() func fo…
terminalmage Mar 4, 2016
8e80535
salt.returners.couchdb_return: add no-op save_minions() func for API …
terminalmage Mar 4, 2016
1dd1061
salt.returners.etcd_return: add no-op save_minions() func for API com…
terminalmage Mar 4, 2016
4322ad9
salt.returners.influxdb_return: add no-op save_minions() func for API…
terminalmage Mar 4, 2016
c13bb65
salt.returners.memcache_return: add no-op save_minions() func for API…
terminalmage Mar 4, 2016
da1acbb
salt.returners.mongo_future_return: add no-op save_minions() func for…
terminalmage Mar 4, 2016
5b4eb58
salt.returners.mongo_return: add no-op save_minions() func for API co…
terminalmage Mar 4, 2016
ef6aa5d
salt.returners.multi_returner: add no-op save_minions() func for API …
terminalmage Mar 4, 2016
a1957c3
salt.returners.mysql: add no-op save_minions() func for API compatibi…
terminalmage Mar 4, 2016
d8f90f6
salt.returners.odbc: add no-op save_minions() func for API compatibility
terminalmage Mar 4, 2016
82750ab
salt.returners.pgjsonb: add no-op save_minions() func for API compati…
terminalmage Mar 4, 2016
d6d794b
salt.returners.postgres: add no-op save_minions() func for API compat…
terminalmage Mar 4, 2016
0ea1b76
salt.returners.postgres_local_cache: add no-op save_minions() func fo…
terminalmage Mar 4, 2016
f866410
salt.returners.redis_return: add no-op save_minions() func for API co…
terminalmage Mar 4, 2016
0f175a4
salt.returners.sqlite3_return: add no-op save_minions() func for API …
terminalmage Mar 4, 2016
651e392
lint fixes
terminalmage Mar 4, 2016
1d39eec
Skip events with minion lists but no jid
terminalmage Mar 5, 2016
cb92114
Add syndic_id param for API compatibility
terminalmage Mar 5, 2016
cf94c25
Add argument to save_minions() to pass a syndic ID
terminalmage Mar 5, 2016
65e5a3c
Pass syndic_id to save_minions()
terminalmage Mar 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/ref/modules/all/salt.modules.slsutil.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
====================
salt.modules.slsutil
====================

.. automodule:: salt.modules.slsutil
:members:
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.cassandra_cql_return
===================================

.. automodule:: salt.returners.cassandra_cql_return
:members:
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.couchdb_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.couchdb_return
=============================

.. automodule:: salt.returners.couchdb_return
:members:
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.etcd_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.etcd_return
==========================

.. automodule:: salt.returners.etcd_return
:members:
:members:
:exclude-members: save_minions
1 change: 1 addition & 0 deletions doc/ref/returners/all/salt.returners.influxdb_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ salt.returners.influxdb_return

.. automodule:: salt.returners.influxdb_return
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.memcache_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.memcache_return
==============================

.. automodule:: salt.returners.memcache_return
:members:
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.mongo_future_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.mongo_future_return
==================================

.. automodule:: salt.returners.mongo_future_return
:members:
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.mongo_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.mongo_return
===========================

.. automodule:: salt.returners.mongo_return
:members:
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.multi_returner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.multi_returner
=============================

.. automodule:: salt.returners.multi_returner
:members:
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.mysql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.mysql
====================

.. automodule:: salt.returners.mysql
:members:
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.odbc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.odbc
===================

.. automodule:: salt.returners.odbc
:members:
:members:
:exclude-members: save_minions
1 change: 1 addition & 0 deletions doc/ref/returners/all/salt.returners.pgjsonb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ salt.returners.pgjsonb

.. automodule:: salt.returners.pgjsonb
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.postgres.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.postgres
=======================

.. automodule:: salt.returners.postgres
:members:
:members:
:exclude-members: save_minions
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ salt.returners.postgres_local_cache

.. automodule:: salt.returners.postgres_local_cache
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.redis_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.redis_return
===========================

.. automodule:: salt.returners.redis_return
:members:
:members:
:exclude-members: save_minions
3 changes: 2 additions & 1 deletion doc/ref/returners/all/salt.returners.sqlite3_return.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ salt.returners.sqlite3
=======================

.. automodule:: salt.returners.sqlite3_return
:members:
:members:
:exclude-members: save_minions
23 changes: 23 additions & 0 deletions salt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

# Import python libs
import copy
import logging
import time

# Import salt libs
import salt.defaults.exitcodes

log = logging.getLogger(__name__)


class SaltException(Exception):
'''
Expand Down Expand Up @@ -98,6 +104,23 @@ class FileserverConfigError(SaltException):
'''


class FileLockError(SaltException):
'''
Used when an error occurs obtaining a file lock
'''
def __init__(self, msg, time_start=None, *args, **kwargs):
super(FileLockError, self).__init__(msg, *args, **kwargs)
if time_start is None:
log.warning(
'time_start should be provided when raising a FileLockError. '
'Defaulting to current time as a fallback, but this may '
'result in an inaccurate timeout.'
)
self.time_start = time.time()
else:
self.time_start = time_start


class SaltInvocationError(SaltException, TypeError):
'''
Used when the wrong number of arguments are sent to modules or invalid
Expand Down
21 changes: 21 additions & 0 deletions salt/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,27 @@ def _handle_minion_event(self, load):
log.error('Received minion error from [{minion}]: '
'{data}'.format(minion=load['id'],
data=load['data']['message']))
for event in load.get('events', []):
event_data = event.get('data', {})
if 'minions' in event_data:
jid = event_data.get('jid')
if not jid:
# Should not happen but if it ever does we definitely want
# to know about it.
log.warning('No jid in event: %s', event_data)
else:
minions = event_data['minions']
try:
salt.utils.job.store_minions(
self.opts,
jid,
minions,
mminion=self.mminion)
except (KeyError, salt.exceptions.SaltCacheError) as exc:
log.error(
'Could not add minion(s) {0} for job {1}: {2}'
.format(minions, jid, exc)
)

def _return(self, load):
'''
Expand Down
7 changes: 7 additions & 0 deletions salt/returners/cassandra_cql_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ def save_load(jid, load):
raise


def save_minions(jid, minions): # pylint: disable=unused-argument
'''
Included for API consistency
'''
pass


# salt-run jobs.list_jobs FAILED
def get_load(jid):
'''
Expand Down
30 changes: 21 additions & 9 deletions salt/returners/couchbase_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def _get_ttl():
def prep_jid(nocache=False, passed_jid=None):
'''
Return a job id and prepare the job id directory
This is the function responsible for making sure jids don't collide (unless its passed a jid)
This is the function responsible for making sure jids don't collide (unless
its passed a jid)
So do what you have to do to make sure that stays the case
'''
if passed_jid is None:
Expand Down Expand Up @@ -195,6 +196,9 @@ def save_load(jid, clear_load):
log.warning('Could not write job cache file for jid: {0}'.format(jid))
return False

jid_doc.value['load'] = clear_load
cb_.replace(str(jid), jid_doc.value, cas=jid_doc.cas, ttl=_get_ttl())

# if you have a tgt, save that for the UI etc
if 'tgt' in clear_load:
ckminions = salt.utils.minions.CkMinions(__opts__)
Expand All @@ -203,16 +207,24 @@ def save_load(jid, clear_load):
clear_load['tgt'],
clear_load.get('tgt_type', 'glob')
)
# save the minions to a cache so we can see in the UI
jid_doc.value['minions'] = minions
save_minions(jid, minions)

jid_doc.value['load'] = clear_load

cb_.replace(str(jid),
jid_doc.value,
cas=jid_doc.cas,
ttl=_get_ttl()
)
def save_minions(jid, minions):
'''
Save/update the minion list for a given jid
'''
cb_ = _get_connection()

try:
jid_doc = cb_.get(str(jid))
except couchbase.exceptions.NotFoundError:
log.warning('Could not write job cache file for jid: {0}'.format(jid))
return False

# save the minions to a cache so we can see in the UI
jid_doc.value['minions'] = minions
cb_.replace(str(jid), jid_doc.value, cas=jid_doc.cas, ttl=_get_ttl())


def get_load(jid):
Expand Down
7 changes: 7 additions & 0 deletions salt/returners/couchdb_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,10 @@ def prep_jid(nocache=False, passed_jid=None): # pylint: disable=unused-argument
Do any work necessary to prepare a JID, including sending a custom id
'''
return passed_jid if passed_jid is not None else salt.utils.jid.gen_jid()


def save_minions(jid, minions): # pylint: disable=unused-argument
'''
Included for API consistency
'''
pass
7 changes: 7 additions & 0 deletions salt/returners/etcd_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ def save_load(jid, load):
)


def save_minions(jid, minions): # pylint: disable=unused-argument
'''
Included for API consistency
'''
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sort of inclined to raise exceptions for these and catch and log higher up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason that I did not is that we're not already saving the minion list for this returner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Good point.



def get_load(jid):
'''
Return the load data that marks a specified jid
Expand Down
7 changes: 7 additions & 0 deletions salt/returners/influxdb_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ def save_load(jid, load):
log.critical('Failed to store load with InfluxDB returner: {0}'.format(ex))


def save_minions(jid, minions): # pylint: disable=unused-argument
'''
Included for API consistency
'''
pass


def get_load(jid):
'''
Return the load data that marks a specified jid
Expand Down