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 1624043 - symlinks not copied when directory of the same name created automatically before
Summary: symlinks not copied when directory of the same name created automatically before
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: sos
Version: 7.6
Hardware: All
OS: Linux
urgent
urgent
Target Milestone: rc
: ---
Assignee: Pavel Moravec
QA Contact: Miroslav Hradílek
URL:
Whiteboard:
Depends On:
Blocks: 1627543
TreeView+ depends on / blocked
 
Reported: 2018-08-30 17:55 UTC by Pavel Moravec
Modified: 2018-10-30 10:34 UTC (History)
7 users (show)

Fixed In Version: sos-3.6-9.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1627543 (view as bug list)
Environment:
Last Closed: 2018-10-30 10:33:42 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github sosreport sos issues 1404 0 None closed [archive] symlinks not copied when directory of the same name created automatically before 2021-02-18 23:42:26 UTC
Red Hat Bugzilla 1597532 0 urgent CLOSED "AttributeError: module 'stat' has no attribute 'ISBLK'" seen on ppc64le 2021-02-22 00:41:40 UTC
Red Hat Product Errata RHEA-2018:3144 0 None None None 2018-10-30 10:34:57 UTC

Internal Links: 1597532

Description Pavel Moravec 2018-08-30 17:55:08 UTC
Description of problem:
https://github.com/sosreport/sos/issues/1404 separated from bz1597532 as independent issue:

sosreport sometimes does not collect content of a path that is a symbolic link, raising a plugin exception instead.

Particular reproducer: see either:
- https://bugzilla.redhat.com/show_bug.cgi?id=1597532#c7 
- https://github.com/sosreport/sos/issues/1404



Version-Release number of selected component (if applicable):
sos-3.6-5.el7.noarch


How reproducible:
100%


Steps to Reproduce:
# have /etc/sysconfig/rhn (collected by system plugin) as a symlink
mv /etc/sysconfig/rhn /etc/sysconfig/rhn.target
ln -s /etc/sysconfig/rhn.target /etc/sysconfig/rhn

# have a symlink (collected by yum plugin) pointing "into" the rhn symlink
date > /etc/sysconfig/rhn/rhn.link.repo
ln -s /etc/sysconfig/rhn/rhn.link.repo /etc/yum.repos.d/rhn.link.repo

# call sos for those 2 relevant plugins:
sosreport -o yum,system --batch --build


Actual results:
sos_logs/system-plugin-errors.txt having:

Traceback (most recent call last):
  File "/root/sos-master/sos/sosreport.py", line 1104, in collect_plugin
    plug.collect()
  File "/root/sos-master/sos/plugins/__init__.py", line 947, in collect
    self._collect_copy_specs()
  File "/root/sos-master/sos/plugins/__init__.py", line 905, in _collect_copy_specs
    self._do_copy_path(path)
  File "/root/sos-master/sos/plugins/__init__.py", line 435, in _do_copy_path
    self._copy_dir(srcpath)
  File "/root/sos-master/sos/plugins/__init__.py", line 381, in _copy_dir
    self._do_copy_path(os.path.join(srcpath, afile), dest=None)
  File "/root/sos-master/sos/plugins/__init__.py", line 431, in _do_copy_path
    self._copy_symlink(srcpath)
  File "/root/sos-master/sos/plugins/__init__.py", line 353, in _copy_symlink
    self.archive.add_link(reldest, dstpath)
  File "/root/sos-master/sos/archive.py", line 315, in add_link
    dest = self._check_path(link_name, P_LINK)
  File "/root/sos-master/sos/archive.py", line 224, in _check_path
    raise ValueError(ve_msg % (dest, "symbolic link"))
ValueError: path '/var/tmp/sos.qQBlL1/sosreport-pmoravec-sat63-2018-08-28-etvyibz/etc/sysconfig/rhn' exists and is not a symbolic link


Expected results:
- no such plugin uncaught exception
- the path is collected


Additional info:

Comment 1 Bryn M. Reeves 2018-08-31 12:13:30 UTC
I have what seems to be a fix for this now. It's a bit more complex than I would like (it extends the _check_path() changes we introduced to deal with the first Archive/threadpool race).

The fundamental problem was our reliance on the Python os.makedirs() function to create leading path components. This just creates directories: it does not attempt to accurately reflect an existing namespace structure.

The solution is to walk the paths ourselves, and to inspect the host file system to decide whether to create a directory, or a symbolic link. It's complicated by the fact that we need to handle both paths that exist in the host file system, and those that are specific to the archive (sos_commands etc.), although it also means that we can hide the path setup inside _check_path(), avoiding the need for all add_* methods to call it directly (and so it's always called under the path lock, avoiding races while we are actually setting things up).

https://github.com/sosreport/sos/tree/bmr-fix-archive-leading-paths

I'll give it some more review and testing time with a view to merging it at the beginning of next week.

Comment 2 Pavel Moravec 2018-08-31 13:43:45 UTC
(In reply to Bryn M. Reeves from comment #1)
> 
> https://github.com/sosreport/sos/tree/bmr-fix-archive-leading-paths
> 
> I'll give it some more review and testing time with a view to merging it at
> the beginning of next week.

I tested the branch via various scenarios of creating (cross-)symlinks to a content and collecting them in various order, and found no issue. Good work!

Comment 4 Pavel Moravec 2018-09-13 10:03:32 UTC
How to verify:

1) in general: check sosreport does not contain broken symlinks (until they appear on the system as well):

dir=$(sosreport --batch --build | grep "sosreport build tree is located at" | cut -d: -f2)
file $(find -L $dir -lname "*")

Prior the patch, there were broken symlinks like:

/var/tmp/sosreport-gss5-2018-09-13-riwrrdl/lib/systemd/system/dracut-shutdown.service:                            broken symbolic link to `../lib/dracut/modules.d/98systemd/dracut-shutdown.service'

while the real symlink was working:

# file /lib/systemd/system/dracut-shutdown.service
/lib/systemd/system/dracut-shutdown.service: symbolic link to `../../dracut/modules.d/98systemd/dracut-shutdown.service'
#

Now, the "file $(find ..)" command shall not find any broken symlink - or more precisely whatever it detects inside sosreport directory, it must happen on the system directory structure as well.


2) in particular: typical example is systemd plugin collecting /lib/systemd where /lib is symlink to /usr/lib (where further symlinks appear with relative AND also absolute path) - either was possible to be broken but now it should work

3) in particular: s390 has complex /sys/bus/ccwgroup directory structure - verify 1) on s390 machine in particular

Comment 7 errata-xmlrpc 2018-10-30 10:33:42 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.