Red Hat Bugzilla – Bug 967129
add support for inline comments
Last modified: 2016-04-22 01:04:06 EDT
Description of problem:
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. openstack-config --set /etc/keystone/keystone.conf DEFAULT compute_port "3000 # Evil"
$ /etc/init.d/openstack-keystone restart
Stopping keystone: [FAILED]
Starting keystone: [ OK ]
$ /etc/init.d/openstack-keystone status
keystone dead but pid file exists
service do not start, nothing in log
service started or error in log
The standard python ini parsing libs support inline comments,
but only with ; as the comment delimeter. It seems the standard
windows ini parse doesn't even allow that.
Looking at the example.ini from the crudini project we see
comment_after1=val ;a comment
comment_after2=val;not a comment
comment_after3=val #not a comment
The # is not usable in an inline comment for "backwards compat" reasons according to the python docs. So I would say the particular use case is catered for here by:
openstack-config --set /etc/keystone/keystone.conf DEFAULT compute_port "3000 ;Evil"
But having a quick look at the code suggests that even ; isn't supported unless at the start of the line, since: https://review.openstack.org/#/c/5375/
It's a pity the existing stdlib parser couldn't be extended somehow to
Another option is to add the --comment option to openstack-config (or more likely crudini), that would add the associated option on an adjacent line.
The hack to set the comment as part of the --set value is not good,
because that would repeat comments for existing values.
I'm not sure it's appropriate at this stage to change the config file format upstream to support inline comments, given how non standard this is
anyway as noted in comment #1
The best option woule be to abstract the file representation,
using a --comment option in crudini, which would update comments,
probably on a separate line.