saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.18k stars 5.48k forks source link

Proxy minions: grains functions are started before proxy init() #27384

Closed jejenone closed 9 years ago

jejenone commented 9 years ago

on 2015.8, it seems that grains functions are run before the proxy init() function. That renders impossible to retrieve grains from proxied device

[DEBUG   ] ----------- Trying to get facts
[DEBUG   ] LazyLoaded junos.facts
[CRITICAL] Failed to load grains defined in grain file junos.facts in function <function facts at 0x7fa371224758>, error:
Traceback (most recent call last):
  File "/usr/local/salt/virtualenv/lib/python2.7/site-packages/salt/loader.py", line 621, in grains
    ret = fun()
  File "/usr/local/salt/virtualenv/lib/python2.7/site-packages/salt/grains/junos.py", line 48, in facts
    facts = __opts__['proxymodule']['junos.facts']()
  File "/usr/local/salt/virtualenv/lib/python2.7/site-packages/salt/proxy/junos.py", line 43, in facts
    return thisproxy['conn'].facts
KeyError: 'conn'
[DEBUG   ] Opening connection to junos
[DEBUG   ] <SSHSession(session, initial daemon)> created: client_capabilities=['urn:ietf:params:netconf:capability:writable-running:1.0', 'urn:ietf:params:netconf:capability:rollback-on-error:1.0', 'urn:ietf:params:netconf:capability:validate:1.0', 'urn:ietf:params:netconf:capability:confirmed-commit:1.0', 'urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file,https,sftp', 'urn:ietf:params:netconf:base:1.0', 'urn:liberouter:params:netconf:capability:power-control:1.0', 'urn:ietf:params:netconf:capability:candidate:1.0', 'urn:ietf:params:netconf:capability:xpath:1.0', 'urn:ietf:params:netconf:capability:startup:1.0', 'urn:ietf:params:netconf:capability:interleave:1.0']
jfindlay commented 9 years ago

@jejenone, thanks for the report.

@cro

cro commented 9 years ago

@jejenone What Salt version is this?

jejenone commented 9 years ago

2015.8.0

On Fri, Sep 25, 2015 at 9:31 AM, C. R. Oldham notifications@github.com wrote:

@jejenone https://github.com/jejenone What Salt version is this?

— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/27384#issuecomment-143269956.

cro commented 9 years ago

Ref #27731

jejenone commented 9 years ago

That's a lot of interesting commits here! Thanks!

rallytime commented 9 years ago

@jejenone Have you gotten a change to test the fix from @cro? Do you consider this issue resolved?

jejenone commented 9 years ago

@rallytime I am running on latest 2015.8 and issue is not resolved. Grains collections are still started before the init() phase of the proxy minion.

rallytime commented 9 years ago

@jejenone Just to clarify, are you running from the current HEAD of the branch, or from a release like 2015.8.0 or 2015.8.1?

The fix from @cro is only available from the HEAD of the 2015.8 branch. The reason I am asking is because in #27731, on line 2541 of minion.py we're calling the init before setting the grains like so:

proxy_init_fn = self.proxy[fq_proxyname+'.init']
proxy_init_fn(self.opts)
self.opts['grains'] = salt.loader.grains(self.opts)

So I want to see if this is fixed or to see if this is broken in another way.

cro commented 9 years ago

Closing for now, we believe this is fixed. Feel free to reopen if that's not the case.

jejenone commented 9 years ago

Sorry for late reply, we have a new problem where the proxy object is not available in the grains module.

cro commented 9 years ago

@jejenone Did you open a ticket for that? I'll make sure we look at it asap.

mirceaulinic commented 8 years ago

Actually there are two issues that might have the same root cause: in the grains the object proxy is not available:

NameError: global name '__proxy__' is not defined

And the grains are loaded before calling the init method from the proxy.