def test_add_filter_to_parser(): filter_string = "bash" filters.add_filter(PsAux, filter_string) spec_filters = filters.get_filters(Specs.ps_aux) assert filter_string in spec_filters parser_filters = filters.get_filters(PsAux) assert not parser_filters
def test_add_filter_to_parser_patterns_list(): filters_list = ["bash", "systemd", "Network"] filters.add_filter(PsAux, filters_list) spec_filters = filters.get_filters(Specs.ps_aux) assert all(f in spec_filters for f in filters_list) parser_filters = filters.get_filters(PsAux) assert not parser_filters
def test_add_filter_to_parser_non_filterable(): filter_string = "bash" filters.add_filter(PsAuxcww, filter_string) spec_filters = filters.get_filters(Specs.ps_auxcww) assert not spec_filters parser_filters = filters.get_filters(PsAuxcww) assert not parser_filters
def setup_function(func): if Specs.package_provides_command in filters._CACHE: del filters._CACHE[Specs.package_provides_command] if Specs.package_provides_command in filters.FILTERS: del filters.FILTERS[Specs.package_provides_command] if func is test_cmd_and_pkg: filters.add_filter(Specs.package_provides_command, ['httpd', 'java']) elif func is test_cmd_and_pkg_not_found: filters.add_filter(Specs.package_provides_command, ['not_found'])
def setup_function(func): if Specs.awx_manage_check_license_data in filters._CACHE: del filters._CACHE[Specs.awx_manage_check_license_data] if Specs.awx_manage_check_license_data in filters.FILTERS: del filters.FILTERS[Specs.awx_manage_check_license_data] if func is test_ansible_tower_license_datasource or func is test_ansible_tower_license_datasource_NG_output: filters.add_filter(Specs.awx_manage_check_license_data, ["license_type", "support_level", "instance_count", "time_remaining"]) if func is test_ansible_tower_license_datasource_no_filter: filters.add_filter(Specs.awx_manage_check_license_data, [])
def test_filter_dumps_loads(): key = "test_filter_dump" value = key filters.add_filter(key, value) r = filters.dumps() assert r is not None filters.FILTERS = defaultdict(set) filters.loads(r) assert key in filters.FILTERS assert filters.FILTERS[key] == set([value])
def test_get_filter(): filters.add_filter(Specs.fstab, "COMMAND") f = filters.get_filters(Specs.fstab) assert "COMMAND" in f f = filters.get_filters(DefaultSpecs.fstab) assert "COMMAND" in f lines = ["COMMAND", "DISCARD"] lines = filters.apply_filters(DefaultSpecs.fstab, lines) assert "COMMAND" in lines assert "DISCARD" not in lines
def setup_function(func): if func is test_get_filter: filters.add_filter(Specs.ps_aux, "COMMAND") if func is test_get_filter_registry_point: filters.add_filter(Specs.ps_aux, "COMMAND") filters.add_filter(DefaultSpecs.ps_aux, "MEM") if func is test_filter_dumps_loads: filters.add_filter(Specs.ps_aux, "COMMAND")
def setup_function(func): if Specs.cloud_cfg in filters._CACHE: del filters._CACHE[Specs.cloud_cfg] if Specs.cloud_cfg in filters.FILTERS: del filters.FILTERS[Specs.cloud_cfg] if func is test_cloud_cfg: filters.add_filter(Specs.cloud_cfg, ['ssh_deletekeys', 'network', 'debug']) if func is test_cloud_cfg_no_filter: filters.add_filter(Specs.cloud_cfg, []) elif func is test_cloud_cfg_bad: filters.add_filter(Specs.cloud_cfg, ['not_found'])
def test_add_filter_exception_raw(): with pytest.raises(Exception): filters.add_filter(Specs.metadata_json, "[]")
def test_add_filter_exception_not_filterable(): with pytest.raises(Exception): filters.add_filter(Specs.ps_auxcww, "bash")
from insights.core.filters import add_filter from insights.specs import Specs from insights.tests import context_wrap, DEFAULT_RELEASE, DEFAULT_HOSTNAME DATA = """ One Two Three Four """ DATA_FILTERED = """ Two Four """ add_filter(Specs.messages, ["Two", "Four", "Five"]) def test_context_wrap_unfiltered(): context = context_wrap(DATA) assert context is not None assert context.content == DATA.strip().splitlines() assert context.release == DEFAULT_RELEASE assert context.hostname == DEFAULT_HOSTNAME assert context.version == ["-1", "-1"] assert context.machine_id == "machine_id" def test_context_wrap_filtered(): context = context_wrap(DATA, filtered_spec=Specs.messages) assert context is not None
from insights.core.plugins import parser from insights.specs import Specs filter_list = [ '[', 'interval', 'oneshot', 'type', 'server', 'debug', 'log_', 'configs', 'owner', 'env', ] add_filter(Specs.virt_who_conf, filter_list) @parser(Specs.virt_who_conf) class VirtWhoConf(IniConfigFile): """ Parse the ``virt-who`` configuration files ``/etc/virt-who.conf`` and ``/etc/virt-who.d/*.conf``. Sample configuration file:: #Terse version of the general config template: [global] interval=3600 #reporter_id=
""" NeutronDhcpAgentIni - file ``/etc/neutron/dhcp_agent.ini`` ========================================================== """ from insights.core import IniConfigFile from insights.core.plugins import parser from insights.core.filters import add_filter from insights.specs import Specs add_filter(Specs.neutron_dhcp_agent_ini, ["["]) @parser(Specs.neutron_dhcp_agent_ini) class NeutronDhcpAgentIni(IniConfigFile): """ Parse the ``/etc/neutron/dhcp_agent.ini`` configuration file. Sample configuration:: [DEFAULT] ovs_integration_bridge = br-int ovs_use_veth = false interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver ovs_vsctl_timeout = 10 resync_interval = 30 dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq enable_isolated_metadata = True force_metadata = False enable_metadata_network = False root_helper=sudo neutron-rootwrap /etc/neutron/rootwrap.conf
total 41472 -rwxr-xr-x. 1 0 0 11720 Mar 18 2014 accessdb -rwxr-sr-x. 1 0 90 218552 Jan 27 2014 postdrop Examples: >>> "accessdb" in ls_usr_sbin False >>> "/usr/sbin" in ls_usr_sbin True >>> ls_usr_sbin.dir_entry('/usr/sbin', 'accessdb')['type'] '-' >>> ls_usr_sbin.dir_entry('/usr/sbin', 'postdrop')['type'] '-' """ from insights.core.filters import add_filter from insights.specs import Specs from .. import CommandParser, parser from .. import FileListing add_filter(Specs.ls_usr_sbin, "total") @parser(Specs.ls_usr_sbin) class LsUsrSbin(CommandParser, FileListing): """Parses output of ``ls -ln /usr/sbin`` command.""" pass
""" SetupNamedChroot - file ``/usr/libexec/setup-named-chroot.sh`` ============================================================== This module provides class ``SetupNamedChroot`` for parsing the output of file ``/usr/libexec/setup-named-chroot.sh``. """ from insights import Parser, get_active_lines, parser from insights.core.filters import add_filter from insights.parsers import SkipException from insights.specs import Specs add_filter(Specs.setup_named_chroot, ["ROOTDIR_MOUNT", "/"]) @parser(Specs.setup_named_chroot) class SetupNamedChroot(Parser, dict): """ Class for parsing the `/usr/libexec/setup-named-chroot.sh` file. Typical content of the filtered file is:: #!/bin/bash # it MUST be listed last. (/var/named contains /var/named/chroot) ROOTDIR_MOUNT='/etc/localtime /etc/named /etc/pki/dnssec-keys /etc/named.root.key /etc/named.conf /etc/named.dnssec.keys /etc/named.rfc1912.zones /etc/rndc.conf /etc/rndc.key /usr/lib64/bind /usr/lib/bind /etc/named.iscdlv.key /run/named /var/named /etc/protocols /etc/services' for all in $ROOTDIR_MOUNT; do for all in $ROOTDIR_MOUNT; do, # Check if file is mount target. Do not use /proc/mounts because detecting
/var/tmp: total 20 drwxr-xr-x. 2 0 0 4096 Mar 26 02:25 a1 drwxr-xr-x. 2 0 0 4096 Mar 26 02:25 a2 drwxr-xr-x. 2 0 0 4096 Apr 28 2018 foreman-ssh-cmd-fc3f65c9-2b35-480d-87e3-1d971433d6ad Examples: >>> "a1" in ls_var_tmp False >>> "/var/tmp" in ls_var_tmp True >>> ls_var_tmp.dir_entry('/var/tmp', 'a1')['type'] 'd' """ from insights.specs import Specs from insights.core.filters import add_filter from .. import FileListing from .. import parser, CommandParser add_filter(Specs.ls_var_tmp, "/var/tmp") @parser(Specs.ls_var_tmp) class LsVarTmp(CommandParser, FileListing): """Parses output of ``ls -ln /var/tmp`` command.""" pass
[main] gpgcheck=1 installonly_limit=3 clean_requirements_on_remove=True best=False skip_if_unavailable=True Examples: >>> 'main' in dconf True >>> 'rhel-7-server-rpms' in dconf False >>> dconf.has_option('main', 'gpgcheck') True >>> dconf.has_option('main', 'foo') False """ from insights import parser from insights.specs import Specs from insights.core.filters import add_filter from insights.parsers.yum_conf import YumConf add_filter(Specs.dnf_conf, '[') @parser(Specs.dnf_conf) class DnfConf(YumConf): """Parse contents of file ``/etc/dnf/dnf.conf``.""" pass
# Since the key values in file odbc.ini is case insensitive, # and curent filter_list is not support case insensitive, # will add several duplicate keys here to filter out more useful data. filter_list = [ '[', 'DRIVER', 'Driver', 'driver', 'SERVER', 'Server', 'server', 'NO_SSPS', 'No_ssps', 'no_ssps', ] add_filter(Specs.odbc_ini, filter_list) @parser(Specs.odbc_ini) class ODBCIni(IniConfigFile): """ The ``/etc/odbc.ini`` file is in a standard '.ini' format, and this parser uses the IniConfigFile base class to read this. Sample command output:: [myodbc5w] Driver = /usr/lib64/libmyodbc5w.so Description = DSN to MySQL server SERVER = localhost NO_SSPS = 1
""" Installed product IDs ===================== InstalledProductIDs - command ``find /etc/pki/product-default/ /etc/pki/product/ -name '*pem' -exec rct cat-cert --no-content '{}' \;`` --------------------------------------------------------------------------------------------------------------------------------------- This module provides a parser for information about certificates for Red Hat product subscriptions. """ from insights.core.filters import add_filter from insights.specs import Specs from .. import parser, CommandParser add_filter(Specs.subscription_manager_installed_product_ids, 'ID:') @parser(Specs.subscription_manager_installed_product_ids) class InstalledProductIDs(CommandParser): """ Parses the output of the comand:: find /etc/pki/product-default/ /etc/pki/product/ -name '*pem' -exec rct cat-cert --no-content '{}' \; Sample output from the unfiltered command looks like:: +-------------------------------------------+ Product Certificate +-------------------------------------------+
from insights import rule, make_pass from insights.core.filters import add_filter from insights.parsers.ps import PsAux, PsAuxww, PsAlxwww from insights.specs import Specs @rule(PsAux) def psaux_no_filter(ps_aux): return make_pass("FAKE RESULT") add_filter(Specs.ps_auxww, "fake-filter") @rule(PsAuxww) def psauxww_ds_filter(ps_auxww): return make_pass("FAKE RESULT") add_filter(PsAlxwww, "fake-filter") @rule(PsAlxwww) def psalxwww_parser_filter(ps_alxwww): return make_pass("FAKE RESULT")
def test_add_filter_exception_empty(): with pytest.raises(Exception): filters.add_filter(Specs.ps_aux, "")
from insights.core.plugins import make_fail, rule, condition from insights.combiners.redhat_release import RedHatRelease from insights.parsers.installed_rpms import InstalledRpms, InstalledRpm from insights.specs import Specs from insights.core.filters import add_filter from insights.parsers.messages import Messages from mycomponents.rules.plugins.shift import is_shift_node_service_running ERROR_KEY = "OCP_SYSTEMD_DBUS_REGRESSION" ERROR_LOG_CROND = 'pam_systemd(crond:session): Failed to create session: Connection timed out' ERROR_LOG_SYSTEMD_LOGIND1 = 'slice, ignoring: Connection timed out' ERROR_LOG_SYSTEMD_LOGIND2 = 'scope: Connection timed out' ERROR_LOG_SYSTEMD = 'Failed to propagate agent release message: Operation not supported' add_filter(Specs.messages, ERROR_LOG_CROND) add_filter(Specs.messages, ERROR_LOG_SYSTEMD_LOGIND1) add_filter(Specs.messages, ERROR_LOG_SYSTEMD_LOGIND2) add_filter(Specs.messages, ERROR_LOG_SYSTEMD) Messages.keep_scan('checking_crond_msg', ERROR_LOG_CROND) Messages.keep_scan('checking_systemd-logind_msg1', ERROR_LOG_SYSTEMD_LOGIND1) Messages.keep_scan('checking_systemd-logind_msg2', ERROR_LOG_SYSTEMD_LOGIND2) Messages.keep_scan('checking_systemd_msg', ERROR_LOG_SYSTEMD) @condition(InstalledRpms) def is_affected_systemd_version(rpms): installed_systemd = rpms.newest('systemd') systemd760 = InstalledRpm.from_package('systemd-219-62.el7') systemd770 = InstalledRpm.from_package('systemd-219-67.el7')
drwxr-xr-x. 3 0 0 20 Nov 3 2016 krb5 -rwxr-xr-x. 1 0 0 155464 Oct 28 2016 ld-2.17.so drwxr-xr-x. 3 0 0 20 Jun 10 2016 ldb lrwxrwxrwx. 1 0 0 10 Apr 30 2017 ld-linux-x86-64.so.2 -> ld-2.17.so lrwxrwxrwx. 1 0 0 21 Apr 30 2017 libabrt_dbus.so.0 -> libabrt_dbus.so.0.0.1 Examples: >>> "krb5" in ls_usr_lib64 False >>> "/usr/lib64" in ls_usr_lib64 True >>> "krb5" in ls_usr_lib64.dirs_of('/usr/lib64') True >>> ls_usr_lib64.dir_entry('/usr/lib64', 'ld-linux-x86-64.so.2')['type'] 'l' """ from insights.specs import Specs from insights.core.filters import add_filter from insights import parser, CommandParser, FileListing add_filter(Specs.ls_usr_lib64, "total") @parser(Specs.ls_usr_lib64) class LsUsrLib64(CommandParser, FileListing): """Parses output of ``ls -lan /usr/lib64`` command.""" pass
import string from insights import parser from insights.core import ConfigParser from insights.core.filters import add_filter from insights.parsr.query import eq from insights.parsr import (Char, EOF, HangingString, InSet, LeftBracket, Lift, LineEnd, Literal, RightBracket, Many, Number, OneLineComment, Opt, PosMarker, QuotedString, skip_none, String, WithIndent, WS, WSChar) from insights.parsr.query import Directive, Entry, Section from insights.parsers import ParseException, SkipException from insights.specs import Specs # Filter to ensure that the section headings will always be included. add_filter(Specs.php_ini, "[") @parser(Specs.php_ini, continue_on_error=False) class PHPConf(ConfigParser): """ Class for php configuration file. """ def parse_doc(self, content): try: def to_directive(x): name, rest = x rest = [rest] if rest is not None else [] return Directive(name=name.value.strip(), attrs=rest, lineno=name.lineno, src=self) def to_section(name, rest):
search criteria. Examples: >>> ps.search(COMMAND__contains='bash') [{'%MEM': '0.0', 'TTY': 'pts/3', 'VSZ': '108472', 'ARGS': '', 'PID': '20160', '%CPU': '0.0', 'START': '10:09', 'COMMAND': '/bin/bash', 'USER': '******', 'STAT': 'Ss', 'TIME': '0:00', 'COMMAND_NAME': 'bash', 'RSS': '1896'}, {'%MEM': '0.0', 'TTY': '?', 'VSZ': '9120', 'ARGS': '', 'PID': '20457', '%CPU': '0.0', 'START': '10:09', 'COMMAND': '/bin/bash', 'USER': '******', 'STAT': 'Ss', 'TIME': '0:00', 'COMMAND_NAME': 'bash', 'RSS': '832'}] >>> ps.search(USER='******', COMMAND__contains='bash') [{'%MEM': '0.0', 'TTY': '?', 'VSZ': '9120', 'ARGS': '', 'PID': '20457', '%CPU': '0.0', 'START': '10:09', 'COMMAND': '/bin/bash', 'USER': '******', 'STAT': 'Ss', 'TIME': '0:00', 'COMMAND_NAME': 'bash', 'RSS': '832'}] >>> ps.search(TTY='pts/3') [{'%MEM': '0.0', 'TTY': 'pts/3', 'VSZ': '108472', 'ARGS': '', 'PID': '20160', '%CPU': '0.0', 'START': '10:09', 'COMMAND': '/bin/bash', 'USER': '******', 'STAT': 'Ss', 'TIME': '0:00', 'COMMAND_NAME': 'bash', 'RSS': '1896'}] >>> ps.search(STAT__contains='Z') [{'%MEM': '0.0', 'TTY': '?', 'VSZ': '0', 'ARGS': '', 'PID': '1821', '%CPU': '0.0', 'START': 'May31', 'COMMAND': '[kondemand/0]', 'USER': '******', 'STAT': 'Z', 'TIME': '0:29', 'COMMAND_NAME': '[kondemand/0]', 'RSS': '0'}] """ return keyword_search(self.data, **kwargs) add_filter(Specs.ps_auxww, "COMMAND") @parser(Specs.ps_auxww) class PsAuxww(Ps): """ Class ``PsAuxww`` parses the output of the ``ps auxww`` command. A small sample of the output of this command looks like:: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 19356 1544 ? Ss May31 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 root 1661 0.0 0.0 126252 1392 ? Ss May31 0:04 /usr/sbin/crond -n root 1691 0.0 0.0 42688 172 ? Ss May31 0:00 /usr/sbin/rpc.mountd root 1821 0.0 0.0 0 0 ? Z May31 0:29 [kondemand/0] root 1864 0.0 0.0 18244 668 ? Ss May31 0:05 /usr/sbin/irqbalance --foreground user1 20160 0.0 0.0 108472 1896 pts/3 Ss 10:09 0:00 /bin/bash
""" NeutronMetadataAgentIni - file ``/etc/neutron/metadata_agent.ini`` ================================================================== """ from insights.core import IniConfigFile from insights.core.filters import add_filter from insights.core.plugins import parser from insights.specs import Specs add_filter(Specs.neutron_metadata_agent_ini, ["["]) @parser(Specs.neutron_metadata_agent_ini) class NeutronMetadataAgentIni(IniConfigFile): """ Parse the ``/etc/neutron/metadata_agent.ini`` configuration file. Sample configuration:: [DEFAULT] debug = False auth_url = http://localhost:35357/v2.0 auth_insecure = False admin_tenant_name = service admin_user = neutron nova_metadata_ip = 127.0.0.1 nova_metadata_port = 8775 nova_metadata_protocol = http metadata_workers =0 metadata_backlog = 4096
""" from .. import parser, CommandParser from ..parsers import ParseException from insights.specs import Specs from insights.core.filters import add_filter SAP_INST_FILTERS = [ '******', 'CreationClassName', 'SID', 'SystemNumber', 'InstanceName', 'Hostname', 'SapVersionInfo', ] add_filter(Specs.saphostctl_getcimobject_sapinstance, SAP_INST_FILTERS) @parser(Specs.saphostctl_getcimobject_sapinstance) class SAPHostCtrlInstances(CommandParser): """ This class provides processing for the output of the ``/usr/sap/hostctrl/exe/saphostctrl -function GetCIMObject -enuminstances SAPInstance`` command on SAP systems. Sample output of the command:: ********************************************************* CreationClassName , String , SAPInstance SID , String , D89 SystemNumber , String , 88
""" NeutronSriovAgent - file ``/etc/neutron/plugins/ml2/sriov_agent.ini`` ===================================================================== """ from insights.core import IniConfigFile from insights.core.filters import add_filter from insights.core.plugins import parser from insights.specs import Specs FILTERS = [ "debug", "[", "physical_device_mappings", "exclude_devices", "extensions" ] add_filter(Specs.neutron_sriov_agent, FILTERS) @parser(Specs.neutron_sriov_agent) class NeutronSriovAgent(IniConfigFile): """ This class provides parsing for the files: ``/etc/neutron/plugins/ml2/sriov_agent.ini`` ``/var/lib/config-data/puppet-generated/neutron/etc/neutron/plugins/ml2/sriov_agent.ini`` Sample input data is in the format:: [DEFAULT] debug = false [sriov_nic] physical_device_mappings=datacentre:enp2s0f6 [agent]
'rpc_thread_pool_size', 'server_ca', 'service_name', 'signing_digest', 'sock_rlimit', 'spare_amphora_pool_size', 'spare_check_interval', 'stats_max_processes', 'stats_request_timeout', 'stats_socket_path', 'stats_update_driver', 'stats_update_threads', 'status_max_processes', 'status_request_timeout', 'status_socket_path', 'status_update_threads', 'storage_path', 'tenant_log_targets', 'topic', 'topics', 'udp_connect_min_interval_health_monitor', 'use_oslo_messaging', 'use_upstart', 'user_data_config_drive', 'user_log_facility', 'user_log_format', 'volume_create_max_retries', 'volume_create_retry_interval', 'volume_create_timeout', 'volume_driver', 'volume_size', 'volume_type', 'vrrp_advert_int', 'vrrp_check_interval', 'vrrp_fail_count', 'vrrp_garp_refresh_count', 'vrrp_garp_refresh_interval', 'vrrp_success_count', 'workers' ] add_filter(Specs.octavia_conf, VALID_KEYS) @parser(Specs.octavia_conf) class OctaviaConf(IniConfigFile): """ Provides a parser arser for file ``/var/lib/config-data/puppet-generated/octavia/etc/octavia/octavia.conf``. Filters have been added to this parser to ensure that the necessary data will be collected. Sample input data:: [DEFAULT] # Print debugging output (set logging level to DEBUG instead of default WARNING level). debug = False