config_template fails to parse template if it contains a comment with leading spaces

Bug #1755821 reported by Mohammed Naser
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack-Ansible
Fix Released
High
Jean-Philippe Evrard

Bug Description

If you use config_template with a template which contains leading spaces in a comment before the first section, for example

"""
  # foo
[DEFAULT]
foo=bar
"""

The above will fail to parse because of the spaces, however, the following should work:

"""
# foo
[DEFAULT]
foo=bar
"""

config_template should be able to gracefully handle these cases, though, it seems that the issue stems from ConfigParser not liking that behaviour.

Changed in openstack-ansible:
importance: Undecided → High
assignee: nobody → Kevin Carter (kevin-carter)
Changed in openstack-ansible:
assignee: Kevin Carter (kevin-carter) → nobody
Changed in openstack-ansible:
assignee: nobody → Jean-Philippe Evrard (jean-philippe-evrard)
status: New → Confirmed
Revision history for this message
Sam Choraria (samc-bbc) wrote :

In trying to address this bug we found that Pythons ConfigParser
module will not parse an input file with an indented comment line
with leading whitespace before the first section header.

We added a valid test case to `test_with_comments.ini`
which could be loaded by the ansible-config_template
module with minor changes, but subsequent ini lookup
tests fail due to Pythons ConfigParser.

We think allowing ansible-config_template to parse files
with indented comment lines with leading whitespace will cause
ansible ini lookups to fail.

>>> import ConfigParser, os
>>> config = ConfigParser.ConfigParser()
>>> config.readfp(open('/tmp/test_with_comments.ini'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/ConfigParser.py", line 324, in readfp
    self._read(fp, filename)
  File "/usr/lib/python2.7/ConfigParser.py", line 512, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
ConfigParser.MissingSectionHeaderError: File contains no section headers.
file: /tmp/test_with_comments.ini, line: 1

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to ansible-config_template (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/636935

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to openstack-ansible-plugins (stable/rocky)

Fix proposed to branch: stable/rocky
Review: https://review.openstack.org/637495

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to ansible-config_template (master)

Reviewed: https://review.openstack.org/636935
Committed: https://git.openstack.org/cgit/openstack/ansible-config_template/commit/?id=66a97f2b403252d2b6f8aaa38f17deccbd753b4c
Submitter: Zuul
Branch: master

commit 66a97f2b403252d2b6f8aaa38f17deccbd753b4c
Author: Georgina Shippey <email address hidden>
Date: Thu Feb 14 11:50:50 2019 +0000

    Remove whitespace before comments

    Python 2.7 ConfigParser does not accept whitespace before comments.
    To keep config files produced by ansible-config_temple parsable
    we will strip out the whitespace preceding comments.

    Change-Id: I39c88578d0a9e42fded7410d7eb4ec8bd415550c
    Related-Bug: #1755821

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to openstack-ansible-plugins (stable/rocky)

Reviewed: https://review.openstack.org/637495
Committed: https://git.openstack.org/cgit/openstack/openstack-ansible-plugins/commit/?id=43d2ef6a000c44da3358e2dd0d7c04db68c9b1a9
Submitter: Zuul
Branch: stable/rocky

commit 43d2ef6a000c44da3358e2dd0d7c04db68c9b1a9
Author: Georgina Shippey <email address hidden>
Date: Mon Feb 18 08:54:38 2019 +0000

    Remove whitespace before comments

    Python 2.7 ConfigParser does not accept whitespace before comments.
    To keep config files produced by ansible-config_temple parsable
    we will strip out the whitespace preceding comments.

    Change-Id: Ie1236c4c44dc39c7172b7a02afe9c35d92ee9e0a
    Closes-Bug: #1755821

tags: added: in-stable-rocky
Changed in openstack-ansible:
status: Confirmed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/openstack-ansible-plugins rocky-eol

This issue was fixed in the openstack/openstack-ansible-plugins rocky-eol release.

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.