示例#1
0
    def begin(self):
        if self.functional or self.collect_only:
            return
        # initialize CTRexScenario global testing class, to be used by all tests
        CTRexScenario.configuration = self.configuration
        CTRexScenario.benchmark = self.benchmark
        CTRexScenario.modes = set(self.modes)
        CTRexScenario.server_logs = self.server_logs

        # launch TRex daemon on relevant setup
        start_trex_remote_server(self.configuration.trex, self.kill_running)
        CTRexScenario.trex = CTRexClient(
            trex_host=self.configuration.trex['trex_name'],
            verbose=self.verbose_mode)

        if 'loopback' not in self.modes:
            CTRexScenario.router_cfg = dict(
                config_dict=self.configuration.router,
                forceImageReload=self.load_image,
                silent_mode=not self.verbose_mode,
                forceCleanConfig=self.clean_config,
                tftp_config_dict=self.configuration.tftp)
        try:
            CustomLogger.setup_custom_logger('TRexLogger', self.loggerPath)
        except AttributeError:
            CustomLogger.setup_custom_logger('TRexLogger')
示例#2
0
    def begin (self):
        client = CTRexScenario.trex
        if self.pkg and not CTRexScenario.pkg_updated:
            self._update_trex()
        if self.functional or self.collect_only:
            return
        if self.pkg or self.restart_daemon:
            print('Restarting TRex daemon server')
            res = client.restart_trex_daemon(tries = 30)
            if not res:
                fatal('Could not restart TRex daemon server')
            print('Restarted.')

        if not self.no_daemon:
            if self.kill_running:
                client.kill_all_trexes()
            elif (not self.allow_multi_instance) and client.get_trex_cmds():
                fatal('TRex is already running. Use --kill-running flag to kill it.')
            try:
                client.check_server_connectivity()
            except Exception as e:
                fatal(e)


        if 'loopback' not in CTRexScenario.modes:
            CTRexScenario.router_cfg = dict(config_dict      = CTRexScenario.configuration.router,
                                            forceImageReload = self.load_image,
                                            silent_mode      = not self.telnet_verbose,
                                            forceCleanConfig = self.clean_config,
                                            no_dut_config    = self.no_dut_config,
                                            tftp_config_dict = CTRexScenario.configuration.tftp)
        try:
            CustomLogger.setup_custom_logger('TRexLogger', self.loggerPath)
        except AttributeError:
            CustomLogger.setup_custom_logger('TRexLogger')
示例#3
0
    def begin (self):
        client = CTRexScenario.trex
        if self.pkg and not CTRexScenario.is_copied:
            if client.master_daemon.is_trex_daemon_running() and client.get_trex_cmds() and not self.kill_running:
                print("Can't update TRex, it's running")
                sys.exit(-1)
            print('Updating TRex to %s' % self.pkg)
            if not client.master_daemon.update_trex(self.pkg):
                print('Failed updating TRex')
                sys.exit(-1)
            else:
                print('Updated')
            CTRexScenario.is_copied = True
        if self.functional or self.collect_only:
            return
        if not self.no_daemon:
            print('Restarting TRex daemon server')
            res = client.restart_trex_daemon()
            if not res:
                print('Could not restart TRex daemon server')
                sys.exit(-1)
            print('Restarted.')

            if self.kill_running:
                client.kill_all_trexes()
            else:
                if client.get_trex_cmds():
                    print('TRex is already running')
                    sys.exit(-1)

        if self.stateless:
            cores = self.configuration.trex.get('trex_cores', 1)
            if 'virt_nics' in self.modes and cores > 1:
                raise Exception('Number of cores should be 1 with virtual NICs')
            if not self.no_daemon:
                client.start_stateless(c = cores)
            CTRexScenario.stl_trex = STLClient(username = '******',
                                               server = self.configuration.trex['trex_name'],
                                               verbose_level = self.json_verbose)
        if 'loopback' not in self.modes:
            CTRexScenario.router_cfg = dict(config_dict      = self.configuration.router,
                                            forceImageReload = self.load_image,
                                            silent_mode      = not self.telnet_verbose,
                                            forceCleanConfig = self.clean_config,
                                            tftp_config_dict = self.configuration.tftp)
        try:
            CustomLogger.setup_custom_logger('TRexLogger', self.loggerPath)
        except AttributeError:
            CustomLogger.setup_custom_logger('TRexLogger')
示例#4
0
    def begin (self):
        if self.pkg and not CTRexScenario.is_copied and not self.no_ssh:
            new_path = '/tmp/trex-scripts'
            rsync_template = 'rm -rf /tmp/trex-scripts; mkdir -p %s; rsync -Lc %s /tmp; tar -mxzf /tmp/%s -C %s; mv %s/v*.*/* %s'
            rsync_command = rsync_template % (new_path, self.pkg, os.path.basename(self.pkg), new_path, new_path, new_path)
            return_code, stdout, stderr = trex_remote_command(self.configuration.trex, rsync_command, from_scripts = False, timeout = 300)
            if return_code:
                print('Failed copying')
                sys.exit(-1)
            CTRexScenario.scripts_path = new_path
            CTRexScenario.is_copied = True
        if self.functional or self.collect_only:
            return
        # launch TRex daemon on relevant setup
        if not self.no_ssh:
            if self.kill_running:
                if self.stateful:
                    trex_remote_command(self.configuration.trex, STATEFUL_STOP_COMMAND)
                kill_trex_process(self.configuration.trex)
                time.sleep(1)
            elif check_trex_running(self.configuration.trex):
                print('TRex is already running')
                sys.exit(-1)


        if self.stateful:
            if not self.no_ssh:
                trex_remote_command(self.configuration.trex, STATEFUL_RUN_COMMAND)
            CTRexScenario.trex = CTRexClient(trex_host = self.configuration.trex['trex_name'], verbose = self.json_verbose)
        elif self.stateless:
            if not self.no_ssh:
                cores = self.configuration.trex.get('trex_cores', 1)
                if 'virt_nics' in self.modes and cores > 1:
                    raise Exception('Number of cores should be 1 with virtual NICs')
                trex_remote_command(self.configuration.trex, './t-rex-64 -i -c %s' % cores, background = True)
            CTRexScenario.stl_trex = STLClient(username = '******',
                                               server = self.configuration.trex['trex_name'],
                                               verbose_level = self.json_verbose)
        if 'loopback' not in self.modes:
            CTRexScenario.router_cfg = dict(config_dict      = self.configuration.router,
                                            forceImageReload = self.load_image,
                                            silent_mode      = not self.telnet_verbose,
                                            forceCleanConfig = self.clean_config,
                                            tftp_config_dict = self.configuration.tftp)
        try:
            CustomLogger.setup_custom_logger('TRexLogger', self.loggerPath)
        except AttributeError:
            CustomLogger.setup_custom_logger('TRexLogger')
示例#5
0
    def begin(self):
        client = CTRexScenario.trex
        if self.pkg and not CTRexScenario.pkg_updated:
            if client.master_daemon.is_trex_daemon_running(
            ) and client.get_trex_cmds() and not self.kill_running:
                fatal(
                    "Can't update TRex, it's running. Consider adding --kill-running flag."
                )
            print('Updating TRex to %s' % self.pkg)
            if not client.master_daemon.update_trex(self.pkg):
                fatal('Failed to update TRex.')
            else:
                print('Updated.')
            CTRexScenario.pkg_updated = True
        if self.functional or self.collect_only:
            return
        if self.pkg or self.restart_daemon:
            print('Restarting TRex daemon server')
            res = client.restart_trex_daemon()
            if not res:
                fatal('Could not restart TRex daemon server')
            print('Restarted.')

        if not self.no_daemon:
            if self.kill_running:
                client.kill_all_trexes()
            elif client.get_trex_cmds():
                fatal(
                    'TRex is already running. Use --kill-running flag to kill it.'
                )
            try:
                client.check_server_connectivity()
            except Exception as e:
                fatal(e)

        if 'loopback' not in self.modes:
            CTRexScenario.router_cfg = dict(
                config_dict=self.configuration.router,
                forceImageReload=self.load_image,
                silent_mode=not self.telnet_verbose,
                forceCleanConfig=self.clean_config,
                no_dut_config=self.no_dut_config,
                tftp_config_dict=self.configuration.tftp)
        try:
            CustomLogger.setup_custom_logger('TRexLogger', self.loggerPath)
        except AttributeError:
            CustomLogger.setup_custom_logger('TRexLogger')
    def begin (self):
        client = CTRexScenario.trex
        if self.pkg and not CTRexScenario.is_copied:
            if client.master_daemon.is_trex_daemon_running() and client.get_trex_cmds() and not self.kill_running:
                print("Can't update TRex, it's running")
                sys.exit(-1)
            print('Updating TRex to %s' % self.pkg)
            if not client.master_daemon.update_trex(self.pkg):
                print('Failed updating TRex')
                sys.exit(-1)
            else:
                print('Updated')
            CTRexScenario.is_copied = True
        if self.functional or self.collect_only:
            return
        if not self.no_daemon:
            print('Restarting TRex daemon server')
            res = client.restart_trex_daemon()
            if not res:
                print('Could not restart TRex daemon server')
                sys.exit(-1)
            print('Restarted.')

            if self.kill_running:
                client.kill_all_trexes()
            else:
                if client.get_trex_cmds():
                    print('TRex is already running')
                    sys.exit(-1)

        if 'loopback' not in self.modes:
            CTRexScenario.router_cfg = dict(config_dict      = self.configuration.router,
                                            forceImageReload = self.load_image,
                                            silent_mode      = not self.telnet_verbose,
                                            forceCleanConfig = self.clean_config,
                                            tftp_config_dict = self.configuration.tftp)
        try:
            CustomLogger.setup_custom_logger('TRexLogger', self.loggerPath)
        except AttributeError:
            CustomLogger.setup_custom_logger('TRexLogger')
    def begin (self):
        if self.functional or self.collect_only:
            return
        # initialize CTRexScenario global testing class, to be used by all tests
        CTRexScenario.configuration = self.configuration
        CTRexScenario.benchmark     = self.benchmark
        CTRexScenario.modes         = set(self.modes)
        CTRexScenario.server_logs   = self.server_logs

        # launch TRex daemon on relevant setup
        start_trex_remote_server(self.configuration.trex, self.kill_running)
        CTRexScenario.trex          = CTRexClient(trex_host = self.configuration.trex['trex_name'], verbose = self.verbose_mode)

        if 'loopback' not in self.modes:
            CTRexScenario.router_cfg    = dict( config_dict  = self.configuration.router, 
                                                                        forceImageReload = self.load_image, 
                                                                        silent_mode      = not self.verbose_mode,
                                                                        forceCleanConfig = self.clean_config,
                                                                        tftp_config_dict = self.configuration.tftp )
        try:
            CustomLogger.setup_custom_logger('TRexLogger', self.loggerPath)
        except AttributeError:
            CustomLogger.setup_custom_logger('TRexLogger')
示例#8
0
    a.land()
    a.motor.set_speed(2000.0)
    for i in range(20):
        b = a.refresh()
        a.altitude.set_sensor_altitude_current(
            a.altitude.get_altitude_current() - 3)
        print a.altitude.get_altitudes(), b


def sim_ultrasound(a):
    """
    Simulates Ultrasound detection
    :param a:
    :return:
    """
    a.takeoff()
    sensor_vals = [1, 2, 3, 4]
    a.ultra.set_sensor_ultra_values(25, 60, 60, 60)
    for i in range(20):
        b = a.refresh()


if __name__ == '__main__':
    import CustomLogger

    a = Quadcopter(CustomLogger.pi_logger())
    sim_ypr_change(a)
    a = Quadcopter(CustomLogger.pi_logger())
    sim_altitude(a)
    # a = Quadcopter(CustomLogger.pi_logger())
    # sim_ultrasound(a)
 def __init__(self):
     self.logger = CustomLogger.setup_logger(config.outlog)
     DatabaseConnection.check_database()
     self.start_unblocking()