Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
luizsilva opened this issue Feb 21, 2014 · 19 comments
Closed
Labels
Bug broken, incorrect, or confusing behavior Regression The issue is a bug that breaks functionality known to work in previous releases. severity-low 4th level, cosemtic problems, work around exists

Comments

@luizsilva
Copy link

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.

@basepi
Copy link
Contributor

basepi commented Feb 21, 2014

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

@basepi basepi added this to the Outstanding Bugs milestone Feb 21, 2014
@dmyerscough
Copy link
Contributor

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

@luizsilva
Copy link
Author

@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 luizsilva reopened this Feb 24, 2014
@luizsilva
Copy link
Author

Sorry, clicked "close" by mistake.

@dmyerscough
Copy link
Contributor

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

@defunctzombie
Copy link

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.

@JensRantil
Copy link
Contributor

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

@fsniper
Copy link

fsniper commented Mar 11, 2014

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
Copy link

fsniper commented Mar 11, 2014

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
Copy link

fsniper commented Mar 11, 2014

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

s0undt3ch added a commit that referenced this issue Mar 11, 2014
Fix for #10656: __env__ should be passed around instead of env
@JensRantil
Copy link
Contributor

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

I can confirm that the workaround worked for me.

@basepi
Copy link
Contributor

basepi commented Mar 11, 2014

Is this issue fixed with the above commits?

@defunctzombie
Copy link

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" notifications@github.com wrote:

Is this issue fixed with the above commits?

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

@dmyerscough
Copy link
Contributor

@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

@defunctzombie
Copy link

local:
    - ...
    - files/crontab

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

@defunctzombie
Copy link

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.

@basepi
Copy link
Contributor

basepi commented Mar 13, 2014

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

@defunctzombie
Copy link

@basepi seems to be

@basepi
Copy link
Contributor

basepi commented Mar 13, 2014

Awesome!

@basepi basepi closed this as completed Mar 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Regression The issue is a bug that breaks functionality known to work in previous releases. severity-low 4th level, cosemtic problems, work around exists
Projects
None yet
Development

No branches or pull requests

6 participants