RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1549503 - Python global name 'FileNotFoundError' is not defined
Summary: Python global name 'FileNotFoundError' is not defined
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: sos
Version: 7.5
Hardware: x86_64
OS: Linux
low
low
Target Milestone: rc
: ---
Assignee: Pavel Moravec
QA Contact: Miroslav Hradílek
URL:
Whiteboard:
Depends On:
Blocks: 1477664 1552138
TreeView+ depends on / blocked
 
Reported: 2018-02-27 09:48 UTC by Nikola Kresic
Modified: 2021-12-10 15:43 UTC (History)
10 users (show)

Fixed In Version: sos-3.6-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-10-30 10:31:19 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github sosreport sos pull 1230 0 None closed [plugins] dont catch FileNotFoundError specifically 2021-01-19 01:39:07 UTC
Red Hat Knowledge Base (Solution) 4432961 0 None None None 2019-09-23 05:04:57 UTC
Red Hat Product Errata RHEA-2018:3144 0 None None None 2018-10-30 10:33:21 UTC

Description Nikola Kresic 2018-02-27 09:48:10 UTC
Description of problem:
sos-report logs an error. 

[nkresic@fubar sos_logs]$ cat grub2-plugin-errors.txt 
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1252, in setup
    plug.setup()
  File "/usr/lib/python2.7/site-packages/sos/plugins/grub2.py", line 34, in setup
    "/etc/grub.d"
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 572, in add_copy_spec
    files.sort(key=getmtime, reverse=True)
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 569, in getmtime
    except (OSError, FileNotFoundError):
NameError: global name 'FileNotFoundError' is not defined


Possibly a "global name" is defined, that does not exist in python 2.7 ?



Version-Release number of selected component (if applicable):

sos-3.5-6.el7.noarch                                        
python-2.7.5-66.el7.x86_64



How reproducible:

While collecting a normal sos-report, no special flags set



Steps to Reproduce:
1. start sosreport collection
2. wait until finished
3. check for run logs, found a file grub2-plugin-errors.txt with the above error



Actual results:

python throws an exception NameError: global name 'FileNotFoundError' is not defined



Expected results:

No errors

Additional info:

Comment 2 Bryn M. Reeves 2018-02-27 12:37:25 UTC
This is a bit strange: that line of code has been present since last May, and we've not seen this previously. It looks as though Python only cares about this in the case that the exception is taken:

>>> try:
...     print("foo")
... except (OSError, FileNotFoundError):
...     print("qux")
... 
foo

>>> try:
...     raise OSError
... except (OSError, FileNotFoundError):
...     print("qux")
... 
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
NameError: name 'FileNotFoundError' is not defined

And poking about other py2 packages I see matplotlib is using Six to determine the exception class to use:

matplotlib/dviread.py
389         if tfm is None:
390             if six.PY2:
391                 error_class = OSError
392             else:
393                 error_class = FileNotFoundError
394             raise error_class("missing font metrics file: %s" % fontname)

So it seems like in this case the stat() failed for a file that appeared to exist in the file system (it's a path formed by glob expansion in Plugin._expand_copy_spec()). That's a bit strange and we should try to understand what happened there.

There are only two references to this exception class in sos so it's a simple fix but too late for 7.5.0 now.

Comment 3 Pavel Moravec 2018-02-27 13:40:12 UTC
This is due to the fact FileNotFoundError exception does not occur in python2 and getmtime was called to a non-existing file (where python raises OSError instead).

IMHO we shall replace the catch by EnvironmentError class that covers both types.

Comment 4 Pavel Moravec 2018-02-27 14:20:11 UTC
even simplier fix in the PR..

Comment 5 Pavel Moravec 2018-03-03 13:24:36 UTC
re-scheduling for inclusion in 7.6. Though reproducr isnt known (/me trying one artificial now), the PR shall fix it either way - just hard to verify it.

Comment 6 Pavel Moravec 2018-04-02 12:22:47 UTC
devel_ack+ for 7.6

no reproducer known ATM, currently the only possible verification just by code check :-/

Comment 8 Pavel Moravec 2018-05-25 06:57:08 UTC
POSTed to upstream in PR 1230 / upstream commit 8673e0e.

Comment 12 errata-xmlrpc 2018-10-30 10:31:19 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, 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/RHEA-2018:3144


Note You need to log in before you can comment on or make changes to this bug.