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

file.directory state fails if directory contains an invalid symlink #49204

Closed
mchugh19 opened this issue Aug 20, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@mchugh19
Copy link
Contributor

commented Aug 20, 2018

Description of Issue/Question

If a file.directory state is run on a directory which contains a broken symlink, the state crashes.

Setup

test state:

/tmp/dirtest:
  file.directory:
    - user: root
    - group: root
    - mode: 755
    - recurse:
      - user
      - group
      - mode

Steps to Reproduce Issue

Success

# salt-call state.sls dir
local:
----------
          ID: /tmp/dirtest
    Function: file.directory
      Result: True
     Comment: The directory /tmp/dirtest is in the correct state
     Started: 10:34:25.797989
    Duration: 11.287 ms
     Changes:

Summary for local
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:  11.287 ms

Create bad symlink

ln -s /tmp/dirtest/thing /tmp/dirtest/nope

State now crashes

# salt-call state.sls dir
/usr/local/lib/python2.7/dist-packages/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/salt/state.py", line 1905, in call
    **cdata['kwargs'])
  File "/usr/local/lib/python2.7/dist-packages/salt/loader.py", line 1830, in wrapper
    return f(*args, **kwargs)
  File "/var/cache/salt/minion/extmods/states/file.py", line 3421, in directory
    full, ret, user, group, file_mode, None, follow_symlinks)
  File "/usr/local/lib/python2.7/dist-packages/salt/modules/file.py", line 4460, in check_perms
    lattrs = lsattr(name)
  File "/usr/local/lib/python2.7/dist-packages/salt/modules/file.py", line 564, in lsattr
    raise SaltInvocationError("File or directory does not exist.")
SaltInvocationError: File or directory does not exist.

local:
----------
          ID: /tmp/dirtest
    Function: file.directory
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/local/lib/python2.7/dist-packages/salt/state.py", line 1905, in call
                  **cdata['kwargs'])
                File "/usr/local/lib/python2.7/dist-packages/salt/loader.py", line 1830, in wrapper
                  return f(*args, **kwargs)
                File "/var/cache/salt/minion/extmods/states/file.py", line 3421, in directory
                  full, ret, user, group, file_mode, None, follow_symlinks)
                File "/usr/local/lib/python2.7/dist-packages/salt/modules/file.py", line 4460, in check_perms
                  lattrs = lsattr(name)
                File "/usr/local/lib/python2.7/dist-packages/salt/modules/file.py", line 564, in lsattr
                  raise SaltInvocationError("File or directory does not exist.")
              SaltInvocationError: File or directory does not exist.
     Started: 10:34:39.631296
    Duration: 27.711 ms
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:  27.711 ms

Versions Report

Salt Version:
           Salt: 2018.3.1

Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.5.0
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 17.0.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 5.0.2
            ZMQ: 4.1.6

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-130-generic
         system: Linux
        version: Ubuntu 16.04 xenial
@gtmanfred

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2018

I hate that lsattr function.

Thanks for reporting this, if you had time to fix it, we would greatly appreciate it, probably could get away with just catching that exception in a try: except: block.

Otherwise we will get it fixed.

Thanks!
Daniel

@gtmanfred

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2018

Actually, fixed here.

#49209

@gtmanfred

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2018

The fix has been merged.

Thanks for reporting.
Daniel

@gtmanfred gtmanfred closed this Aug 20, 2018

dgmorrisjr pushed a commit to dgmorrisjr/salt that referenced this issue Sep 28, 2018

cachedout pushed a commit that referenced this issue Sep 30, 2018

Mike Place
Merge pull request #49827 from dgmorrisjr/fix_modules_file
fixing mis-spelling of lattrs in file.py, referncing #49204

rallytime added a commit to rallytime/salt that referenced this issue Oct 1, 2018

gitebra pushed a commit to gitebra/salt that referenced this issue Oct 2, 2018

Merge remote-tracking branch 'upstream/develop' into develop
* upstream/develop: (379 commits)
  Update unit test to match expected behavior change.
  Couple lint fixes.
  Adding some tests for the vault execution module.
  Don't return False when target exists. (Fixes: saltstack#49748)
  Option print_result should be true by default
  Adding some changes for the status
  referncing saltstack#49204, fixing mis-spelling of lattrs on line 4514 per request from @gtmanfred
  Updating syntax to be better and with new lines
  Skip test_local_pkg_install for now: this is causing the test suite to hang
  Skip test_local_pkg_install for now: this is causing the test suite to hang
  Adding timeout to all pipelines so that the build aborts
  Removed blacklist of pkg_resources
  Remove development stub. Ughh...
  Lintfix: mute fopen warning
  Lintfix: explicitly close filehandle
  Mute pylint: file handler explicitly needed
  Fix six import
  Fix unit tests
  Lintfix: use salt.utils.files.fopen instead of open
  Lintfix: Uses of an external blacklisted import 'six': Please use 'import salt.ext.six as six'
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.