Skip to content

Commit

Permalink
fix: remove the inner functions of the _make_rpm_formatter (#3574)
Browse files Browse the repository at this point in the history
* fix: remove the inner functions of the _make_rpm_formatter

Signed-off-by: Xiangce Liu <[email protected]>

* tiny: update the comment

Signed-off-by: Xiangce Liu <[email protected]>

* move rpm_format to the Dep Specs section

Signed-off-by: Xiangce Liu <[email protected]>

* move non-specs outside of the class

Signed-off-by: Xiangce Liu <[email protected]>

* fix flake8

Signed-off-by: Xiangce Liu <[email protected]>

Signed-off-by: Xiangce Liu <[email protected]>
  • Loading branch information
xiangce authored Nov 3, 2022
1 parent 020dc42 commit 1878a29
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,20 @@ def _make_rpm_formatter(fmt=None):
'"buildhost":"%{BUILDHOST}"',
'"sigpgp":"%{SIGPGP:pgpsig}"'
]
return "\{" + ",".join(fmt) + "\}\n"

def inner(idx=None):
if idx:
return "\{" + ",".join(fmt[:idx]) + "\}\n"
else:
return "\{" + ",".join(fmt) + "\}\n"
return inner


format_rpm = _make_rpm_formatter()
_etc_and_sub_dirs = sorted(["/etc", "/etc/pki/tls/private", "/etc/pki/tls/certs",
"/etc/pki/ovirt-vmconsole", "/etc/nova/migration", "/etc/sysconfig",
"/etc/cloud/cloud.cfg.d", "/etc/rc.d/init.d"])
""" List of directories for spec `ls_etc` """
_rpm_format = _make_rpm_formatter()
""" Query format for specs `installed_rpms` and `container_installed_rpms` """


class DefaultSpecs(Specs):
# Dep specs that aren't in the registry
block_devices_by_uuid = listdir("/dev/disk/by-uuid/", context=HostContext)
etc_and_sub_dirs = sorted(["/etc", "/etc/pki/tls/private", "/etc/pki/tls/certs",
"/etc/pki/ovirt-vmconsole", "/etc/nova/migration", "/etc/sysconfig",
"/etc/cloud/cloud.cfg.d", "/etc/rc.d/init.d"])
httpd_pid = simple_command("/usr/bin/pgrep -o httpd")
openshift_router_pid = simple_command("/usr/bin/pgrep -n openshift-route")
ovs_vsctl_list_br = simple_command("/usr/bin/ovs-vsctl list-br")
Expand Down Expand Up @@ -267,7 +263,7 @@ class DefaultSpecs(Specs):
init_process_cgroup = simple_file("/proc/1/cgroup")
initctl_lst = simple_command("/sbin/initctl --system list")
insights_client_conf = simple_file('/etc/insights-client/insights-client.conf')
installed_rpms = simple_command("/bin/rpm -qa --qf '%s'" % format_rpm(), context=HostContext, signum=signal.SIGTERM)
installed_rpms = simple_command("/bin/rpm -qa --qf '%s'" % _rpm_format, context=HostContext, signum=signal.SIGTERM)
interrupts = simple_file("/proc/interrupts")
ip6tables = simple_command("/sbin/ip6tables-save")
ip_addr = simple_command("/sbin/ip addr")
Expand Down Expand Up @@ -314,7 +310,7 @@ class DefaultSpecs(Specs):
ls_dev = simple_command("/bin/ls -lanR /dev")
ls_disk = simple_command("/bin/ls -lanR /dev/disk")
ls_edac_mc = simple_command("/bin/ls -lan /sys/devices/system/edac/mc")
ls_etc = simple_command("/bin/ls -lan {0}".format(' '.join(etc_and_sub_dirs)), keep_rc=True)
ls_etc = simple_command("/bin/ls -lan {0}".format(' '.join(_etc_and_sub_dirs)), keep_rc=True)
ls_etc_ssh = simple_command("/bin/ls -lanL /etc/ssh")
ls_ipa_idoverride_memberof = simple_command("/bin/ls -lan /usr/share/ipa/ui/js/plugins/idoverride-memberof")
ls_krb5_sssd = simple_command("/bin/ls -lan /var/lib/sss/pubconf/krb5.include.d")
Expand Down Expand Up @@ -676,6 +672,6 @@ class DefaultSpecs(Specs):
zipl_conf = simple_file("/etc/zipl.conf")

# Container collection specs
container_installed_rpms = container_execute(running_rhel_containers, "rpm -qa --qf '%s'" % format_rpm(), context=HostContext, signum=signal.SIGTERM)
container_installed_rpms = container_execute(running_rhel_containers, "rpm -qa --qf '%s'" % _rpm_format, context=HostContext, signum=signal.SIGTERM)
container_nginx_conf = container_collect(container_nginx_conf_ds)
container_redhat_release = container_collect(running_rhel_containers, "/etc/redhat-release")

0 comments on commit 1878a29

Please sign in to comment.