salt icon indicating copy to clipboard operation
salt copied to clipboard

ini.options_present uses DEFAULT_IMPLICIT as a literal section name

Open giannello opened this issue 10 years ago • 6 comments

Description of Issue/Question

With 2016.6.3, ini.options_present doesn't work as expected when DEFAULT_IMPLICIT is used as section name.

Setup

The following code used to work:

test:
  ini.options_present:
    - name: /tmp/test
    - sections:
        DEFAULT_IMPLICIT:
          TEST: 'AAA'

and created a file with

TEST = AAA

Now the file is created as

[DEFAULT_IMPLICIT]
TEST = AAA

Removing DEFAULT_IMPLICIT as section makes it work again

test:
  ini.options_present:
    - name: /tmp/test
    - sections:
        TEST: 'AAA'

giannello avatar Jun 01 '16 13:06 giannello

@giannello looks like this was changed on purpose according to this issue: #16294

Looks liek it would be useful to update the documentation though. I'll add it as a documentation bug.

Ch3LL avatar Jun 01 '16 21:06 Ch3LL

Got hit by this too (is the +1 from github taken into account?)

arthurzenika avatar Jan 27 '17 15:01 arthurzenika

Oh, and I get the following bug in test=True

    Function: ini.options_present
      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 1733, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1653, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/states/ini_manage.py", line 53, in options_present
                  cur_value = __salt__['ini.get_option'](name, section, key)
                File "/usr/lib/python2.7/dist-packages/salt/modules/ini_manage.py", line 99, in get_option
                  return inifile.get(section, {}).get(option, None)
              AttributeError: 'str' object has no attribute 'get'
     Started: 16:59:09.469528
    Duration: 4.075 ms
     Changes:   

arthurzenika avatar Jan 27 '17 16:01 arthurzenika

ping @Akilesh1597

arthurzenika avatar Jun 07 '17 14:06 arthurzenika

I suspect that this is because the get_option function doesn't handle the "no sections" case:

https://github.com/Akilesh1597/salt/blob/develop/salt/modules/ini_manage.py#L79

It looks like other functions there may also fail to cope with this.

Orlando-Richards avatar Jan 25 '18 11:01 Orlando-Richards

This should have been fixed by 479c8dee

mtorromeo avatar Jun 18 '18 10:06 mtorromeo