Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plugin] Standardize directory listings with new method #3664

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

TurboTurtle
Copy link
Member

This commit adds a new add_dir_listing() wrapper method to standardize the collection of directory content listings across plugins. By default this will use the ls command, and will use tree if the tree parameter is set to True.

This wrapper is not intended to replace directory listing that are handlded by other components with their own ls functionality (e.g. npm ls in the npm plugin). Additionally this does not replace the direct calling of ls when used with Plugin.exec_cmd() to take some action based on the output of the ls command.


Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines

  • Is the commit message split over multiple lines and hard-wrapped at 72 characters?
  • Is the subject and message clear and concise?
  • Does the subject start with [plugin_name] if submitting a plugin patch or a [section_name] if part of the core sosreport code?
  • Does the commit contain a Signed-off-by: First Lastname email@example.com?
  • Are any related Issues or existing PRs properly referenced via a Closes (Issue) or Resolved (PR) line?
  • Are all passwords or private data gathered by this PR obfuscated?

Copy link

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/sosreport-sos-3664
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

Copy link
Member

@arif-ali arif-ali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, there is some inconsistency where we have used -R previously and hence stuff with the new default or recursive=True. But we've had newer updates here now where some places where we didn't have -R before we are now doing recursive and some we aren't.

Happy though, if this was all intended

sos/report/plugins/aap_gateway.py Outdated Show resolved Hide resolved
sos/report/plugins/grub2.py Outdated Show resolved Hide resolved
'/var/lib/awx',
'/var/lib/awx/venv',
'/etc/tower',
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing recursive=False?

(should recursive have default value True or False? I would expect False since that follows default ls behaviour and I would expect it as a human-default thinking of "list directory" as well; also since the patch replaces 38 instances of recursive listings and 32 non-recursive ones, there is no need to have such strong preference to the "recursive is far more used default")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(should recursive have default value True or False? I would expect False since that follows default ls behaviour and I would expect it as a human-default thinking of "list directory" as well; also since the patch replaces 38 instances of recursive listings and 32 non-recursive ones, there is no need to have such strong preference to the "recursive is far more used default")

When I was first reviewing the PR I was thinking the same, and missed the recursive=True as the default in the function definition, and had put in ~10 comments before abandoning it. I would agree with @pmoravec here, I think having recursive=False should be default and we use recursive=True where needed

@TurboTurtle
Copy link
Member Author

I've swapped the default to recursive=False and re-aligned things as needed. I believe I hit all of them, but a second pair of eyes to keep me honest is appreciated.

sos/report/plugins/aap_eda.py Show resolved Hide resolved
sos/report/plugins/aap_hub.py Show resolved Hide resolved
sos/report/plugins/ds.py Outdated Show resolved Hide resolved
sos/report/plugins/filesys.py Outdated Show resolved Hide resolved
sos/report/plugins/ovn_central.py Outdated Show resolved Hide resolved
@TurboTurtle TurboTurtle force-pushed the dir-listing-methods branch 2 times, most recently from 34da14d to c674473 Compare June 21, 2024 21:19
@TurboTurtle
Copy link
Member Author

@arif-ali - updated and I dropped the duplicate collection from grub2.

Copy link
Member

@arif-ali arif-ali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully last review, missed a couple where -d is being used, where it only gives the information of that dir, and doesn't actually list the contents of the directory. It does give the same info at the top, with . for the directory, instead of the directory name.

@@ -108,6 +108,6 @@ class RedHatFilesys(Filesys, RedHatPlugin):

def setup(self):
super().setup()
self.add_cmd_output("ls -ltradZ /tmp")
self.add_dir_listing('/tmp')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what this did before, and what it will give now are 2 distinct things, not sure how we best want to do that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options are being removed: -d to list just directory like:

$ ls -ltradZ /tmp
drwxrwxrwt. 25 root root system_u:object_r:tmp_t:s0 640 Jun 22 14:44 /tmp
$

and not the directory content. -t and -r to sort reversely by time is irelevant with -d option.

Calling self.add_dir_listing('/tmp') would collect same info via:

$ ls -alhZ /tmp
total 44K
drwxrwxrwt. 25 root     root     system_u:object_r:tmp_t:s0          640 Jun 22 14:44 .
..

line, but will also et details about files under /tmp. I doubt the content of the directory is important to collect at all, moreover listing the dir can be undesired ("show me your temporary filenames" has some Big Brother vibes).

We requested the current info in #1327 and that is reasonable request. Content of the directory is irelevant. So I would vote for keeping the current ls command (maybe strip redundant options to ls -ladZ /tmp?), or for some equivalent (stat?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, will move this one back to ls directly. a also is meaningless with d, so this will become ls -ldZ /tmp.

])

self.add_dir_listing(
['/etc/vdsm', '/rhev/data-center'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, the -ldZ gives only the details of the directory, and no listing

@@ -84,6 +84,6 @@ def user_ssh_files_permissions(self):
for user in users_data:
home_dir = self.path_join(user.pw_dir, '.ssh')
if self.path_isdir(home_dir):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth removing this check now, as you're checking if the path exists in add_dir_listing()

@TurboTurtle
Copy link
Member Author

Hopefully last review, missed a couple where -d is being used, where it only gives the information of that dir, and doesn't actually list the contents of the directory. It does give the same info at the top, with . for the directory, instead of the directory name.

I think we can accept that difference. For the vdsm ones, RHV is an EOL product that won't be getting updated further, and I wasn't aware of any automation around those collections when I left RH, and I seriously doubt anything has been added for it since.

For /tmp, I think falling back on the . listing should be fine, but I'll defer to @pmoravec on that one.

is it worth removing this check now, as you're checking if the path exists in add_dir_listing()

Oh, good eye. I'll drop that check in the next update, pending Pavel's thoughts on /tmp.

Comment on lines +38 to +40
self.add_cmd_output("aap-gateway-manage list_services")
self.add_dir_listing("/etc/ansible-automation-platform/",
recursive=True)
Copy link
Contributor

@pmoravec pmoravec Jun 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will additionally collect all recursive subdirs of /etc/ansible-automation-platform/ but I doubt that will cause an issue (like, speculating, some fiel in nested dir has some secret name we should not collect - but I doubt that would ever happen). ACK

@pmoravec
Copy link
Contributor

I see one skipped placefor the new method:

sos/report/plugins/openstack_neutron.py:        self.add_cmd_output("ls -laZR /var/lib/neutron/lock")

Comment on lines +55 to +56
self.add_dir_listing(["/etc/rhsm", "/sys/kernel", "/var/lib/sss"],
recursive=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We stop adding tags here. Also not sure if -n is important or not (like -l, but list numeric user and group IDs).

I am checking this internally..

Comment on lines -47 to +50
self.add_cmd_output(f"ls -lanH {' '.join(dirs)}",
suggest_filename="ld_so_cache")
self.add_dir_listing(
f"{' '.join(dirs)}",
suggest_filename='ld_so_cache'
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will stop printing UIDs/GIDs here (dropping -n option), no idea if / how much it can matter. I expect no big deal - can @rmetrich as author of ff74942 confirm?

self.add_cmd_output("ls -lanR /tftpboot")
self.add_cmd_output('ls -lanR /srv/tftp')

self.add_dir_listing(['/tftpboot', '/sr/tftp'], recursive=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also removing -n option, again no idea if it matters or not. I am ok with removal, if somebody will miss it, we can add it back.

@rmetrich
Copy link
Contributor

rmetrich commented Jun 22, 2024 via email

This commit adds a new `add_dir_listing()` wrapper method to standardize
the collection of directory content listings across plugins. By default
this will use the `ls` command, and will use `tree` if the `tree`
parameter is set to `True`.

This wrapper is not intended to replace directory listing that are
handlded by other components with their own `ls` functionality (e.g.
`npm ls` in the `npm` plugin). Additionally this does not replace the
direct calling of `ls` when used with `Plugin.exec_cmd()` to take some
action based on the output of the `ls` command.

Signed-off-by: Jake Hunsaker <jacob.r.hunsaker@gmail.com>
@TurboTurtle
Copy link
Member Author

@pmoravec any other remaining concerns?

Copy link
Contributor

@pmoravec pmoravec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, sorry for a delay.

@arif-ali arif-ali merged commit b7d4e30 into sosreport:main Jun 26, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants