salt icon indicating copy to clipboard operation
salt copied to clipboard

On Windows file state throws exception in check_perms: global name '__salt__' is not defined

Open belawaeckerlig opened this issue 12 years ago • 37 comments

Hi,

when i try to use a file.managed or file.recurse state, very often the following exception will be thrown:

An exception occurred in this state: Traceback (most recent call last):
  File "salt/state.py", line 1316, in call
  File "salt/states/file.py", line 1157, in managed
  File "salt/modules/file.py", line 2095, in manage_file
  File "salt/modules/file.py", line 2234, in makedirs
  File "salt/modules/file.py", line 2193, in mkdir
  File "salt/modules/file.py", line 2269, in makedirs_perms
  File "salt/modules/file.py", line 1690, in check_perms
NameError: global name '__salt__' is not defined

Sometimes it runs without a exception but mostly not.

Minion (Windows Server 2008 R2):

Salt: 0.17.5-52-g2d4772c
             Python: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
             Jinja2: 2.7.1
           M2Crypto: 0.21.1
     msgpack-python: 0.4.0
       msgpack-pure: Not Installed
           pycrypto: 2.6
             PyYAML: 3.10
              PyZMQ: 13.1.0
                ZMQ: 3.2.2

Master (Ubuntu 12.04 LTS AMD64):

Salt: 0.17.5
         Python: 2.7.3 (default, Sep 26 2013, 20:03:06)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.4.1
         PyYAML: 3.10
          PyZMQ: 13.0.0
            ZMQ: 3.2.2

belawaeckerlig avatar Feb 26 '14 12:02 belawaeckerlig

Thanks for the report!

@UtahDave ping

basepi avatar Feb 26 '14 23:02 basepi

Running into this as well. Trying to run file.recurse on a directory and this is making it impossible. Is there a version that doesn't have this issue? I'm trying to evaluate salt for work and this is completely blocking me.

gtmacdonald avatar Mar 05 '14 03:03 gtmacdonald

@todesregen @gtmacdonald Can you test this on 2014.1.0? I believe this has been fixed.

UtahDave avatar Mar 05 '14 04:03 UtahDave

Hi,

tested with 2014.1.0 and it is still not working. the same execption occures:

2014-03-05 08:26:41,761 [salt.fileclient  ][DEBUG   ] Fetching file from saltenv 'base', ** attempting ** 'salt://win/process-explorer/procexp.exe'
2014-03-05 08:26:42,026 [salt.fileclient  ][INFO    ] Fetching file from saltenv 'base', ** done ** 'win/process-explorer/procexp.exe'
2014-03-05 08:26:42,042 [salt.loaded.int.states.file][DEBUG   ] Traceback (most recent call last):
  File "salt/states/file.py", line 1293, in managed
  File "salt/modules/file.py", line 2625, in manage_file
  File "salt/modules/file.py", line 2764, in makedirs
  File "salt/modules/file.py", line 2723, in mkdir
  File "salt/modules/file.py", line 2799, in makedirs_perms
  File "salt/modules/file.py", line 2196, in check_perms
NameError: global name '__salt__' is not defined

2014-03-05 08:26:42,042 [salt.state       ][ERROR   ] Unable to manage file: global name '__salt__' is not defined
2014-03-05 08:26:42,042 [salt.state       ][INFO    ] Completed state [C:\process-explorer\procexp.exe] at time 08:26:42.042000

and what may be also interresting for you, the postgres module also throws an exception:

2014-03-05 08:26:41,902 [salt.loader      ][DEBUG   ] Failed to import module postgres, this is most likely NOT a problem:
Traceback (most recent call last):
  File "salt/loader.py", line 700, in gen_functions
  File "salt/modules/postgres.py", line 29, in <module>
ImportError: No module named csv

It looks a litte bit messy in the log file :P

belawaeckerlig avatar Mar 05 '14 07:03 belawaeckerlig

Looks like it's fixed! Thank you very much!!!

I've been running a large directory sync for 15 minutes now without the exception where it was dying immediately before. I get the postgres stacktrace too but it doesn't seem to matter.

@todesregen Did you update both server and minion? That may be something to try.

gtmacdonald avatar Mar 05 '14 20:03 gtmacdonald

Yes, I updated both. I did not try a file.recurse but the file.managed still raises the above exception sometimes.

belawaeckerlig avatar Mar 05 '14 20:03 belawaeckerlig

Oh ok, I haven't tried file.managed yet. I'll let you know when I do.

gtmacdonald avatar Mar 05 '14 20:03 gtmacdonald

@UtahDave @todesregen I take it back, it is happening with file.recurse as well. :( Seems to be intermittent.

gtmacdonald avatar Mar 05 '14 20:03 gtmacdonald

OK, I'll do some testing on this today. Thanks for the info!

UtahDave avatar Mar 05 '14 21:03 UtahDave

@UtahDave Were you able to reproduce the issue? If not I can try and take a look.

gtmacdonald avatar Mar 06 '14 21:03 gtmacdonald

I haven't. On Mar 6, 2014 2:43 PM, "Greg MacDonald" [email protected] wrote:

@UtahDave https://github.com/UtahDave Were you able to reproduce the issue? If not I can try and take a look.

Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/10773#issuecomment-36940895 .

UtahDave avatar Mar 06 '14 23:03 UtahDave

Since you can't reproduce, it might be that I changed the username and group of the file server root to a user account in order to setup samba. I'll try switching it back to root and see...

gtmacdonald avatar Mar 07 '14 19:03 gtmacdonald

Ah, sorry for the unclear answer. I meant I haven't had time to try to reproduce it. I've been slammed with some deadlines On Mar 7, 2014 12:38 PM, "Greg MacDonald" [email protected] wrote:

Since you can't reproduce, it might be that I changed the username and group of the file server root to a user account in order to setup samba.

Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/10773#issuecomment-37059667 .

UtahDave avatar Mar 07 '14 20:03 UtahDave

I understand, I'm in the same boat. :)

Changing the username and group back to root seems to have removed the stack trace, but I still got this message on the first run:

Unable to manage file: global name 'salt' is not defined

I didn't see it on the second run, and both runs completed without throwing exceptions. And it looks like the directory was successfully copied down to the minion.

So I'm not blocked anymore but it looks like there still might be something going on.

gtmacdonald avatar Mar 07 '14 20:03 gtmacdonald

I can confirm this intermittent bug. Here is a pastebin of my output: http://pastebin.com/iWGRR3YX

shealutton avatar Mar 18 '14 20:03 shealutton

This seems to be affecting about 20% of my windows servers on each salt '*' state.highstate run. Since it is intermittent I thought it (a long shot) might be related to the number of worker threads on the master. I reduced the workers from 20 to 2, but it did not seem to help solve the problem, there were still many failures.

It makes it nearly impossible to control my environment when 20% of my windows machines fail to take the proper state. This is a pretty major problem for my company.

shealutton avatar Mar 19 '14 15:03 shealutton

@shealutton I'm sorry this is causing you difficulties. I'm traveling for work this week. I'll get working on this first thing Monday.

UtahDave avatar Mar 20 '14 17:03 UtahDave

Also, bumping this to high severity

UtahDave avatar Mar 20 '14 17:03 UtahDave

Thanks UtahDave, much appreciated.

shealutton avatar Mar 20 '14 19:03 shealutton

@UtahDave this could be in the loader, like #11235. However, the issue he's having over there is much more consistent and seemingly reproduceable. Since states should be executed in the same order every time, I doubt they're the same issue, but could be related.

basepi avatar Mar 20 '14 22:03 basepi