Exception from scheduled runner
I'm trying to use the scheduler to exec a runner. Whenever it runs, I get the following exception:
2016-02-10 21:10:25,405 [salt.utils.schedule][ERROR ][21581] Unhandled exception running state.orch
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/utils/schedule.py", line 703, in handle_func
ret['retcode'] = self.functions.pack['__context__']['retcode']
AttributeError: 'ClientFuncsDict' object has no attribute 'pack'
It seems to do this for any runner - I'm using sample based on the docs (https://docs.saltstack.com/en/latest/topics/jobs/schedule.html#runners)
$ cat /etc/salt/master.d/schedule.conf
schedule:
run_my_orch:
function: state.orch
seconds: 15
args:
- orch.test
$ cat /srv/salt/orch/test.sls
cmd.run:
salt.function:
- tgt: 'master-*'
- arg:
- /bin/echo asdf
@dmacvicar #24237
I reverted salt/utils/schedule.py to c462139dbb7937e9f7e3c4c670a4adfb3f7b8ad1 and my salt-master scheduler returned to its blissful state of usefulness.
schedule:
CA_update:
function: tls_ca.update_fileserver
minutes: 15
maxrunning: 1
(master log)
2016-02-10 22:24:44,212 [salt.utils.schedule][ERROR ][15681] Unhandled exception running tls_ca.update_fileserver
Traceback (most recent call last):
File "/srv/.virtualenvs/salt/local/lib/python2.7/site-packages/salt/utils/schedule.py", line 703, in handle_func
ret['retcode'] = self.functions.pack['__context__']['retcode']
AttributeError: 'ClientFuncsDict' object has no attribute 'pack'
:unamused:
Salt Version:
Salt: 2015.8.5
Dependency Versions:
Jinja2: 2.8
M2Crypto: 0.21.1
Mako: Not Installed
PyYAML: 3.11
PyZMQ: 15.1.0
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
RAET: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.2
cffi: 1.2.1
cherrypy: 3.8.0
dateutil: 2.4.2
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
libgit2: Not Installed
libnacl: 1.4.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: 2.14
pycrypto: 2.6.1
pygit2: Not Installed
python-gnupg: 2.0.2
smmap: Not Installed
timelib: 0.
I think I saw this once, and I assumed that at some point of the loop this was not available, but I did not thought about "schedule running on the master" case. I will try to reproduce.
@rvandegrift, thanks for reporting.
I am not sure the "runs on the master" pattern applies as I saw this with mine.update. I am also not sure if the missing pack is related to existing pack but missing retcode.
2016-02-11 15:24:38,599 [salt.utils.schedule][ERROR ][12357] Unhandled exception running mine.update
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/utils/schedule.py", line 703, in handle_func
ret['retcode'] = self.functions.pack['__context__']['retcode']
KeyError: 'retcode'
However, I see other mine.update events on the master having retcode.
So for the missing pack ClientFuncsDict comes from one of the mixins:
class SyncClientMixin(object):
# ...
def functions_dict(self):
'''
Return a dict that will mimic the "functions" dict used all over salt.
It creates a wrapper around the function allowing **kwargs, and if pub_data
is passed in as kwargs, will re-use the JID passed in
'''
return ClientFuncsDict(self)
This mixin is used by the runner client:
class RunnerClient(mixins.SyncClientMixin, mixins.AsyncClientMixin, object):
# ...
Who has its own way to get the functions using the loader:
@property
def functions(self):
if not hasattr(self, '_functions'):
self._functions = salt.loader.runner(self.opts) # Must be self.functions for mixin to work correctly :-/
return self._functions
The loader one sets pack explicitly:
def runner(opts):
'''
Directly call a function inside a loader directory
'''
ret = LazyLoader(_module_dirs(opts, 'runners', 'runner', ext_type_dirs='runner_dirs'),
opts,
tag='runners',
)
# TODO: change from __salt__ to something else, we overload __salt__ too much
ret.pack['__salt__'] = ret
return ret
However, when the schedule is instantiated on master, the other functions (the one that is wrapped into ClientFuncsDict) are used:
self.schedule = salt.utils.schedule.Schedule(self.opts,
runner_client.functions_dict(),
While on the minion, they just use the ones from the loader:
self.schedule = salt.utils.schedule.Schedule(
self.opts,
self.functions,
self.returners)
I guess finding out the why the difference could help in finding a workaround.
@dmacvicar, the first error you mention may be #30472, which should have been fixed in #30978 but not released yet.
@jfindlay thanks for the pointer, so that error is specific about state.py not setting retcode.
This error seems to be two parts. One not being to access the pack with the runner wrapper. For this, I can get over this by implementing:
def __getattr__(self, attr):
return getattr(self.client.functions, attr)
on the ClientFuncsDict wrapper, so that pack is forwarded. Does this make sense? I am not sure about the consequences unless I figure what is the purpose of the wrapper.
Then you still get the error that the runner is not setting retcode.
[ERROR ] Unhandled exception running test.stdout_print
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/utils/schedule.py", line 705, in handle_func
ret['retcode'] = self.functions.pack['__context__']['retcode']
KeyError: 'retcode'
For the missing retcode in runner, as a normal call with salt-run does not provide retcode, the schedule call should mimic the normal call behavior and also not have it. Something like:
if 'retcode' in self.functions.pack['__context__']:
ret['retcode'] = self.functions.pack['__context__']['retcode']
The fix above would make sure pack is accessible and I hope __context___ is there all the time.
That fixes the crash completely for me. I can prepare a patch but some feedback would be appreciated.
@rvandegrift Does the fix in #31189 resolve the bug you were seeing here? (@dmacvicar thank you very much!)
I setup the original test, no exceptions. Thanks, looks good!
Does that mean, that scheduling and/or salt mine in 2015.8.5 is broken?
Just tested Runner scheduling with 2015.8.7 (Master). The same error:
2016-02-19 10:51:58,512 [salt.utils.schedule][ERROR ][15105] Unhandled exception running myrun.test Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/salt/utils/schedule.py", line 703, in handle_func ret['retcode'] = self.functions.pack['context']['retcode']
AttributeError: 'ClientFuncsDict' object has no attribute 'pack'
The fix in #31189 solves the problem. No more errors and the runner works as expected
The fix was only recently submitted and merged, and did not make it into the 2015.8.7 release. It will be available in the next release, however, which will be 2015.8.8.
@rallytime Any idea when 2015.8.8 will be released? This is pretty important functionality that's now broken in the current release
The next point release will come out in March, so should be within the next couple of weeks or so.
This fix is in the upcoming 2015.8.8 which should be released very soon. Closing.