コード例 #1
0
ファイル: webserver.py プロジェクト: Hurenka/yandex-tank-api
    def get(self):
        breakpoint = self.get_argument('break', 'finished')
        session_id = self.get_argument('session')
        hb_timeout = self.get_argument('heartbeat', None)

        self.set_header('Content-type', 'application/json')

        # 400 if invalid breakpoint
        if not common.is_valid_break(breakpoint):
            self.reply_json(
                400, {
                    'reason':
                    'Specified break is not a valid test stage name.',
                    'hint': {
                        'breakpoints': common.get_valid_breaks()
                    }
                })
            return

        # 404 if no such session
        try:
            status_dict = self.srv.status(session_id)
        except KeyError:
            self.reply_reason(404, 'No session with this ID.')
            return

        if session_id != self.srv.running_id:
            self.reply_reason(
                418,
                'I\'m a teapot! Can\'t set break for session that\'s not running!'
            )
            return

        # 418 if in higher state
        if common.is_a_earlier_than_b(breakpoint, status_dict['break']):
            reply = {
                'reason': 'I\'m a teapot! I know nothing of time-travel!',
                'hint': {
                    'breakpoints': common.get_valid_breaks()
                }
            }
            reply.update(status_dict)
            self.reply_json(418, reply)
            return

        # Post run command to manager queue
        self.srv.cmd({
            'session': session_id,
            'cmd': 'run',
            'break': breakpoint
        })

        self.srv.heartbeat(session_id, hb_timeout)
        self.reply_reason(200, 'Will try to set break before ' + breakpoint)
コード例 #2
0
ファイル: webserver.py プロジェクト: krylov/yandex-tank-api
    def get(self):
        breakpoint = self.get_argument("break", "finished")
        session_id = self.get_argument("session")
        hb_timeout = self.get_argument("heartbeat", None)

        self.set_header("Content-type", "application/json")

        # 400 if invalid breakpoint
        if not common.is_valid_break(breakpoint):
            self.reply_json(
                400, {
                    'reason': 'Specified break is not a valid test stage name.',
                    'hint':
                    {'breakpoints': common.get_valid_breaks()}
                })
            return

        # 404 if no such session
        try:
            status_dict = self.srv.status(session_id)
        except KeyError:
            self.reply_reason(404, 'No session with this ID.')
            return

	if session_id!=self.srv.running_id:
            self.reply_reason(418,
                "I'm a teapot! Can't set break for session that's not running!")
            return

        # 418 if in higher state
        if common.is_A_earlier_than_B(breakpoint, status_dict['break']):
            reply = {'reason': 'I am a teapot! I know nothing of time-travel!',
                     'hint': {'breakpoints': common.get_valid_breaks()}}
            reply.update(status_dict)
            self.reply_json(418, reply)
            return

        # Post run command to manager queue
        self.srv.cmd({
            'session': session_id,
            'cmd': 'run',
            'break': breakpoint})

        self.srv.heartbeat(session_id, hb_timeout)
        self.reply_reason(200, "Will try to set break before " + breakpoint)
コード例 #3
0
ファイル: webserver.py プロジェクト: Hurenka/yandex-tank-api
    def post(self):

        offered_test_id = self.get_argument(
            'test',
            datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
        breakpoint = self.get_argument('break', 'finished')
        hb_timeout = self.get_argument('heartbeat', None)

        config = self.request.body

        # 503 if any running session exists
        if self.srv.running_id is not None:
            reply = {'reason': 'Another session is already running.'}
            reply.update(self.srv.running_status)
            self.reply_json(503, reply)
            return

        # 400 if invalid breakpoint
        if not common.is_valid_break(breakpoint):
            self.reply_json(
                400, {
                    'reason':
                    'Specified break is not a valid test stage name.',
                    'hint': {
                        'breakpoints': common.get_valid_breaks()
                    }
                })
            return
        try:
            session_id = self.srv.create_session_dir(offered_test_id)
        except RuntimeError as err:
            self.reply_reason(500, str(err))
            return

        # Remember that such session exists
        self.srv.set_session_status(session_id, {
            'status': 'starting',
            'break': breakpoint
        })
        # Post run command to manager queue
        self.srv.cmd({
            'session': session_id,
            'cmd': 'run',
            'break': breakpoint,
            'config': config
        })

        self.srv.heartbeat(session_id, hb_timeout)
        self.reply_json(200, {'session': session_id})
コード例 #4
0
ファイル: webserver.py プロジェクト: krylov/yandex-tank-api
    def post(self):

        offered_test_id = self.get_argument("test", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
        breakpoint = self.get_argument("break", "finished")
        hb_timeout = self.get_argument("heartbeat", None)

        config = self.request.body

        # 503 if any running session exists
        if self.srv.running_id is not None:
            reply = {'reason': 'Another session is already running.'}
            reply.update(self.srv.running_status)
            self.reply_json(503, reply)
            return

        # 400 if invalid breakpoint
        if not common.is_valid_break(breakpoint):
            self.reply_json(
                400,
                {'reason': 'Specified break is not a valid test stage name.',
                 'hint': {'breakpoints': common.get_valid_breaks()}}
            )
            return
        try:
            session_id = self.srv.create_session_dir(offered_test_id)
        except RuntimeError as err:
            self.reply_reason(500, str(err))
            return

        # Remember that such session exists
        self.srv.set_session_status(
            session_id,
            {'status': 'starting', 'break': breakpoint}
        )
        # Post run command to manager queue
        self.srv.cmd({'session': session_id,
                      'cmd': 'run',
                      'break': breakpoint,
                      'config': config})

        self.srv.heartbeat(session_id, hb_timeout)
        self.reply_json(200, {"session": session_id})