Ejemplo n.º 1
0
    def get_history(self):
        """Get log file read history from database.

        :returns: (line_matcher_name progress)

        .. note::
           The function should be called out of database session.
           It reads the log_progressing_history table to get the
           position in the log file it has read in last run,
           the partial line of the log, the line matcher name
           in the last run, the progress, the message and the
           severity it has got in the last run.
        """
        with database.session() as session:
            history = session.query(LogProgressingHistory).filter_by(
                pathname=self.pathname_).first()
            if history:
                self.position_ = history.position
                self.partial_line_ = history.partial_line
                line_matcher_name = history.line_matcher_name
                progress = Progress(history.progress, history.message,
                                    history.severity)
            else:
                line_matcher_name = 'start'
                progress = Progress(0.0, '', None)

            return line_matcher_name, progress
Ejemplo n.º 2
0
    def getHistory(self):
        '''Get log file read history from database.

        Args:
            None

        Returns:
            line_matcher_name: str, line matcher name.
            progress: Progress instance record the installing history.

        The function should be called out of database session.
        It reads the log_progressing_history table to get the
        position in the log file it has read in last run,
        the partial line of the log, the line matcher name
        in the last run, the progress, the message and the
        severity it has got in the last run.
        '''
        with database.session() as session:
            history = session.query(LogProgressingHistory).filter_by(
                pathname=self.pathname).first()
            if history:
                logging.log(logging.DEBUG - 1, 'get file %s history %s',
                            self.pathname, history)
                self.position = history.position
                self.partial_line = history.partial_line
                line_matcher_name = history.line_matcher_name
                progress = Progress(history.progress, history.message,
                                    history.severity)
            else:
                line_matcher_name = 'start'
                progress = Progress(0.0, '', None)

            return line_matcher_name, progress
Ejemplo n.º 3
0
    def test_update_history_failure(self):
        config_locals = {}
        config_globals = {}
        execfile(self.config_file, config_globals, config_locals)
        prepare_database(config_locals)

        with database.session() as session:
            history = LogProgressingHistory(line_matcher_name='start',
                                            progress=0.5,
                                            message='dummy',
                                            severity='INFO',
                                            position=0,
                                            partial_line='',
                                            pathname='dummy')
            session.add(history)

        expected = {'progress': 0.8, 'line_matcher_name': 'start'}
        reader = file_matcher.FileReader('dummy')
        reader.update_history(
            expected['line_matcher_name'],
            Progress(progress=expected['progress'],
                     message='',
                     severity='INFO'))
        res = {}
        with database.session() as session:
            history = session.query(LogProgressingHistory).first()
            res.update({
                'line_matcher_name': history.line_matcher_name,
                'progress': history.progress
            })
        self.assertNotEqual(expected, res)
Ejemplo n.º 4
0
    def test_update_total_progress(self):
        file_progress = Progress(message='dummy',
                                 progress=0.5,
                                 severity='info')

        total_progress = Progress(message='dummy',
                                  progress=0.4,
                                  severity='info')

        matcher = file_matcher.FileMatcher(
            filename='sys.log',
            min_progress=0.0,
            max_progress=0.1,
            line_matchers={
                'start':
                LineMatcher(pattern=r'NOTICE (?P<message>.*)',
                            progress=IncrementalProgress(.1, .9, .1),
                            message_template='%(message)s',
                            unmatch_nextline_next_matcher_name='start',
                            match_nextline_next_matcher_name='exit'),
            })
        matcher.update_total_progress(file_progress, total_progress)
        self.assertEqual(0.5, total_progress.progress)
Ejemplo n.º 5
0
    def _get_host_progress(cls, hostid):
        """Get Host Progress from database.

        .. notes::
           The function should be called in database session.
        """
        session = database.current_session()
        host = session.query(ClusterHost).filter_by(id=hostid).first()
        if not host:
            logging.error('there is no host for %s in ClusterHost', hostid)
            return None, None, None

        if not host.state:
            logging.error('there is no related HostState for %s', hostid)
            return host.fullname, None, None

        return (host.fullname, host.state.state,
                Progress(host.state.progress, host.state.message,
                         host.state.severity))
Ejemplo n.º 6
0
    def _get_cluster_progress(cls, clusterid):
        """Get cluster progress from database.

        .. notes::
           The function should be called out of database session.
        """
        with database.session() as session:
            cluster = session.query(Cluster).filter_by(id=clusterid).first()
            if not cluster:
                logging.error('there is no Cluster for %s', clusterid)
                return None, None

            if not cluster.state:
                logging.error('there is no ClusterState for %s', clusterid)
                return None, None

            return (cluster.state.state,
                    Progress(cluster.state.progress, cluster.state.message,
                             cluster.state.severity))