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

Fixes #37697 - scan CDN fails silently #11100

Merged
merged 1 commit into from
Aug 19, 2024
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
4 changes: 3 additions & 1 deletion app/lib/katello/util/cdn_var_substitutor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def find_substitutions(paths_with_substitutions)

futures.each do |future|
resolved << future.value
Rails.logger.error("Failed at scanning for repository: #{future.reason}") if future.rejected?
if future.rejected?
fail Errors::CdnSubstitutionError, "Failed at scanning for repository: #{future.reason}"
end
end
end

Expand Down
17 changes: 17 additions & 0 deletions test/actions/katello/repository_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ class ScanCdnTest < TestBase
assert_equal action.output[:results].first[:enabled], true
end

it 'raises CdnSubstitutionError when substitute_vars fails' do
planned_action = plan_action action, product, content.id

error_message = "Failed at scanning for repository: Connection refused - connect(2) for \"cdn.redhat.com\" port 443"

Katello::Util::CdnVarSubstitutor.any_instance.stubs(:substitute_vars).raises(Katello::Errors::CdnSubstitutionError, error_message)

assert_raises_with_message Katello::Errors::CdnSubstitutionError, error_message do
run_action planned_action do |run_action|
substitutor = stub(:cdn_var_substitutor)
substitutor.stubs(:substitute_vars).raises(Katello::Errors::CdnSubstitutionError, error_message)
run_action.stubs(content: content)
run_action.stubs(cdn_var_substitutor: substitutor)
end
end
end

def simulate_run
planned_action = plan_action action, product, content.id

Expand Down
12 changes: 12 additions & 0 deletions test/lib/util/cdn_var_subsitutor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ def check_validating_subscriptions(content, substitutions, error_message)
cdn_var.validate_substitutions(content, substitutions)
end
end

def test_substitute_vars_raises_error
cdn_var = CdnVarSubstitutor.new(@resource)

path = '/content/dist/rhel/server/5/$releasever/$basearch/os'

cdn_var.stubs(:resolve_path).raises(StandardError.new("Connection refused - connect(2) for \"cdn.redhat.com\" port 443"))

assert_raises(Errors::CdnSubstitutionError, "Failed at scanning for repository: Connection refused - connect(2) for \"cdn.redhat.com\" port 443") do
cdn_var.substitute_vars(path)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ const loadRepositorySetRepos = (contentId, productId) => async (dispatch) => {
productId,
results: data.results,
});
} catch (response) {
const error = response && response.data && response.data.error;
return dispatch({
type: REPOSITORY_SET_REPOSITORIES_FAILURE,
contentId,
} catch (error) {
return dispatch(apiError(
REPOSITORY_SET_REPOSITORIES_FAILURE,
error,
});
{ contentId },
));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('repositorySetRepositories reducer', () => {
it('should have error on REPOSITORY_SET_REPOSITORIES_FAILURE', () => {
expect(reducer(initialState, {
type: types.REPOSITORY_SET_REPOSITORIES_FAILURE,
contentId,
payload: { contentId },
error: 'Unable to process request.',
})).toEqual(errorState);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default (state = initialState, action) => {
});

case REPOSITORY_SET_REPOSITORIES_FAILURE:
return state.set(action.contentId, {
return state.set(action.payload.contentId, {
loading: false,
repositories: [],
error: action.error,
Expand Down
Loading