示例#1
0
    def test_execute(self):
        """Testing method or function named execute."""
        # Test known bad command
        command = '{}'.format(random())
        with self.assertRaises(SystemExit):
            files.execute(command)

        # Test known bad command, but don't die
        command = '{}'.format(random())
        result = files.execute(command, die=False)
        self.assertTrue(bool(result))

        # Test known good command (Works in Windows and Linux)
        result = files.execute('date')
        self.assertFalse(bool(result))
示例#2
0
    def query(self):
        """Query all remote targets for data.

        Args:
            None

        Returns:
            None

        """
        # Initialize key variables
        use_script = False
        _running = False
        config = self.config
        interval = config.ingester_interval()
        script = '{}{}{}'.format(_BIN_DIRECTORY, os.sep,
                                 PATTOO_INGESTER_SCRIPT)

        # Post data to the remote server
        while True:
            # Get start time
            ts_start = time()

            # Check lockfile status
            if use_script is True:
                _running = check_lockfile()

            # Process
            if _running is False:
                if bool(use_script) is True:
                    # Process cache with script
                    _result = shared_files.execute(script, die=False)
                    success = not bool(_result)
                else:
                    # Process cache with function
                    success = files.process_cache()

                if bool(success) is False:
                    log_message = ('''\
Ingester failed to run. Please check log files for possible causes.''')
                    log.log2warning(20029, log_message)
            else:
                log_message = ('''\
Ingester is unexpectedly still running. Check your parameters of error logs \
for possible causes.''')
                log.log2warning(20129, log_message)

            # Sleep. The duration could exceed the polling interval. Set sleep
            # time to the polling interval when this occurs.
            duration = time() - ts_start
            if duration >= interval:
                log_message = ('''Ingestion exceeded configured \
"ingester_interval" parameter by {:6.2f}s.'''.format(duration - interval))
                sleep_time = 0
            else:
                sleep_time = abs(interval - duration)
            log_message = (
                'Ingester sleeping for {:6.2f}s.'.format(sleep_time))
            log.log2info(20100, log_message)
            sleep(sleep_time)