Bug 2176149

Summary: [leapp] UnicodeDecodeError: 'ascii' codec can't decode byte during the DNF transaction actor
Product: Red Hat Enterprise Linux 7 Reporter: Christophe Besson <cbesson>
Component: leapp-repositoryAssignee: Leapp Notifications Bot <leapp-notifications-bot>
Status: NEW --- QA Contact: upgrades-and-conversions
Severity: medium Docs Contact:
Priority: low    
Version: 7.9CC: pstodulk
Target Milestone: rcKeywords: WorkAround
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Christophe Besson 2023-03-07 14:15:03 UTC
Description of problem:
An error occurred just after the DNF transaction, leading to the emergency shell.
It seems to fail while trying to remove the target userspace directory in using shutil.rmtree().
Rebooting shows a RHEL 8 OS without post-upgrade actions which was problematic (Satellite server here).

Version-Release number of selected component (if applicable):
leapp-upgrade-el7toel8-0.17.0-1.el7_9

How reproducible:
Always for the customer. Unable to reproduce internally.

Actual results:
[ 1617.173425] localhost upgrade[2241]:   tfm-rubygem-thor-1.0.1-3.el7sat.noarch
[ 1622.741102] localhost upgrade[2241]:   tfm-rubygem-thread_safe-0.3.6-6.el7sat.noarch              Process Process-216:
[ 1622.741102] localhost upgrade[2241]: Traceback (most recent call last):
[ 1622.743537] localhost upgrade[2241]:   File "/usr/lib64/python2.7/multiprocessing/process.py", line 258, in _bootstrap
[ 1622.743537] localhost upgrade[2241]:     sys.stdin.close()
[ 1622.743537] localhost upgrade[2241]:   File "/usr/lib64/python2.7/multiprocessing/process.py", line 114, in run
[ 1622.743537] localhost upgrade[2241]:     self._target(*self._args, **self._kwargs)
[ 1622.743537] localhost upgrade[2241]:   File "/usr/lib/python2.7/site-packages/leapp/repository/actor_definition.py", line 72, in _do_run
[ 1622.746925] localhost upgrade[2241]:     actor_instance.run(*args, **kwargs)
[ 1622.746925] localhost upgrade[2241]:   File "/usr/lib/python2.7/site-packages/leapp/actors/__init__.py", line 289, in run
[ 1622.746925] localhost upgrade[2241]:     self.process(*args)
[ 1622.746925] localhost upgrade[2241]:   File "/usr/share/leapp-repository/repositories/system_upgrade/common/actors/dnfupgradetransaction/actor.py", line 60, in process
[ 1622.749744] localhost upgrade[2241]:     shutil.rmtree(userspace.path)
[ 1622.749744] localhost upgrade[2241]:   File "/usr/lib64/python2.7/shutil.py", line 247, in rmtree
[ 1622.749744] localhost upgrade[2241]:     elif onerror is None:
[ 1622.749744] localhost upgrade[2241]:   File "/usr/lib64/python2.7/shutil.py", line 247, in rmtree
[ 1622.749744] localhost upgrade[2241]:     elif onerror is None:
[ 1622.749744] localhost upgrade[2241]:   File "/usr/lib64/python2.7/shutil.py", line 247, in rmtree
[ 1622.749744] localhost upgrade[2241]:     elif onerror is None:
[ 1622.749744] localhost upgrade[2241]:   File "/usr/lib64/python2.7/shutil.py", line 247, in rmtree
[ 1622.749744] localhost upgrade[2241]:     elif onerror is None:
[ 1622.749744] localhost upgrade[2241]:   File "/usr/lib64/python2.7/shutil.py", line 247, in rmtree
[ 1622.749744] localhost upgrade[2241]:     elif onerror is None:
[ 1622.749744] localhost upgrade[2241]:   File "/usr/lib64/python2.7/shutil.py", line 241, in rmtree
[ 1622.749744] localhost upgrade[2241]:     is false and onerror is None, an exception is raised.
[ 1622.749744] localhost upgrade[2241]:   File "/usr/lib64/python2.7/posixpath.py", line 80, in join
[ 1622.749744] localhost upgrade[2241]:     # Trailing '/'es are stripped from head unless it is the root.
[ 1622.749744] localhost upgrade[2241]: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 29: ordinal not in range(128)
[ 1622.749744] localhost upgrade[2241]:                    
[ 1622.749744] localhost upgrade[2241]:   tfm-rubygem-tilt-2.0.8-5.el7sat.noarch
[ 1622.749744] localhost upgrade[2241]:   tfm-rubygem-timeliness-0.3.10-2.el7sat.noarch
[ 1622.749744] localhost upgrade[2241]:   tfm-rubygem-tzinfo-1.2.10-1.el7sat.noarch

Additional info:
As a workaround it has been suggested to catch all errors in the except clause line 61 (remove EnvironmentError).
From `/usr/share/leapp-repository/repositories/system_upgrade/common/actors/dnfupgradetransaction/actor.py`:
 56         self.produce(TransactionCompleted())
 57         userspace = next(self.consume(TargetUserSpaceInfo), None)
 58         if userspace:
 59             try:
 60                 shutil.rmtree(userspace.path)
 61             except EnvironmentError:
 62                 self.log.info("Failed to remove temporary userspace - error ignored", exc_info=True)

Comment 3 Petr Stodulka 2023-03-07 17:15:35 UTC
Hi Chris \o Thanks for the report. I am thinking whether we should not use rather classical `rm -rf PATH` instead of the shutil.rmtree (or put it into the different actor...) to make it more safe - considering the original python2 is removed in that time and the cleaning operation is not fundamental for the upgrade procedure.