Skip to content

Commit

Permalink
Fixes #37697 - ScanCdn task raises error when substitute_vars fails
Browse files Browse the repository at this point in the history
  • Loading branch information
wbclark committed Aug 19, 2024
1 parent e50aca7 commit 0f7c58f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
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

0 comments on commit 0f7c58f

Please sign in to comment.