salt icon indicating copy to clipboard operation
salt copied to clipboard

Exceptions in ini_manage state module during dry run

Open slivik opened this issue 8 years ago • 4 comments

Description of Issue/Question

Every state in state module ini_manage (except for section_absent) throws an Exception during dry run when option without a section is provided no matter what is already in ini file.

Setup

ini-present:
    ini.options_present:
        - name: /tmp/test.ini
        - strict: True
        - sections:
            selfopt1: val1
            sect1:
                sopt1: val11

ini-absent:
    ini.options_absent:
        - name: /tmp/test.ini
        - sections:
            selfopt1: val1
            sect1:
                sopt1: val11

ini-sect-present:
    ini.sections_present:
        - name: /tmp/test.ini
        - sections:
            - sect1
            - sect2

Steps to Reproduce Issue

Command: saltcall --local state.sls dev.ini test=True

Result:

local:
----------
          ID: ini-present
    Function: ini.options_present
        Name: /tmp/test.ini
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/home/js/work/git/salt/salt/state.py", line 1918, in call                                                                                                                           
                  **cdata['kwargs'])                                                                                                                                                                              
                File "/home/js/work/git/salt/salt/loader.py", line 1830, in wrapper                                                                                                                       
                  return f(*args, **kwargs)                                                                                                                                                                       
                File "/home/js/work/git/salt/salt/states/ini_manage.py", line 68, in options_present                                                                                                      
                  if cur_value == six.text_type(sections[section][key]):                                                                                                                                          
              TypeError: string indices must be integers                                                                                                                                                          
     Started: 11:44:26.917548
    Duration: 2.082 ms
     Changes:   
----------
          ID: ini-absent
    Function: ini.options_absent
        Name: /tmp/test.ini
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/home/js/work/git/salt/salt/state.py", line 1918, in call
                  **cdata['kwargs'])
                File "/home/js/work/git/salt/salt/loader.py", line 1830, in wrapper
                  return f(*args, **kwargs)
                File "/home/js/work/git/salt/salt/states/ini_manage.py", line 142, in options_absent
                  cur_section = __salt__['ini.get_section'](name, section, separator)
                File "/home/js/work/git/salt/salt/modules/ini_manage.py", line 159, in get_section
                  for key, value in six.iteritems(inifile.get(section, {})):
                File "/home/js/work/git/salt/salt/ext/six.py", line 606, in iteritems
                  return d.iteritems(**kw)
              AttributeError: 'unicode' object has no attribute 'iteritems'
     Started: 11:44:26.921172
    Duration: 1.063 ms
     Changes:   
----------
          ID: ini-sect-present
    Function: ini.sections_present
        Name: /tmp/test.ini
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/home/js/work/git/salt/salt/state.py", line 1918, in call
                  **cdata['kwargs'])
                File "/home/js/work/git/salt/salt/loader.py", line 1830, in wrapper
                  return f(*args, **kwargs)
                File "/home/js/work/git/salt/salt/states/ini_manage.py", line 207, in sections_present
                  if dict(sections[section]) == cur_section:
              TypeError: list indices must be integers, not unicode
     Started: 11:44:26.923578
    Duration: 0.851 ms
     Changes:   

Versions Report

It is present in all version from 2016.3 for sure (maybe even earlier ones).

Salt Version:                                                                                                                                                                                                     
           Salt: 2018.2.0-427-g279bd98                                                                                                                                                                            
                                                                                                                                                                                                                  
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.10                                                                                                                                                                                             
        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.14 (default, Sep 23 2017, 22:06:14)                                                                                                                                                          
   python-gnupg: Not Installed                                                                                                                                                                                    
         PyYAML: 3.12                                                                                                                                                                                             
          PyZMQ: 17.0.0                                                                                                                                                                                           
           RAET: Not Installed                                                                                                                                                                                    
          smmap: Not Installed                                                                                                                                                                                    
        timelib: Not Installed                                                                                                                                                                                    
        Tornado: 4.5.3                                                                                                                                                                                            
            ZMQ: 4.1.6                                                                                                                                                                                            
                                                                                                                                                                                                                  
System Versions:                                                                                                                                                                                                  
           dist: Ubuntu 17.10 artful                                                                                                                                                                              
         locale: UTF-8                                                                                                                                                                                            
        machine: x86_64                                                                                                                                                                                           
        release: 4.13.0-38-generic                                                                                                                                                                                
         system: Linux                                                                                                                                                                                            
        version: Ubuntu 17.10 artful

slivik avatar May 22 '18 10:05 slivik

Thanks for reporting.

A PR to fix this would be greatly appreciated, otherwise I have marked the core team as owners.

Thanks, Daniel

gtmanfred avatar May 22 '18 15:05 gtmanfred

Yes, I will provide PR soon.

slivik avatar May 22 '18 15:05 slivik

Awesome, thanks!

gtmanfred avatar May 22 '18 16:05 gtmanfred

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[bot] avatar Sep 04 '19 17:09 stale[bot]