Skip to content

Commit 326a11c

Browse files
šŸ› EFS Guardian - not need of owner information if project lock in MAINTAINING state 🚨 (#6581)
1 parent aaabc92 commit 326a11c

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

ā€Žpackages/models-library/src/models_library/projects_state.pyā€Ž

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from enum import Enum, unique
66
from typing import Any, ClassVar
77

8-
from pydantic import BaseModel, Extra, Field, validator
8+
from pydantic import BaseModel, Extra, Field, root_validator, validator
99

1010
from .projects_access import Owner
1111

@@ -57,10 +57,10 @@ class ProjectStatus(str, Enum):
5757

5858
class ProjectLocked(BaseModel):
5959
value: bool = Field(..., description="True if the project is locked")
60+
status: ProjectStatus = Field(..., description="The status of the project")
6061
owner: Owner | None = Field(
6162
default=None, description="If locked, the user that owns the lock"
6263
)
63-
status: ProjectStatus = Field(..., description="The status of the project")
6464

6565
class Config:
6666
extra = Extra.forbid
@@ -80,14 +80,6 @@ class Config:
8080
]
8181
}
8282

83-
@validator("owner", pre=True, always=True)
84-
@classmethod
85-
def check_not_null(cls, v, values):
86-
if values["value"] is True and v is None:
87-
msg = "value cannot be None when project is locked"
88-
raise ValueError(msg)
89-
return v
90-
9183
@validator("status", always=True)
9284
@classmethod
9385
def check_status_compatible(cls, v, values):
@@ -99,6 +91,23 @@ def check_status_compatible(cls, v, values):
9991
raise ValueError(msg)
10092
return v
10193

94+
@root_validator(pre=True)
95+
@classmethod
96+
def check_owner_compatible(cls, values):
97+
if (
98+
values["value"] is True
99+
and values.get("owner") is None
100+
and values["status"]
101+
in [
102+
status.value
103+
for status in ProjectStatus
104+
if status != ProjectStatus.MAINTAINING
105+
]
106+
):
107+
msg = "Owner must be specified when the project is not in the 'MAINTAINING' status."
108+
raise ValueError(msg)
109+
return values
110+
102111

103112
class ProjectRunningState(BaseModel):
104113
value: RunningState = Field(

ā€Žpackages/models-library/tests/test_projects_state.pyā€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ def test_project_locked_with_missing_owner_raises():
88
ProjectLocked.parse_obj({"value": False, "status": ProjectStatus.OPENED})
99

1010

11+
def test_project_locked_with_missing_owner_ok_during_maintaining():
12+
ProjectLocked.parse_obj({"value": True, "status": ProjectStatus.MAINTAINING})
13+
14+
1115
@pytest.mark.parametrize(
1216
"lock, status",
1317
[

ā€Žservices/efs-guardian/src/simcore_service_efs_guardian/services/background_tasks.pyā€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ async def removal_policy_task(app: FastAPI) -> None:
3434
efs_project_ids: list[
3535
ProjectID
3636
] = await efs_manager.list_projects_across_whole_efs()
37+
_logger.info(
38+
"Number of projects that are currently in the EFS file system: %s",
39+
len(efs_project_ids),
40+
)
3741

3842
projects_repo = ProjectsRepo(app.state.engine)
3943
for project_id in efs_project_ids:

ā€Žservices/efs-guardian/src/simcore_service_efs_guardian/services/background_tasks_setup.pyā€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
_logger = logging.getLogger(__name__)
1616

17-
_SEC = 1000 # in ms
18-
_MIN = 60 * _SEC # in ms
19-
_HOUR = 60 * _MIN # in ms
17+
_SEC = 1 # in s
18+
_MIN = 60 * _SEC # in s
19+
_HOUR = 60 * _MIN # in s
2020

2121

2222
class EfsGuardianBackgroundTask(TypedDict):

ā€Žservices/efs-guardian/src/simcore_service_efs_guardian/services/process_messages_setup.pyā€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def _subscribe_to_rabbitmq(app) -> str:
3939
def _on_app_startup(app: FastAPI) -> Callable[[], Awaitable[None]]:
4040
async def _startup() -> None:
4141
with log_context(
42-
_logger, logging.INFO, msg="setup resource tracker"
42+
_logger, logging.INFO, msg="setup efs guardian process messages"
4343
), log_catch(_logger, reraise=False):
4444
app_settings: ApplicationSettings = app.state.settings
4545
app.state.efs_guardian_rabbitmq_consumer = None

0 commit comments

Comments
Ā (0)