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

♻️Fixed Unit test director v2 #6733

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
29 changes: 11 additions & 18 deletions packages/models-library/src/models_library/clusters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from enum import auto
from pathlib import Path
from typing import Final, Literal, TypeAlias
from typing import Final, Literal, Self, TypeAlias

from models_library.utils._original_fastapi_encoders import jsonable_encoder
from pydantic import (
AnyUrl,
BaseModel,
Expand Down Expand Up @@ -222,29 +221,23 @@ class Cluster(BaseCluster):
},
)

@model_validator(mode="before")
@classmethod
def check_owner_has_access_rights(cls, values):
values = jsonable_encoder(values)

is_default_cluster = bool(values["id"] == DEFAULT_CLUSTER_ID)
owner_gid = values["owner"]
@model_validator(mode="after")
def check_owner_has_access_rights(self: Self) -> Self:
is_default_cluster = bool(self.id == DEFAULT_CLUSTER_ID)
owner_gid = self.owner

# check owner is in the access rights, if not add it
access_rights = values.get("access_rights", values.get("accessRights", {}))
access_rights = self.access_rights.copy()
if owner_gid not in access_rights:
access_rights[owner_gid] = (
CLUSTER_USER_RIGHTS.model_dump()
if is_default_cluster
else CLUSTER_ADMIN_RIGHTS.model_dump()
CLUSTER_USER_RIGHTS if is_default_cluster else CLUSTER_ADMIN_RIGHTS
)
# check owner has the expected access
if access_rights[owner_gid] != (
CLUSTER_USER_RIGHTS.model_dump()
if is_default_cluster
else CLUSTER_ADMIN_RIGHTS.model_dump()
CLUSTER_USER_RIGHTS if is_default_cluster else CLUSTER_ADMIN_RIGHTS
):
msg = f"the cluster owner access rights are incorrectly set: {access_rights[owner_gid]}"
raise ValueError(msg)
values["access_rights"] = access_rights
return values
# NOTE: overcomes frozen configuration (far fetched in ClusterGet model of webserver)
object.__setattr__(self, "access_rights", access_rights)
sanderegg marked this conversation as resolved.
Show resolved Hide resolved
return self
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ def convert_null_to_empty_metadata(cls, v):
"cluster_id": 0,
"iteration": 42,
"result": "UNKNOWN",
"created": "2021-03-01 13:07:34.19161",
"modified": "2021-03-01 13:07:34.19161",
"started": None,
"ended": None,
"created": "2021-03-01T13:07:34.191610",
"modified": "2021-03-01T13:07:34.191610",
"cancelled": None,
"use_on_demand_clusters": False,
},
Expand All @@ -107,8 +109,10 @@ def convert_null_to_empty_metadata(cls, v):
"cluster_id": None, # this default to DEFAULT_CLUSTER_ID
"iteration": 42,
"result": "NOT_STARTED",
"created": "2021-03-01 13:07:34.19161",
"modified": "2021-03-01 13:07:34.19161",
"started": None,
"ended": None,
"created": "2021-03-01T13:07:34.191610",
"modified": "2021-03-01T13:07:34.191610",
"cancelled": None,
"use_on_demand_clusters": False,
},
Expand All @@ -119,10 +123,10 @@ def convert_null_to_empty_metadata(cls, v):
"cluster_id": 123,
"iteration": 12,
"result": "SUCCESS",
"created": "2021-03-01 13:07:34.19161",
"modified": "2021-03-01 13:07:34.19161",
"started": "2021-03-01 08:07:34.19161",
"ended": "2021-03-01 13:07:34.10",
"created": "2021-03-01T13:07:34.191610",
"modified": "2021-03-01T13:07:34.191610",
"started": "2021-03-01T08:07:34.191610",
"ended": "2021-03-01T13:07:34.10",
"cancelled": None,
"metadata": {
"node_id_names_map": {},
Expand All @@ -140,10 +144,10 @@ def convert_null_to_empty_metadata(cls, v):
"cluster_id": 123,
"iteration": 12,
"result": "SUCCESS",
"created": "2021-03-01 13:07:34.19161",
"modified": "2021-03-01 13:07:34.19161",
"started": "2021-03-01 8:07:34.19161",
"ended": "2021-03-01 13:07:34.10",
"created": "2021-03-01T13:07:34.191610",
sanderegg marked this conversation as resolved.
Show resolved Hide resolved
"modified": "2021-03-01T13:07:34.191610",
"started": "2021-03-01T08:07:34.191610",
"ended": "2021-03-01T13:07:34.10",
"cancelled": None,
"metadata": None,
"use_on_demand_clusters": False,
Expand Down
Loading