Inline ini comments are parsed along value

Bug #1999144 reported by Medhy DOHOU
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.config
Won't Fix
Undecided
Unassigned

Bug Description

During my usage of cloudbase-init (https://github.com/cloudbase/cloudbase-init), I encountered a bug, where oslo.config would parse the value of the setting, alongside with the inline comment.

2022-11-25 15:25:18.360 1820 ERROR cloudbaseinit.init [-] plugin 'SetUserPasswordPlugin' failed with error 'Value for option inject_user_password from LocationInfo(location=<Locations.user: (4, True)>, detail='C:\\Program Files\\Cloudbase Solutions\\Cloudbase-Init\\conf\\cloudbase-init.conf') is not valid: Unexpected boolean value 'True # Use password from the metadata (not random).'': oslo_config.cfg.ConfigFileValueError: Value for option inject_user_password from LocationInfo(location=<Locations.user: (4, True)>, detail='C:\\Program Files\\Cloudbase Solutions\\Cloudbase-Init\\conf\\cloudbase-init.conf') is not valid: Unexpected boolean value 'True # Use password from the metadata (not random).'
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init [-] Value for option inject_user_password from LocationInfo(location=<Locations.user: (4, True)>, detail='C:\\Program Files\\Cloudbase Solutions\\Cloudbase-Init\\conf\\cloudbase-init.conf') is not valid: Unexpected boolean value 'True # Use password from the metadata (not random).': oslo_config.cfg.ConfigFileValueError: Value for option inject_user_password from LocationInfo(location=<Locations.user: (4, True)>, detail='C:\\Program Files\\Cloudbase Solutions\\Cloudbase-Init\\conf\\cloudbase-init.conf') is not valid: Unexpected boolean value 'True # Use password from the metadata (not random).'
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init Traceback (most recent call last):
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\oslo_config\cfg.py", line 2694, in _do_get
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init return (convert(val), alt_loc)
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\oslo_config\cfg.py", line 2664, in convert
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init self._substitute(value, group, namespace), opt)
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\oslo_config\cfg.py", line 2791, in _convert_value
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init return opt.type(value)
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\oslo_config\types.py", line 250, in __call__
2022-11-25 15:25:18.439 1820 ERROR cloudbaseinit.init raise ValueError('Unexpected boolean value %r' % value)

Although INI files don't have a defined specification or RFC, I think inline comments are valuable, and the library could benefit from them.

I am willing to create a fix for that, if necessary.

Revision history for this message
Takashi Kajinami (kajinamit) wrote :

I don't think inline comment support is such common. For example configparser in python does not support it either.

$ cat test.ini
[foo]
key1=val1
key2=val2 # comment
$ python
Python 3.11.7 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231011 (Red Hat 13.2.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import configparser
>>> parser = configparser.ConfigParser()
>>> parser.read('test.ini')
['test.ini']
>>> parser.sections()
['foo']
>>> parser['foo']
<Section: foo>
>>> parser['foo']['key1']
'val1'
>>> parser['foo']['key2']
'val2 # comment'
>>>

Users can put comments in separate lines.

Revision history for this message
Takashi Kajinami (kajinamit) wrote :

crudini, which is another common tool to parse ini file, does not support inline comments.

$ crudini --get test.ini foo key1
val1
$ crudini --get test.ini foo key2
val2 # comment

Revision history for this message
Takashi Kajinami (kajinamit) wrote :

Based on the fact this is not supported in common tools/libraries I'm closing this RFE.
I don't think adding that uncommon support does not bring much benefit (because users can use the legit alternative approach) while it can bring different problems (for example when a value actually need to contain #).

Changed in oslo.config:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.