def test_omit_symbolic_name(InsightsCommand, InsightsFile, parse_file_spec): """ Files/commands are omitted based on their symbolic name in uploader.json """ c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'files': [{ "file": "/etc/pam.d/vsftpd", "pattern": [], "symbolic_name": "vsftpd" }], 'commands': [{ "command": "/sbin/chkconfig --list", "pattern": [], "symbolic_name": "chkconfig" }], 'pre_commands': [] } rm_conf = {'files': ["vsftpd"], "commands": ["chkconfig"]} data_collector.run_collection(collection_rules, rm_conf, {}, '') parse_file_spec.assert_not_called() InsightsFile.assert_not_called() InsightsCommand.assert_not_called()
def test_symbolic_name_bc(_, InsightsArchive, InsightsFile, InsightsCommand): """ WICKED EDGE CASE: in case uploader.json is old and doesn't have symbolic names, don't crash """ c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'files': [{ "file": "/etc/pam.d/vsftpd", "pattern": [] }], 'commands': [{ "command": "/sbin/chkconfig --list", "pattern": [] }], 'pre_commands': [] } rm_conf = {'files': ["vsftpd"], "commands": ["chkconfig"]} data_collector.run_collection(collection_rules, rm_conf, {}, {}) InsightsFile.assert_called_once() InsightsCommand.assert_called_once() InsightsArchive.return_value.add_to_archive.assert_has_calls( [call(InsightsFile.return_value), call(InsightsCommand.return_value)], any_order=True)
def test_omit_after_parse_command(InsightsCommand, run_pre_command): """ Files are omitted based on the expanded paths of the uploader.json path """ c = InsightsConfig() data_collector = DataCollector(c) collection_rules = {'commands': [{"command": "/sbin/ethtool -i", "pattern": [], "pre_command": "iface", "symbolic_name": "ethtool"}], 'files': [], "pre_commands": {"iface": "/sbin/ip -o link | awk -F ': ' '/.*link\\/ether/ {print $2}'"}} rm_conf = {'commands': ["/sbin/ethtool -i eth0"]} data_collector.run_collection(collection_rules, rm_conf, {}) InsightsCommand.assert_not_called()
def test_systemd_notify_called_cmd(Popen, systemd_notify): ''' Systemd_notify is called before a command is run or a file is collected ''' process_mock = mock.Mock() attrs = {'communicate.return_value': (b'output', b'error')} process_mock.configure_mock(**attrs) Popen.return_value = process_mock cs = InsightsCommand(MagicMock(), { 'command': '', 'pattern': [], 'symbolic_name': '' }, None, '/', parent_pid='420') cs.get_output() systemd_notify.assert_called_with('420')