예제 #1
0
    def complete_before_timeout():
        """Complete opertion before timeout occurs."""
        watchdog.start()
        with watchdog.timeout(10, "complete_before_timeout"):
            time.sleep(0.1)

        sys.exit(ExitCode.OK)
예제 #2
0
    def timeout_before_complete():
        """Timeout before operation completes."""
        watchdog.start()
        with watchdog.timeout(1, "timeout_before_complete"):
            time.sleep(2)

        sys.exit(ExitCode.NOT_RESTARTED)
    def doTask(self):
        """Collect a single PythonDataSource."""
        ds = self.config.datasources[0]
        template = ds.template
        datasource = ds.datasource
        plugin_classname = ds.plugin_classname

        if plugin_classname in self.blockingPlugins:
            log.warning(
                "Task %s is disabled (%s/%s)",
                self.name,
                template,
                datasource)

            return defer.fail(Exception('disabled'))

        with watchdog.timeout(self.blockingTimeout, plugin_classname):
            d = self.pluginCalls['collect'](self.config)

        d.addBoth(self.pluginCalls['onResult'], self.config)
        d.addCallback(self.pluginCalls['onSuccess'], self.config)
        d.addErrback(self.pluginCalls['onError'], self.config)
        d.addBoth(self.pluginCalls['onComplete'], self.config)
        d.addCallback(self.processResults)
        d.addErrback(self.handleError)
        return d
    def doTask(self):
        """Collect a single PythonDataSource."""
        ds = self.config.datasources[0]
        template = ds.template
        datasource = ds.datasource
        plugin_classname = ds.plugin_classname

        # Prevent disabled plugins (due to BLOCKING) from running.
        if plugin_classname in self.blockingPlugins:
            log.warning(
                "Task %s is disabled (%s/%s)",
                self.name,
                template,
                datasource)

            return defer.fail(Exception('disabled'))

        # Guard against plugin's collect method BLOCKING for too long.
        with watchdog.timeout(self.blockingTimeout, plugin_classname):
            d = self.pluginCalls['collect'](self.config)

        # Guard against plugin's collect method RUNNING for too long.
        if self.runningTimeout:
            d = twisted_utils.add_timeout(
                d,
                ds.cycletime * self.runningTimeout,
                exception_class=RunningTimeoutError)

        # Allow the plugin to handle results from it's collect method.
        d.addBoth(self.pluginCalls['onResult'], self.config)
        d.addCallback(self.pluginCalls['onSuccess'], self.config)
        d.addErrback(self.pluginCalls['onError'], self.config)
        d.addBoth(self.pluginCalls['onComplete'], self.config)

        # Have zenpython handle RunningTimeoutError if the plugin doesn't.
        if self.runningTimeout:
            d.addBoth(self.handleTimeout)

        # Have zenpython process the results: events, values, maps.
        d.addCallback(self.processResults)

        # Have zenpython handle any errors not handled by the plugin.
        d.addErrback(self.handleError)

        # Return Deferred to the collector framework.
        return d
    def timeout_file():
        """Validate operation timeout is recorded and we're restarted."""
        timeout_file = os.path.join(tempfile.gettempdir(),
                                    'test_watchdog.timeouts')

        entries = watchdog.get_timeout_entries(timeout_file=timeout_file)
        if os.path.isfile(timeout_file):
            os.unlink(timeout_file)

        if 'timeout_file' in entries:
            sys.exit(ExitCode.OK)
        else:
            watchdog.start()
            with watchdog.timeout(1, 'timeout_file'):
                time.sleep(2)

            sys.exit(ExitCode.NOT_RESTARTED)
    def timeout_file():
        """Validate operation timeout is recorded and we're restarted."""
        timeout_file = os.path.join(
            tempfile.gettempdir(),
            'test_watchdog.timeouts')

        entries = watchdog.get_timeout_entries(timeout_file=timeout_file)
        if os.path.isfile(timeout_file):
            os.unlink(timeout_file)

        if 'timeout_file' in entries:
            sys.exit(ExitCode.OK)
        else:
            watchdog.start()
            with watchdog.timeout(1, 'timeout_file'):
                time.sleep(2)

            sys.exit(ExitCode.NOT_RESTARTED)
예제 #7
0
    def doTask(self):
        """Collect a single PythonDataSource."""
        ds = self.config.datasources[0]
        template = ds.template
        datasource = ds.datasource
        plugin_classname = ds.plugin_classname

        # Prevent disabled plugins (due to BLOCKING) from running.
        if plugin_classname in self.blockingPlugins:
            log.warning("Task %s is disabled (%s/%s)", self.name, template,
                        datasource)

            return defer.fail(Exception('disabled'))

        # Guard against plugin's collect method BLOCKING for too long.
        with watchdog.timeout(self.blockingTimeout, plugin_classname):
            d = self.pluginCalls['collect'](self.config)

        # Guard against plugin's collect method RUNNING for too long.
        if self.runningTimeout:
            d = twisted_utils.add_timeout(d,
                                          ds.cycletime * self.runningTimeout,
                                          exception_class=RunningTimeoutError)

        # Allow the plugin to handle results from it's collect method.
        d.addBoth(self.pluginCalls['onResult'], self.config)
        d.addCallback(self.pluginCalls['onSuccess'], self.config)
        d.addErrback(self.pluginCalls['onError'], self.config)
        d.addBoth(self.pluginCalls['onComplete'], self.config)

        # Have zenpython handle RunningTimeoutError if the plugin doesn't.
        if self.runningTimeout:
            d.addBoth(self.handleTimeout)

        # Have zenpython process the results: events, values, maps.
        d.addCallback(self.processResults)

        # Have zenpython handle any errors not handled by the plugin.
        d.addErrback(self.handleError)

        # Return Deferred to the collector framework.
        return d
    def doTask(self):
        """Collect a single PythonDataSource."""
        ds = self.config.datasources[0]
        template = ds.template
        datasource = ds.datasource
        plugin_classname = ds.plugin_classname

        if plugin_classname in self.blockingPlugins:
            log.warning("Task %s is disabled (%s/%s)", self.name, template,
                        datasource)

            return defer.fail(Exception('disabled'))

        with watchdog.timeout(self.blockingTimeout, plugin_classname):
            d = self.pluginCalls['collect'](self.config)

        d.addBoth(self.pluginCalls['onResult'], self.config)
        d.addCallback(self.pluginCalls['onSuccess'], self.config)
        d.addErrback(self.pluginCalls['onError'], self.config)
        d.addBoth(self.pluginCalls['onComplete'], self.config)
        d.addCallback(self.processResults)
        d.addErrback(self.handleError)
        return d