Beispiel #1
0
    def logout(self):
        try:
            if self.user_id:
                user = User.by_id(self.user_id)
                user.update_session()

                transaction.commit()

                kv_store = SessionKeyValueStore(db, self.session._session().id)
                kv_store.remove_all()
                transaction.commit()

            self.session.invalidate()
            self.session.delete()

        except Exception, e:
            ixiacrlogger.exception('Excepted: {0}'.format(str(e)))
            transaction.abort()
Beispiel #2
0
    def get_istestready(self):
        '''
        Check the test task chain for it's current status, wrap it in a
        json blob, and return it.
        Do this until the task chain gets to the 'execute' task, at which
        point the test 'is ready'...
        '''
        messages = list()
        is_ready = is_valid = False
        result = None

        def get_header(result):
            header_by_task = {
                'ixiacr.tasks.reservations.create': 'Reserving Test Resources',
                'ixiacr.tasks.test.create': 'Creating Test Configuration',
                'ixiacr.tasks.test.validate': 'Validating Test Configuration'}

            task_name = result.task_name
            if task_name in header_by_task:
                return self.localizer.translate(_(header_by_task[task_name]))

            return '{0} needs a header'.format(task_name)

        def get_content(result):
            state = result.result
            if isinstance(state, dict) and 'message' in state:
                raw_msg = self.localizer.translate(_(state['message']))
                if 'format_kwargs' in state:
                    msg = raw_msg.format(**state['format_kwargs'])
                else:
                    msg = raw_msg
            else:
                msg = str()
            return msg

        def prognosticate_test_success(sct):
            # XXX: This info is pulled back out of the database in
            # ixiacr.views.ixiacr_json.request_final_table at the end
            # of the test.
            try:
                pass
            except:
                raise

        try:
            kv_store = SessionKeyValueStore(db, self.session._session().id)
            validate_task_ids = kv_store.get_value('validate_task_ids')

            if validate_task_ids is not None:
                is_valid = True
                messages.append({
                    'header': '',
                    'content': '',
                    'is_error': False})
            else:
                is_valid = True
                is_ready = False
                header = self.localizer.translate(_('Missing'))
                content = self.localizer.translate(
                    _('No test currently configured'))

                ixiacrlogger.error('get_istestready: {0}'.format(content))

                messages.append({
                    'header': header,
                    'content': content,
                    'is_error': True})

        # Lots of possible exceptions here, and like Pokemon
        # we gotta catch 'em all!
        except Exception, e:
            ixiacrlogger.exception('get_istestready: {0}'.format(e))
            messages.append({
                'header': 'Failed',
                'content': str(e),
                'is_error': True
            })