Skip to content
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
2 changes: 1 addition & 1 deletion iris/api/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def unfold_agent(
for uuid, active_agent in active_agents.items():
if parameters := active_agent.parameters:
if tagged_agent.tag in parameters.tags:
agents.append(tagged_agent.copy(update={"tag": None, "uuid": uuid}))
agents.append(tagged_agent.model_copy(update={"tag": None, "uuid": uuid}))
return agents


Expand Down
12 changes: 6 additions & 6 deletions iris/commons/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def set_agent_parameters(
self, uuid: str, parameters: AgentParameters
) -> None:
self.logger.info("Setting agent parameters")
await self.set(agent_parameters_key(uuid), parameters.json())
await self.set(agent_parameters_key(uuid), parameters.model_dump_json())

async def delete_agent_parameters(self, uuid: str) -> None:
self.logger.info("Deleting agent parameters")
Expand Down Expand Up @@ -162,15 +162,15 @@ async def get_measurement_stats(
self, measurement_uuid: str, agent_uuid: str
) -> ProbingStatistics | None:
if state := await self.get(measurement_stats_key(measurement_uuid, agent_uuid)):
return ProbingStatistics.parse_raw(state)
return ProbingStatistics.model_validate_json(state)
return None

async def set_measurement_stats(
self, measurement_uuid: str, agent_uuid: str, stats: ProbingStatistics
) -> None:
self.logger.info("Setting measurement statistics")
await self.set(
measurement_stats_key(measurement_uuid, agent_uuid), stats.json()
measurement_stats_key(measurement_uuid, agent_uuid), stats.model_dump_json()
)

async def delete_measurement_stats(
Expand All @@ -190,7 +190,7 @@ async def get_random_request(
while True:
if keys := await self.hkeys(agent_queue_key(uuid)):
value = await self.hget(agent_queue_key(uuid), random.choice(keys))
return MeasurementRoundRequest.parse_raw(value)
return MeasurementRoundRequest.model_validate_json(value)
await asyncio.sleep(interval)

async def get_requests(self, uuid: str
Expand All @@ -207,12 +207,12 @@ async def get_request(
) -> MeasurementRoundRequest | None:
"""Return the measurement request for the specified agent and measurement."""
if value := await self.hget(agent_queue_key(agent_uuid), measurement_uuid):
return MeasurementRoundRequest.parse_raw(value)
return MeasurementRoundRequest.model_validate_json(value)
return None

async def set_request(self, uuid: str, request: MeasurementRoundRequest) -> None:
"""Set the measurement request for a specified agent and measurement."""
await self.hset(agent_queue_key(uuid), request.measurement_uuid, request.json())
await self.hset(agent_queue_key(uuid), request.measurement_uuid, request.model_dump_json())

async def delete_request(self, measurement_uuid: str, agent_uuid: str) -> None:
"""Delete the measurement request for a specified agent and measurement."""
Expand Down
963 changes: 481 additions & 482 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bcrypt = "4.3.0"
diamond-miner = "^1.1.3"
dramatiq = {extras = ["redis", "watch"], version = "^1.13.0"}
email-validator = "^2.0.0"
fastapi = "^0.120.1"
fastapi = "^0.137.2"
fastapi-users = {extras = ["sqlalchemy"], version = "^15.0.4"}
fastapi-users-db-sqlalchemy = "^7.0.0"
gunicorn = "^23.0.0"
Expand All @@ -40,7 +40,7 @@ pych-client = {extras = ["orjson"], version = "^0.4.1"}
pydantic = "^2.0.0"
pydantic-settings = "^2.0.0"
python-jose = {extras = ["cryptography"], version = "^3.3.0"}
python-multipart = "^0.0.27"
python-multipart = "^0.0.30"
pytricia = "^1.0.2"
SQLAlchemy = "^2.0.44"
SQLAlchemy-Utils = ">=0.41.2"
Expand Down
14 changes: 7 additions & 7 deletions tests/api/test_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ async def test_post_measurement_unknown_uuid(make_client, make_user):
tags=[],
agents=[MeasurementAgentCreate(uuid=str(uuid4()), target_file="targets.csv")],
)
response = client.post("/measurements/", content=body.json())
response = client.post("/measurements/", json=body.model_dump(mode="json"))
assert_status_code(response, 404)
assert "No agent associated with UUID" in response.text

Expand All @@ -324,7 +324,7 @@ async def test_post_measurement_unknown_tag(make_client, make_user):
tags=[],
agents=[MeasurementAgentCreate(tag="unknown", target_file="targets.csv")],
)
response = client.post("/measurements/", content=body.json())
response = client.post("/measurements/", json=body.model_dump(mode="json"))
assert_status_code(response, 404)
assert "No agents associated with tag" in response.text

Expand All @@ -336,7 +336,7 @@ async def test_post_measurement_public_tag_disallowed(make_client, make_user):
tags=["visibility:public"],
agents=[MeasurementAgentCreate(uuid=str(uuid4()), target_file="targets.csv")],
)
response = client.post("/measurements/", content=body.json())
response = client.post("/measurements/", json=body.model_dump(mode="json"))
assert_status_code(response, 403)
assert "You cannot use public tag" in response.text

Expand All @@ -348,7 +348,7 @@ async def test_post_measurement_reserved_tag_disallowed(make_client, make_user):
tags=["collection:test"],
agents=[MeasurementAgentCreate(uuid=str(uuid4()), target_file="targets.csv")],
)
response = client.post("/measurements/", content=body.json())
response = client.post("/measurements/", json=body.model_dump(mode="json"))
assert_status_code(response, 403)
assert "You cannot use reserved tags" in response.text

Expand All @@ -369,7 +369,7 @@ async def test_post_measurement_uuid(
tool=Tool.DiamondMiner,
agents=[MeasurementAgentCreate(uuid=agent_uuid, target_file="targets.csv")],
)
response = client.post("/measurements/", content=body.json())
response = client.post("/measurements/", json=body.model_dump(mode="json"))
assert_status_code(response, 201)
result = cast_response(response, MeasurementReadWithAgents)
assert result.state == MeasurementAgentState.Created
Expand All @@ -396,7 +396,7 @@ async def test_post_measurement_tag(
tool=Tool.DiamondMiner,
agents=[MeasurementAgentCreate(tag="tag1", target_file="targets.csv")],
)
response = client.post("/measurements/", content=body.json())
response = client.post("/measurements/", json=body.model_dump(mode="json"))
assert_status_code(response, 201)
result = cast_response(response, MeasurementReadWithAgents)
assert result.state == MeasurementAgentState.Created
Expand All @@ -423,6 +423,6 @@ async def test_post_measurement_duplicate(
MeasurementAgentCreate(uuid=agent_uuid, target_file="targets.csv"),
],
)
response = client.post("/measurements/", content=body.json())
response = client.post("/measurements/", json=body.model_dump(mode="json"))
assert_status_code(response, 400)
assert "Multiple assignment of key" in response.text
2 changes: 1 addition & 1 deletion tests/api/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def test_get_status(
tool=Tool.DiamondMiner,
agents=[MeasurementAgentCreate(uuid=agent_uuid, target_file="targets.csv")],
)
client.post("/measurements/", content=body.json())
client.post("/measurements/", json=body.model_dump(mode="json"))

# Check status
status = cast_response(client.get("/status"), Status)
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def settings():
def api_settings(settings):
return APISettings(
API_CORS_ALLOW_ORIGIN="https://example.org,http://localhost:8000",
**settings.dict(),
**settings.model_dump(),
)


@pytest.fixture
def agent_settings(settings, tmp_path):
return AgentSettings(
**settings.dict(),
**settings.model_dump(),
AGENT_MIN_TTL=0,
AGENT_RESULTS_DIR_PATH=tmp_path / "agent_results",
AGENT_TARGETS_DIR_PATH=tmp_path / "agent_targets",
Expand All @@ -78,7 +78,7 @@ def agent_settings(settings, tmp_path):
@pytest.fixture
def worker_settings(settings, tmp_path):
return WorkerSettings(
**settings.dict(),
**settings.model_dump(),
WORKER_RESULTS_DIR_PATH=tmp_path / "worker_results",
WORKER_MAX_OPEN_FILES=128,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_e2e(
await create_user_buckets(storage, user)
await upload_target_file(storage, user, "targets.csv", ["1.0.0.0/24,icmp,8,32,6"])

response = client.post("/measurements/", content=body.json())
response = client.post("/measurements/", json=body.model_dump(mode="json"))
measurement = cast_response(response, MeasurementReadWithAgents)

# Emulate dramatiq and launch the watchers
Expand Down
Loading