示例#1
0
    def __init__(self, toml_config: RecursiveNestedDict):
        try:
            self.name = toml_config.find('experiment.name')
            self.clients = toml_config.find('experiment.clients')
            self.runs = toml_config.find('experiment.runs')
            self.docker_img = toml_config.find('experiment.docker_img')

            num_steps = toml_config.find('experiment.trace.steps')
            trace_dir = toml_config.find('experiment.trace.dir')

            # verify trace dir actually exists
            if not os.path.isdir(trace_dir):
                error_str = 'Invalid trace directory.'
                LOGGER.error(error_str)
                raise ConfigException(error_str)

            # verify that step files exist
            self.trace_steps = []
            for i in range(1, num_steps + 1):
                filename = constants.STEP_FILE_FMT.format(i)
                path = os.path.join(trace_dir, filename)
                if not os.path.isfile(path):
                    error_str = '{} does not seem to be a valid step trace'
                    'file'.format(path)
                    LOGGER.error(error_str)
                    raise Exception(error_str)
                else:
                    self.trace_steps.append(path)

            self.trace_fps = toml_config.find('experiment.trace.fps')
            self.rewind_seconds = toml_config.find(
                'experiment.trace.rewind_seconds')
            self.max_replays = toml_config.find('experiment.trace.max_replays')

            self.ntp_servers = toml_config.find('experiment.ntp.servers')

            # performance settings
            self.cpu_cores = toml_config.find(
                'experiment.performance.cpu_cores')

            if len(self.cpu_cores) == 0:
                self.cpu_cores = list(range(psutil.cpu_count()))

            self.gen_load = toml_config.find(
                'experiment.performance.artificial_load')
            self.target_load = toml_config.find(
                'experiment.performance.artificial_load_percent') * 0.01
            # load is in percent

            self.port_configs = []
            for port_cfg in toml_config.find('experiment.ports'):
                self.port_configs.append(
                    PortConfig(video=port_cfg['video'],
                               result=port_cfg['results'],
                               control=port_cfg['control']))

        except KeyError as e:
            LOGGER.error('Error when parsing TOML config.')
            LOGGER.error('Missing required configuration key: %s', *e.args)
            raise ConfigException('Missing required configuration key: '
                                  '{}'.format(*e.args)) from e

        self.__raw_cfg = toml_config
示例#2
0
    def shutdown(self, e=None):
        LOGGER.warning('Shut down!')

        if e:
            LOGGER.critical(e)

        try:
            for client in self.clients:
                client.shutdown()
        except Exception as e:
            LOGGER.error('Something went wrong while shutting down clients')
            LOGGER.error(e)

        try:
            if self.tcpdump_proc:
                self.tcpdump_proc.send_signal(signal.SIGINT)
        except Exception as e:
            LOGGER.error('Something went wrong while shutting down TCPDUMP')
            LOGGER.error(e)

        try:
            if self.backend_mgr:
                self.backend_mgr.shutdown()
        except Exception as e:
            LOGGER.error(
                'Something went wrong while shutting down Docker containers')
            LOGGER.error(e)