Exemplo n.º 1
0
    def shutdown_ixiacr(self):
        """Shutdown the entire system
        """
        ixiacrlogger.debug('Entering: shutdown_ixiacr')
        try:
            # Delay 3 seconds to wait Logout Ixia
            time.sleep(3)
            res = shutdown_task.delay()
            return {'task_id': res.task_id}
        except Exception, e:
            ixiacrlogger.exception('shutdown_ixiacr: Exception. %s' % e)
            self.messages.append({'is_error': True, 'header': 'Failed',
                                       'content': str(e)})
            return {'result': 'FAILURE', 'messages': self.messages}
        finally:
            ixiacrlogger.debug('Exiting: shutdown_ixiacr')

    @action(renderer='json')
    def get_ixiacr_logs(self):
        """Generate a diagnostic bundle
        """
        ixiacrlogger.debug('Entering: IxiaAdminHandler.get_ixiacr_logs')
        self.messages = []
        try:
            (result, obj, err) = admin_helper('generate-diag-bundle',{})

            ixiacrlogger.debug('Exiting: IxiaAdminHandler.get_ixiacr_logs')
            return {'result': 'SUCCESS',
                    "messages": [{"is_error": False,
                                 "header": "Success",
                                 "content": obj}]}
Exemplo n.º 2
0
                    cm = self.localizer.translate(cred_message)
                    em = self.localizer.translate(
                        error_message, mapping={'user': user.username,'address': user.remote_addr})
                    message = cm + "<br><br>" + em
                else:
                    message = self.localizer.translate(cred_message)

            return {'username': username,
                    'password': password,
                    'message': message,
                    'invoke_override': invoke_override,
                    'global_vars': get_global_vars()}
        except Exception, e:
            ixiacrlogger.exception("Exception: {0}".format(str(e)))
        finally:
            ixiacrlogger.debug('Exiting: login')

    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()
Exemplo n.º 3
0
                method = getattr(uilogger, method)
            except AttributeError, e:
                # Trying to log an error with unsupported type, default to error
                method = uilogger.error

            message = data['message'] + ' ' if 'message' in data else ''
            method(message + dumps(data, indent=4))

            return {'result': 'SUCCESS'}

        except Exception, e:
            ixiacrlogger.exception('%s' % e)

            return {'result': 'FAILURE: %s' % e}
        finally:
            ixiacrlogger.debug('Exiting: log_js')

    @action(renderer='json')
    def update_user_timestamp(self):
        ixiacrlogger.debug('Entering: update_user_timestamp')
        #ixiacrlogger.info(str(self.request.cookies))
        #ixiacrlogger.info(str(self.request.cookies.get('auth_tkt')))
        self.messages = []
        ixiacrlogger.debug(str(self.request.cookies.get('auth_tkt').split('!')[0]))
        try:
            user = User.by_id(self.user_id)
            if user:
                if user.session_id != self.request.cookies.get('auth_tkt').split('!')[0]:
                    #return HTTPSeeOther(route_url('logout', self.request))
                    return {'result': 'FAILURE'}
                else:
Exemplo n.º 4
0
class ResultsConsumer(object):

    RESULT_SYNC_TRIGGERS = [
        ResultPacket.ResultType.TestStop,
        ResultPacket.ResultType.ResultSetStop
    ]

    def __init__(self):
        db.configure(bind=create_engine(
            'sqlite:///%(here)s/cyberrange.sqlite'))

        self.rr = results.ResultReader()

        self.log = IxiaLogger(__name__)

        self.log.debug('ResultsConsumer: initialized')

        self._test_result_id = None
        self._test_config_obj = None

        self._results = list()

    @property
    def current_config(self):
        return None

    def _sync_results(self):
        '''
        Process all of the accumulated results in one swell foop.
        '''
        config = self.current_config

        start = time.time()

        with transaction.manager:
            sp = transaction.savepoint()
            for count, result in enumerate(self._results):
                if not config.test.process_result_transactionless(
                        config, result.__dict__, config.result_id, db):
                    self.log.error('ResultsConsumer: Processing failed for {0}. '
                                   'Rolling back to last savepoint.'.format(result))
                    sp.rollback()
                    break

        stop = time.time()

        fargs = {
            'count': count,
            'time': stop - start,
            'avg': (stop - start) / float(count) if count > 0 else 0
        }
        self.log.debug('ResultsConsumer: Processed {count} results in {time:.3f} seconds '
                       '({avg:.3f} seconds/result)'.format(**fargs))

        self._results = list()

    def process_result(self, ch, method, properties, body):
        '''
        The result data consumer callback that processes results into the data
        object being passed in from the task consumer.
        '''
        try:
            result = cPickle.loads(body)
            assert result, 'Unable to unpickle result object'

            self._results.append(result)

            if result.resulttype in self.RESULT_SYNC_TRIGGERS:
                self._sync_results()

            return True

        except Exception as e:
            self.log.exception('ResultsConsumer: {0}'.format(e))
            return False

    def run(self):
        self.rr.read(self.process_result)
Exemplo n.º 5
0
    @action(renderer='json')
    def config_test(self):
        '''Set the data for the current test.

        '''
        ixiacrlogger.debug('Entering: config_test')
        try:
            return True

        except Exception, e:
            ixiacrlogger.exception('Exception in config_test: {0}'.format(e))
            self.messages.append({'header': 'Failed', 'content': str(e)})
            return self.fail(self.messages)
        finally:
            ixiacrlogger.debug('Exiting: config_test')

    def updateTestResults(self, test_result_id, **kwargs):
        if test_result_id:
            tcr = TestResult.query.filter_by(id=test_result_id).first()
            if tcr:
                for key, value in kwargs.items():
                    if key == 'result_path':
                        tcr.result_path = value
                    elif key == 'end_result':
                        tcr.end_result = value
                    elif key == 'run_id':
                        tcr.run_id = value
                    elif key == 'progress':
                        tcr.progress = value