e2e: move to EU datacenter
This commit is contained in:
parent
153dbb2de1
commit
180df967e8
|
@ -57,7 +57,7 @@ def upload_to_saucelabs(file)
|
|||
username = ENV['SAUCE_USERNAME']
|
||||
unique_name = ENV['SAUCE_LABS_NAME']
|
||||
|
||||
url = "https://saucelabs.com/rest/v1/storage/#{username}/#{unique_name}?overwrite=true"
|
||||
url = "https://eu-central-1.saucelabs.com/rest/v1/storage/#{username}/#{unique_name}?overwrite=true"
|
||||
|
||||
upload_result = retry_curl_upload(url, file, "#{username}:#{key}")
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ class BaseTestReport:
|
|||
|
||||
def get_sauce_job_url(self, job_id, first_command=0):
|
||||
token = self.get_sauce_token(job_id)
|
||||
url = 'https://saucelabs.com/jobs/%s?auth=%s' % (job_id, token)
|
||||
url = 'https://eu-central-1.saucelabs.com/jobs/%s?auth=%s' % (job_id, token)
|
||||
if first_command > 0:
|
||||
url += "#%s" % first_command
|
||||
return url
|
||||
|
@ -114,11 +114,11 @@ class BaseTestReport:
|
|||
|
||||
def get_sauce_final_screenshot_url(self, job_id):
|
||||
token = self.get_sauce_token(job_id)
|
||||
from tests.conftest import sauce
|
||||
from tests.cloudbase_test_api import sauce
|
||||
for _ in range(10):
|
||||
try:
|
||||
scr_number = sauce.jobs.get_job_assets(job_id)['screenshots'][-1]
|
||||
return 'https://assets.saucelabs.com/jobs/%s/%s?auth=%s' % (job_id, scr_number, token)
|
||||
return 'https://assets.eu-central-1.saucelabs.com/jobs/%s/%s?auth=%s' % (job_id, scr_number, token)
|
||||
except SauceException:
|
||||
time.sleep(3)
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import time
|
|||
|
||||
async def start_threads(quantity: int, func: type, returns: dict, *args):
|
||||
loop = asyncio.get_event_loop()
|
||||
from tests.conftest import sauce
|
||||
from tests.cloudbase_test_api import sauce
|
||||
for _ in range(60):
|
||||
if 16 - len([job for job in sauce.jobs.get_jobs() if job['status'] == 'in progress']) < quantity:
|
||||
time.sleep(10)
|
||||
|
|
|
@ -24,13 +24,13 @@ from tests import test_suite_data, start_threads, appium_container, pytest_confi
|
|||
import base64
|
||||
from re import findall
|
||||
|
||||
from tests.conftest import sauce
|
||||
from tests.cloudbase_test_api import sauce
|
||||
|
||||
sauce_username = environ.get('SAUCE_USERNAME')
|
||||
|
||||
sauce_access_key = environ.get('SAUCE_ACCESS_KEY')
|
||||
|
||||
executor_sauce_lab = 'http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (sauce_username, sauce_access_key)
|
||||
executor_sauce_lab = 'https://%s:%s@ondemand.eu-central-1.saucelabs.com:443/wd/hub' % (sauce_username, sauce_access_key)
|
||||
|
||||
executor_local = 'http://localhost:4723/wd/hub'
|
||||
|
||||
|
@ -397,7 +397,7 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
|
|||
driver.quit()
|
||||
except WebDriverException:
|
||||
pass
|
||||
url = sauce.jobs.get_job_asset_url(job_id=session_id, filename="log.json")
|
||||
url = 'https://eu-central-1.saucelabs.com/rest/v1/%s/jobs/%s/assets/%s' % (sauce_username, session_id, "log.json")
|
||||
WebDriverWait(driver, 60, 2).until(lambda _: requests_session.get(url).status_code == 200)
|
||||
commands = requests_session.get(url).json()
|
||||
for command in commands:
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
from os import environ
|
||||
import json
|
||||
import requests
|
||||
from io import BytesIO
|
||||
from time import sleep
|
||||
|
||||
from sauceclient import SauceClient, SauceException
|
||||
|
||||
try:
|
||||
import http.client as http_client
|
||||
from urllib.parse import urlencode
|
||||
except ImportError:
|
||||
import httplib as http_client
|
||||
from urllib import urlencode
|
||||
|
||||
|
||||
sauce_username = environ.get('SAUCE_USERNAME')
|
||||
sauce_access_key = environ.get('SAUCE_ACCESS_KEY')
|
||||
|
||||
sauce = SauceClient(sauce_username, sauce_access_key)
|
||||
apibase = 'eu-central-1.saucelabs.com'
|
||||
|
||||
|
||||
def request(method, url, body=None, content_type='application/json'):
|
||||
"""This is to monkey patch further this method in order to use apibase"""
|
||||
headers = sauce.make_auth_headers(content_type)
|
||||
connection = http_client.HTTPSConnection(apibase)
|
||||
connection.request(method, url, body, headers=headers)
|
||||
response = connection.getresponse()
|
||||
data = response.read()
|
||||
connection.close()
|
||||
if response.status not in [200, 201]:
|
||||
raise SauceException('{}: {}.\nSauce Status NOT OK'.format(
|
||||
response.status, response.reason), response=response)
|
||||
return json.loads(data.decode('utf-8'))
|
||||
|
||||
sauce.request = request
|
||||
|
||||
def upload_from_url(apk_path = str()):
|
||||
response = requests.get(apk_path, stream=True)
|
||||
response.raise_for_status()
|
||||
apk_name = apk_path.split("/")[-1]
|
||||
file = BytesIO(response.content)
|
||||
del response
|
||||
for _ in range(3):
|
||||
try:
|
||||
requests.post('https://eu-central-1.saucelabs.com/rest/v1/storage/'
|
||||
+ sauce_username + '/' + apk_name + '?overwrite=true',
|
||||
auth=(sauce_username, sauce_access_key),
|
||||
data=file,
|
||||
headers={'Content-Type': 'application/octet-stream'})
|
||||
break
|
||||
except ConnectionError:
|
||||
sleep(10)
|
|
@ -12,6 +12,7 @@ from datetime import datetime
|
|||
from os import environ
|
||||
from io import BytesIO
|
||||
from sauceclient import SauceClient, SauceException
|
||||
import tests.cloudbase_test_api
|
||||
from support.api.network_api import NetworkApi
|
||||
from support.github_report import GithubHtmlReport
|
||||
from support.testrail_report import TestrailReport
|
||||
|
@ -143,7 +144,7 @@ def is_master(config):
|
|||
|
||||
|
||||
def is_uploaded():
|
||||
stored_files = sauce.storage.get_stored_files()
|
||||
stored_files = tests.cloudbase_test_api.sauce.storage.get_stored_files()
|
||||
for i in range(len(stored_files['files'])):
|
||||
if stored_files['files'][i]['name'] == test_suite_data.apk_name:
|
||||
return True
|
||||
|
@ -176,22 +177,9 @@ def pytest_configure(config):
|
|||
if config.getoption('env') == 'sauce':
|
||||
if not is_uploaded():
|
||||
if 'http' in config.getoption('apk'):
|
||||
response = requests.get(config.getoption('apk'), stream=True)
|
||||
response.raise_for_status()
|
||||
file = BytesIO(response.content)
|
||||
del response
|
||||
for _ in range(3):
|
||||
try:
|
||||
requests.post('http://saucelabs.com/rest/v1/storage/'
|
||||
+ sauce_username + '/' + test_suite_data.apk_name + '?overwrite=true',
|
||||
auth=(sauce_username, sauce_access_key),
|
||||
data=file,
|
||||
headers={'Content-Type': 'application/octet-stream'})
|
||||
break
|
||||
except ConnectionError:
|
||||
time.sleep(10)
|
||||
tests.cloudbase_test_api.upload_from_url(config.getoption('apk'))
|
||||
else:
|
||||
sauce.storage.upload_file(config.getoption('apk'))
|
||||
tests.cloudbase_test_api.sauce.storage.upload_file(config.getoption('apk'))
|
||||
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
|
@ -304,7 +292,7 @@ def pytest_runtest_makereport(item, call):
|
|||
def update_sauce_jobs(test_name, job_ids, passed):
|
||||
for job_id in job_ids.keys():
|
||||
try:
|
||||
sauce.jobs.update_job(job_id, name=test_name, passed=passed)
|
||||
tests.cloudbase_test_api.sauce.jobs.update_job(job_id, name=test_name, passed=passed)
|
||||
except (RemoteDisconnected, SauceException):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue