Skip to content

Commit

Permalink
call correct mkdir when trying to create /etc/rhsm/facts (oamg#1132)
Browse files Browse the repository at this point in the history
os.path has no mkdir, but os does.

traceback without the patch:

    Traceback (most recent call last):
      File "/bin/leapp", line 11, in <module>
        load_entry_point('leapp==0.16.0', 'console_scripts', 'leapp')()
      File "/usr/lib/python3.6/site-packages/leapp/cli/__init__.py", line 45, in main
        cli.command.execute('leapp version {}'.format(VERSION))
      File "/usr/lib/python3.6/site-packages/leapp/utils/clicmd.py", line 111, in execute
        args.func(args)
      File "/usr/lib/python3.6/site-packages/leapp/utils/clicmd.py", line 133, in called
        self.target(args)
      File "/usr/lib/python3.6/site-packages/leapp/cli/commands/upgrade/breadcrumbs.py", line 170, in wrapper
        breadcrumbs.save()
      File "/usr/lib/python3.6/site-packages/leapp/cli/commands/upgrade/breadcrumbs.py", line 116, in save
        self._save_rhsm_facts(doc['activities'])
      File "/usr/lib/python3.6/site-packages/leapp/cli/commands/upgrade/breadcrumbs.py", line 64, in _save_rhsm_facts
        os.path.mkdir('/etc/rhsm/facts')
    AttributeError: module 'posixpath' has no attribute 'mkdir'

While at it, also catch OSError with errno 17, to safeguard against race
conditions if anything has created the directory between us checking for
it and us trying to create it.
  • Loading branch information
evgeni authored Oct 30, 2023
1 parent 6661e49 commit 17c88d9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion commands/upgrade/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def _save_rhsm_facts(self, activities):
if not os.path.exists('/etc/rhsm'):
# If there's no /etc/rhsm folder just skip it
return
os.path.mkdir('/etc/rhsm/facts')
try:
os.mkdir('/etc/rhsm/facts')
except OSError as e:
if e.errno == 17:
# The directory already exists which is all we need.
pass
try:
with open('/etc/rhsm/facts/leapp.facts', 'w') as f:
json.dump(_flattened({
Expand Down

0 comments on commit 17c88d9

Please sign in to comment.