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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,45 @@ def _add_cmd_output(self, **kwargs):
else:
self.log_skipped_cmd(soscmd.cmd, pred, changes=soscmd.changes)

def add_dir_listing(self, paths, tree=False, recursive=False, chroot=True,
env=None, sizelimit=None, pred=None, subdir=None,
tags=[], runas=None, container=None,
suggest_filename=None):
"""
Used as a way to standardize our collections of directory listings,
either as an output of `ls` or `tree` depending on if the `tree`
parameter is set to `True`.

This is ultimately a wrapper around `add_cmd_output()` and supports
several, but not all, of the options for that method.

:param paths: The path(s) to collect a listing for
:type paths: ``str`` or a ``list`` of ``str``s

:param tree: Collect output with `tree` instead of `ls`
:type tree: ``bool`` (default: False)

:param recursive: Recursively list directory contents with `ls`
:type recursive: ``bool`` (default: False)
"""
if isinstance(paths, str):
paths = [paths]

paths = [p for p in paths if self.path_exists(p)]

if not tree:
options = f"alhZ{'R' if recursive else ''}"
else:
options = 'lhp'

for path in paths:
self.add_cmd_output(
f"{'tree' if tree else 'ls'} -{options} {path}",
chroot=chroot, env=env, sizelimit=sizelimit, pred=pred,
subdir=subdir, tags=tags, container=container, runas=runas,
suggest_filename=suggest_filename
)

def add_cmd_output(self, cmds, suggest_filename=None,
root_symlink=None, timeout=None, stderr=True,
chroot=True, runat=None, env=None, binary=False,
Expand Down
11 changes: 7 additions & 4 deletions sos/report/plugins/aap_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ def setup(self):
"/var/lib/awx/venv/awx/bin/pip freeze -l",
"/var/lib/awx/venv/ansible/bin/pip freeze",
"/var/lib/awx/venv/ansible/bin/pip freeze -l",
"tree -d /var/lib/awx",
"ls -ll /var/lib/awx",
"ls -ll /var/lib/awx/venv",
"ls -ll /etc/tower",
"umask -p",
])

self.add_dir_listing([
'/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

self.add_dir_listing('/var/lib/awx', tree=True)

def postproc(self):
# remove database password
jreg = r"(\s*\'PASSWORD\'\s*:(\s))(?:\"){1,}(.+)(?:\"){1,}"
Expand Down
10 changes: 5 additions & 5 deletions sos/report/plugins/aap_eda.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def setup(self):
"/etc/ansible-automation-platform/eda/server.key",
])

self.add_cmd_output([
"aap-eda-manage --version", # eda version
"ls -alhR /etc/ansible-automation-platform/",
"ls -alhR /var/log/ansible-automation-platform/",
])
self.add_cmd_output("aap-eda-manage --version")
self.add_dir_listing([
"/etc/ansible-automation-platform/",
"/var/log/ansible-automation-platform/",
arif-ali marked this conversation as resolved.
Show resolved Hide resolved
], recursive=True)

self.add_cmd_output("su - eda -c 'export'",
suggest_filename="eda_export")
Expand Down
8 changes: 3 additions & 5 deletions sos/report/plugins/aap_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ def setup(self):
"/etc/ansible-automation-platform/gateway/*.cert",
])

self.add_cmd_output([
"aap-gateway-manage list_services",
"ls -ll /etc/ansible-automation-platform/",
"ls -ll /etc/ansible-automation-platform/gateway/",
])
self.add_cmd_output("aap-gateway-manage list_services")
self.add_dir_listing("/etc/ansible-automation-platform/",
recursive=True)
Comment on lines +38 to +40
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


def postproc(self):
# remove database password
Expand Down
8 changes: 4 additions & 4 deletions sos/report/plugins/aap_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def setup(self):

])

self.add_cmd_output([
"ls -alhR /etc/ansible-automation-platform/",
"ls -alhR /var/log/ansible-automation-platform/",
])
self.add_dir_listing([
"/etc/ansible-automation-platform/",
"/var/log/ansible-automation-platform/",
arif-ali marked this conversation as resolved.
Show resolved Hide resolved
], recursive=True)

# vim: set et ts=4 sw=4 :
8 changes: 4 additions & 4 deletions sos/report/plugins/aap_receptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def setup(self):
"/etc/receptor/*key.pem"
])

self.add_cmd_output([
"ls -llZ /etc/receptor",
"ls -llZ /var/run/receptor",
"ls -llZ /var/run/awx-receptor"
self.add_dir_listing([
"/etc/receptor",
"/var/run/receptor",
"/var/run/awx-receptor"
])

for s in glob.glob('/var/run/*receptor/*.sock'):
Expand Down
9 changes: 5 additions & 4 deletions sos/report/plugins/apparmor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def setup(self):
"/etc/apparmor.d/abstractions"
])

self.add_cmd_output([
"apparmor_status",
"ls -alh /etc/apparmor.d/abstractions",
"ls -alh /etc/apparmor.d/libvirt",
self.add_cmd_output("apparmor_status")

self.add_dir_listing([
arif-ali marked this conversation as resolved.
Show resolved Hide resolved
'/etc/apparmor.d/abstractions',
'/etc/apparmor.d/libvirt'
])

# vim: set et ts=4 sw=4 :
2 changes: 1 addition & 1 deletion sos/report/plugins/apport.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setup(self):
"gdbus call -y -d com.ubuntu.WhoopsiePreferences \
-o /com/ubuntu/WhoopsiePreferences \
-m com.ubuntu.WhoopsiePreferences.GetIdentifier")
self.add_cmd_output("ls -alhR /var/crash/")
self.add_dir_listing('/var/crash', recursive=True)
self.add_cmd_output("bash -c 'grep -B 50 -m 1 ProcMaps /var/crash/*'")

# vim: set et ts=4 sw=4 :
5 changes: 3 additions & 2 deletions sos/report/plugins/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ def setup(self):
'/sys/block/.*/queue/scheduler': 'scheduler'
})

self.add_dir_listing('/dev', tags=['ls_dev'], recursive=True)
self.add_dir_listing('/sys/block', recursive=True)

self.add_cmd_output("blkid -c /dev/null", tags="blkid")
self.add_cmd_output("ls -lanR /dev", tags="ls_dev")
self.add_cmd_output("lsblk", tags="lsblk")
self.add_cmd_output("lsblk -O -P", tags="lsblk_pairs")
self.add_cmd_output([
"lsblk -t",
"lsblk -D",
"blockdev --report",
"ls -lanR /sys/block",
"losetup -a",
])

Expand Down
9 changes: 5 additions & 4 deletions sos/report/plugins/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ def setup(self):
"/boot/yaboot.conf"
])

self.add_cmd_output("ls -lanR /boot", tags="ls_boot")
self.add_cmd_output("ls -lanR /sys/firmware",
tags="ls_sys_firmware")
self.add_dir_listing('/boot', tags=['ls_boot'], recursive=True)
self.add_dir_listing('/sys/firmware/', tags=['ls_sys_firmware'],
recursive=True)
self.add_dir_listing(['/initrd.img', '/boot/initrd.img'])

self.add_cmd_output("lsinitrd", tags="lsinitrd")
self.add_cmd_output("mokutil --sb-state",
tags="mokutil_sbstate")

self.add_cmd_output([
"efibootmgr -v",
"ls -l /initrd.img /boot/initrd.img",
"lsinitramfs -l /initrd.img",
"lsinitramfs -l /boot/initrd.img"
])
Expand Down
3 changes: 2 additions & 1 deletion sos/report/plugins/crio.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ def setup(self):
])

self.add_cmd_output([
"ls -alhR /etc/cni",
"crio config"
])

self.add_dir_listing('/etc/cni', recursive=True)

# base cri-o installation does not require cri-tools, which is what
# supplies the crictl utility
self.set_cmd_predicate(SoSPredicate(self, packages=['cri-tools']))
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def setup(self):
])

self.add_journal(units="docker")
self.add_cmd_output("ls -alhR /etc/docker")
self.add_dir_listing('/etc/docker', recursive=True)

self.set_cmd_predicate(SoSPredicate(self, services=["docker"]))

Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/docker_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setup(self):
for line in file:
if 'rootdirectory' in line:
loc = line.split()[1]
self.add_cmd_output('tree ' + loc)
self.add_dir_listing(loc, tree=True)


class RedHatDockerDistribution(DockerDistribution, RedHatPlugin):
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def setup(self):
"/opt/redhat-ds/slapd-*/logs"
])

self.add_cmd_output("ls -l /var/lib/dirsrv/slapd-*/db/*")
self.add_dir_listing("/var/lib/dirsrv/slapd-*/db/*")

def postproc(self):
# Example for scrubbing rootpw hash
Expand Down
3 changes: 2 additions & 1 deletion sos/report/plugins/etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def setup(self):
'/etc/etcd/*.key'
])

self.add_cmd_output('ls -lR /var/lib/etcd/', container=etcd_con)
self.add_dir_listing('/var/lib/etcd/', container=etcd_con,
recursive=True)
self.add_copy_spec('/etc/etcd', container=etcd_con)

subcmds = [
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/filesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ class RedHatFilesys(Filesys, RedHatPlugin):

def setup(self):
super().setup()
self.add_cmd_output("ls -ltradZ /tmp")
self.add_cmd_output('ls -ldZ /tmp')

# vim: set et ts=4 sw=4 :
8 changes: 6 additions & 2 deletions sos/report/plugins/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ def setup(self):
'passenger-status --show requests',
'passenger-status --show backtraces',
'passenger-memory-stats',
'ls -lanR /root/ssl-build',
'ls -lanR /usr/share/foreman/config/hooks',
f'ping -c1 -W1 {_hostname}',
f'ping -c1 -W1 {_host_f}',
'ping -c1 -W1 localhost'
])

self.add_dir_listing([
'/root/ssl-build',
'/usr/share/foreman/config/hooks'
], recursive=True)

self.add_cmd_output(
'qpid-stat -b amqps://localhost:5671 -q \
--ssl-certificate=/etc/pki/katello/qpid_router_client.crt \
Expand Down
1 change: 0 additions & 1 deletion sos/report/plugins/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def setup(self):
"/etc/grub2-efi.cfg"
])

self.add_cmd_output("ls -lanR /boot", tags="ls_boot")
# call grub2-mkconfig with GRUB_DISABLE_OS_PROBER=true to prevent
# possible unwanted loading of some kernel modules
# further, check if the command supports --no-grubenv-update option
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def setup(self):
timeout=30
)

for _dir in ["/etc/rhsm", "/sys/kernel", "/var/lib/sss"]:
self.add_cmd_output(f"/bin/ls -lanR {_dir}", cmd_as_tag=True)
self.add_dir_listing(["/etc/rhsm", "/sys/kernel", "/var/lib/sss"],
recursive=True)
Comment on lines +55 to +56
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..


def postproc(self):
for conf in self.config_and_status:
Expand Down
3 changes: 2 additions & 1 deletion sos/report/plugins/ipa.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def setup(self):
])

self.add_cmd_output([
"ls -la /etc/dirsrv/slapd-*/schema/",
"certutil -L -d /etc/httpd/alias/",
"pki-server cert-find --show-all",
"pki-server subsystem-cert-validate ca",
Expand All @@ -173,6 +172,8 @@ def setup(self):
"klist -ket /var/lib/ipa/gssproxy/http.keytab"
])

self.add_dir_listing("/etc/dirsrv/slapd-*/schema/")

getcert_pred = SoSPredicate(self,
services=['certmonger'])

Expand Down
8 changes: 4 additions & 4 deletions sos/report/plugins/juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def setup(self):
self.add_copy_spec("/var/lib/juju/agents/*/agent.conf")

# Get a directory listing of /var/log/juju and /var/lib/juju
self.add_cmd_output([
"ls -alRh /var/log/juju*",
"ls -alRh /var/lib/juju*"
])
self.add_dir_listing([
'/var/log/juju*',
'/var/lib/juju*'
], recursive=True)

if self.get_option("all_logs"):
# /var/lib/juju used to be in the default capture moving here
Expand Down
6 changes: 3 additions & 3 deletions sos/report/plugins/kdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def setup(self):
# set no filesystem and default path
path = "/var/crash"

self.add_cmd_output(f"ls -alhR {path}")
self.add_dir_listing(path, recursive=True)
self.add_copy_spec(f"{path}/*/vmcore-dmesg.txt")
self.add_copy_spec(f"{path}/*/kexec-dmesg.log")

Expand Down Expand Up @@ -131,7 +131,7 @@ class CosKDump(KDump, CosPlugin):

def setup(self):
super().setup()
self.add_cmd_output('ls -alRh /var/kdump*')
self.add_dir_listing('/var/kdump*', recursive=True)
if self.get_option("collect-kdumps"):
self.add_copy_spec(["/var/kdump-*"])

Expand Down Expand Up @@ -172,7 +172,7 @@ def setup(self):
# set no filesystem and default path
path = "/var/crash"

self.add_cmd_output(f"ls -alhR {path}")
self.add_dir_listing(path, recursive=True)
self.add_copy_spec(f"{path}/*/vmcore-dmesg.txt")
self.add_copy_spec(f"{path}/*/kexec-dmesg.log")

Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setup(self):
# compat
self.add_cmd_output("uname -a", root_symlink="uname", tags="uname")
self.add_cmd_output("lsmod", root_symlink="lsmod", tags="lsmod")
self.add_cmd_output("ls -lt /sys/kernel/slab")
self.add_dir_listing('/sys/kernel/slab')

try:
modules = self.listdir(self.sys_module)
Expand Down
6 changes: 4 additions & 2 deletions sos/report/plugins/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def setup(self):
dirs.add(fqlib[1].rsplit('/', 1)[0])

if dirs:
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'
)
Comment on lines -47 to +50
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?


# vim: set et ts=4 sw=4 :
2 changes: 1 addition & 1 deletion sos/report/plugins/libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def setup(self):
if self.path_exists(self.path_join(libvirt_keytab)):
self.add_cmd_output(f"klist -ket {libvirt_keytab}")

self.add_cmd_output("ls -lR /var/lib/libvirt/qemu")
self.add_dir_listing("/var/lib/libvirt/qemu", recursive=True)

# get details of processes of KVM hosts
for pidfile in glob.glob("/run/libvirt/*/*.pid"):
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setup(self):
])

self.add_cmd_output("journalctl --disk-usage")
self.add_cmd_output('ls -alRh /var/log/')
self.add_dir_listing('/var/log', recursive=True)

# collect journal logs if:
# - there is some data present, either persistent or runtime only
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def setup(self):
f' but not found in {kerberoskeytabfile}')
if kerberoskeytabfile is not None:
if self.path_isfile(kerberoskeytabfile):
self.add_cmd_output(f'ls -l {kerberoskeytabfile}')
self.add_dir_listing(kerberoskeytabfile)
self.add_cmd_output(f'klist -e -k {kerberoskeytabfile}')
else:
self._log_error(keytab_err)
Expand Down
Loading
Loading