-
Notifications
You must be signed in to change notification settings - Fork 188
fix: ensure input sandboxes assigned to transformations to avoid premature cleaning #8621
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
Open
ryuwd
wants to merge
8
commits into
DIRACGrid:integration
Choose a base branch
from
ryuwd:roneil-trf-sandbox-assignment
base: integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+430
−3
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
69ea110
feat(transformation): pin input sandboxes to the transformation on cr…
ryuwd 811423a
test(sandbox): cover transformation entity assign/unassign in Sandbox…
ryuwd 93da003
feat(transformation): unassign input sandboxes on clean/archive
ryuwd 4166034
refactor(transformation): accept list- or string-valued InputSandbox …
ryuwd e2d7e98
fix(transformation): fail loudly and leave no bad state on sandbox pi…
ryuwd 41e8dd7
test(transformation): cover sandbox pin/unpin handling; rename test m…
ryuwd c6d3b08
docs(transformation): document input sandboxes and their pinning
ryuwd ea3e979
fix: Don't start services if we can't setup the SandboxMetadataDB
ryuwd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/DIRAC/TransformationSystem/Agent/test/Test_TransformationCleaningAgent.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # pylint: disable=missing-docstring | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from DIRAC.TransformationSystem.Agent.TransformationCleaningAgent import TransformationCleaningAgent | ||
|
|
||
| # The agent's __init__ needs a running config, so these exercise the methods with a | ||
| # stand-in ``self`` (a MagicMock) carrying only the attributes the methods touch. | ||
|
|
||
|
|
||
| def test_unassign_callsDBWithTransformationEntity(): | ||
| agent = MagicMock() | ||
| agent.sandboxDB.unassignEntities.return_value = {"OK": True, "Value": 1} | ||
|
|
||
| res = TransformationCleaningAgent._unassignTransformationSandboxes(agent, 12345) | ||
|
|
||
| assert res["OK"] | ||
| agent.sandboxDB.unassignEntities.assert_called_once_with(["Transformation:12345"]) | ||
| agent.log.error.assert_not_called() | ||
| agent.log.exception.assert_not_called() | ||
|
|
||
|
|
||
| def test_unassign_noDBisOk(): | ||
| agent = MagicMock() | ||
| agent.sandboxDB = None | ||
| # Nothing to unassign: succeed so cleaning is not blocked in DB-less deployments. | ||
| assert TransformationCleaningAgent._unassignTransformationSandboxes(agent, 12345)["OK"] | ||
|
|
||
|
|
||
| def test_unassign_dbErrorIsLoggedAndReturnsError(): | ||
| agent = MagicMock() | ||
| agent.sandboxDB.unassignEntities.return_value = {"OK": False, "Message": "boom"} | ||
|
|
||
| # A failed unassignment must be loud AND returned as an error so the caller fails | ||
| # the cleaning and retries (otherwise the sandboxes leak). | ||
| res = TransformationCleaningAgent._unassignTransformationSandboxes(agent, 12345) | ||
|
|
||
| assert not res["OK"] | ||
| agent.sandboxDB.unassignEntities.assert_called_once_with(["Transformation:12345"]) | ||
| agent.log.error.assert_called_once() | ||
|
|
||
|
|
||
| def test_unassign_unexpectedExceptionIsLoggedAndReturnsError(): | ||
| agent = MagicMock() | ||
| agent.sandboxDB.unassignEntities.side_effect = RuntimeError("db down") | ||
|
|
||
| # An unexpected exception must not propagate, but must be logged loudly and returned | ||
| # as an error so the cleaning is retried. | ||
| res = TransformationCleaningAgent._unassignTransformationSandboxes(agent, 12345) | ||
|
|
||
| assert not res["OK"] | ||
| agent.log.exception.assert_called_once() | ||
|
|
||
|
|
||
| def test_cleanTransformation_failsWhenUnassignFails(): | ||
| # The whole clean must fail (and be retried) if the sandbox can't be unassigned, | ||
| # rather than proceeding and leaking the now-orphaned sandbox assignment. | ||
| agent = MagicMock() | ||
| agent._unassignTransformationSandboxes.return_value = {"OK": False, "Message": "boom"} | ||
|
|
||
| res = TransformationCleaningAgent.cleanTransformation(agent, 12345) | ||
|
|
||
| assert not res["OK"] | ||
| agent.getTransformationDirectories.assert_not_called() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.