def backend_conf(id, conf_env_var, conf_filename, defaults, opts): """ Build a _BeahConfig object for backends. This will look-up BACKEND section in beah-server configuration file to override defaults. """ conf2 = {"BEAH_CONF": opts.get("BEAH_CONF", "")} conf = _BeahConfig.beah_conf(conf2, id=None).conf defs = dict(conf.items("BACKEND", raw=True)) dict_update(defs, defaults) return _BeahConfig(id, conf_env_var, conf_filename, defs, opts)
def backend_conf(id, conf_env_var, conf_filename, defaults, opts): """ Build a _BeahConfig object for backends. This will look-up BACKEND section in beah-server configuration file to override defaults. """ conf2 = {'BEAH_CONF': opts.get('BEAH_CONF', '')} conf = _BeahConfig.beah_conf(conf2, id=None).conf defs = dict(conf.items('BACKEND', raw=True)) dict_update(defs, defaults) return _BeahConfig(id, conf_env_var, conf_filename, defs, opts)
def spawn(controller, backend, task_info, env, args): task_env = dict(env) # 1. set env.variables # BEAH_THOST - host name # BEAH_TPORT - port # BEAH_TSOCKET - socket # BEAH_TID - id of task - used to introduce itself when opening socket task_id = task_info['id'] conf = config.get_conf('beah') env_file = os.path.join(conf.get('TASK', 'VAR_ROOT'), ENV_PATHNAME_TEMPLATE % task_id) dict_update( task_env, CALLED_BY_BEAH="1", BEAH_THOST=str(host), BEAH_TPORT=str(port), BEAH_TSOCKET=str(socket), BEAH_TID=str(task_id), BEAH_ROOT=conf.get('TASK', 'ROOT'), BEAH_ENV=env_file, ) ll = conf.get('TASK', 'LOG') task_env.setdefault('BEAH_TASK_LOG', ll) task_env.setdefault('BEAH_TASK_CONSOLE', conf.get('TASK', 'CONSOLE_LOG', 'False')) task_env.setdefault('TERM', 'dumb') val = os.getenv('PYTHONPATH') if val: task_env['PYTHONPATH'] = val jsonenv.export_env(env_file, task_env) # 2. spawn a task protocol = (proto or TaskStdoutProtocol)(task_id) protocol.controller = controller log.debug('spawn: Environment: %r.', task_env) reactor.spawnProcess(protocol, task_info['file'], args=[task_info['file']] + (args or []), env=task_env) # FIXME: send an answer to backend(?) return protocol.task_protocol
def proc_cmd(self, backend, cmd): """Process Command received from backend. @backend is the backend, which issued the command. @cmd is a command. Should be an instance of Command class. This is the only method mandatory for Backend side Controller-Adaptor.""" log.debug("Controller: proc_cmd(..., %r)", cmd) handler = getattr(self, "proc_cmd_"+cmd.command(), None) if not handler: evt = event.echo(cmd, ECHO.NOT_IMPLEMENTED, origin=self.__origin) else: evt = event.echo(cmd, ECHO.OK, origin=self.__origin) try: handler(backend, cmd, evt) except: self.handle_exception("Handling %s raised an exception." % cmd.command()) dict_update(evt.args(), rc=ECHO.EXCEPTION, exception=format_exc()) log.debug("Controller: echo(%r)", evt) backend.proc_evt(evt, explicit=True)
def spawn(controller, backend, task_info, env, args): task_env = dict(env) # 1. set env.variables # BEAH_THOST - host name # BEAH_TPORT - port # BEAH_TSOCKET - socket # BEAH_TID - id of task - used to introduce itself when opening socket task_id = task_info['id'] conf = config.get_conf('beah') env_file = os.path.join(conf.get('TASK', 'VAR_ROOT'), ENV_PATHNAME_TEMPLATE % task_id) dict_update(task_env, CALLED_BY_BEAH="1", BEAH_THOST=str(host), BEAH_TPORT=str(port), BEAH_TSOCKET=str(socket), BEAH_TID=str(task_id), BEAH_ROOT=conf.get('TASK', 'ROOT'), BEAH_ENV=env_file, ) ll = conf.get('TASK', 'LOG') task_env.setdefault('BEAH_TASK_LOG', ll) task_env.setdefault('BEAH_TASK_CONSOLE', conf.get('TASK', 'CONSOLE_LOG', 'False')) task_env.setdefault('TERM', 'dumb') val = os.getenv('PYTHONPATH') if val: task_env['PYTHONPATH'] = val jsonenv.export_env(env_file, task_env) # 2. spawn a task protocol = (proto or TaskStdoutProtocol)(task_id) protocol.controller = controller log.debug('spawn: Environment: %r.', task_env) reactor.spawnProcess(protocol, task_info['file'], args=[task_info['file']]+(args or []), env=task_env) # FIXME: send an answer to backend(?) return protocol.task_protocol
def __call__(self, iline): answ = [] result_dict = {} m_comment = self.comment_re.match(iline) if m_comment: (line, comment) = m_comment.groups() m_directive = self.directive_re.match(comment) if m_directive: (_, directive, _) = m_directive.groups() else: directive = '' else: line = iline comment = '' directive = '' if comment: result_dict['diagnostics'] = comment if directive: result_dict['directive'] = directive if not self.plan: m_plan = self.plan_re.match(line) if m_plan: plan = m_plan.groups() self.plan = (int(plan[0]), int(plan[1])) self.test_case = self.plan[0]-1 return answ m_testcase = self.testcase_re.match(line) if m_testcase: if not self.plan: self.plan = (-1, -1) if not m_testcase.group(1): result = RC.PASS else: result = RC.FAIL self.test_case = int(m_testcase.group(2) or '0') or self.test_case+1 description = m_testcase.group(3) if self.plan[0] >= 0: if self.test_case < self.plan[0] or \ self.test_case > self.plan[1]: answ.append(event.lwarning( message="${test_case} is out of plan range ${test_plan}!", origin=self.origin, test_case=self.test_case, test_plan=self.plan)) if self.test_cases.has_key(self.test_case): if self.test_cases[self.test_case] != result: answ.append(event.lwarning( message="${test_case} was processed already and returned different result ${prev_result}!", origin=self.origin, test_case=self.test_case, prev_result=result)) else: answ.append(event.lwarning( message="${test_case} was processed already", origin=self.origin, test_case=self.test_case)) self.test_cases[self.test_case] = result result_dict['test_case'] = self.test_case if description: result_dict['message'] = description answ.append(event.result(result,**result_dict)) return answ m_bailout = self.bail_out_re.match(line) if m_bailout: result_dict['message'] = line answ.append(event.result(RC.FATAL, **result_dict)) return answ if self.error_re.match(line): # FIXME: using ${var} in strings. This is both well understood and # easy to process on server dict_update(result_dict, origin=self.origin, message="${line} does not match Test::Harness::TAP format", line=line) # we update result_dict in this case, not to lose information answ.append(event.lwarning(**result_dict)) return answ if comment or directive: answ.append(event.linfo(**result_dict)) return answ return answ
def __call__(self, iline): answ = [] result_dict = {} m_comment = self.comment_re.match(iline) if m_comment: (line, comment) = m_comment.groups() m_directive = self.directive_re.match(comment) if m_directive: (_, directive, _) = m_directive.groups() else: directive = '' else: line = iline comment = '' directive = '' if comment: result_dict['diagnostics'] = comment if directive: result_dict['directive'] = directive if not self.plan: m_plan = self.plan_re.match(line) if m_plan: plan = m_plan.groups() self.plan = (int(plan[0]), int(plan[1])) self.test_case = self.plan[0] - 1 return answ m_testcase = self.testcase_re.match(line) if m_testcase: if not self.plan: self.plan = (-1, -1) if not m_testcase.group(1): result = RC.PASS else: result = RC.FAIL self.test_case = int(m_testcase.group(2) or '0') or self.test_case + 1 description = m_testcase.group(3) if self.plan[0] >= 0: if self.test_case < self.plan[0] or \ self.test_case > self.plan[1]: answ.append( event.lwarning( message= "${test_case} is out of plan range ${test_plan}!", origin=self.origin, test_case=self.test_case, test_plan=self.plan)) if self.test_cases.has_key(self.test_case): if self.test_cases[self.test_case] != result: answ.append( event.lwarning( message= "${test_case} was processed already and returned different result ${prev_result}!", origin=self.origin, test_case=self.test_case, prev_result=result)) else: answ.append( event.lwarning( message="${test_case} was processed already", origin=self.origin, test_case=self.test_case)) self.test_cases[self.test_case] = result result_dict['test_case'] = self.test_case if description: result_dict['message'] = description answ.append(event.result(result, **result_dict)) return answ m_bailout = self.bail_out_re.match(line) if m_bailout: result_dict['message'] = line answ.append(event.result(RC.FATAL, **result_dict)) return answ if self.error_re.match(line): # FIXME: using ${var} in strings. This is both well understood and # easy to process on server dict_update( result_dict, origin=self.origin, message="${line} does not match Test::Harness::TAP format", line=line) # we update result_dict in this case, not to lose information answ.append(event.lwarning(**result_dict)) return answ if comment or directive: answ.append(event.linfo(**result_dict)) return answ return answ