示例#1
0
    def get(self):
        test_id = self.get_argument("test")
        filename = self.get_argument("filename", None)

        # look for test directory
        if not os.path.exists(os.path.join(self.working_dir, test_id)):
            self.reply_json(404, {
                'reason': 'No test with this ID found',
                'test': test_id,
            })
            return

        # look for status.json (any test that went past lock stage should have
        # it)
        if not os.path.exists(os.path.join(self.working_dir, test_id, 'status.json')):
            self.reply_json(404, {
                'reason': 'Test was not performed, no artifacts.',
                'test': test_id,
            })
            return

        if filename:
            filepath = os.path.join(self.working_dir, test_id, filename)
            if os.path.exists(filepath):
                file_size = os.stat(filepath).st_size

                if file_size > TRANSFER_SIZE_LIMIT and\
                any(s['status'] not in ['success','failed'] and\
                        common.is_A_earlier_than_B(s['current_stage'],'postprocess') for s in self.sessions.values()):
                    self.reply_json(503,{
                        'reason': 'File is too large and test is running',
                        'test': test_id,
                        'filename': filename,
                        'filesize': file_size,
                        'limit': TRANSFER_SIZE_LIMIT,
                    })
                    return
                else:
                    self.set_header("Content-type", "application/octet-stream")
                    with open(filepath, 'rb') as f:
                        data = f.read()
                        self.write(data)
                    self.finish()
                    return
            else:
                self.reply_json(404, {
                    'reason': 'No such file',
                    'test': test_id,
                    'filename': filename,
                })
                return
        else:
            basepath = os.path.join(self.working_dir, test_id)
            onlyfiles = [
                f for f in os.listdir(basepath)
                if os.path.isfile(os.path.join(basepath, f))
            ]
            self.reply_json(200, onlyfiles)
示例#2
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})