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

ini.options_present will crash if there is nothing to change #43388

Closed
ikoruk opened this issue Sep 7, 2017 · 5 comments
Closed

ini.options_present will crash if there is nothing to change #43388

ikoruk opened this issue Sep 7, 2017 · 5 comments
Labels
Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix MacOS pertains to the OS of fruit P2 Priority 2 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@ikoruk
Copy link

ikoruk commented Sep 7, 2017

Description of Issue/Question

When running ini.options_present on MacOS, if the keys are different or don't exist, the command will work as expected. However, when running again with no changes needed it crashes with this trace:

          ID: Test
    Function: ini.options_present
        Name: /Users/--/test.ini
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/local/Cellar/saltstack/2017.7.1/libexec/lib/python2.7/site-packages/salt/state.py", line 1837, in call
                  **cdata['kwargs'])
                File "/usr/local/Cellar/saltstack/2017.7.1/libexec/lib/python2.7/site-packages/salt/loader.py", line 1794, in wrapper
                  return f(*args, **kwargs)
                File "/usr/local/Cellar/saltstack/2017.7.1/libexec/lib/python2.7/site-packages/salt/states/ini_manage.py", line 90, in options_present
                  __salt__['ini.set_option'](name, {section_name: section_body}, separator)[section_name])
              KeyError: 'test'
     Started: 16:15:13.835260
    Duration: 0.997 ms
     Changes:

Setup

Test:
  ini.options_present:
    - name: /Users/--/test.ini
    - sections:
        test:
          'a': 'aa'

Steps to Reproduce Issue

$ touch ~/test.ini
Then using salt-call on the sls above, first time it is successful. Second time the crash as above.

Versions Report

Salt Version:
           Salt: 2017.7.1

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.9.6
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.10 (default, Feb  7 2017, 00:08:15)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.1
            ZMQ: 4.2.2

System Versions:
           dist:
         locale: UTF-8
        machine: x86_64
        release: 16.7.0
         system: Darwin
        version: 10.12.6 x86_64
@garethgreenaway garethgreenaway added this to the Approved milestone Sep 7, 2017
@garethgreenaway garethgreenaway added Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around P2 Priority 2 MacOS pertains to the OS of fruit labels Sep 7, 2017
@garethgreenaway
Copy link
Contributor

@ikoruk Thanks for the report. I haven't been able to reproduce this issue so I suspect it's only happening on MacOS. Have you managed to reproduce it anywhere else?

@zomeck
Copy link

zomeck commented Sep 8, 2017

I can reproduce using Ubuntu Xenial (using 2017.7.1 installed through pip).

Doing as described I get the following stacktrace when no changes need to be applied to the file:

[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/salt/state.py", line 1837, in call
    **cdata['kwargs'])
  File "/usr/local/lib/python2.7/dist-packages/salt/loader.py", line 1794, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/salt/states/ini_manage.py", line 90, in options_present
    __salt__['ini.set_option'](name, {section_name: section_body}, separator)[section_name])
KeyError: 'test'

local:
----------
          ID: Test
    Function: ini.options_present
        Name: /home/user/test.ini
      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 1837, in call
                  **cdata['kwargs'])
                File "/usr/local/lib/python2.7/dist-packages/salt/loader.py", line 1794, in wrapper
                  return f(*args, **kwargs)
                File "/usr/local/lib/python2.7/dist-packages/salt/states/ini_manage.py", line 90, in options_present
                  __salt__['ini.set_option'](name, {section_name: section_body}, separator)[section_name])
              KeyError: 'test'
     Started: 09:20:17.596333
    Duration: 1.768 ms
     Changes:   

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

Here you can see my versions report:

Salt Version:
           Salt: 2017.7.1
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: 1.10.6
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.1
            ZMQ: 4.1.6
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-93-generic
         system: Linux
        version: Ubuntu 16.04 xenial
 

I also managed to reproduce using docker with debian and alpine. Here are the 2 Dockerfiles that I used:

FROM alpine:latest

RUN apk update

RUN apk add --no-cache python
RUN python -m ensurepip

RUN apk add g++ gcc python-dev

RUN pip install salt
FROM debian:latest

RUN apt update

RUN apt install python python-pip -y

RUN pip install salt

@gulbinas
Copy link

gulbinas commented Sep 14, 2017

i get very same error on ubuntu 16.04

ini.options_present fails when there is no changes

           Salt: 2017.7.1

Dependency Versions:
           cffi: 1.5.2
       cherrypy: 3.2.3
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: 0.24.0
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.24.0
         Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-1031-aws
         system: Linux
        version: Ubuntu 16.04 xenial

also looks like problem has been fixed: 9478729

@rallytime
Copy link
Contributor

Thanks for tracking that down @gulbinas. That change was back-ported to the 2017.7 branch after the fix went into develop. The fix will be included in the upcoming 2017.7.2 release.

@ikoruk Do you think this issue can be closed?

@rallytime rallytime added the fixed-pls-verify fix is linked, bug author to confirm fix label Sep 14, 2017
@ikoruk
Copy link
Author

ikoruk commented Sep 19, 2017

Good for me.

@ikoruk ikoruk closed this as completed Sep 19, 2017
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 fixed-pls-verify fix is linked, bug author to confirm fix MacOS pertains to the OS of fruit P2 Priority 2 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