chore: use ftest_common
This commit is contained in:
parent
40d1ab1cfa
commit
faa67e9408
9 changed files with 23 additions and 140 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
FROM python as builder
|
||||||
|
WORKDIR /src/
|
||||||
|
RUN git clone https://git.batsense.net/ForgeFlux/ftest-common-py .
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
RUN python3 -m build
|
||||||
FROM python
|
FROM python
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source https://git.batsense.net/ForgeFlux/ap-test
|
LABEL org.opencontainers.image.source https://git.batsense.net/ForgeFlux/ap-test
|
||||||
|
@ -7,6 +12,8 @@ RUN apt-get update && apt-get install -y ca-certificates git
|
||||||
WORKDIR /src/
|
WORKDIR /src/
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
COPY --from=builder /src/dist/ftest_common-0.0.1-py3-none-any.whl .
|
||||||
|
RUN pip install ./ftest_common-0.0.1-py3-none-any.whl
|
||||||
|
|
||||||
USER ap
|
USER ap
|
||||||
WORKDIR /home/ap
|
WORKDIR /home/ap
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
from .logger import logger
|
|
|
@ -1,23 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from .logger import logger
|
|
||||||
|
|
||||||
|
|
||||||
def get_env(name) -> str:
|
|
||||||
env = FTEST_AUTH = os.environ.get(name)
|
|
||||||
logger.info(f"Environment: {name}: {env}")
|
|
||||||
if env is None:
|
|
||||||
raise Exception(
|
|
||||||
f"Please set environment variable {name}. See https://git.batsense.net/ForgeFlux/nodeinfo-test#environment-variables"
|
|
||||||
)
|
|
||||||
return env
|
|
||||||
|
|
||||||
|
|
||||||
FTEST_AUTH = get_env("FTEST_AUTH")
|
|
||||||
FTEST_HOST = get_env("FTEST_HOST")
|
|
||||||
FTEST_USER = get_env("FTEST_USER")
|
|
||||||
TARGET_HOST = get_env("FTEST_TARGET_HOST")
|
|
|
@ -1,54 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
from urllib.parse import urlparse, urlunparse
|
|
||||||
import logging
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
LOG_FILE = "ap.log"
|
|
||||||
|
|
||||||
|
|
||||||
def configure_logger():
|
|
||||||
logger = logging.getLogger("ap")
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
fh = logging.FileHandler(LOG_FILE)
|
|
||||||
fh.setLevel(logging.DEBUG)
|
|
||||||
ch = logging.StreamHandler()
|
|
||||||
ch.setLevel(logging.DEBUG)
|
|
||||||
formatter = logging.Formatter(
|
|
||||||
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
||||||
)
|
|
||||||
fh.setFormatter(formatter)
|
|
||||||
ch.setFormatter(formatter)
|
|
||||||
logger.addHandler(fh)
|
|
||||||
logger.addHandler(ch)
|
|
||||||
return logger
|
|
||||||
|
|
||||||
|
|
||||||
logger = configure_logger()
|
|
||||||
|
|
||||||
|
|
||||||
def upload_logs_to_ftest(success: bool, logs: str):
|
|
||||||
from .env import FTEST_HOST, FTEST_AUTH
|
|
||||||
|
|
||||||
parsed_ftest_host = urlparse(FTEST_HOST)
|
|
||||||
ftest = urlunparse(
|
|
||||||
(
|
|
||||||
parsed_ftest_host.scheme,
|
|
||||||
parsed_ftest_host.netloc,
|
|
||||||
f"/api/v1/{FTEST_AUTH}/results",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
logger.info(f"Uploading logs to ftest server {ftest}")
|
|
||||||
|
|
||||||
payload = {"success": success, "logs": logs}
|
|
||||||
|
|
||||||
res = requests.post(ftest, json=payload, headers={"Origin": "http://example.org"})
|
|
||||||
if res.status_code == 200:
|
|
||||||
logger.info("Upload successful")
|
|
||||||
else:
|
|
||||||
print(res)
|
|
|
@ -1,18 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from .logger import logger
|
|
||||||
|
|
||||||
|
|
||||||
def get_ap_obj(url):
|
|
||||||
logger.info(f"Getting object: {url}")
|
|
||||||
res = requests.get(url, headers={"Accept": "application/activity+json"})
|
|
||||||
msg = f"AP server response:\n\nSTATUS: {res.status_code}\n\nHEADERS:\n {res.headers}\n\nRESPONSE PAYLOAD:\n{res.text}"
|
|
||||||
logger.debug(msg)
|
|
||||||
assert res.status_code == 200, f"Request FAILURE. {msg}"
|
|
||||||
return res.json()
|
|
|
@ -1,33 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
from urllib.parse import urlparse, urlunparse
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from .logger import logger
|
|
||||||
|
|
||||||
|
|
||||||
def get_webfinger():
|
|
||||||
from .env import TARGET_HOST, FTEST_USER
|
|
||||||
|
|
||||||
parsed_target_host = urlparse(TARGET_HOST)
|
|
||||||
webfinger = urlunparse(
|
|
||||||
(
|
|
||||||
parsed_target_host.scheme,
|
|
||||||
parsed_target_host.netloc,
|
|
||||||
"/.well-known/webfinger",
|
|
||||||
"",
|
|
||||||
f"resource=acct:{FTEST_USER}",
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
logger.info(f"Query webfinger: {webfinger}")
|
|
||||||
res = requests.get(webfinger)
|
|
||||||
logger.debug(
|
|
||||||
f"webfinger response:\n\nSTATUS: {res.status_code}\n\nHEADERS:\n {res.headers}\n\nRESPONSE PAYLOAD:\n{res.json()}"
|
|
||||||
)
|
|
||||||
assert res.status_code == 200
|
|
||||||
logger.info("[SUCCESS] webfinger query response is HTTP 200")
|
|
||||||
return res.json()
|
|
|
@ -1,6 +1,6 @@
|
||||||
from behave import *
|
from behave import *
|
||||||
|
|
||||||
from common.logger import upload_logs_to_ftest
|
from ftest_common.logger import upload_logs_to_ftest
|
||||||
|
|
||||||
|
|
||||||
def before_all(context):
|
def before_all(context):
|
||||||
|
@ -37,4 +37,5 @@ def after_all(context):
|
||||||
print(log)
|
print(log)
|
||||||
logs += log
|
logs += log
|
||||||
|
|
||||||
upload_logs_to_ftest(score == max_score, logs)
|
|
||||||
|
# upload_logs_to_ftest(score == max_score, logs)
|
||||||
|
|
|
@ -8,10 +8,10 @@ from urllib.parse import urlparse, urlunparse
|
||||||
import requests
|
import requests
|
||||||
from behave import *
|
from behave import *
|
||||||
|
|
||||||
from common.env import FTEST_USER
|
from ftest_common.env import FTEST_USER
|
||||||
from common import logger
|
from ftest_common.logger import logger
|
||||||
from common.webfinger import get_webfinger
|
from ftest_common.webfinger import get_webfinger
|
||||||
from common.obj import get_ap_obj
|
from ftest_common.obj import get_ap_obj
|
||||||
|
|
||||||
|
|
||||||
@given("A Fediverse server")
|
@given("A Fediverse server")
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
attrs==23.1.0
|
attrs==23.1.0
|
||||||
behave==1.2.6
|
behave==1.2.6
|
||||||
|
blinker==1.6.2
|
||||||
certifi==2023.7.22
|
certifi==2023.7.22
|
||||||
charset-normalizer==3.3.0
|
charset-normalizer==3.3.0
|
||||||
|
click==8.1.7
|
||||||
|
Flask==3.0.0
|
||||||
|
Flask-Cors==4.0.0
|
||||||
idna==3.4
|
idna==3.4
|
||||||
|
itsdangerous==2.1.2
|
||||||
|
Jinja2==3.1.2
|
||||||
jsonschema==4.19.1
|
jsonschema==4.19.1
|
||||||
jsonschema-specifications==2023.7.1
|
jsonschema-specifications==2023.7.1
|
||||||
|
MarkupSafe==2.1.3
|
||||||
parse==1.19.1
|
parse==1.19.1
|
||||||
parse-type==0.6.2
|
parse-type==0.6.2
|
||||||
referencing==0.30.2
|
referencing==0.30.2
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
rpds-py==0.10.3
|
rpds-py==0.10.3
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
urllib3==2.0.5
|
urllib3==2.0.6
|
||||||
|
Werkzeug==3.0.0
|
||||||
|
|
Loading…
Reference in a new issue