Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #118 from 2gis/separate-get-wd-hub-session-route
Browse files Browse the repository at this point in the history
separate /wd/hub/session_id GET route
  • Loading branch information
z00sts committed Oct 14, 2015
2 parents 9b2ba2d + 5191c4c commit e8d7aa9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from core.config import config
from core.logger import log
from core.exceptions import SessionException

from vmpool.endpoint import delete_vm
from core.utils.vnc_recorder import VNCRecorder

Expand Down
20 changes: 12 additions & 8 deletions vmmaster/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@ def verify_token(username, client_token):

@webdriver.route('/session/<session_id>', methods=['DELETE'])
def delete_session(session_id):
session = current_app.sessions.get_session(session_id)
request.session = session
request.session = current_app.sessions.get_session(session_id)
status, headers, body = helpers.transparent()

session.add_session_step(control_line=status,
body=body)
session.succeed()
request.session.add_session_step(
control_line=status, body=body
)
request.session.succeed()

# Session is done, forget about it
del request.session
return helpers.form_response(status, headers, body)

Expand All @@ -114,11 +113,16 @@ def create_session():


@webdriver.route("/session/<string:session_id>", methods=['GET'])
def get_session(session_id):
request.session = current_app.sessions.get_session(session_id)
status, headers, body = helpers.transparent()
return helpers.form_response(status, headers, body)


@webdriver.route("/session/<string:session_id>/<path:url>",
methods=['GET', 'POST', 'DELETE'])
def proxy_request(session_id, url=None):
if not hasattr(request, 'session'):
request.session = current_app.sessions.get_session(session_id)
request.session = current_app.sessions.get_session(session_id)

if url:
last = url.split("/")[-1]
Expand Down
10 changes: 3 additions & 7 deletions vmmaster/webdriver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
from core.logger import log

from core import utils
from core.sessions import Session
from core.sessions import Session, RequestHelper
from vmpool import endpoint
from PIL import Image


def is_request_closed():
Expand Down Expand Up @@ -91,8 +92,6 @@ def make_thumbnail_for_screenshot(screenshot_path):


def screenshot_resize(screenshot_path, width, height=None, postfix=None):
from PIL import Image

try:
img = Image.open(screenshot_path)

Expand Down Expand Up @@ -132,8 +131,6 @@ def swap_session(req, desired_session):

@connection_watcher
def transparent():
from core.sessions import RequestHelper

status, headers, body = None, None, None
swap_session(request, request.session.selenium_session)
for status, headers, body in request.session.make_request(
Expand Down Expand Up @@ -163,7 +160,6 @@ def internal_exec(command):


def check_to_exist_ip(session, tries=10, timeout=5):
from time import sleep
i = 0
while True:
if session.endpoint_ip is not None:
Expand All @@ -175,7 +171,7 @@ def check_to_exist_ip(session, tries=10, timeout=5):
i += 1
log.info('IP is %s for VM %s, wait for %ss. before next try...' %
(session.endpoint_ip, session.endpoint_name, timeout))
sleep(timeout)
time.sleep(timeout)


@connection_watcher
Expand Down

0 comments on commit e8d7aa9

Please sign in to comment.