From 00d284bbab336e3d80133fd5b47ce3a240d8c92b Mon Sep 17 00:00:00 2001 From: Xinting Li Date: Thu, 18 Aug 2022 09:54:21 +0800 Subject: [PATCH 1/4] Feat: New parser for 'ls -lanL /etc/ssh' command Signed-off-by: Xinting Li --- docs/shared_parsers_catalog/ls_etc_ssh.rst | 3 ++ insights/parsers/ls_etc_ssh.py | 44 ++++++++++++++++++++++ insights/specs/__init__.py | 1 + insights/specs/default.py | 1 + insights/tests/parsers/test_ls_etc_ssh.py | 35 +++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 docs/shared_parsers_catalog/ls_etc_ssh.rst create mode 100644 insights/parsers/ls_etc_ssh.py create mode 100644 insights/tests/parsers/test_ls_etc_ssh.py diff --git a/docs/shared_parsers_catalog/ls_etc_ssh.rst b/docs/shared_parsers_catalog/ls_etc_ssh.rst new file mode 100644 index 0000000000..a06055f7b5 --- /dev/null +++ b/docs/shared_parsers_catalog/ls_etc_ssh.rst @@ -0,0 +1,3 @@ +.. automodule:: insights.parsers.ls_etc_ssh + :members: + :show-inheritance: diff --git a/insights/parsers/ls_etc_ssh.py b/insights/parsers/ls_etc_ssh.py new file mode 100644 index 0000000000..8ccd447a1f --- /dev/null +++ b/insights/parsers/ls_etc_ssh.py @@ -0,0 +1,44 @@ +""" +LsEtc - command ``/bin/ls -lanL /etc/ssh`` +========================================== + +The ``/bin/ls -lanL /etc/ssh`` command provides information for the +listing of the ``/etc/ssh`` directory. See ``FileListing`` class for +additional information. + +Sample ``ls -lanL /etc/ssh`` output:: + + total 612 + drwxr-xr-x. 3 0 0 245 Aug 11 14:19 . + drwxr-xr-x. 138 0 0 8192 Jul 29 19:11 .. + -rw-r--r--. 1 0 0 577388 Mar 27 2020 moduli + -rw-r--r--. 1 0 0 1770 Mar 27 2020 ssh_config + drwxr-xr-x. 2 0 0 28 May 12 17:10 ssh_config.d + -rw-r-----. 1 0 994 480 May 13 09:58 ssh_host_ecdsa_key + -rw-r--r--. 1 0 0 162 May 13 09:58 ssh_host_ecdsa_key.pub + -rw-r-----. 1 0 994 387 May 13 09:58 ssh_host_ed25519_key + -rw-r--r--. 1 0 0 82 May 13 09:58 ssh_host_ed25519_key.pub + -rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key + -rw-r--r--. 1 0 0 554 May 13 09:58 ssh_host_rsa_key.pub + -rw-------. 1 0 0 4260 Aug 11 14:19 sshd_config + +Examples: + >>> type(ls_etc_ssh) + + >>> ls_etc_ssh.files_of("/etc/ssh") + ['moduli', 'ssh_config', 'ssh_host_ecdsa_key', 'ssh_host_ecdsa_key.pub', 'ssh_host_ed25519_key', 'ssh_host_ed25519_key.pub', 'ssh_host_rsa_key', 'ssh_host_rsa_key.pub', 'sshd_config'] + >>> ls_etc_ssh.dir_entry('/etc/ssh', 'ssh_host_rsa_key')['perms'] + 'rw-r-----.' +""" + +from insights.core import CommandParser, FileListing +from insights.core.plugins import parser +from insights.specs import Specs + + +@parser(Specs.ls_etc_ssh) +class LsEtcSsh(CommandParser, FileListing): + """ + Parses output of ``ls -lanL /etc/ssh`` command. + """ + pass diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py index a54fa4f36d..a096d9f8c2 100644 --- a/insights/specs/__init__.py +++ b/insights/specs/__init__.py @@ -322,6 +322,7 @@ class Specs(SpecSet): ls_docker_volumes = RegistryPoint() ls_edac_mc = RegistryPoint() ls_etc = RegistryPoint() + ls_etc_ssh = RegistryPoint() ls_ipa_idoverride_memberof = RegistryPoint() ls_lib_firmware = RegistryPoint() ls_ocp_cni_openshift_sdn = RegistryPoint() diff --git a/insights/specs/default.py b/insights/specs/default.py index 7d7bbacb40..be653a8af8 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -324,6 +324,7 @@ class DefaultSpecs(Specs): "/etc/pki/ovirt-vmconsole", "/etc/nova/migration", "/etc/sysconfig", "/etc/cloud/cloud.cfg.d", "/etc/rc.d/init.d"]) 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_lib_firmware = simple_command("/bin/ls -lanR /lib/firmware") ls_ocp_cni_openshift_sdn = simple_command("/bin/ls -l /var/lib/cni/networks/openshift-sdn") diff --git a/insights/tests/parsers/test_ls_etc_ssh.py b/insights/tests/parsers/test_ls_etc_ssh.py new file mode 100644 index 0000000000..186f31b339 --- /dev/null +++ b/insights/tests/parsers/test_ls_etc_ssh.py @@ -0,0 +1,35 @@ +from insights.parsers.ls_etc_ssh import LsEtcSsh +from insights.tests import context_wrap +from insights.parsers import ls_etc_ssh +import doctest + +LS_ETC_SSH = """ +total 612 +drwxr-xr-x. 3 0 0 245 Aug 11 14:19 . +drwxr-xr-x. 138 0 0 8192 Jul 29 19:11 .. +-rw-r--r--. 1 0 0 577388 Mar 27 2020 moduli +-rw-r--r--. 1 0 0 1770 Mar 27 2020 ssh_config +drwxr-xr-x. 2 0 0 28 May 12 17:10 ssh_config.d +-rw-r-----. 1 0 994 480 May 13 09:58 ssh_host_ecdsa_key +-rw-r--r--. 1 0 0 162 May 13 09:58 ssh_host_ecdsa_key.pub +-rw-r-----. 1 0 994 387 May 13 09:58 ssh_host_ed25519_key +-rw-r--r--. 1 0 0 82 May 13 09:58 ssh_host_ed25519_key.pub +-rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key +-rw-r--r--. 1 0 0 554 May 13 09:58 ssh_host_rsa_key.pub +-rw-------. 1 0 0 4260 Aug 11 14:19 sshd_config +""" + + +def test_ls_etc_ssh(): + ls_etc_ssh = LsEtcSsh(context_wrap(LS_ETC_SSH, path='ls_-lanL_.etc.ssh')) + assert '/etc/ssh' in ls_etc_ssh + assert len(ls_etc_ssh.files_of("/etc/ssh")) == 9 + assert ls_etc_ssh.files_of("/etc/ssh") == ['moduli', 'ssh_config', 'ssh_host_ecdsa_key', 'ssh_host_ecdsa_key.pub', 'ssh_host_ed25519_key', 'ssh_host_ed25519_key.pub', 'ssh_host_rsa_key', 'ssh_host_rsa_key.pub', 'sshd_config'] + assert ls_etc_ssh.dirs_of("/etc/ssh") == ['.', '..', 'ssh_config.d'] + assert ls_etc_ssh.listing_of("/etc/ssh")['ssh_host_rsa_key'] == {'group': '994', 'name': 'ssh_host_rsa_key', 'links': 1, 'perms': 'rw-r-----.', 'raw_entry': '-rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key', 'owner': '0', 'date': 'May 13 09:58', 'type': '-', 'dir': '/etc/ssh', 'size': 2578} + + +def test_ls_etc_ssh_doc_examples(): + env = {'ls_etc_ssh': LsEtcSsh(context_wrap(LS_ETC_SSH, path='ls_-lanL_.etc.ssh'))} + failed, total = doctest.testmod(ls_etc_ssh, globs=env) + assert failed == 0 From be82323aeda41dd1bd36998094a2ad25eff6c8a6 Mon Sep 17 00:00:00 2001 From: Xinting Li Date: Thu, 18 Aug 2022 10:08:25 +0800 Subject: [PATCH 2/4] Update insights_archive.py Signed-off-by: Xinting Li --- insights/specs/insights_archive.py | 1 + 1 file changed, 1 insertion(+) diff --git a/insights/specs/insights_archive.py b/insights/specs/insights_archive.py index e62891e6e0..a9bf6df86b 100644 --- a/insights/specs/insights_archive.py +++ b/insights/specs/insights_archive.py @@ -116,6 +116,7 @@ class InsightsArchiveSpecs(Specs): ls_disk = simple_file("insights_commands/ls_-lanR_.dev.disk") ls_edac_mc = simple_file("insights_commands/ls_-lan_.sys.devices.system.edac.mc") ls_etc = simple_file("insights_commands/ls_-lan_.etc_.etc.cloud.cloud.cfg.d_.etc.nova.migration_.etc.pki.ovirt-vmconsole_.etc.pki.tls.certs_.etc.pki.tls.private_.etc.rc.d.init.d_.etc.sysconfig") + ls_etc_ssh = simple_file("insights_commands/ls_-lanL_.etc.ssh") ls_ipa_idoverride_memberof = simple_file("insights_commands/ls_-lan_.usr.share.ipa.ui.js.plugins.idoverride-memberof") ls_lib_firmware = simple_file("insights_commands/ls_-lanR_.lib.firmware") ls_ocp_cni_openshift_sdn = simple_file("insights_commands/ls_-l_.var.lib.cni.networks.openshift-sdn") From bf944d9b1ea1825ef4ed00e05c7a1f64cb10d5d4 Mon Sep 17 00:00:00 2001 From: Xinting Li Date: Mon, 22 Aug 2022 09:54:21 +0800 Subject: [PATCH 3/4] Move LsEtcSsh from ls_etc_ssh.py to ls_etc.py Signed-off-by: Xinting Li --- docs/shared_parsers_catalog/ls_etc_ssh.rst | 3 - insights/parsers/ls_etc.py | 165 +++++++++++++-------- insights/parsers/ls_etc_ssh.py | 44 ------ insights/tests/parsers/test_ls_etc.py | 28 +++- insights/tests/parsers/test_ls_etc_ssh.py | 35 ----- 5 files changed, 130 insertions(+), 145 deletions(-) delete mode 100644 docs/shared_parsers_catalog/ls_etc_ssh.rst delete mode 100644 insights/parsers/ls_etc_ssh.py delete mode 100644 insights/tests/parsers/test_ls_etc_ssh.py diff --git a/docs/shared_parsers_catalog/ls_etc_ssh.rst b/docs/shared_parsers_catalog/ls_etc_ssh.rst deleted file mode 100644 index a06055f7b5..0000000000 --- a/docs/shared_parsers_catalog/ls_etc_ssh.rst +++ /dev/null @@ -1,3 +0,0 @@ -.. automodule:: insights.parsers.ls_etc_ssh - :members: - :show-inheritance: diff --git a/insights/parsers/ls_etc.py b/insights/parsers/ls_etc.py index cf987b9ef8..1e24843cf7 100644 --- a/insights/parsers/ls_etc.py +++ b/insights/parsers/ls_etc.py @@ -1,67 +1,14 @@ """ +Ls Etc Directory +================ + +Parsers provided in this module includes: + LsEtc - command ``ls -lan /etc `` -================================================ - -The ``ls -lan /etc `` command provides information for -the listing of the ``/etc`` directory and specified sub-directories. -See ``FileListing`` class for additional information. - -Sample ``ls -lan /etc/sysconfig /etc/rc.d/rc3.d`` output:: - - /etc/sysconfig: - total 96 - drwxr-xr-x. 7 0 0 4096 Jul 6 23:41 . - drwxr-xr-x. 77 0 0 8192 Jul 13 03:55 .. - drwxr-xr-x. 2 0 0 41 Jul 6 23:32 cbq - drwxr-xr-x. 2 0 0 6 Sep 16 2015 console - -rw-------. 1 0 0 1390 Mar 4 2014 ebtables-config - -rw-r--r--. 1 0 0 72 Sep 15 2015 firewalld - lrwxrwxrwx. 1 0 0 17 Jul 6 23:32 grub -> /etc/default/grub - - /etc/rc.d/rc3.d: - total 4 - drwxr-xr-x. 2 0 0 58 Jul 6 23:32 . - drwxr-xr-x. 10 0 0 4096 Sep 16 2015 .. - lrwxrwxrwx. 1 0 0 20 Jul 6 23:32 K50netconsole -> ../init.d/netconsole - lrwxrwxrwx. 1 0 0 17 Jul 6 23:32 S10network -> ../init.d/network - lrwxrwxrwx. 1 0 0 15 Jul 6 23:32 S97rhnsd -> ../init.d/rhnsd - -Examples: - - >>> "sysconfig" in ls_etc - False - >>> "/etc/sysconfig" in ls_etc - True - >>> len(ls_etc.files_of('/etc/sysconfig')) - 3 - >>> ls_etc.files_of("/etc/sysconfig") - ['ebtables-config', 'firewalld', 'grub'] - >>> ls_etc.dirs_of("/etc/sysconfig") - ['.', '..', 'cbq', 'console'] - >>> ls_etc.specials_of("/etc/sysconfig") - [] - >>> ls_etc.total_of("/etc/sysconfig") - 96 - >>> ls_etc.dir_entry('/etc/sysconfig', 'grub') == {'group': '0', 'name': 'grub', 'links': 1, 'perms': 'rwxrwxrwx.', 'raw_entry': 'lrwxrwxrwx. 1 0 0 17 Jul 6 23:32 grub -> /etc/default/grub', 'owner': '0', 'link': '/etc/default/grub', 'date': 'Jul 6 23:32', 'type': 'l', 'dir': '/etc/sysconfig', 'size': 17} - True - >>> ls_etc.files_of('/etc/rc.d/rc3.d') - ['K50netconsole', 'S10network', 'S97rhnsd'] - >>> sorted(ls_etc.listing_of("/etc/sysconfig").keys()) == sorted(['console', 'grub', '..', 'firewalld', '.', 'cbq', 'ebtables-config']) - True - >>> sorted(ls_etc.listing_of("/etc/sysconfig")['console'].keys()) == sorted(['group', 'name', 'links', 'perms', 'raw_entry', 'owner', 'date', 'type', 'dir', 'size']) - True - >>> ls_etc.listing_of("/etc/sysconfig")['console']['type'] - 'd' - >>> ls_etc.listing_of("/etc/sysconfig")['console']['perms'] - 'rwxr-xr-x.' - >>> ls_etc.dir_contains("/etc/sysconfig", "console") - True - >>> ls_etc.dir_entry("/etc/sysconfig", "console") == {'group': '0', 'name': 'console', 'links': 2, 'perms': 'rwxr-xr-x.', 'raw_entry': 'drwxr-xr-x. 2 0 0 6 Sep 16 2015 console', 'owner': '0', 'date': 'Sep 16 2015', 'type': 'd', 'dir': '/etc/sysconfig', 'size': 6} - True - >>> ls_etc.dir_entry("/etc/sysconfig", "grub")['type'] - 'l' - >>> ls_etc.dir_entry("/etc/sysconfig", "grub")['link'] - '/etc/default/grub' +------------------------------------------------ + +LsEtcSsh - command ``/bin/ls -lanL /etc/ssh`` +--------------------------------------------- """ from .. import parser, CommandParser from .. import FileListing @@ -72,5 +19,99 @@ class LsEtc(CommandParser, FileListing): """ Parses output of ``ls -lan /etc `` command. + + The ``ls -lan /etc `` command provides information for + the listing of the ``/etc`` directory and specified sub-directories. + See ``FileListing`` class for additional information. + + Sample ``ls -lan /etc/sysconfig /etc/rc.d/rc3.d`` output:: + + /etc/sysconfig: + total 96 + drwxr-xr-x. 7 0 0 4096 Jul 6 23:41 . + drwxr-xr-x. 77 0 0 8192 Jul 13 03:55 .. + drwxr-xr-x. 2 0 0 41 Jul 6 23:32 cbq + drwxr-xr-x. 2 0 0 6 Sep 16 2015 console + -rw-------. 1 0 0 1390 Mar 4 2014 ebtables-config + -rw-r--r--. 1 0 0 72 Sep 15 2015 firewalld + lrwxrwxrwx. 1 0 0 17 Jul 6 23:32 grub -> /etc/default/grub + + /etc/rc.d/rc3.d: + total 4 + drwxr-xr-x. 2 0 0 58 Jul 6 23:32 . + drwxr-xr-x. 10 0 0 4096 Sep 16 2015 .. + lrwxrwxrwx. 1 0 0 20 Jul 6 23:32 K50netconsole -> ../init.d/netconsole + lrwxrwxrwx. 1 0 0 17 Jul 6 23:32 S10network -> ../init.d/network + lrwxrwxrwx. 1 0 0 15 Jul 6 23:32 S97rhnsd -> ../init.d/rhnsd + + Examples: + + >>> "sysconfig" in ls_etc + False + >>> "/etc/sysconfig" in ls_etc + True + >>> len(ls_etc.files_of('/etc/sysconfig')) + 3 + >>> ls_etc.files_of("/etc/sysconfig") + ['ebtables-config', 'firewalld', 'grub'] + >>> ls_etc.dirs_of("/etc/sysconfig") + ['.', '..', 'cbq', 'console'] + >>> ls_etc.specials_of("/etc/sysconfig") + [] + >>> ls_etc.total_of("/etc/sysconfig") + 96 + >>> ls_etc.dir_entry('/etc/sysconfig', 'grub') == {'group': '0', 'name': 'grub', 'links': 1, 'perms': 'rwxrwxrwx.', 'raw_entry': 'lrwxrwxrwx. 1 0 0 17 Jul 6 23:32 grub -> /etc/default/grub', 'owner': '0', 'link': '/etc/default/grub', 'date': 'Jul 6 23:32', 'type': 'l', 'dir': '/etc/sysconfig', 'size': 17} + True + >>> ls_etc.files_of('/etc/rc.d/rc3.d') + ['K50netconsole', 'S10network', 'S97rhnsd'] + >>> sorted(ls_etc.listing_of("/etc/sysconfig").keys()) == sorted(['console', 'grub', '..', 'firewalld', '.', 'cbq', 'ebtables-config']) + True + >>> sorted(ls_etc.listing_of("/etc/sysconfig")['console'].keys()) == sorted(['group', 'name', 'links', 'perms', 'raw_entry', 'owner', 'date', 'type', 'dir', 'size']) + True + >>> ls_etc.listing_of("/etc/sysconfig")['console']['type'] + 'd' + >>> ls_etc.listing_of("/etc/sysconfig")['console']['perms'] + 'rwxr-xr-x.' + >>> ls_etc.dir_contains("/etc/sysconfig", "console") + True + >>> ls_etc.dir_entry("/etc/sysconfig", "console") == {'group': '0', 'name': 'console', 'links': 2, 'perms': 'rwxr-xr-x.', 'raw_entry': 'drwxr-xr-x. 2 0 0 6 Sep 16 2015 console', 'owner': '0', 'date': 'Sep 16 2015', 'type': 'd', 'dir': '/etc/sysconfig', 'size': 6} + True + >>> ls_etc.dir_entry("/etc/sysconfig", "grub")['type'] + 'l' + >>> ls_etc.dir_entry("/etc/sysconfig", "grub")['link'] + '/etc/default/grub' """ pass + + +@parser(Specs.ls_etc_ssh) +class LsEtcSsh(CommandParser, FileListing): + """ + Parses output of ``ls -lanL /etc/ssh`` command. + + Sample ``ls -lanL /etc/ssh`` output:: + + total 612 + drwxr-xr-x. 3 0 0 245 Aug 11 14:19 . + drwxr-xr-x. 138 0 0 8192 Jul 29 19:11 .. + -rw-r--r--. 1 0 0 577388 Mar 27 2020 moduli + -rw-r--r--. 1 0 0 1770 Mar 27 2020 ssh_config + drwxr-xr-x. 2 0 0 28 May 12 17:10 ssh_config.d + -rw-r-----. 1 0 994 480 May 13 09:58 ssh_host_ecdsa_key + -rw-r--r--. 1 0 0 162 May 13 09:58 ssh_host_ecdsa_key.pub + -rw-r-----. 1 0 994 387 May 13 09:58 ssh_host_ed25519_key + -rw-r--r--. 1 0 0 82 May 13 09:58 ssh_host_ed25519_key.pub + -rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key + -rw-r--r--. 1 0 0 554 May 13 09:58 ssh_host_rsa_key.pub + -rw-------. 1 0 0 4260 Aug 11 14:19 sshd_config + + Examples: + >>> type(ls_etc_ssh) + + >>> ls_etc_ssh.files_of("/etc/ssh") + ['moduli', 'ssh_config', 'ssh_host_ecdsa_key', 'ssh_host_ecdsa_key.pub', 'ssh_host_ed25519_key', 'ssh_host_ed25519_key.pub', 'ssh_host_rsa_key', 'ssh_host_rsa_key.pub', 'sshd_config'] + >>> ls_etc_ssh.dir_entry('/etc/ssh', 'ssh_host_rsa_key')['perms'] + 'rw-r-----.' + """ + pass + diff --git a/insights/parsers/ls_etc_ssh.py b/insights/parsers/ls_etc_ssh.py deleted file mode 100644 index 8ccd447a1f..0000000000 --- a/insights/parsers/ls_etc_ssh.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -LsEtc - command ``/bin/ls -lanL /etc/ssh`` -========================================== - -The ``/bin/ls -lanL /etc/ssh`` command provides information for the -listing of the ``/etc/ssh`` directory. See ``FileListing`` class for -additional information. - -Sample ``ls -lanL /etc/ssh`` output:: - - total 612 - drwxr-xr-x. 3 0 0 245 Aug 11 14:19 . - drwxr-xr-x. 138 0 0 8192 Jul 29 19:11 .. - -rw-r--r--. 1 0 0 577388 Mar 27 2020 moduli - -rw-r--r--. 1 0 0 1770 Mar 27 2020 ssh_config - drwxr-xr-x. 2 0 0 28 May 12 17:10 ssh_config.d - -rw-r-----. 1 0 994 480 May 13 09:58 ssh_host_ecdsa_key - -rw-r--r--. 1 0 0 162 May 13 09:58 ssh_host_ecdsa_key.pub - -rw-r-----. 1 0 994 387 May 13 09:58 ssh_host_ed25519_key - -rw-r--r--. 1 0 0 82 May 13 09:58 ssh_host_ed25519_key.pub - -rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key - -rw-r--r--. 1 0 0 554 May 13 09:58 ssh_host_rsa_key.pub - -rw-------. 1 0 0 4260 Aug 11 14:19 sshd_config - -Examples: - >>> type(ls_etc_ssh) - - >>> ls_etc_ssh.files_of("/etc/ssh") - ['moduli', 'ssh_config', 'ssh_host_ecdsa_key', 'ssh_host_ecdsa_key.pub', 'ssh_host_ed25519_key', 'ssh_host_ed25519_key.pub', 'ssh_host_rsa_key', 'ssh_host_rsa_key.pub', 'sshd_config'] - >>> ls_etc_ssh.dir_entry('/etc/ssh', 'ssh_host_rsa_key')['perms'] - 'rw-r-----.' -""" - -from insights.core import CommandParser, FileListing -from insights.core.plugins import parser -from insights.specs import Specs - - -@parser(Specs.ls_etc_ssh) -class LsEtcSsh(CommandParser, FileListing): - """ - Parses output of ``ls -lanL /etc/ssh`` command. - """ - pass diff --git a/insights/tests/parsers/test_ls_etc.py b/insights/tests/parsers/test_ls_etc.py index 0dd8854b35..cfd1f771c8 100644 --- a/insights/tests/parsers/test_ls_etc.py +++ b/insights/tests/parsers/test_ls_etc.py @@ -201,6 +201,22 @@ lrwxrwxrwx. 1 0 0 15 Jul 6 23:32 S97rhnsd -> ../init.d/rhnsd """ +LS_ETC_SSH = """ +total 612 +drwxr-xr-x. 3 0 0 245 Aug 11 14:19 . +drwxr-xr-x. 138 0 0 8192 Jul 29 19:11 .. +-rw-r--r--. 1 0 0 577388 Mar 27 2020 moduli +-rw-r--r--. 1 0 0 1770 Mar 27 2020 ssh_config +drwxr-xr-x. 2 0 0 28 May 12 17:10 ssh_config.d +-rw-r-----. 1 0 994 480 May 13 09:58 ssh_host_ecdsa_key +-rw-r--r--. 1 0 0 162 May 13 09:58 ssh_host_ecdsa_key.pub +-rw-r-----. 1 0 994 387 May 13 09:58 ssh_host_ed25519_key +-rw-r--r--. 1 0 0 82 May 13 09:58 ssh_host_ed25519_key.pub +-rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key +-rw-r--r--. 1 0 0 554 May 13 09:58 ssh_host_rsa_key.pub +-rw-------. 1 0 0 4260 Aug 11 14:19 sshd_config +""" + def test_ls_etc(): list_etc = ls_etc.LsEtc(context_wrap(LS_ETC)) @@ -234,6 +250,16 @@ def test_ls_etc(): def test_ls_etc_documentation(): failed_count, tests = doctest.testmod( ls_etc, - globs={'ls_etc': ls_etc.LsEtc(context_wrap(LS_ETC))} + globs={'ls_etc': ls_etc.LsEtc(context_wrap(LS_ETC)), + 'ls_etc_ssh': ls_etc.LsEtcSsh(context_wrap(LS_ETC_SSH, path='ls_-lanL_.etc.ssh'))} ) assert failed_count == 0 + + +def test_ls_etc_ssh(): + ls_etc_ssh = ls_etc.LsEtcSsh(context_wrap(LS_ETC_SSH, path='ls_-lanL_.etc.ssh')) + assert '/etc/ssh' in ls_etc_ssh + assert len(ls_etc_ssh.files_of("/etc/ssh")) == 9 + assert ls_etc_ssh.files_of("/etc/ssh") == ['moduli', 'ssh_config', 'ssh_host_ecdsa_key', 'ssh_host_ecdsa_key.pub', 'ssh_host_ed25519_key', 'ssh_host_ed25519_key.pub', 'ssh_host_rsa_key', 'ssh_host_rsa_key.pub', 'sshd_config'] + assert ls_etc_ssh.dirs_of("/etc/ssh") == ['.', '..', 'ssh_config.d'] + assert ls_etc_ssh.listing_of("/etc/ssh")['ssh_host_rsa_key'] == {'group': '994', 'name': 'ssh_host_rsa_key', 'links': 1, 'perms': 'rw-r-----.', 'raw_entry': '-rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key', 'owner': '0', 'date': 'May 13 09:58', 'type': '-', 'dir': '/etc/ssh', 'size': 2578} diff --git a/insights/tests/parsers/test_ls_etc_ssh.py b/insights/tests/parsers/test_ls_etc_ssh.py deleted file mode 100644 index 186f31b339..0000000000 --- a/insights/tests/parsers/test_ls_etc_ssh.py +++ /dev/null @@ -1,35 +0,0 @@ -from insights.parsers.ls_etc_ssh import LsEtcSsh -from insights.tests import context_wrap -from insights.parsers import ls_etc_ssh -import doctest - -LS_ETC_SSH = """ -total 612 -drwxr-xr-x. 3 0 0 245 Aug 11 14:19 . -drwxr-xr-x. 138 0 0 8192 Jul 29 19:11 .. --rw-r--r--. 1 0 0 577388 Mar 27 2020 moduli --rw-r--r--. 1 0 0 1770 Mar 27 2020 ssh_config -drwxr-xr-x. 2 0 0 28 May 12 17:10 ssh_config.d --rw-r-----. 1 0 994 480 May 13 09:58 ssh_host_ecdsa_key --rw-r--r--. 1 0 0 162 May 13 09:58 ssh_host_ecdsa_key.pub --rw-r-----. 1 0 994 387 May 13 09:58 ssh_host_ed25519_key --rw-r--r--. 1 0 0 82 May 13 09:58 ssh_host_ed25519_key.pub --rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key --rw-r--r--. 1 0 0 554 May 13 09:58 ssh_host_rsa_key.pub --rw-------. 1 0 0 4260 Aug 11 14:19 sshd_config -""" - - -def test_ls_etc_ssh(): - ls_etc_ssh = LsEtcSsh(context_wrap(LS_ETC_SSH, path='ls_-lanL_.etc.ssh')) - assert '/etc/ssh' in ls_etc_ssh - assert len(ls_etc_ssh.files_of("/etc/ssh")) == 9 - assert ls_etc_ssh.files_of("/etc/ssh") == ['moduli', 'ssh_config', 'ssh_host_ecdsa_key', 'ssh_host_ecdsa_key.pub', 'ssh_host_ed25519_key', 'ssh_host_ed25519_key.pub', 'ssh_host_rsa_key', 'ssh_host_rsa_key.pub', 'sshd_config'] - assert ls_etc_ssh.dirs_of("/etc/ssh") == ['.', '..', 'ssh_config.d'] - assert ls_etc_ssh.listing_of("/etc/ssh")['ssh_host_rsa_key'] == {'group': '994', 'name': 'ssh_host_rsa_key', 'links': 1, 'perms': 'rw-r-----.', 'raw_entry': '-rw-r-----. 1 0 994 2578 May 13 09:58 ssh_host_rsa_key', 'owner': '0', 'date': 'May 13 09:58', 'type': '-', 'dir': '/etc/ssh', 'size': 2578} - - -def test_ls_etc_ssh_doc_examples(): - env = {'ls_etc_ssh': LsEtcSsh(context_wrap(LS_ETC_SSH, path='ls_-lanL_.etc.ssh'))} - failed, total = doctest.testmod(ls_etc_ssh, globs=env) - assert failed == 0 From 07646256738cb78c67d7638a8500488bb5d1deae Mon Sep 17 00:00:00 2001 From: Xinting Li Date: Mon, 22 Aug 2022 09:56:08 +0800 Subject: [PATCH 4/4] Fix flake8 error Signed-off-by: Xinting Li --- insights/parsers/ls_etc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/insights/parsers/ls_etc.py b/insights/parsers/ls_etc.py index 1e24843cf7..b34389eff7 100644 --- a/insights/parsers/ls_etc.py +++ b/insights/parsers/ls_etc.py @@ -114,4 +114,3 @@ class LsEtcSsh(CommandParser, FileListing): 'rw-r-----.' """ pass -