Esempio n. 1
0
    def get(self):
        breakpoint = self.get_argument("break", "finished")
        session_id = self.get_argument("session")
        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
        if not session_id in self.sessions:
            self.reply_json(404, {'reason': 'No session with this ID.'})
            return
        status_dict = self.sessions[session_id]

        # 500 if failed
        if status_dict['status'] == 'failed':
            reply = {'reason': 'Session failed.'}
            reply.update(status_dict)
            self.reply_json(500, reply)
            return

        # 418 if in higher state or not running
        if status_dict['status'] == 'success' or 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.out_queue.put({'session': session_id,
                            'cmd': 'run',
                            'break': breakpoint})

        self.reply_json(
            200, {'reason': "Will try to set break before " + breakpoint})
Esempio n. 2
0
    def post(self):

        test_id = self.get_argument("test", uuid.uuid4().hex)
        breakpoint = self.get_argument("break", "finished")
        session_id = uuid.uuid4().hex
        config = self.request.body

        # Check existing sessions
        running_session = None
        conflict_session = None
        for s in self.sessions.values():
            if s['status'] not in ['success', 'failed']:
                running_session = s
            if s['test'] == test_id:
                conflict_session = s

        # 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

        # 409 if session with this test_id is already running
        if conflict_session is not None:
            reply = {'reason': 'The test with this ID is already running.'}
            reply.update(conflict_session)
            self.reply_json(409, reply)
            return

        # 409 if finished test with this test_id exists
        test_status_file = os.path.join(
            self.working_dir, test_id, 'status.json')
        if os.path.exists(test_status_file):
            reply = {'reason': 'The test with this ID has already finished.'}
            reply.update(json.load(open(test_status_file)))
            self.reply_json(409, reply)
            return

        # 503 if any running session exists (but no test_id conflict)
        if running_session is not None:
            reply = {'reason': 'Another session is already running.'}
            reply.update(running_session)
            self.reply_json(503, reply)
            return

        # Remember that such session exists
        self.sessions[session_id] = {'status': 'starting',
                                     'break': breakpoint,
                                     'test': test_id}

        # Post run command to manager queue
        self.out_queue.put({'session': session_id,
                            'cmd': 'run',
                            'break': breakpoint,
                            'test': test_id,
                            'config': config})

        self.reply_json(200, {
            "test": test_id,
            "session": session_id,
        })