Skip to content

Commit 8dc39d3

Browse files
authored
Merge pull request #75 from PrivateAIM/hub-0.8.17
Update to Hub 0.8.17
2 parents 772f7a4 + b783fd3 commit 8dc39d3

File tree

3 files changed

+47
-39
lines changed

3 files changed

+47
-39
lines changed

.env.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ PYTEST_ADMIN_PASSWORD=start123
77
PYTEST_DEFAULT_MASTER_IMAGE=python/base
88
PYTEST_ASYNC_MAX_RETRIES=5
99
PYTEST_ASYNC_RETRY_DELAY_MILLIS=500
10-
PYTEST_HUB_VERSION=0.8.15
10+
PYTEST_HUB_VERSION=0.8.17

flame_hub/_core_client.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ class UpdateAnalysisNode(BaseModel):
298298

299299
class CreateAnalysisNodeLog(BaseModel):
300300
analysis_id: t.Annotated[uuid.UUID, Field(), WrapValidator(uuid_validator)]
301-
node_id: uuid.UUID
301+
node_id: t.Annotated[uuid.UUID, Field(), WrapValidator(uuid_validator)]
302302
code: str | None
303-
status: str
304-
message: str | None
303+
status: str | None
304+
message: str
305305
level: LogLevel
306306

307307

@@ -641,22 +641,25 @@ def create_analysis_node_log(
641641
analysis_id: Analysis | uuid.UUID | str,
642642
node_id: Node | uuid.UUID | str,
643643
level: LogLevel,
644-
status: str,
644+
message: str,
645+
status: str = None,
645646
code: str = None,
646-
message: str = None,
647-
) -> Log:
648-
return self._create_resource(
649-
Log,
650-
CreateAnalysisNodeLog(
651-
analysis_id=obtain_uuid_from(analysis_id),
652-
node_id=obtain_uuid_from(node_id),
653-
code=code,
654-
status=status,
655-
message=message,
656-
level=level,
657-
),
658-
"analysis-node-logs",
659-
)
647+
) -> None:
648+
"""Note that this method returns :any:`None` since the response does not contain the log resource."""
649+
# TODO: This method should also use _create_resource() from the base client. Therefore creating analysis node
650+
# TODO: logs have to return a status code of 201 and the response has to contain the log resource itself.
651+
resource = CreateAnalysisNodeLog(
652+
analysis_id=analysis_id,
653+
node_id=node_id,
654+
code=code,
655+
status=status,
656+
message=message,
657+
level=level,
658+
)
659+
r = self._client.post("analysis-node-logs", json=resource.model_dump(mode="json"))
660+
if r.status_code != httpx.codes.ACCEPTED.value:
661+
raise new_hub_api_error_from_response(r)
662+
return None
660663

661664
def delete_analysis_node_logs(self, analysis_id: Analysis | uuid.UUID | str, node_id: Node | uuid.UUID | str):
662665
r = self._client.delete(

tests/test_core.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def configured_analysis(core_client, registry, analysis, master_realm, analysis_
190190
return analysis
191191

192192

193-
# TODO: Make it possible to create analysis logs in the current test deployment.
194193
@pytest.fixture()
195194
def analysis_log(core_client, configured_analysis):
196195
core_client.send_analysis_command(configured_analysis, "buildStart")
@@ -203,17 +202,6 @@ def _check_analysis_logs_present():
203202
return core_client.find_analysis_logs(filter={"analysis_id": configured_analysis.id})[0]
204203

205204

206-
@pytest.fixture()
207-
def analysis_node_log(core_client, analysis_node):
208-
new_analysis_node_log = core_client.create_analysis_node_log(
209-
analysis_node.analysis_id, analysis_node.node_id, level="info", status="started"
210-
)
211-
yield new_analysis_node_log
212-
core_client.delete_analysis_node_logs(
213-
analysis_id=new_analysis_node_log.labels["analysis_id"], node_id=new_analysis_node_log.labels["node_id"]
214-
)
215-
216-
217205
@pytest.fixture()
218206
def registry(core_client):
219207
new_registry = core_client.create_registry(
@@ -423,14 +411,13 @@ def test_build_analysis(core_client, configured_analysis):
423411
assert core_client.send_analysis_command(configured_analysis.id, command="buildStop").build_status == "stopping"
424412

425413

426-
@pytest.mark.xfail(reason="It is not possible to create analysis logs in the current test deployment.")
427414
def test_build_status_analysis(core_client, configured_analysis):
428415
core_client.send_analysis_command(configured_analysis.id, command="buildStart")
429416
core_client.send_analysis_command(configured_analysis.id, command="buildStatus")
430417

431418
def _check_checking_event_in_logs():
432419
logs = core_client.find_analysis_logs(filter={"analysis_id": configured_analysis.id})
433-
assert "checking" in [log.event for log in logs]
420+
assert "checking" in [log.labels.get("event", None) for log in logs]
434421

435422
assert_eventually(_check_checking_event_in_logs)
436423

@@ -472,13 +459,31 @@ def test_get_analysis_node_not_found(core_client):
472459
assert core_client.get_analysis_node(next_uuid()) is None
473460

474461

475-
def test_find_analysis_node_logs(core_client, analysis_node_log):
476-
# "node_id" and "analysis_id" have to be specified to filter for analysis node logs.
477-
analysis_node_logs_find = core_client.find_analysis_node_logs(
478-
filter={"node_id": analysis_node_log.labels["node_id"], "analysis_id": analysis_node_log.labels["analysis_id"]}
462+
def test_analysis_node_logs(core_client, analysis_node):
463+
core_client.create_analysis_node_log(
464+
analysis_id=analysis_node.analysis_id, node_id=analysis_node.node_id, level="info", message="test"
479465
)
480466

481-
assert analysis_node_log.time in [log.time for log in analysis_node_logs_find]
467+
def _check_analysis_node_logs_present():
468+
assert (
469+
len(
470+
core_client.find_analysis_node_logs(
471+
filter={"analysis_id": analysis_node.analysis_id, "node_id": analysis_node.node_id}
472+
)
473+
)
474+
== 1
475+
)
476+
477+
assert_eventually(_check_analysis_node_logs_present)
478+
479+
# TODO: Deleting analysis node logs raises am error in the hub.
480+
# core_client.delete_analysis_node_logs(
481+
# analysis_id=analysis_node.analysis_id, node_id=analysis_node.node_id
482+
# )
483+
484+
# assert len(core_client.find_analysis_node_logs(
485+
# filter={"analysis_id": analysis_node.analysis_id, "node_id": analysis_node.node_id}
486+
# )) == 0
482487

483488

484489
def test_get_analysis_bucket(core_client, analysis_buckets, analysis_bucket_includables):
@@ -632,7 +637,7 @@ def test_update_registry_project(core_client, registry_project):
632637
assert new_registry_project.name == new_name
633638

634639

635-
@pytest.mark.xfail(reason="It is not possible to create analysis logs in the current test deployment.")
640+
@pytest.mark.xfail(reason="Bug in Hub, see https://github.com/PrivateAIM/hub/issues/1181.")
636641
def test_delete_analysis_logs(core_client, analysis_log):
637642
core_client.delete_analysis_logs(analysis_id=analysis_log.labels["analysis_id"])
638643

0 commit comments

Comments
 (0)