def _merge_run_info(self, config): config['run_info'] = { 'run_id': self.run_id, 'mac_addr': self.target_mac, 'daq_version': self.runner.version, 'started': gcp.get_timestamp() }
def _merge_run_info(self, config): config['run_info'] = { 'run_id': self.run_id, 'mac_addr': self.target_mac, 'started': gcp.get_timestamp() } config['run_info'].update(self.runner.get_run_info())
def _docker_test(self, test_name): self.test_name = test_name self.test_start = gcp.get_timestamp() self._state_transition(_STATE.TESTING, _STATE.NEXT) params = { 'target_ip': self.target_ip, 'target_mac': self.target_mac, 'gateway_ip': self.gateway.host.IP(), 'gateway_mac': self.gateway.host.MAC(), 'inst_base': self._inst_config_path(), 'port_base': self._port_base, 'device_base': self._device_aux_path(), 'type_base': self._type_aux_path(), 'scan_base': self.scan_base } self.test_host = docker_test.DockerTest(self.runner, self.target_port, self.devdir, test_name) self.test_port = self.runner.allocate_test_port(self.target_port) if 'ext_loip' in self.config: ext_loip = self.config['ext_loip'].replace('@', '%d') params['local_ip'] = ext_loip % self.test_port params['switch_ip'] = self.config['ext_addr'] params['switch_port'] = str(self.target_port) params['switch_model'] = self.config['switch_model'] try: LOGGER.debug('test_host start %s/%s', test_name, self._host_name()) self._set_module_config(self._loaded_config) self.record_result(test_name, state=MODE.EXEC) self.test_host.start(self.test_port, params, self._docker_callback) except: self.test_host = None raise
def _process_results(self): self._all_results = {"modules": {}} for (module_name, result_dict) in self._repitems.items(): module_result = {"tests": {}} self._all_results["modules"][module_name] = module_result for result_type in ResultType: if result_type in result_dict: module_result[result_type.value] = result_dict[result_type] if ResultType.REPORT_PATH not in result_dict: continue path = result_dict[ResultType.REPORT_PATH] with open(path) as stream: for line in stream: match = re.search(self._RESULT_REGEX, line) if match: result, test_name, extra = match.group(1), match.group( 2), match.group(3) self._accumulate_result(test_name, result, extra, module_name=module_name) module_result["tests"][test_name] = self._results[ test_name] self._all_results['timestamp'] = gcp.get_timestamp() self._all_results['missing_tests'] = self._find_missing_test_results()
def __init__(self, runner, device, config): self.runner = runner self._gcp = runner.gcp self.gateway = device.gateway self.config = config self.switch_setup = self.config.get('switch_setup', {}) self._no_test = self.config.get('no_test', False) self.device = device self.target_mac = device.mac self.target_port = device.port.port_no self._use_target_port_mirror = device.is_local() self.fake_target = self.gateway.fake_target self.devdir = self._init_devdir() self.run_id = self.make_runid() self.scan_base = os.path.abspath(os.path.join(self.devdir, 'scans')) self.logger = logger.get_logger('host') self._port_base = self._get_port_base() self._device_base = self._get_device_base() self.state = None self._state_transition(_STATE.READY) self.results = {} self.fake_host = None self.test_name = None self.test_start = gcp.get_timestamp() self.test_host = None self.test_port = None self._startup_time = None self._monitor_scan_sec = int(config.get('monitor_scan_sec', 0)) _default_timeout_sec = int(config.get('default_timeout_sec', 0)) self._default_timeout_sec = _default_timeout_sec if _default_timeout_sec else None self._usi_config = config.get('usi_setup', {}) self._topology_hook_script = config.get('topology_hook') self._mirror_intf_name = None self._monitor_ref = None self._monitor_start = None self.target_ip = None self._dhcp_listeners = [] self._loaded_config = None self.configurator = configurator.Configurator() self.reload_config() assert self._loaded_config, 'config was not loaded' self._write_module_config(self._loaded_config, self._device_aux_path()) self.enabled_tests = self._get_enabled_tests() self.remaining_tests = list(self.enabled_tests) self.logger.info('Host %s running with enabled tests %s', self.target_mac, self.remaining_tests) self._report = ReportGenerator(config, self.target_mac, self._loaded_config, self.runner.report_sink, get_devdir(self.target_mac)) self.record_result('startup', state=MODE.PREP) self._record_result('info', state=self.target_mac, config=self._make_config_bundle()) self._trigger_path = None self._startup_file = None self.timeout_handler = self._aux_module_timeout_handler self._all_ips = [] self._ip_listener = None
def _merge_run_info(self, config): config['run_info'] = { 'run_id': self.run_id, 'mac_addr': self.target_mac, 'started': gcp.get_timestamp(), 'switch': self._get_switch_config(), 'usi': self._usi_config } config['run_info'].update(self.runner.get_run_info())
def record_result(self, name, **kwargs): """Record a named result for this test""" current = gcp.get_timestamp() if name != self.test_name: LOGGER.debug('Target port %d report %s start %d', self.target_port, name, current) self.test_name = name self.test_start = current if name: self._record_result(name, current, **kwargs)
def clear_port(gcp_instance, port): """Clear the given port in the ui to a startup init state""" result = { 'name': 'startup', 'state': MODE.INIT, 'runid': ConnectedHost.make_runid(), 'timestamp': gcp.get_timestamp(), 'port': port } gcp_instance.publish_message('daq_runner', 'test_result', result)
def clear_port(gcp_instance, port): """Clear a port-based entry without having an instantiated host class""" result = { 'name': 'startup', 'state': MODE.INIT, 'runid': ConnectedHost.make_runid(), 'timestamp': gcp.get_timestamp(), 'port': port } gcp_instance.publish_message('daq_runner', 'test_result', result)
def _start_test(self, test_name): self.test_name = test_name self.test_start = gcp.get_timestamp() self._write_module_config(self._loaded_config, self._host_tmp_path()) self._record_result(self.test_name, config=self._loaded_config, state=MODE.CONF) self.record_result(self.test_name, state=MODE.EXEC) self._monitor_scan( os.path.join(self.scan_base, 'test_%s.pcap' % self.test_name)) self._state_transition(_STATE.TESTING, _STATE.NEXT)
def __init__(self, runner, gateway, target, config): self.runner = runner self._gcp = runner.gcp self.gateway = gateway self.config = config self.target_port = target['port'] self.target_mac = target['mac'] self.fake_target = target['fake'] self.devdir = self._init_devdir() self.run_id = self.make_runid() self.scan_base = os.path.abspath(os.path.join(self.devdir, 'scans')) self._port_base = self._get_port_base() self._device_base = self._get_device_base() self.state = None self._state_transition(_STATE.READY) self.results = {} self.dummy = None self.test_name = None self.test_start = gcp.get_timestamp() self.test_host = None self.test_port = None self._startup_time = None self._monitor_scan_sec = int( config.get('monitor_scan_sec', self._MONITOR_SCAN_SEC)) _default_timeout_sec = int( config.get('default_timeout_sec', self._DEFAULT_TIMEOUT_SEC)) self._default_timeout_sec = _default_timeout_sec if _default_timeout_sec else None self._fail_hook = config.get('fail_hook') self._mirror_intf_name = None self._tcp_monitor = None self.target_ip = None self._loaded_config = None self.reload_config() self._dhcp_listeners = [] configurator.write_config(self._device_aux_path(), self._MODULE_CONFIG, self._loaded_config) assert self._loaded_config, 'config was not loaded' self.remaining_tests = self._get_enabled_tests() LOGGER.info('Host %s running with enabled tests %s', self.target_port, self.remaining_tests) self.record_result('startup', state=MODE.PREP) self._record_result('info', state=self.target_mac, config=self._make_config_bundle()) self._report = report.ReportGenerator(config, self._INST_DIR, self.target_mac, self._loaded_config) self._trigger_path = None self._startup_file = None self.timeout_handler = self._aux_module_timeout_handler
def heartbeat(self): """Checks module run time for each event loop""" timeout_sec = self._get_test_timeout(self.test_name) if not timeout_sec or not self.test_start: return timeout = gcp.parse_timestamp( self.test_start) + timedelta(seconds=timeout_sec) nowtime = gcp.parse_timestamp(gcp.get_timestamp()) if nowtime >= timeout: if self.timeout_handler: LOGGER.error('Monitoring timeout for %s after %ds', self.test_name, timeout_sec) # ensure it's called once handler, self.timeout_handler = self.timeout_handler, None handler()
def _record_result(self, name, run_info=True, current=None, **kwargs): result = { 'name': name, 'runid': (self.run_id if run_info else None), 'device_id': self.target_mac, 'started': self.test_start, 'timestamp': current if current else gcp.get_timestamp(), 'port': (self.target_port if run_info else None) } result.update(kwargs) if 'exception' in result: result['exception'] = self._exception_message(result['exception']) if name: self.results[name] = result self._gcp.publish_message('daq_runner', 'test_result', result) return result
def _record_result(self, name, run_info=True, current=None, **kwargs): result = { 'name': name, 'runid': (self.run_id if run_info else None), 'device_id': self.target_mac, 'started': self.test_start, 'timestamp': current if current else gcp.get_timestamp(), 'port': (self.target_port if run_info else None) } for arg in kwargs: result[arg] = None if kwargs[arg] is None else kwargs[arg] if result.get('exception'): result['exception'] = str(result['exception']) if name: self.results[name] = result self._gcp.publish_message('daq_runner', 'test_result', result) return result
def record_result(self, name, **kwargs): """Record a named result for this test""" current = gcp.get_timestamp() if name != self.test_name: self.logger.debug('Target device %s report %s start %s', self, name, current) self.test_name = name self.test_start = current if name: self._record_result(name, current, **kwargs) if kwargs.get("exception"): self._report.accumulate( name, {ResultType.EXCEPTION: str(kwargs["exception"])}) if "code" in kwargs: self._report.accumulate( name, {ResultType.RETURN_CODE: kwargs["code"]}) self._report.accumulate( name, {ResultType.MODULE_CONFIG: self._loaded_config})
def _publish_runner_config(self, loaded_config): result = {'timestamp': gcp.get_timestamp(), 'config': loaded_config} self.gcp.publish_message('daq_runner', 'runner_config', result)
def _make_config_bundle(self, config=None): return { 'config': config if config else self._loaded_config, 'timestamp': gcp.get_timestamp() }