- changes for last day

This commit is contained in:
2023-08-21 19:56:07 +03:00
parent 61cecc52dd
commit 9d2ba8c998
11 changed files with 162 additions and 87 deletions

View File

@@ -62,8 +62,8 @@ class QualtestBackend:
return self.__phone
def preload(self, cache_dir: Path):
self.__phone = self.load_phone(cache_dir)
def preload(self, cache: InfoCache):
self.__phone = self.load_phone(cache)
def upload_report(self, report, cache: InfoCache) -> (str, bool):
@@ -78,15 +78,18 @@ class QualtestBackend:
r = requests.post(url=url, json=report, timeout=utils.NETWORK_TIMEOUT)
utils.log_verbose(f"Upload report finished. Response (probe ID): {r.content}")
if r.status_code != 200:
raise RuntimeError(f'Server returned code {r.status_code} and content {r.content}')
raise RuntimeError(f'Server returned code {r.status_code}')
result = (r.content.decode().strip(), True)
except Exception as e:
utils.log_error(f"Upload report to {self.address} finished with error.", err=e)
# Backup probe result
probe_id = cache.add_report(report)
result = (probe_id, False)
if cache is not None:
probe_id = cache.add_report(report)
utils.log(f' {probe_id}.json report is put to cache.')
result = (probe_id, False)
else:
return (None, None)
return result
@@ -128,8 +131,7 @@ class QualtestBackend:
# Get response from server
response = urllib.request.urlopen(url, timeout=utils.NETWORK_TIMEOUT)
if response.getcode() != 200:
utils.log_error("Failed to get task list. Error code: %s" % response.getcode())
return None
raise RuntimeError(f'Failed to get task list. Error code: {response.getcode()}')
result = TaskList()
response_content = response.read().decode()
@@ -137,7 +139,7 @@ class QualtestBackend:
return result
except Exception as err:
utils.log_error("Exception when fetching task list: {0}".format(err))
utils.log_error(f'Error when fetching task list from backend: {str(err)}')
return None
@@ -154,12 +156,13 @@ class QualtestBackend:
try:
response = urllib.request.urlopen(url, timeout=utils.NETWORK_TIMEOUT)
if response.getcode() != 200:
raise RuntimeError(f'Failed to load phone definition. Error code: {response.getcode()}')
raise RuntimeError(f'Failed to load phone definition from server. Error code: {response.getcode()}')
except Exception as e:
utils.log_error(f'Problem when loading the phone definition from backend. Error: {str(e)}')
r = cache.get_phone(self.instance)
if r is None:
raise RuntimeError(f'No cached phone definition.')
utils.log(f' Found phone definition in cache.')
return r
# Get possible list of phones
@@ -201,7 +204,7 @@ class QualtestBackend:
return result
except Exception as err:
utils.log_error(f"Exception when fetching task list: {str(err)}")
utils.log_error(f"Exception loading phone information: {str(err)}")
return None