예제 #1
0
    def get_session(self, session_id, maybe_closed=False):
        """
        :param session_id: integer
        :param maybe_closed: boolean
        :return: Session
        """
        try:
            session = self._cache[session_id]
        except (KeyError, TypeError):
            log.debug('Cache miss (item={})'.format(session_id))
            session = self.db.get_session(session_id)

        if not session:
            raise SessionException(
                "There is no active session {} (Unknown session)".format(
                    session_id))

        if session.closed and not maybe_closed:
            raise SessionException(
                "Session {}({}) already closed earlier".format(
                    session_id, session.reason))

        if self._cache:
            self._cache[session_id] = session

        return session
예제 #2
0
파일: helpers.py 프로젝트: sh0ked/vmmaster
def get_session_id(path):
    parts = path.split("/")
    try:
        log.warn(parts)
        pos = parts.index("session")
        session_id = parts[pos + 1]
    except IndexError or ValueError:
        raise SessionException("In request path %s not found session id" %
                               path)

    return session_id
예제 #3
0
파일: helpers.py 프로젝트: gridl/vmmaster
    def wrapper(*args, **kwargs):
        for value in func(*args, **kwargs):
            session_timeouted = is_session_timeouted()
            session_closed = is_session_closed()

            if is_request_closed():
                raise ConnectionError("Client has disconnected")
            elif session_timeouted:
                raise TimeoutException(session_timeouted)
            elif session_closed:
                raise SessionException(session_closed)

            time.sleep(0.01)
        return value
예제 #4
0
    def get_session(self, session_id):
        try:
            session = self.active_sessions[str(session_id)]
        except KeyError:
            session = current_app.database.get_session(session_id)
            if session:
                reason = session.reason
            else:
                reason = "Unknown session"

            message = "There is no active session %s" % session_id
            if reason:
                message = "%s (%s)" % (message, reason)

            raise SessionException(message)

        return session
예제 #5
0
def get_session():
    profiler.register_get_session_call()

    dc = commands.get_desired_capabilities(request)
    matched_platform, provider_id = current_app.get_matched_platforms(dc)
    if not matched_platform:
        raise SessionException("Cannot match platform for DesiredCapabilities: {}".format(dc))

    session = Session(platform=matched_platform, dc=dc, provider_id=provider_id)
    request.session = session
    log.info("New session {}({}) on provider {} with dc: {}".format(session.id, session.name, provider_id, dc))
    yield session

    start_time = time.time()
    while not session.endpoint_id:
        time.sleep(constants.GET_SESSION_SLEEP_TIME)
        if time.time() - start_time >= config.GET_VM_TIMEOUT:
            raise CreationException("Timeout getting endpoint for {}".format(session))
        session.refresh()
        yield session

    session.run()
    yield session
예제 #6
0
파일: helpers.py 프로젝트: sh0ked/vmmaster
async def get_vmmaster_session(request):
    session_id = get_session_id(request.path)
    session = request.app.sessions.get(int(session_id))
    if not session:
        raise SessionException("Session %s not found" % session_id)
예제 #7
0
 def put(self, session):
     if str(session.id) not in self.active_sessions.keys():
         self.active_sessions[str(session.id)] = session
     else:
         raise SessionException("Duplicate session id: %s" % session.id)