Bug 2216608

Summary: Exception raised by hpssm plugin in plug.setup().
Product: Red Hat Enterprise Linux 8 Reporter: Daniel Reynolds <dareynol>
Component: sosAssignee: Pavel Moravec <pmoravec>
Status: CLOSED ERRATA QA Contact: Miroslav HradĂ­lek <mhradile>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.6CC: agk, jcastillo, jjansky, mhradile, pgm-rhel-tools, plambri, ppaddhar, sbradley, snavale, theute, toneata
Target Milestone: rcKeywords: OtherQA, Triaged, ZStream
Target Release: ---Flags: dareynol: needinfo-
pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: sos-4.5.5-2.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2221103 (view as bug list) Environment:
Last Closed: 2023-07-26 08:37:56 UTC 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:
Bug Depends On:    
Bug Blocks: 2221103    

Description Daniel Reynolds 2023-06-22 04:49:38 UTC
Description of problem:


Version-Release number of selected component (if applicable):
- sos-4.5.0-1.el8

How reproducible:
- Only on customers specific hardware.  Then, always.


Steps to Reproduce:
1. `sudo sosreport --batch`


Actual results:

Exception running 'hpssm' plugin.
~~~
Please note the 'sosreport' command has been deprecated in favor of the new 'sos' command, E.G. 'sos report'.
Redirecting to 'sos report --batch'

sosreport (version 4.5.0)

[snip]
caught exception in plugin method "hpssm.setup()"
writing traceback to sos_logs/hpssm-plugin-errors.txt
Retrieving Linux Extensions Configuration ...
[snip]

Your sosreport has been generated and saved in:
        /var/tmp/sosreport-dl360x4140-2023-06-07-pmtslmo.tar.xz

 Size   23.51MiB
 Owner  root
 sha256 f8bc2de2ac33af75f518b06ddfa2bf08819d7f1b843d969033d4184d7fcb247e
~~~


Expected results:

No exception running hpssm plugin.

Additional info:

- From 'sos_logs/hpssm-plugin-errors.txt'

    ~~~
    $ cat sos_logs/hpssm-plugin-errors.txt 
    Traceback (most recent call last):
      File "/usr/lib/python3.6/site-packages/sos/report/__init__.py", line 1217, in setup
        plug.setup()
      File "/usr/lib/python3.6/site-packages/sos/report/plugins/hpssm.py", line 67, in setup
        logpath = self.get_cmd_output_path()
      File "/usr/lib/python3.6/site-packages/sos/report/plugins/__init__.py", line 2167, in get_cmd_output_path
        os.makedirs(cmd_output_path)
      File "/usr/lib64/python3.6/os.py", line 220, in makedirs
        mkdir(name, mode)
    FileExistsError: [Errno 17] File exists: '/var/tmp/sos.8d8v8__a/sosreport-seliics03349-2023-06-08-enmwtcf/sos_commands/hpssm'
    ~~~

- If hpssm plugin is disabled, no exception is raised.

- Clearing /var/tmp of sos directories does not resolve the issue.

Comment 1 Jose Castillo 2023-06-22 09:13:19 UTC
The problem here seems to be that we call the function get_cmd_output_path() with the default values, here:

        logpath = self.get_cmd_output_path()


And by default it tries to create the directory, which in our case has been already created, if I'm reading it correctly:

	def get_cmd_output_path(self, name=None, make=True):                     <-- default is to create dir
		"""Get the path where this plugin will save command output

		:param name: Optionally specify a filename to use as part of the
					 command output path
		:type name: ``str`` or ``None``

		:param make: Attempt to create the command output path
		:type make: ``bool``

		:returns: The path where the plugin will write command output data
				  within the archive
		:rtype: ``str``
		"""
		cmd_output_path = os.path.join(self.archive.get_tmp_dir(),
									   'sos_commands', self.name())
		if name:
			cmd_output_path = os.path.join(cmd_output_path, name)
		if make:
			os.makedirs(cmd_output_path)                    <-- So we end up here attempting to create an already existing dir

I have a couple of ideas about how to solve this, but will need to test them first.

Comment 2 Pavel Moravec 2023-06-22 09:41:54 UTC
(In reply to Jose Castillo from comment #1)
> The problem here seems to be that we call the function get_cmd_output_path()
> with the default values, here:
> 
>         logpath = self.get_cmd_output_path()
> 
> 
> And by default it tries to create the directory, which in our case has been
> already created, if I'm reading it correctly:
> 
> 	def get_cmd_output_path(self, name=None, make=True):                    
> <-- default is to create dir
> 		"""Get the path where this plugin will save command output
> 
> 		:param name: Optionally specify a filename to use as part of the
> 					 command output path
> 		:type name: ``str`` or ``None``
> 
> 		:param make: Attempt to create the command output path
> 		:type make: ``bool``
> 
> 		:returns: The path where the plugin will write command output data
> 				  within the archive
> 		:rtype: ``str``
> 		"""
> 		cmd_output_path = os.path.join(self.archive.get_tmp_dir(),
> 									   'sos_commands', self.name())
> 		if name:
> 			cmd_output_path = os.path.join(cmd_output_path, name)
> 		if make:
> 			os.makedirs(cmd_output_path)                    <-- So we end up here
> attempting to create an already existing dir
> 
> I have a couple of ideas about how to solve this, but will need to test them
> first.

Three *possible* ideas (dont saying the best ones):

1) enhance get_cmd_output_path by optional parameter skip_if_present and call os.makedirs with exist_ok=skip_if_present option (to have plugins the ability to configure it (is there a need for it..?))
2) call the os.makedirs always with exist_ok=True (pragmatically saying, we just want to make it created, right?)
3) put the os.makedirs call into try-catch block and raise a warning in catch branch (likewise 2) but with an extra warn log)

Comment 3 Jose Castillo 2023-06-22 10:41:52 UTC
I'm testing exist_ok=True, because that will catch if the dir has been created up to the point when we call os.makedirs(), because I think this may help better to avoid race conditions.

Comment 4 Jose Castillo 2023-06-22 15:15:39 UTC
Upstream PR can be found here:

https://github.com/sosreport/sos/pull/3285

Comment 5 Jan Jansky 2023-06-30 14:05:33 UTC
Will you be able to test this fix for us when we will have release candidate?

Comment 11 Jan Jansky 2023-07-19 07:08:49 UTC
*** Bug 2221103 has been marked as a duplicate of this bug. ***

Comment 14 Daniel Reynolds 2023-07-20 00:21:42 UTC
Hello Jan,

Have shared the links to the new package with the customer and requested that they test it.

Regards

Comment 20 errata-xmlrpc 2023-07-26 08:37:56 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (sos bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:4279