Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker report image AND report service source #57

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Dockerfile.report
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.10

RUN mkdir knowledge-middleware
WORKDIR knowledge-middleware

COPY pyproject.toml /knowledge-middleware/pyproject.toml
COPY poetry.lock /knowledge-middleware/poetry.lock
COPY README.md /knowledge-middleware/README.md

RUN pip install --no-cache-dir poetry==1.5.1
RUN poetry config virtualenvs.create true && \
poetry config virtualenvs.in-project true && \
poetry install --no-root --no-cache

COPY api /knowledge-middleware/api
COPY lib /knowledge-middleware/lib
COPY worker /knowledge-middleware/worker
COPY tests /knowledge-middleware/tests
RUN poetry install --only-root --no-cache

EXPOSE 8000
CMD [ "poetry", "run", "poe", "report" ]
2 changes: 1 addition & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ target "knowledge-middleware-worker-base" {
target "knowledge-middleware-report-base" {
context = "."
tags = tag("knowledge-middleware-report", "", "")
dockerfile = "report/Dockerfile"
dockerfile = "Dockerfile.report"
}

target "knowledge-middleware-api" {
Expand Down
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ pyyaml = "^6.0.1"
pre-commit = "^3.3.3"


[tool.poetry.scripts]
status-test = "tests.report:test"
gen-report = "tests.report:report"

[tool.poe.tasks]
_test = "status-test"
_report = "gen-report"
_test.script = "tests.report:test"
_report.script = "tests.report:gen_report"
report.sequence = ["_test", "_report"]
report.ignore_fail = true

Expand Down
27 changes: 0 additions & 27 deletions report/Dockerfile

This file was deleted.

23 changes: 0 additions & 23 deletions tests/Home.py

This file was deleted.

44 changes: 0 additions & 44 deletions tests/create_table.py

This file was deleted.

91 changes: 0 additions & 91 deletions tests/pages/1_TA1.py

This file was deleted.

46 changes: 35 additions & 11 deletions tests/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ def test(output_file="tests/output/tests.json"):
pytest.main(["--json-report", f"--json-report-file={output_file}"])


def report():
def gen_report():
# TODO: Make this into a predefined struct
report = defaultdict(lambda: {"operations": defaultdict(dict)})
scenarios = defaultdict(lambda: {"operations": defaultdict(dict)})
if os.path.exists("tests/output/qual.csv"):
with open("tests/output/qual.csv", "r", newline="") as file:
qual = csv.reader(file)
for scenario, operation, test, result in qual:
report[scenario]["operations"][operation][test] = result
scenarios[scenario]["operations"][operation][test] = result

with open("tests/output/tests.json", "r") as file:
raw_tests = json.load(file)["tests"]
Expand All @@ -34,24 +34,48 @@ def add_case(testobj):
operation, scenario = match_result[1], match_result[2]
passed = testobj["outcome"] == "passed"
duration = round(testobj["call"]["duration"],2)
report[scenario]["operations"][operation]["Integration Status"] = passed
report[scenario]["operations"][operation]["Execution Time"] = duration
scenarios[scenario]["operations"][operation]["Integration Status"] = passed
scenarios[scenario]["operations"][operation]["Execution Time"] = duration
try:
logs = testobj["call"]["stderr"]
report[scenario]["operations"][operation]["Logs"] = logs
scenarios[scenario]["operations"][operation]["Logs"] = logs
except Exception as e:
print(f"Unable to obtain logs for {full_name}: {e}")
for testobj in raw_tests: add_case(testobj)

for scenario in report:
for scenario in scenarios:
with open(f"tests/scenarios/{scenario}/config.yaml") as file:
spec = yaml.load(file, yaml.CLoader)
report[scenario]["name"] = spec["name"]
report[scenario]["description"] = spec["description"]
scenarios[scenario]["name"] = spec["name"]
scenarios[scenario]["description"] = spec["description"]

report = {
"scenarios": scenarios,
# TODO: Grab version
# NOTE: This is broken up currently because we expect different version calls
"services": {
"TA1_UNIFIED_URL":{
"source": settings.TA1_UNIFIED_URL,
"version": "UNAVAILABLE"
},
"SKEMA_RS_URL":{
"source": settings.SKEMA_RS_URL,
"version": "UNAVAILABLE"
},
"MIT_TR_URL":{
"source": settings.MIT_TR_URL,
"version": "UNAVAILABLE"
},
"COSMOS_URL":{
"source": settings.COSMOS_URL,
"version": "UNAVAILABLE"
},
}
}

timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
filename = f"report_{timestamp}.json"
fullpath = os.path.join("tests/output", "filename")
fullpath = os.path.join("tests/output", filename)
with open(fullpath, "w") as file:
json.dump(report, file, indent=2)

Expand All @@ -60,4 +84,4 @@ def add_case(testobj):
s3.upload_file(fullpath, settings.BUCKET, full_handle)

if __name__ == "__main__":
report()
gen_report()