-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update console_link logic on clearing snapshots with missing repo (#1219
) * Update console_link logic on clearing snapshots with missing repo Signed-off-by: Andre Kurait <[email protected]> * Run 6.8 and 7.10 e2e tests on PR Signed-off-by: Andre Kurait <[email protected]> * Revert "Run 6.8 and 7.10 e2e tests on PR" This reverts commit d49877d. Signed-off-by: Andre Kurait <[email protected]> --------- Signed-off-by: Andre Kurait <[email protected]>
- Loading branch information
1 parent
042b6dc
commit c79186d
Showing
2 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
68 changes: 68 additions & 0 deletions
68
...ution/src/main/docker/migrationConsole/lib/console_link/tests/test_clusters_middleware.py
This file contains 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,68 @@ | ||
import pytest | ||
from unittest.mock import MagicMock | ||
from console_link.middleware.clusters import clear_snapshots | ||
from console_link.models.cluster import Cluster | ||
import requests | ||
import logging | ||
|
||
|
||
# Helper to mock HTTPError with response | ||
def create_http_error_mock(status_code, json_data): | ||
response_mock = MagicMock() | ||
response_mock.status_code = status_code | ||
response_mock.json.return_value = json_data | ||
return requests.exceptions.HTTPError(response=response_mock) | ||
|
||
|
||
@pytest.fixture | ||
def mock_cluster_with_missing_repo(mocker): | ||
cluster = MagicMock(spec=Cluster) | ||
# Simulate repository missing exception | ||
error_mock = create_http_error_mock( | ||
status_code=404, | ||
json_data={ | ||
'error': { | ||
'type': 'repository_missing_exception', | ||
'reason': '[migration_assistant_repo] missing' | ||
} | ||
} | ||
) | ||
mocker.patch.object(cluster, 'call_api', side_effect=error_mock) | ||
return cluster | ||
|
||
|
||
@pytest.fixture | ||
def mock_cluster_with_snapshots(mocker): | ||
cluster = MagicMock(spec=Cluster) | ||
# Mock the response for listing snapshots | ||
mock_response = MagicMock() | ||
mock_response.json.return_value = { | ||
'snapshots': [ | ||
{'snapshot': 'snapshot_1'}, | ||
{'snapshot': 'snapshot_2'} | ||
] | ||
} | ||
mock_response.status_code = 200 | ||
|
||
def mock_call_api(path, *args, **kwargs): | ||
if "_all" in path: | ||
return mock_response | ||
elif "snapshot_1" in path or "snapshot_2" in path: | ||
return MagicMock() # Simulate successful deletion | ||
raise ValueError(f"Unexpected path: {path}") | ||
|
||
mocker.patch.object(cluster, 'call_api', side_effect=mock_call_api) | ||
return cluster | ||
|
||
|
||
def test_clear_snapshots_repository_missing(mock_cluster_with_missing_repo, caplog): | ||
with caplog.at_level(logging.INFO, logger='console_link.middleware.clusters'): | ||
clear_snapshots(mock_cluster_with_missing_repo, 'migration_assistant_repo') | ||
assert "Repository 'migration_assistant_repo' is missing. Skipping snapshot clearing." in caplog.text | ||
|
||
|
||
def test_clear_snapshots_success(mock_cluster_with_snapshots, caplog): | ||
with caplog.at_level(logging.INFO, logger='console_link.middleware.clusters'): | ||
clear_snapshots(mock_cluster_with_snapshots, 'migration_assistant_repo') | ||
assert "Deleted snapshot: snapshot_1 from repository 'migration_assistant_repo'." in caplog.text | ||
assert "Deleted snapshot: snapshot_2 from repository 'migration_assistant_repo'." in caplog.text |