-
Notifications
You must be signed in to change notification settings - Fork 31
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
Update console_link logic on clearing snapshots with missing repo #1219
Merged
AndreKurait
merged 3 commits into
opensearch-project:main
from
AndreKurait:FixRFSE2EJenkins
Jan 3, 2025
+80
−6
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -15,8 +15,11 @@ permissions: | |
contents: read # to fetch code (actions/checkout) | ||
|
||
jobs: | ||
full-es68-e2e-aws-test: | ||
e2e-tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
job-name: [full-es68source-e2e-test, rfs-default-e2e-test] | ||
steps: | ||
- name: Sanitize branch and repo names | ||
env: | ||
|
@@ -34,6 +37,6 @@ jobs: | |
uses: lewijacn/[email protected] | ||
with: | ||
jenkins_url: "https://migrations.ci.opensearch.org" | ||
job_name: "full-es68source-e2e-test" | ||
job_name: "${{ matrix.job-name }}" | ||
api_token: "${{ secrets.JENKINS_MIGRATIONS_GENERIC_WEBHOOK_TOKEN }}" | ||
job_params: "GIT_REPO_URL=${{ steps.sanitize-input.outputs.pr_repo_url }},GIT_BRANCH=${{ steps.sanitize-input.outputs.branch_name }}" |
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 |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few concerns here and would like to wait on enabling another Jenkins job on PRs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed for now, we can revisit later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure happy to chat more around this sometime