grains and pillar not available in provider overrides
While working on fixing a bug, I noticed that grains and pillar don't seem to work at all in provider overrides. So if, for instance, I were to specify a provider override because the service module was not properly detected, the __grains__ dict would be empty and the __pillar__ dict would not exist.
To reproduce, I added a function to the module I was using for the override:
def foo():
import sys
log.debug(len(sys.modules['salt.loaded.int.module.service'].__grains__))
log.debug(len(__grains__))
log.debug(len(sys.modules['salt.loaded.int.module.service'].__pillar__))
log.debug(len(__pillar__))
Here is the logging output from running that function:
[DEBUG ] 47
[DEBUG ] 0
[DEBUG ] 2
[WARNING ] The minion function caused an exception: Traceback (most recent call last):
File "/home/erik/salt/salt/minion.py", line 648, in _thread_return
return_data = func(*args, **kwargs)
File "/home/erik/salt/salt/modules/service.py", line 95, in foo
log.debug(len(__pillar__))
NameError: global name '__pillar__' is not defined
So the python module itself appears to have a __grains__ and __pillar__ attribute, but the __grains__ and __pillar__ dicts don't work or aren't the same.
I've tried, unsuccessfully, to track this down in loader.py, so I'm opening this issue.
Salt 2014.1.7.
I'm trying to access the __pillar__ dunder dict from a custom execution module (under _modules/ in my file root), but getting a traceback. Is that related to this bug, or am I just doing something wrong? :)
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 707, in gen_functions
), fn_, path, desc
File "/var/cache/salt/minion/extmods/modules/edgecast.py", line 11, in <module>
accountnum = __pillar__['edgecast_account']
NameError: name '__pillar__' is not defined
I have a vague recollection of a bug where salt dunder vars were not available outside of functions definitions in custom modules. If you try and access __pillar__ inside a given function does it work? (Or is that what you're doing right now?)
I was trying to access it outside of a function. I moved the lookup down into a function, and it works. Makes for some uglier code since I have to copy/paste the same variable declarations 10 times instead of doing it once globally, but I can deal with it :) Thanks.
Looks like that's potentially Issue #10270?
Yes, that's the one I was thinking of!
We do really need to fix this though. Thanks for the reminder and apologies for the need for the ugly workaround.
On Fri, Sep 19, 2014 at 10:42 AM, Jon Henry [email protected] wrote:
I was trying to access it outside of a function. I moved the lookup down into a function, and it works. Makes for some uglier code since I have to copy/paste the same variable declarations 10 times instead of doing it once globally, but I can deal with it :) Thanks.
Looks like that's potentially Issue #10270 https://github.com/saltstack/salt/issues/10270?
— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/7433#issuecomment-56202586.
Any forward motion on this? Specifically running into https://github.com/saltstack/salt/issues/8648, which I can't find a way to override cpuarch when already overriding the pkg provider.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.