Skip to content

Commit 64c14d5

Browse files
committed
Allow using % character in convert2rhel.ini
Whenever a user entered the % character in the convert2rhel.ini config file, such as in the RHSM password, convert2rhel failed with an error: configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: "%<STRING>" The solution is to disable interpreting the % character as a sign for string replacement. Related: https://access.redhat.com/solutions/7107977
1 parent a35864d commit 64c14d5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

convert2rhel/toolopts/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import copy
2121
import logging
2222
import os
23+
from sys import version_info
2324

2425
import six
2526

@@ -151,7 +152,14 @@ def _parse_options_from_config(self, paths):
151152
them.
152153
:type paths: list[str]
153154
"""
154-
config_file = configparser.ConfigParser()
155+
156+
# The reason for using the RawConfigParser and ConfigParser with interpolation set to None is to prevent
157+
# interpreting % as a sign for string replacement. This interpolation feature would cause convert2rhel to fail
158+
# if the user enters the % character in the config file, for example in the RHSM password.
159+
if version_info.major < 3:
160+
config_file = configparser.RawConfigParser()
161+
else:
162+
config_file = configparser.ConfigParser(interpolation=None)
155163
found_opts = {}
156164

157165
for path in reversed(paths):

convert2rhel/unit_tests/toolopts/config_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def test_options_from_config_files_invalid_head_and_options(self, content, expec
8686
(
8787
"""\
8888
[subscription_manager]
89-
password = correct_password
89+
password = %correct_password%
9090
""",
91-
{"password": "correct_password"},
91+
{"password": "%correct_password%"},
9292
),
9393
(
9494
"""\

0 commit comments

Comments
 (0)