Exemplo n.º 1
0
 def get_next_break(self):
     """
     Read the next break from tank queue
     Check it for sanity
     """
     while True:
         msg = self.tank_queue.get()
         # Check that there is a break in the message
         if 'break' not in msg:
             self.log.error(
                 "No break specified in the recieved message from manager")
             continue
         brk = msg['break']
         # Check taht the name is valid
         if not common.is_valid_break(brk):
             self.log.error(
                 "Manager requested break at an unknown stage: %s", brk)
         # Check that the break is later than br
         elif common.is_A_earlier_than_B(brk, self.break_at):
             self.log.error(
                 "Recieved break %s which is earlier than "
                 "current next break %s", brk, self.break_at)
         else:
             self.log.info(
                 "Changing the next break from %s to %s", self.break_at, brk)
             self.break_at = brk
             return
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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})
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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})