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

pip.install's log param should permit a new file to be created #44722

Open
corywright opened this issue Nov 28, 2017 · 7 comments
Open

pip.install's log param should permit a new file to be created #44722

corywright opened this issue Nov 28, 2017 · 7 comments
Assignees
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Execution-Module severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around

Comments

@corywright
Copy link
Contributor

Description of Issue/Question

When using the pip.installed state and specifying a log parameter the state will fail if the log file does not yet exist. If the log file does not exist and the parent directory is writable then pip.installed should create the file.

The issue is in the underlying pip.install execution module function.

Setup / Steps to Reproduce Issue

I'm trying to install Gnocchi via pip:

gnocchi:
  pip.installed:
    - name: gnocchi[keystone,postgresql,redis]=={{ gnocchi_version }}
    - bin_env: /opt/gnocchi/gnocchi-{{ gnocchi_version }}/bin/pip
    - log: /opt/gnocchi/pip-install-gnocchi-{{ gnocchi_version }}.log

I want to be able to dynamically create a new log file during each pip install. The above should create a /opt/gnocchi/pip-install-gnocchi-{{ gnocchi_version }}.log log file during a highstate, but it does not, and fails with the following error:

----------
      ID: gnocchi
Function: pip.installed
    Name: gnocchi[keystone,postgresql,redis]==4.1.1
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1750, in call
              **cdata['kwargs'])
            File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1705, in wrapper
              return f(*args, **kwargs)
            File "/usr/lib/python2.7/dist-packages/salt/states/pip_state.py", line 708, in installed
              no_cache_dir=no_cache_dir
            File "/usr/lib/python2.7/dist-packages/salt/modules/pip.py", line 602, in install
              raise IOError('\'{0}\' is not writeable'.format(log))
          IOError: '/opt/gnocchi/pip-install-gnocchi-4.1.1.log' is not writeable
 Started: 21:17:32.850211
Duration: 672.218 ms
 Changes:   
----------

If I simply touch the log file before highstating then it succeeds:

# touch /opt/gnocchi/pip-install-gnocchi-4.1.1.log

The problem seems to have been introduced with PR #29470, which added permission checks to pip.install. The check verifies write access to an existing file, but does not check if the file exists or not. There should be an additional check to see if the file does not exist and then verify that the parent directory is writable.

if log:
    if os.path.isdir(log):
        raise IOError(
            '\'{0}\' is a directory. Use --log path_to_file'.format(log))
    elif not os.access(log, os.W_OK):
        raise IOError('\'{0}\' is not writeable'.format(log))

Versions Report

I'm on 2016.11 but the issue exists in develop as well.

Salt Version:
           Salt: 2016.11.7
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.2.2
       dateutil: 1.5
      docker-py: Not Installed
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 0.9.1
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.2.3
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.0.1
           RAET: Not Installed
          smmap: 0.8.2
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
 
System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 3.16.0-77-generic
         system: Linux
        version: Ubuntu 14.04 trusty
@gtmanfred gtmanfred added Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Execution-Module severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around P2 Priority 2 team-core labels Nov 29, 2017
@gtmanfred gtmanfred added this to the Approved milestone Nov 29, 2017
@gtmanfred
Copy link
Contributor

gtmanfred commented Nov 29, 2017

Yikes.

That seems like a totally reasonable path to make this work.

Would you mind submitting a PR to fix this?

Thanks,
Daniel

@corywright
Copy link
Contributor Author

@gtmanfred Sure, I need to finish the project I'm working on and then I'll get a PR submitted.

@gtmanfred
Copy link
Contributor

Awesome!

Much appreciated!

Daniel

@stale
Copy link

stale bot commented Mar 24, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Mar 24, 2019
@corywright
Copy link
Contributor Author

Commenting to keep this issue open.

@stale
Copy link

stale bot commented Mar 25, 2019

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Mar 25, 2019
@sushantkumr
Copy link

Hey ! Is there any progress on this issue? This seems to be affecting us as well.

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 Core relates to code central or existential to Salt Execution-Module severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

5 participants