From 8bafb75abfce6504660f87af6198d1cb1c10bf5b Mon Sep 17 00:00:00 2001 From: Michal Bocek Date: Fri, 14 Mar 2025 23:39:04 +0100 Subject: [PATCH] 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: "%" The solution is to disable interpreting the % character as a sign for string replacement. Related: https://access.redhat.com/solutions/7107977 --- convert2rhel/toolopts/config.py | 10 +++++++++- convert2rhel/unit_tests/toolopts/config_test.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/convert2rhel/toolopts/config.py b/convert2rhel/toolopts/config.py index 8c6cac6635..73c50c38e3 100644 --- a/convert2rhel/toolopts/config.py +++ b/convert2rhel/toolopts/config.py @@ -20,6 +20,7 @@ import copy import logging import os +from sys import version_info import six @@ -151,7 +152,14 @@ def _parse_options_from_config(self, paths): them. :type paths: list[str] """ - config_file = configparser.ConfigParser() + + # The reason for using the RawConfigParser and ConfigParser with interpolation set to None is to prevent + # interpreting % as a sign for string replacement. This interpolation feature would cause convert2rhel to fail + # if the user enters the % character in the config file, for example in the RHSM password. + if version_info.major < 3: + config_file = configparser.RawConfigParser() + else: + config_file = configparser.ConfigParser(interpolation=None) found_opts = {} for path in reversed(paths): diff --git a/convert2rhel/unit_tests/toolopts/config_test.py b/convert2rhel/unit_tests/toolopts/config_test.py index 5762669014..26a6ac51f6 100644 --- a/convert2rhel/unit_tests/toolopts/config_test.py +++ b/convert2rhel/unit_tests/toolopts/config_test.py @@ -86,9 +86,9 @@ def test_options_from_config_files_invalid_head_and_options(self, content, expec ( """\ [subscription_manager] -password = correct_password +password = %correct_password% """, - {"password": "correct_password"}, + {"password": "%correct_password%"}, ), ( """\