Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-62701

Invalid dnf.conf leads to a traceback

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Undefined Undefined
    • None
    • rhel-8.10.z
    • leapp-repository
    • None
    • No
    • Low
    • rhel-sst-upgrades
    • None
    • False
    • Hide

      None

      Show
      None
    • None
    • None
    • None
    • None
    • All
    • None

      What were you trying to do that didn't work?

      During 7>8 upgrade, our customer had an empty dnf.conf leading to a traceback when leapp tried to run the `dnf config-manager --setopt` command.

      This issue can happen when `/etc/dnf/dnf.conf` is empty or does not contain a '[main]' section, the same can happen when a customer created an empty `/etc/leapp/files/dnf.conf`.

      What is the impact of this issue to you?

      Since DNF is able to work with an empty file, the customer cannot easily understand where the problem comes from.

      Please provide the package NVR for which the bug is seen:

      leapp-upgrade-el8toel9-0.20.0-2.el8

      How reproducible is this bug?:

      Always

      Steps to reproduce

      1. echo > /etc/dnf/dnf.conf
      2. leapp preupgrade

      Expected results

      Works

      Actual results

      Actor dnf_transaction_check has crashed: Traceback (most recent call last):
        File "/usr/lib/python2.7/site-packages/leapp/repository/actor_definition.py", line 74, in _do_run
          actor_instance.run(*args, **kwargs)
        File "/usr/lib/python2.7/site-packages/leapp/actors/__init__.py", line 289, in run
          self.process(*args)
        File "/usr/share/leapp-repository/repositories/system_upgrade/common/actors/dnftransactioncheck/actor.py", line 47, in process
          xfs_info=xfs_info, storage_info=storage_info, plugin_info=plugin_info, target_iso=target_iso
        File "/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/dnfplugin.py", line 498, in perform_transaction_check
          dnfconfig.exclude_leapp_rpms(context, disable_plugins)
        File "/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/dnfconfig.py", line 126, in exclude_leapp_rpms
          _set_excluded_pkgs(context, to_exclude, disable_plugins)
        File "/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/dnfconfig.py", line 107, in _set_excluded_pkgs
          context.call(cmd)
        File "/usr/share/leapp-repository/repositories/system_upgrade/common/libraries/mounting.py", line 168, in call
          return run(self.type.make_command(cmd), *args, **kwargs)
        File "/usr/lib/python2.7/site-packages/leapp/libraries/stdlib/__init__.py", line 192, in run
          result=result
      CalledProcessError: Command ['systemd-nspawn', '--register=no', '--quiet', '-D', u'/var/lib/leapp/el8userspace', '--setenv=LEAPP_UPGRADE_PATH_TARGET_RELEASE=8.10', '--setenv=LEAPP_NO_RHSM=0', '--setenv=LEAPP_EXPERIMENTAL=0', '--setenv=LEAPP_TARGET_PRODUCT_CHANNEL=ga', '--setenv=LEAPP_UPGRADE_PATH_FLAVOUR=default', '--setenv=LEAPP_COMMON_TOOLS=:/etc/leapp/repos.d/system_upgrade/common/tools:/etc/leapp/repos.d/system_upgrade/el7toel8/tools', '--setenv=LEAPP_COMMON_FILES=:/etc/leapp/repos.d/system_upgrade/common/files:/etc/leapp/repos.d/system_upgrade/el7toel8/files', '--setenv=LEAPP_IPU_IN_PROGRESS=7to8', '--setenv=LEAPP_UNSUPPORTED=0', '--setenv=LEAPP_EXECUTION_ID=3a5acdd4-8c8e-43eb-893b-70bcca3dee92', '--setenv=LEAPP_HOSTNAME=hpy-pdc-srv-1433', 'dnf', 'config-manager', '--save', '--setopt', 'exclude=python2-leapp,snactor,leapp-upgrade-el7toel8,leapp'] failed with exit code 1. 

      Workaround

      Restore the default one:

      # cat << EOF > /etc/dnf/dnf.conf
      [main]
      gpgcheck=1
      installonly_limit=3
      clean_requirements_on_remove=True
      EOF 

      Suggested fix (minimal)

      --- /usr/share/leapp-repository/repositories/system_upgrade/common/libraries/dnfconfig.py    2024-06-10 21:05:16.000000000 -0400
      +++ /usr/share/leapp-repository/repositories/system_upgrade/common/libraries/dnfconfig.py.fix    2024-10-15 04:17:07.543394666 -0400
      @@ -30,6 +30,28 @@
           return [item.strip() for item in data.split(sep, maxsplit)]
       
       
      +def _check_dnf_conf_file(context):
      +    """
      +    Minimal check on /etc/dnf/dnf.conf
      +    """
      +    check_failed = False
      +    try:
      +        with context.open('/etc/dnf/dnf.conf') as f:
      +            data = f.read()
      +    except IOError:
      +        check_failed = True
      +
      +    if not check_failed and '[main]' not in data:
      +        check_failed = True
      +
      +    if check_failed:
      +        api.current_logger().error('Cannot parse /etc/dnf/dnf.conf')
      +        raise StopActorExecutionError(
      +            message='Cannot parse /etc/dnf/dnf.conf'
      +        )
      +
      +
       def _get_main_dump(context, disable_plugins):
           """
           Return the dnf configuration dump of main options for the given context.
      @@ -86,6 +108,7 @@
           It shouldn't be used on the source system. It is expected this functions
           is called only in the target userspace container or on the target system.
           """
      +    _check_dnf_conf_file(context)
           pkgs = _strip_split(_get_main_dump(context, disable_plugins).get('exclude', ''), ',')
           return [i for i in pkgs if i]
       

       

              leapp-notifications leapp-notifications
              rhn-support-cbesson Christophe Besson
              leapp-notifications leapp-notifications
              RHEL Upgrades QE Team RHEL Upgrades QE Team
              Miriam Portman Miriam Portman
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated: