Skip to content

Commit

Permalink
[Plugin] Fix exception when calling os.makedirs
Browse files Browse the repository at this point in the history
When calling get_cmd_output_path() to create a directory
via the plugin hpssm, sos threw the following exception:

Traceback (most recent call last):
  File "/root/sos/sos/report/__init__.py", line 1224, in setup
    plug.setup()
  File "/root/sos/sos/report/plugins/hpssm.py", line 67, in setup
    logpath = self.get_cmd_output_path()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/sos/sos/report/plugins/__init__.py", line 2168,
	in get_cmd_output_path
    os.makedirs(cmd_output_path)
  File "<frozen os>", line 225, in makedirs
FileExistsError: [Errno 17] File exists:
'/var/tmp/sos.1gdy83zb/sosreport-localhost-vbwfnpn/sos_commands/hpssm'

This was happening because the directory 'hpssm' was already created.
With this change we avoid any race where we call os.makedirs() after
we have already created the plugin directory.

Closes: RHBZ #2216608

Signed-off-by: Jose Castillo <[email protected]>
  • Loading branch information
jcastill authored and TurboTurtle committed Jun 22, 2023
1 parent dc75ed4 commit c0865c1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,7 @@ def get_cmd_output_path(self, name=None, make=True):
if name:
cmd_output_path = os.path.join(cmd_output_path, name)
if make:
os.makedirs(cmd_output_path)
os.makedirs(cmd_output_path, exist_ok=True)

return cmd_output_path

Expand Down

0 comments on commit c0865c1

Please sign in to comment.