feat: upload logs to ftest server
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Aravinth Manivannan 2023-09-28 22:15:41 +05:30
parent c40f72911c
commit ec2eabe19b
Signed by: realaravinth
GPG key ID: F8F50389936984FF
2 changed files with 13 additions and 19 deletions

View file

@ -6,7 +6,7 @@
## TODO
- [ ] Write code to upload to ftest server
- [x] Write code to upload to ftest server
- [x] Package Docker container
- [x] Upload to Docker Hub

30
run.py
View file

@ -11,6 +11,7 @@ from urllib.parse import urlparse, urlunparse
LOG_FILE = "webfinger.log"
def configure_logger():
logger = logging.getLogger("webfinger")
logger.setLevel(logging.DEBUG)
@ -131,35 +132,26 @@ def test_access_control_allow_origin(resp):
), "Access-Control-Allow-Origin header should be '*' to allow any domain to access the resource with CORS. Please see https://www.rfc-editor.org/rfc/rfc7033.html#section-5"
logger.info("[SUCESS] WebFinger endpoint is configured correctly for CORS")
def upload_logs_to_ftest(success: bool, logs: str):
parsed_ftest_host = urlparse(FTEST_HOST)
ftest = urlunparse(
(
parsed_ftest_host.scheme,
parsed_ftest_host.netloc,
"/suites//tests/results",
"",
""
"/api/v1/results",
"",
"" "",
)
)
logger.info("Uploading logs to ftest server {ftest}")
payload = {"success": success, "logs": logs, "auth": FTEST_AUTH}
raw_logs = ""
with open(LOG_FILE) as log_file:
for line in log_file:
raw_logs += line
payload = {
"success": success,
"logs": logs,
"raw_logs": raw_logs,
}
res = requests.post(webfinger, headers={"Origin": "http://example.org"})
res = requests.post(
FTEST_HOST, json=payload, headers={"Origin": "http://example.org"}
)
logger.info("Upload successful")
if __name__ == "__main__":
@ -226,3 +218,5 @@ if __name__ == "__main__":
log = f"[FAIL] {test} failed with error:\n{error}\n-----\n"
print(log)
logs.append(log)
upload_logs_to_ftest(success, logs)