e2e: move to EU datacenter

This commit is contained in:
Churikova Tetiana 2022-10-20 10:07:16 +02:00
parent 153dbb2de1
commit 180df967e8
No known key found for this signature in database
GPG Key ID: 0D4EA7B33B47E6D8
6 changed files with 67 additions and 25 deletions

View File

@ -57,7 +57,7 @@ def upload_to_saucelabs(file)
username = ENV['SAUCE_USERNAME'] username = ENV['SAUCE_USERNAME']
unique_name = ENV['SAUCE_LABS_NAME'] 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}") upload_result = retry_curl_upload(url, file, "#{username}:#{key}")

View File

@ -102,7 +102,7 @@ class BaseTestReport:
def get_sauce_job_url(self, job_id, first_command=0): def get_sauce_job_url(self, job_id, first_command=0):
token = self.get_sauce_token(job_id) 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: if first_command > 0:
url += "#%s" % first_command url += "#%s" % first_command
return url return url
@ -114,11 +114,11 @@ class BaseTestReport:
def get_sauce_final_screenshot_url(self, job_id): def get_sauce_final_screenshot_url(self, job_id):
token = self.get_sauce_token(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): for _ in range(10):
try: try:
scr_number = sauce.jobs.get_job_assets(job_id)['screenshots'][-1] 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: except SauceException:
time.sleep(3) time.sleep(3)

View File

@ -11,7 +11,7 @@ import time
async def start_threads(quantity: int, func: type, returns: dict, *args): async def start_threads(quantity: int, func: type, returns: dict, *args):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
from tests.conftest import sauce from tests.cloudbase_test_api import sauce
for _ in range(60): for _ in range(60):
if 16 - len([job for job in sauce.jobs.get_jobs() if job['status'] == 'in progress']) < quantity: if 16 - len([job for job in sauce.jobs.get_jobs() if job['status'] == 'in progress']) < quantity:
time.sleep(10) time.sleep(10)

View File

@ -24,13 +24,13 @@ from tests import test_suite_data, start_threads, appium_container, pytest_confi
import base64 import base64
from re import findall from re import findall
from tests.conftest import sauce from tests.cloudbase_test_api import sauce
sauce_username = environ.get('SAUCE_USERNAME') sauce_username = environ.get('SAUCE_USERNAME')
sauce_access_key = environ.get('SAUCE_ACCESS_KEY') 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' executor_local = 'http://localhost:4723/wd/hub'
@ -397,7 +397,7 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
driver.quit() driver.quit()
except WebDriverException: except WebDriverException:
pass 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) WebDriverWait(driver, 60, 2).until(lambda _: requests_session.get(url).status_code == 200)
commands = requests_session.get(url).json() commands = requests_session.get(url).json()
for command in commands: for command in commands:

View File

@ -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)

View File

@ -12,6 +12,7 @@ from datetime import datetime
from os import environ from os import environ
from io import BytesIO from io import BytesIO
from sauceclient import SauceClient, SauceException from sauceclient import SauceClient, SauceException
import tests.cloudbase_test_api
from support.api.network_api import NetworkApi from support.api.network_api import NetworkApi
from support.github_report import GithubHtmlReport from support.github_report import GithubHtmlReport
from support.testrail_report import TestrailReport from support.testrail_report import TestrailReport
@ -143,7 +144,7 @@ def is_master(config):
def is_uploaded(): 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'])): for i in range(len(stored_files['files'])):
if stored_files['files'][i]['name'] == test_suite_data.apk_name: if stored_files['files'][i]['name'] == test_suite_data.apk_name:
return True return True
@ -176,22 +177,9 @@ def pytest_configure(config):
if config.getoption('env') == 'sauce': if config.getoption('env') == 'sauce':
if not is_uploaded(): if not is_uploaded():
if 'http' in config.getoption('apk'): if 'http' in config.getoption('apk'):
response = requests.get(config.getoption('apk'), stream=True) tests.cloudbase_test_api.upload_from_url(config.getoption('apk'))
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)
else: else:
sauce.storage.upload_file(config.getoption('apk')) tests.cloudbase_test_api.sauce.storage.upload_file(config.getoption('apk'))
def pytest_unconfigure(config): def pytest_unconfigure(config):
@ -304,7 +292,7 @@ def pytest_runtest_makereport(item, call):
def update_sauce_jobs(test_name, job_ids, passed): def update_sauce_jobs(test_name, job_ids, passed):
for job_id in job_ids.keys(): for job_id in job_ids.keys():
try: 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): except (RemoteDisconnected, SauceException):
pass pass