Ejemplo n.º 1
0
    def run(self, test_id, **kw_args):
        if not self.match_profile(test_id):
            logger.info("Test doesn't match the profile")
            return True

        redirs = get_redirect_uris(kw_args['client_info'])

        self.sh.session_setup(path=test_id)
        _flow = self.flows[test_id]
        _cli, _c_info = kw_args['client_factory'].make_client(
            **kw_args['client_info'])
        self.conv = Conversation(_flow,
                                 _cli,
                                 msg_factory=kw_args["msg_factory"],
                                 callback_uris=redirs,
                                 opid=kw_args['opid'])
        _cli.conv = self.conv
        _cli.event_store = self.conv.events
        self.conv.entity_config = _c_info
        self.conv.sequence = self.sh["sequence"]
        self.conv.tool_config = kw_args['tool_conf']
        self.sh["conv"] = self.conv

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args["conf"])
        except Exception as err:
            exception_trace("", err, logger)
            # res = Result(self.sh, self.kwargs['profile_handler'])
            # res.print_info(test_id)
            return self.inut.err_response("run", err)
Ejemplo n.º 2
0
def run_one(test_id, flows, profile, profiles, io, sh, **kw_args):
    try:
        redirs = kw_args["cinfo"]["client"]["redirect_uris"]
    except KeyError:
        redirs = kw_args["cinfo"]["registered"]["redirect_uris"]

    io = ClIO(flows=flows, profile=profile, **kw_args)
    sh = SessionHandler(None, profile, flows, **kw_args)

    _flow = flows[test_id]
    _cli = make_client(**kw_args)
    conversation = Conversation(
        _flow,
        _cli,
        kw_args["msg_factory"],
        interaction=kw_args["conf"].INTERACTION,
        trace_cls=Trace,
        callback_uris=redirs,
    )
    # noinspection PyTypeChecker
    try:
        run_flow(profiles, conversation, test_id, kw_args["conf"], profile, kw_args["check_factory"], io, sh)
    except Exception as err:
        exception_trace("", err, logger)
        print(conversation.trace)
Ejemplo n.º 3
0
    def run(self, test_id, **kw_args):
        if not self.match_profile(test_id):
            logger.info("Test doesn't match the profile")
            return True

        redirs = get_redirect_uris(kw_args['client_info'])

        self.sh.session_setup(path=test_id)
        _flow = self.flows[test_id]
        _cli, _c_info = kw_args['client_factory'].make_client(
            **kw_args['client_info'])
        self.conv = Conversation(_flow, _cli,
                                 msg_factory=kw_args["msg_factory"],
                                 callback_uris=redirs, opid=kw_args['opid'])
        _cli.conv = self.conv
        _cli.event_store = self.conv.events
        self.conv.entity_config = _c_info
        self.conv.sequence = self.sh["sequence"]
        self.conv.tool_config = kw_args['tool_conf']
        self.sh["conv"] = self.conv

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args["conf"])
        except Exception as err:
            exception_trace("", err, logger)
            # res = Result(self.sh, self.kwargs['profile_handler'])
            # res.print_info(test_id)
            return self.inut.err_response("run", err)
Ejemplo n.º 4
0
    def run(self, test_id, **kw_args):
        self.setup(test_id, **kw_args)

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args["conf"])
        except Exception as err:
            exception_trace("", err, logger)
            # self.inut.dump_log(self.sh, test_id)
            return self.inut.err_response("run", err)
Ejemplo n.º 5
0
Archivo: tool.py Proyecto: rohe/otest
    def run(self, test_id, **kw_args):
        if not self.setup(test_id, **kw_args):
            raise ConfigurationError()

        # noinspection PyTypeChecker
        try:
            return self.run_item(test_id, index=0, **kw_args)
        except Exception as err:
            exception_trace("", err, logger)
            return self.inut.err_response("run", err)
Ejemplo n.º 6
0
    def run(self, test_id, **kw_args):
        if not self.setup(test_id, **kw_args):
            raise ConfigurationError()

        # noinspection PyTypeChecker
        try:
            return self.run_item(test_id, index=0, **kw_args)
        except Exception as err:
            exception_trace("", err, logger)
            return self.inut.err_response("run", err)
Ejemplo n.º 7
0
    def run(self, test_id, **kw_args):
        self.setup(test_id, **kw_args)

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args["conf"])
        except Exception as err:
            exception_trace("", err, logger)
            # self.inut.dump_log(self.sh, test_id)
            return self.inut.err_response("run", err)
Ejemplo n.º 8
0
    def run(self, test_id, **kw_args):
        if not self.setup(test_id, **kw_args):
            raise ConfigurationError()

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args['conf'])
        except Exception as err:
            exception_trace("", err, logger)
            self.store_result()
            return self.inut.err_response("run", err)
Ejemplo n.º 9
0
    def run(self, test_id, **kw_args):
        self.setup(test_id, **kw_args)

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args["conf"])
        except (cherrypy.HTTPRedirect, cherrypy.HTTPError):
            raise
        except Exception as err:
            exception_trace("", err, logger)
            raise cherrypy.HTTPError(500, str(err))
Ejemplo n.º 10
0
    def run(self, test_id, **kw_args):
        self.setup(test_id, **kw_args)

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args["conf"])
        except (cherrypy.HTTPRedirect, cherrypy.HTTPError):
            raise
        except Exception as err:
            exception_trace("", err, logger)
            raise cherrypy.HTTPError(500, str(err))
Ejemplo n.º 11
0
Archivo: tool.py Proyecto: rohe/otest
    def run(self, test_id, **kw_args):
        if not self.setup(test_id, **kw_args):
            raise ConfigurationError()

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args['conf'])
        except Exception as err:
            exception_trace("", err, logger)
            self.store_result()
            return self.inut.err_response("run", err)
Ejemplo n.º 12
0
def run_flow(profiles,
             conv,
             test_id,
             conf,
             profile,
             check_factory,
             io,
             sh,
             index=0):
    print(("==" + test_id))
    conv.test_id = test_id
    conv.conf = conf

    if index >= len(conv.flow["sequence"]):
        return None

    conv.index = index

    for item in conv.flow["sequence"][index:]:
        if isinstance(item, tuple):
            cls, funcs = item
        else:
            cls = item
            funcs = {}

        _oper = cls(conv,
                    io,
                    sh,
                    profile=profile,
                    test_id=test_id,
                    conf=conf,
                    funcs=funcs)
        conv.operation = _oper
        _oper.setup(profiles.PROFILEMAP)
        _oper()

        conv.index += 1

    try:
        if conv.flow["assert"]:
            _ver = Verify(check_factory, conv)
            _ver.test_sequence(conv.flow["tests"])
    except KeyError:
        pass
    except Exception as err:
        otest.exception_trace('run_flow', err, logger)
        raise

    info = assert_summation(conv.events, test_id)

    return info
Ejemplo n.º 13
0
    def cont(self, **kwargs):
        path = kwargs['path']
        index = int(kwargs['index'])
        index += 1

        self.store_result()

        try:
            return self.run_flow(path, index=index)
        except cherrypy.HTTPRedirect:
            raise
        except Exception as err:
            exception_trace("", err, logger)
            self.store_result()
            return self.inut.err_response("run", err)
Ejemplo n.º 14
0
Archivo: tool.py Proyecto: rohe/otest
 def display_test_list(self):
     try:
         if self.sh.session_init():
             return self.inut.flow_list()
         else:
             try:
                 resp = Redirect("%sopresult#%s" % (
                     self.kwargs['base_url'], self.sh["testid"][0]))
             except KeyError:
                 return self.inut.flow_list()
             else:
                 return resp(self.inut.environ, self.inut.start_response)
     except Exception as err:
         exception_trace("display_test_list", err)
         return self.inut.err_response("session_setup", err)
Ejemplo n.º 15
0
 def display_test_list(self, **kwargs):
     try:
         if self.sh.session_init():
             return self.inut.flow_list()
         else:
             try:
                 resp = Redirect("%s/opresult#%s" %
                                 (self.base_url, self.sh["testid"][0]))
             except KeyError:
                 return self.inut.flow_list(**kwargs)
             else:
                 return resp(self.inut.environ, self.inut.start_response)
     except Exception as err:
         exception_trace("display_test_list", err)
         return self.inut.err_response("session_setup", err)
Ejemplo n.º 16
0
Archivo: tool.py Proyecto: rohe/otest
    def cont(self, **kwargs):
        path = kwargs['path']
        index = int(kwargs['index'])
        index += 1

        self.store_result()

        try:
            return self.run_flow(path, index=index)
        except cherrypy.HTTPRedirect:
            raise
        except Exception as err:
            exception_trace("", err, logger)
            self.store_result()
            return self.inut.err_response("run", err)
Ejemplo n.º 17
0
 def index(self):
     try:
         if self.sh.session_init():
             return as_bytes(self.info.flow_list())
         else:
             try:
                 _url = "{}opresult#{}".format(self.kwargs['base_url'],
                                               self.sh["testid"][0])
                 cherrypy.HTTPRedirect(_url)
             except KeyError:
                 return as_bytes(self.info.flow_list())
     except cherrypy.HTTPRedirect:
         raise
     except Exception as err:
         exception_trace("display_test_list", err)
         cherrypy.HTTPError(message=str(err))
Ejemplo n.º 18
0
 def index(self):
     try:
         if self.sh.session_init():
             return as_bytes(self.info.flow_list())
         else:
             try:
                 _url = "{}opresult#{}".format(self.kwargs['base_url'],
                                               self.sh["testid"][0])
                 cherrypy.HTTPRedirect(_url)
             except KeyError:
                 return as_bytes(self.info.flow_list())
     except cherrypy.HTTPRedirect:
         raise
     except Exception as err:
         exception_trace("display_test_list", err)
         cherrypy.HTTPError(message=str(err))
Ejemplo n.º 19
0
    def authz_cb(self, **kwargs):
        if cherrypy.request.method != 'GET':
            # You should only get query/fragment here using GET
            return self.process_error(
                'Wrong HTTP method used expected GET got "{}". Could be that '
                'I got a form_post to the wrong redirect_uri'.format(
                    cherrypy.request.method), 'authz_cb')

        _conv = self.sh["conv"]
        try:
            _response_mode = expected_response_mode(_conv)
        except ValueError as err:
            return self.process_error(err, 'authz_cb')

        if _response_mode == "form_post":
            return self.process_error("Expected form_post, didn't get it",
                                      'authz_cb')
        elif _response_mode == 'fragment':
            try:
                kwargs = cherrypy.request.params
            except KeyError:
                pass
            else:
                _conv.events.store(EV_HTTP_ARGS, kwargs, ref='authz_cb')
                _conv.query_component = kwargs

            return self.info.opresult_fragment()

        if kwargs == {}:  # This should never be the case
            return self.process_error(
                'Got empty response could be I got something fragment '
                'encoded. Expected query response mode', 'authz_cb')

        _conv.events.store(EV_RESPONSE, 'Response URL with query part')

        try:
            resp = self.tester.async_response(self.webenv["conf"],
                                              response=kwargs)
        except cherrypy.HTTPRedirect:
            # self.tester.flows.store_test_info(self)
            raise
        except Break:
            resp = False
            self.tester.store_result()
        except Exception as err:
            _trace = exception_trace('authz_cb', err, logger)
            _conv.events.store(EV_FAULT, _trace)
            self.tester.store_result()
            return self.display_exception(exception_trace=_trace)

        if resp is False or resp is True:
            pass
        elif isinstance(resp, dict) and 'exception_trace' in resp:
            return self.display_exception(**resp)
        elif not isinstance(resp, int):
            return resp

        self.opresult()
Ejemplo n.º 20
0
    def authz_cb(self, **kwargs):
        if cherrypy.request.method != 'GET':
            # You should only get query/fragment here using GET
            return self.process_error(
                'Wrong HTTP method used expected GET got "{}". Could be that '
                'I got a form_post to the wrong redirect_uri'.format(
                    cherrypy.request.method), 'authz_cb')

        _conv = self.sh["conv"]
        try:
            _response_mode = expected_response_mode(_conv)
        except ValueError as err:
            return self.process_error(err, 'authz_cb')

        if _response_mode == "form_post":
            return self.process_error("Expected form_post, didn't get it",
                                      'authz_cb')
        elif _response_mode == 'fragment':
            try:
                kwargs = cherrypy.request.params
            except KeyError:
                pass
            else:
                _conv.events.store(EV_HTTP_ARGS, kwargs, ref='authz_cb')
                _conv.query_component = kwargs

            return self.info.opresult_fragment()

        if kwargs == {}:  # This should never be the case
            return self.process_error(
                'Got empty response could be I got something fragment '
                'encoded. Expected query response mode', 'authz_cb')

        _conv.events.store(EV_RESPONSE, 'Response URL with query part')

        try:
            resp = self.tester.async_response(self.webenv["conf"],
                                              response=kwargs)
        except cherrypy.HTTPRedirect:
            raise
        except Break:
            resp = False
            self.tester.store_result()
        except Exception as err:
            _trace = exception_trace('authz_cb', err, logger)
            _conv.events.store(EV_FAULT, _trace)
            self.tester.store_result()
            return self.display_exception(exception_trace=_trace)

        if resp is False or resp is True:
            pass
        elif isinstance(resp, dict) and 'exception_trace' in resp:
            return self.display_exception(**resp)
        elif not isinstance(resp, int):
            return resp

        self.opresult()
Ejemplo n.º 21
0
Archivo: common.py Proyecto: rohe/otest
def run_flow(profiles, conv, test_id, conf, profile, check_factory, io, sh,
             index=0):
    print(("==" + test_id))
    conv.test_id = test_id
    conv.conf = conf

    if index >= len(conv.flow["sequence"]):
        return None

    conv.index = index

    for item in conv.flow["sequence"][index:]:
        if isinstance(item, tuple):
            cls, funcs = item
        else:
            cls = item
            funcs = {}

        _oper = cls(conv, io, sh, profile=profile, test_id=test_id, conf=conf,
                    funcs=funcs)
        conv.operation = _oper
        _oper.setup(profiles.PROFILEMAP)
        _oper()

        conv.index += 1

    try:
        if conv.flow["assert"]:
            _ver = Verify(check_factory, conv)
            _ver.test_sequence(conv.flow["tests"])
    except KeyError:
        pass
    except Exception as err:
        otest.exception_trace('run_flow', err, logger)
        raise

    info = assert_summation(conv.events, test_id)

    return info
Ejemplo n.º 22
0
def main(flows, profile, profiles, **kw_args):
    try:
        redirs = kw_args["cinfo"]["client"]["redirect_uris"]
    except KeyError:
        redirs = kw_args["cinfo"]["registered"]["redirect_uris"]

    test_list = make_list(flows, profile, **kw_args)

    for tid in test_list:
        io = ClIO(flows=flows, profile=profile, **kw_args)
        sh = SessionHandler(profile, flows, **kw_args)

        _flow = flows[tid]
        _cli, _cliconf = make_client(**kw_args)
        conversation = Conversation(
            _flow,
            _cli,
            kw_args["msg_factory"],
            interaction=kw_args["conf"].INTERACTION,
            trace_cls=Trace,
            callback_uris=redirs,
        )

        _cli.conv = conversation
        # noinspection PyTypeChecker
        try:
            info = run_flow(profiles, conversation, tid, kw_args["conf"], profile, kw_args["check_factory"], io, sh)
            if info["status"] == OK:
                print("+{}".format(tid))
            else:
                print("!{}".format(tid))
                for ev in conversation.events:
                    print(ev)
                break
        except Exception as err:
            exception_trace("", err, logger)
            print(conversation.trace)
            break
Ejemplo n.º 23
0
def main(flows, profile, profiles, **kw_args):
    try:
        redirs = kw_args["cinfo"]["client"]["redirect_uris"]
    except KeyError:
        redirs = kw_args["cinfo"]["registered"]["redirect_uris"]

    test_list = make_list(flows, profile, **kw_args)

    for tid in test_list:
        io = ClIO(flows=flows, profile=profile, **kw_args)
        sh = SessionHandler(profile, flows, **kw_args)

        _flow = flows[tid]
        _cli, _cliconf = make_client(**kw_args)
        conversation = Conversation(_flow,
                                    _cli,
                                    kw_args["msg_factory"],
                                    interaction=kw_args["conf"].INTERACTION,
                                    trace_cls=Trace,
                                    callback_uris=redirs)

        _cli.conv = conversation
        # noinspection PyTypeChecker
        try:
            info = run_flow(profiles, conversation, tid, kw_args["conf"],
                            profile, kw_args["check_factory"], io, sh)
            if info['status'] == OK:
                print('+{}'.format(tid))
            else:
                print('!{}'.format(tid))
                for ev in conversation.events:
                    print(ev)
                break
        except Exception as err:
            exception_trace("", err, logger)
            print(conversation.trace)
            break
Ejemplo n.º 24
0
    def authz_post(self, **kwargs):
        if cherrypy.request.method != 'POST':
            return self.process_error(
                'Wrong HTTP method used expected POST got "{}"'.format(
                    cherrypy.request.method),
                'authz_post')

        _conv = self.sh["conv"]
        try:
            _response_mode = expected_response_mode(_conv)
        except ValueError as err:
            return self.process_error(err, 'authz_cb')

        # Can get here 2 ways, either directly if form_post is used or
        # indirectly if fragment encoding
        if _response_mode == 'query':  # should not be here at all
            if 'fragment' in kwargs:
                return self.process_error(
                    'Expected URL with query part got fragment', 'authz_post')
            else:
                return self.process_error(
                    'Expected URL with query part got form_post', 'authz_post')
        elif _response_mode == 'fragment':
            if 'fragment' in kwargs:  # everything OK
                self.tester.conv.events.store(EV_RESPONSE,
                                              'URL with fragment')
            else:
                return self.process_error(
                    'Expected URL with fragment part got form_post',
                    'authz_post')
        else:
            self.tester.conv.events.store(EV_RESPONSE, 'Form post')

        try:
            resp = self.tester.async_response(self.webenv["conf"],
                                              response=kwargs)
        except cherrypy.HTTPRedirect:
            raise
        except Exception as err:
            _trace = exception_trace('authz_post', err, logger)
            return self.display_exception(exception_trace=_trace)
            # return self.info.err_response("authz_cb", err)
        else:
            if resp is False or resp is True:
                pass
            elif not isinstance(resp, int):
                return resp

            self.opresult()
Ejemplo n.º 25
0
    def authz_post(self, **kwargs):
        if cherrypy.request.method != 'POST':
            return self.process_error(
                'Wrong HTTP method used expected POST got "{}"'.format(
                    cherrypy.request.method),
                'authz_post')

        _conv = self.sh["conv"]
        try:
            _response_mode = expected_response_mode(_conv)
        except ValueError as err:
            return self.process_error(err, 'authz_cb')

        # Can get here 2 ways, either directly if form_post is used or
        # indirectly if fragment encoding
        if _response_mode == 'query':  # should not be here at all
            if 'fragment' in kwargs:
                return self.process_error(
                    'Expected URL with query part got fragment', 'authz_post')
            else:
                return self.process_error(
                    'Expected URL with query part got form_post', 'authz_post')
        elif _response_mode == 'fragment':
            if 'fragment' in kwargs:  # everything OK
                self.tester.conv.events.store(EV_RESPONSE,
                                              'URL with fragment')
            else:
                return self.process_error(
                    'Expected URL with fragment part got form_post',
                    'authz_post')
        else:
            self.tester.conv.events.store(EV_RESPONSE, 'Form post')

        try:
            resp = self.tester.async_response(self.webenv["conf"],
                                              response=kwargs)
        except cherrypy.HTTPRedirect:
            raise
        except Exception as err:
            _trace = exception_trace('authz_post', err, logger)
            return self.display_exception(exception_trace=_trace)
            # return self.info.err_response("authz_cb", err)
        else:
            if resp is False or resp is True:
                pass
            elif not isinstance(resp, int):
                return resp

            self.opresult()
Ejemplo n.º 26
0
def run_one(test_id, flows, profile, profiles, io, sh, **kw_args):
    try:
        redirs = kw_args["cinfo"]["client"]["redirect_uris"]
    except KeyError:
        redirs = kw_args["cinfo"]["registered"]["redirect_uris"]

    io = ClIO(flows=flows, profile=profile, **kw_args)
    sh = SessionHandler(None, profile, flows, **kw_args)

    _flow = flows[test_id]
    _cli = make_client(**kw_args)
    conversation = Conversation(_flow,
                                _cli,
                                kw_args["msg_factory"],
                                interaction=kw_args["conf"].INTERACTION,
                                trace_cls=Trace,
                                callback_uris=redirs)
    # noinspection PyTypeChecker
    try:
        run_flow(profiles, conversation, test_id, kw_args["conf"], profile,
                 kw_args["check_factory"], io, sh)
    except Exception as err:
        exception_trace("", err, logger)
        print(conversation.trace)
Ejemplo n.º 27
0
    def do_check(self, test, **kwargs):
        logger.debug("do_check({}, {})".format(test, kwargs))
        if isinstance(test, str):
            try:
                chk = self.check_factory(test)(**kwargs)
            except TypeError:
                raise MissingTest(test)
        else:
            chk = test(**kwargs)

        if chk.__class__.__name__ not in self.ignore_check:
            self.conv.events.store(EV_ASSERTION, chk.__class__.__name__)
            try:
                stat = chk(self.conv)
            except Exception as err:
                exception_trace('do_check', err, logger)
                raise
            else:
                if self.cls_name:
                    stat.context = self.cls_name

                self.conv.events.store(EV_CONDITION, stat,
                                       sender=self.__class__)
                self.check_severity(stat)
Ejemplo n.º 28
0
    def _endpoint(self, ref, request=None, **kwargs):
        _conv = self.sh['conv']

        # continue with next operation in the sequence
        self.sh["index"] += 1
        item = self.sh["sequence"][self.sh["index"]]
        if isinstance(item, tuple):
            cls, _ = item
        else:
            cls = item
        logger.debug('Next operation: %s (ref:%s)', cls.__name__, ref)
        if LOGOUT_MAP[cls.__name__] != ref:
            _conv.events.store(
                EV_FAULT, "Expected {} but got {}".format(cls.__name__, ref))
            self.tester.store_result()
            self.opresult()

        try:
            resp = self.tester.handle_request(request, **kwargs)
        except cherrypy.HTTPRedirect:
            self.tester.flows.store_test_info(self.tester)
            raise
        except (Break, OperationError) as err:
            resp = False
            _conv.events.store(EV_FAULT, err)
            self.tester.store_result()
        except Exception as err:
            _trace = exception_trace(ref, err, logger)
            _conv.events.store(EV_FAULT, _trace)
            self.tester.store_result()
            return self.display_exception(exception_trace=_trace)

        if resp is False or resp is True:
            pass
        elif resp in ["DONE", ""]:
            pass
        elif isinstance(resp, dict) and 'exception_trace' in resp:
            return self.display_exception(**resp)
        elif not isinstance(resp, int):
            return resp

        self.opresult()
Ejemplo n.º 29
0
    def run(self, test):
        try:
            resp = self.tester.run(test, **self.webenv)
        except HTTPRedirect:
            raise
        except Exception as err:
            #test_id = list(self.flows.complete.keys())[0]
            _trace = exception_trace('run', err, logger)
            self.tester.conv.events.store(EV_FAULT, _trace)
            return self.display_exception(exception_trace=_trace)

        self.sh['session_info'] = self.info.session

        if isinstance(resp, dict):
            return self.display_exception(**resp)
        elif resp is False or resp is True:
            pass
        elif isinstance(resp, list):
            return conv_response(self.sh.events, resp)
        elif isinstance(resp, bytes):
            return resp

        self.opresult()
Ejemplo n.º 30
0
    def run(self, test):
        try:
            resp = self.tester.run(test, **self.webenv)
        except HTTPRedirect:
            raise
        except Exception as err:
            #test_id = list(self.flows.complete.keys())[0]
            _trace = exception_trace('run', err, logger)
            self.tester.conv.events.store(EV_FAULT, _trace)
            return self.display_exception(exception_trace=_trace)

        self.sh['session_info'] = self.info.session

        if isinstance(resp, dict):
            return self.display_exception(**resp)
        elif resp is False or resp is True:
            pass
        elif isinstance(resp, list):
            return conv_response(self.sh.events, resp)
        elif isinstance(resp, bytes):
            return resp

        self.opresult()
Ejemplo n.º 31
0
Archivo: tool.py Proyecto: rohe/otest
    def run_flow(self, test_id, index=0, profiles=None, **kwargs):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        _ss = self.sh
        _ss.test_flows.complete[test_id] = False

        self.conv.test_id = test_id
        res = Result(self.sh, self.kwargs['profile_handler'])

        if index >= len(self.conv.sequence):
            return CRITICAL

        _oper = None
        for item in self.conv.sequence[index:]:
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            logger.info("<--<-- {} --- {} -->-->".format(index, cls))
            self.conv.events.store('operation', cls, sender='run_flow')
            try:
                _oper = cls(conv=self.conv, inut=self.inut, sh=self.sh,
                            profile=self.profile, test_id=test_id,
                            funcs=funcs, check_factory=self.check_factory,
                            cache=self.cache)
                # self.conv.operation = _oper
                if profiles:
                    profile_map = profiles.PROFILEMAP
                else:
                    profile_map = None
                _oper.setup(profile_map)
                resp = _oper()
            except ConditionError:
                self.store_result(res)
                return ERROR
            except Exception as err:
                exception_trace('run_flow', err)
                self.conv.events.store(EV_FAULT, err)
                #self.sh["index"] = index
                self.store_result(res)
                return CRITICAL
            else:
                if isinstance(resp, self.response_cls):
                    return resp

                if resp:
                    if self.com_handler:
                        resp = self.com_handler(resp)

                    resp = _oper.handle_response(self.get_response(resp))

                    if resp:
                        return self.inut.respond(resp)

            # should be done as late as possible, so all processing has been
            # done
            try:
                _oper.post_tests()
            except ConditionError:
                tinfo = self.store_result(res)
                return tinfo['state']

            index += 1

        _ss['index'] = self.conv.index = index

        try:
            if self.conv.flow["assert"]:
                _ver = Verify(self.check_factory, self.conv)
                _ver.test_sequence(self.conv.flow["assert"])
        except KeyError:
            pass
        except Exception as err:
            logger.error(err)
            raise

        if isinstance(_oper, Done):
            self.conv.events.store(EV_CONDITION, State('Done', OK),
                                   sender='run_flow')

        tinfo = self.store_result(res)

        return tinfo['state']
Ejemplo n.º 32
0
Archivo: tool.py Proyecto: rohe/otest
    def run_flow(self, test_id, index=0, profiles=None, conf=None):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        self.flows.complete[test_id] = False
        self.conv.test_id = test_id
        self.conv.conf = conf

        if index >= len(self.conv.sequence):
            return CRITICAL

        res = Result(self.sh, self.kwargs['profile_handler'])

        _oper = None
        for item in self.conv.sequence[index:]:
            self.sh["index"] = index
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            _name = cls.__name__
            _line = "<--<-- {} --- {} -->-->".format(index, _name)
            logger.info(_line)
            self.conv.events.store(EV_OPERATION, _line)
            try:
                _oper = cls(conv=self.conv, inut=self.inut, sh=self.sh,
                            profile=self.sh.profile, test_id=test_id, conf=conf,
                            funcs=funcs, check_factory=self.check_factory,
                            cache=self.cache,
                            tool_conf=self.kwargs['tool_conf'])
                self.conv.operation = _oper
                _oper.setup(self.profiles.PROFILEMAP)
                if _oper.fail:
                    break
                resp = _oper()
            except Break:
                break
            except cherrypy.HTTPError:
                raise
            except Exception as err:
                self.conv.events.store(
                    EV_CONDITION,
                    State(test_id=test_id, status=ERROR, message=err,
                          context=cls.__name__))
                _trace = exception_trace(cls.__name__, err, logger)
                self.sh["index"] = index
                self.store_result(res)
                return {'exception_trace': _trace}
            else:
                rsp = self.handle_response(resp, index)
                if rsp:
                    self.store_result(res)
                    return self.inut.respond(rsp)

            index += 1
            if index == len(self.conv.sequence):
                break

        if isinstance(_oper, Done):
            try:
                if self.conv.flow["assert"]:
                    _ver = Verify(self.check_factory, self.conv)
                    _ver.test_sequence(self.conv.flow["assert"])
            except (KeyError, Break):
                self.conv.events.store(EV_CONDITION, State('Done', status=OK))
            except ConditionError:
                pass
            except Exception as err:
                raise
            else:
                self.conv.events.store(EV_CONDITION, State('Done', status=OK))

        tinfo = self.store_result(res)
        return tinfo['state']
Ejemplo n.º 33
0
 def _store_error(self, where, err):
     if err:
         exception_trace(where, err, logger)
Ejemplo n.º 34
0
    def run_flow(self, test_id, index=0, profiles=None, conf=None):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        self.flows.complete[test_id] = False
        self.conv.test_id = test_id
        self.conv.conf = conf

        if index >= len(self.conv.sequence):
            return CRITICAL

        res = Result(self.sh, self.kwargs['profile_handler'])

        _oper = None
        for item in self.conv.sequence[index:]:
            self.sh["index"] = index
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            _name = cls.__name__
            _line = "<--<-- {} --- {} -->-->".format(index, _name)
            logger.info(_line)
            self.conv.events.store(EV_OPERATION, _line)
            try:
                _oper = cls(conv=self.conv,
                            inut=self.inut,
                            sh=self.sh,
                            profile=self.sh.profile,
                            test_id=test_id,
                            conf=conf,
                            funcs=funcs,
                            check_factory=self.check_factory,
                            cache=self.cache,
                            tool_conf=self.kwargs['tool_conf'])
                self.conv.operation = _oper
                _oper.setup(self.profiles.PROFILEMAP)
                if _oper.fail:
                    break
                resp = _oper()
            except Break:
                break
            except cherrypy.HTTPError:
                raise
            except Exception as err:
                self.conv.events.store(
                    EV_CONDITION,
                    State(test_id=test_id,
                          status=ERROR,
                          message=err,
                          context=cls.__name__))
                _trace = exception_trace(cls.__name__, err, logger)
                self.sh["index"] = index
                self.store_result(res)
                return {'exception_trace': _trace}
            else:
                rsp = self.handle_response(resp, index)
                if rsp:
                    self.store_result(res)
                    return self.inut.respond(rsp)

            index += 1
            if index == len(self.conv.sequence):
                break

        if isinstance(_oper, Done):
            try:
                if self.conv.flow["assert"]:
                    _ver = Verify(self.check_factory, self.conv)
                    _ver.test_sequence(self.conv.flow["assert"])
            except (KeyError, Break):
                self.conv.events.store(EV_CONDITION, State('Done', status=OK))
            except ConditionError:
                pass
            except Exception as err:
                raise
            else:
                self.conv.events.store(EV_CONDITION, State('Done', status=OK))

        tinfo = self.store_result(res)
        return tinfo['state']
Ejemplo n.º 35
0
    def run_item(self, test_id, index, profiles=None, **kw_args):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)

        _ss = self.sh
        try:
            _ss.test_flows.complete[test_id] = False
        except KeyError:
            pass

        self.conv.test_id = test_id
        res = Result(self.sh, self.kwargs['profile_handler'])

        if index >= len(self.conv.sequence):
            return None

        try:
            internal = kw_args['internal']
        except KeyError:
            internal = True

        cls, funcs = self.get_cls_and_func(index)

        try:
            _name = cls.__name__
        except AttributeError:
            _name = 'none'
        logger.info("<--<-- {} --- {} -->-->".format(index, _name))
        self.conv.events.store(EV_OPERATION, _name, sender='run_flow')
        try:
            _oper = cls(conv=self.conv,
                        inut=self.inut,
                        sh=self.sh,
                        profile=self.profile,
                        test_id=test_id,
                        funcs=funcs,
                        check_factory=self.chk_factory,
                        cache=self.cache,
                        internal=internal)
            # self.conv.operation = _oper
            if profiles:
                profile_map = profiles.PROFILEMAP
            else:
                profile_map = None
            _oper.setup(profile_map)
            resp = _oper()
        except ConditionError:
            self.store_result(res)
            return False
        except Exception as err:
            exception_trace('run_flow', err)
            self.sh["index"] = index
            return self.inut.err_response("run_sequence", err)
        else:
            if isinstance(resp, self.response_cls):
                if self.conv.sequence[index + 1] == Done:
                    self.post_op(_oper, res, test_id)
                return resp

            if resp:
                if self.conv.sequence[index + 1] == Done:
                    self.post_op(_oper, res, test_id)
                return resp

        # should be done as late as possible, so all processing has been
        # done
        try:
            _oper.post_tests()
        except ConditionError:
            self.store_result(res)
            return False

        _ss['index'] = self.conv.index = index + 1

        return True
Ejemplo n.º 36
0
    def run_flow(self, test_id, index=0, profiles=None, **kwargs):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        _ss = self.sh
        _ss.test_flows.complete[test_id] = False

        self.conv.test_id = test_id
        res = Result(self.sh, self.kwargs['profile_handler'])

        if index >= len(self.conv.sequence):
            return CRITICAL

        _oper = None
        for item in self.conv.sequence[index:]:
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            logger.info("<--<-- {} --- {} -->-->".format(index, cls))
            self.conv.events.store('operation', cls, sender='run_flow')
            try:
                _oper = cls(conv=self.conv,
                            inut=self.inut,
                            sh=self.sh,
                            profile=self.profile,
                            test_id=test_id,
                            funcs=funcs,
                            check_factory=self.check_factory,
                            cache=self.cache)
                # self.conv.operation = _oper
                if profiles:
                    profile_map = profiles.PROFILEMAP
                else:
                    profile_map = None
                _oper.setup(profile_map)
                resp = _oper()
            except ConditionError:
                self.store_result(res)
                return ERROR
            except Exception as err:
                exception_trace('run_flow', err)
                self.conv.events.store(EV_FAULT, err)
                #self.sh["index"] = index
                self.store_result(res)
                return CRITICAL
            else:
                if isinstance(resp, self.response_cls):
                    return resp

                if resp:
                    if self.com_handler:
                        resp = self.com_handler(resp)

                    resp = _oper.handle_response(self.get_response(resp))

                    if resp:
                        return self.inut.respond(resp)

            # should be done as late as possible, so all processing has been
            # done
            try:
                _oper.post_tests()
            except ConditionError:
                tinfo = self.store_result(res)
                return tinfo['state']

            index += 1

        _ss['index'] = self.conv.index = index

        try:
            if self.conv.flow["assert"]:
                _ver = Verify(self.check_factory, self.conv)
                _ver.test_sequence(self.conv.flow["assert"])
        except KeyError:
            pass
        except Exception as err:
            logger.error(err)
            raise

        if isinstance(_oper, Done):
            self.conv.events.store(EV_CONDITION,
                                   State('Done', OK),
                                   sender='run_flow')

        tinfo = self.store_result(res)

        return tinfo['state']
Ejemplo n.º 37
0
Archivo: tool.py Proyecto: rohe/otest
    def run_item(self, test_id, index, profiles=None, **kw_args):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)

        _ss = self.sh
        try:
            _ss.test_flows.complete[test_id] = False
        except KeyError:
            pass

        self.conv.test_id = test_id
        res = Result(self.sh, self.kwargs['profile_handler'])

        if index >= len(self.conv.sequence):
            return None

        try:
            internal = kw_args['internal']
        except KeyError:
            internal = True

        cls, funcs = self.get_cls_and_func(index)

        try:
            _name = cls.__name__
        except AttributeError:
            _name = 'none'
        logger.info("<--<-- {} --- {} -->-->".format(index, _name))
        self.conv.events.store(EV_OPERATION, _name, sender='run_flow')
        try:
            _oper = cls(conv=self.conv, inut=self.inut, sh=self.sh,
                        profile=self.profile, test_id=test_id,
                        funcs=funcs, check_factory=self.chk_factory,
                        cache=self.cache, internal=internal)
            # self.conv.operation = _oper
            if profiles:
                profile_map = profiles.PROFILEMAP
            else:
                profile_map = None
            _oper.setup(profile_map)
            resp = _oper()
        except ConditionError:
            self.store_result(res)
            return False
        except Exception as err:
            exception_trace('run_flow', err)
            self.sh["index"] = index
            return self.inut.err_response("run_sequence", err)
        else:
            if isinstance(resp, self.response_cls):
                if self.conv.sequence[index+1] == Done:
                    self.post_op(_oper, res, test_id)
                return resp

            if resp:
                if self.conv.sequence[index+1] == Done:
                    self.post_op(_oper, res, test_id)
                return resp

        # should be done as late as possible, so all processing has been
        # done
        try:
            _oper.post_tests()
        except ConditionError:
            self.store_result(res)
            return False

        _ss['index'] = self.conv.index = index + 1

        return True