salt icon indicating copy to clipboard operation
salt copied to clipboard

Cron.file is not working - 'NoneType' object has no attribute 'startswith'

Open luizsilva opened this issue 12 years ago • 19 comments

After updating salt to 2014.1 (from 0.17) the cron state is not working anymore.

I was under the impression it was because the crontab for user root was empty but even with something on it (in this case a comment) the state still fails.

[INFO ] Running state [salt://cron/configs/ops_root.txt] at time 16:47:40.498803 [INFO ] Executing state cron.file for salt://cron/configs/ops_root.txt [INFO ] Executing command 'crontab -l -u root' in directory '/root' [INFO ] stdout: #

[ERROR ] Unable to manage file: 'NoneType' object has no attribute 'startswith' [INFO ] Completed state [salt://cron/configs/ops_root.txt] at time 16:47:40.521779

This is an Arch Linux box ( 2.6.32-23-pve #1 SMP Tue Aug 6 07:04:06 CEST 2013 x86_64 GNU/Linux) running as a container on proxmox.

luizsilva avatar Feb 21 '14 22:02 luizsilva

Strange, thanks for the report. We'll look into this.

basepi avatar Feb 21 '14 23:02 basepi

@luizsilva can you show me the cron state you are using.

dmyerscough avatar Feb 24 '14 03:02 dmyerscough

@dmyerscough :

{% if grains['class'] != 'dev' %} root_crontab: cron: - file - name: salt://cron/configs/{{ grains['class'] }}_root.txt - template: jinja - user: root - require: - pkg: cronie {% endif %}

cronie: pkg: - installed require: - pkg.removed: dcron

service: - running - enable: true - require: - pkg: cronie

luizsilva avatar Feb 24 '14 13:02 luizsilva

Sorry, clicked "close" by mistake.

luizsilva avatar Feb 24 '14 13:02 luizsilva

Thank you @luizsilva I will try get to this at the weekend.

dmyerscough avatar Feb 27 '14 07:02 dmyerscough

I am seeing a similar failure in cron.file after upgrading to 2014.1.0 (from 0.17).

My cron state is a bit simpler:

crontab:
  cron.file:
    - name: salt://files/crontab
    - user: root

Salt fails with

----------
          ID: crontab
    Function: cron.file
        Name: salt://files/crontab
      Result: False
     Comment: Source file salt://files/crontab not found
     Changes:

I am not using templates like OP is, but these issue may be related.

defunctzombie avatar Mar 10 '14 15:03 defunctzombie

I am too seeing the "Source file salt://files/crontab not found" issue after upgrading to 2014.1.0.

JensRantil avatar Mar 10 '14 16:03 JensRantil

Seems like,

on def cache_loc(self, path, saltenv='base', env=None) at salt/fileclient.py, if saltenv is None

    dest = os.path.join(self.opts['cachedir'],
                        'files',
                        saltenv,
                        path)

code block threws

  >>> os.path.join("a", None, "b")
  Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/usr/lib/python2.7/posixpath.py", line 75, in join
     if b.startswith('/'):
     AttributeError: 'NoneType' object has no attribute 'startswith'

(it's strange that it is None because the prototype shows a default value for the param)

fsniper avatar Mar 11 '14 06:03 fsniper

So python 2.7 has the tendency to use None value if you intensionally pass a None value to a parameter with a default.

   >>> def test(a, b="Def"):
   ...     print a
   ...     print b
   ... 
   .>>> test("a","b")
   a
   b
   .>>> test("a")
   a
   Def
   .>>> test("a",None)
   a
   None

fsniper avatar Mar 11 '14 06:03 fsniper

For a workaround one may use env: prod in the cron.file state.

fsniper avatar Mar 11 '14 06:03 fsniper

For a workaround one may use env: prod in the cron.file state.

I can confirm that the workaround worked for me.

JensRantil avatar Mar 11 '14 12:03 JensRantil

Is this issue fixed with the above commits?

basepi avatar Mar 11 '14 20:03 basepi

I don't see the nonetype issue, but I still get the source file not found issue. On Mar 11, 2014 4:43 PM, "Colton Myers" [email protected] wrote:

Is this issue fixed with the above commits?

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

defunctzombie avatar Mar 11 '14 20:03 defunctzombie

@defunctzombie can you view your crontab file on the master from the client? Can you verify this with cp.list_master

sudo salt-call cp.list_master

dmyerscough avatar Mar 12 '14 01:03 dmyerscough

local:
    - ...
    - files/crontab

I get that result back with the file shown in the list. Guessing that is as expected?

defunctzombie avatar Mar 12 '14 02:03 defunctzombie

So after applying the patch I think the issue with file not found goes away (when I run salt-call locally on the machine it works) but when I do state.highstate from the master it doesn't until I restart the minion to use the patched version. So it seems the patch did help.

defunctzombie avatar Mar 12 '14 03:03 defunctzombie

So the source file not found issue is now fixed as well?

basepi avatar Mar 13 '14 22:03 basepi

@basepi seems to be

defunctzombie avatar Mar 13 '14 22:03 defunctzombie

Awesome!

basepi avatar Mar 13 '14 22:03 basepi