From 0f7c58fd9a1f9dd6ee34ea2c3ffd76f99c86fddc Mon Sep 17 00:00:00 2001 From: William Bradford Clark Date: Thu, 1 Aug 2024 10:38:02 -0400 Subject: [PATCH] Fixes #37697 - ScanCdn task raises error when substitute_vars fails --- app/lib/katello/util/cdn_var_substitutor.rb | 4 +++- test/actions/katello/repository_set_test.rb | 17 +++++++++++++++++ test/lib/util/cdn_var_subsitutor_test.rb | 12 ++++++++++++ .../repositorySetRepositories.js | 11 +++++------ .../__tests__/repositorySetRepositories.test.js | 2 +- .../repositorySetRepositories.js | 2 +- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/app/lib/katello/util/cdn_var_substitutor.rb b/app/lib/katello/util/cdn_var_substitutor.rb index 617c3fb8018..ba46a564762 100644 --- a/app/lib/katello/util/cdn_var_substitutor.rb +++ b/app/lib/katello/util/cdn_var_substitutor.rb @@ -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 diff --git a/test/actions/katello/repository_set_test.rb b/test/actions/katello/repository_set_test.rb index cb7bc6b3400..707caf6f92e 100644 --- a/test/actions/katello/repository_set_test.rb +++ b/test/actions/katello/repository_set_test.rb @@ -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 diff --git a/test/lib/util/cdn_var_subsitutor_test.rb b/test/lib/util/cdn_var_subsitutor_test.rb index 5b5d2126836..e92c8d50afc 100644 --- a/test/lib/util/cdn_var_subsitutor_test.rb +++ b/test/lib/util/cdn_var_subsitutor_test.rb @@ -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 diff --git a/webpack/redux/actions/RedHatRepositories/repositorySetRepositories.js b/webpack/redux/actions/RedHatRepositories/repositorySetRepositories.js index de11fda4ddc..bb1e8de6405 100644 --- a/webpack/redux/actions/RedHatRepositories/repositorySetRepositories.js +++ b/webpack/redux/actions/RedHatRepositories/repositorySetRepositories.js @@ -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 }, + )); } }; diff --git a/webpack/redux/reducers/RedHatRepositories/__tests__/repositorySetRepositories.test.js b/webpack/redux/reducers/RedHatRepositories/__tests__/repositorySetRepositories.test.js index 8157227bd28..55bc864e9c5 100644 --- a/webpack/redux/reducers/RedHatRepositories/__tests__/repositorySetRepositories.test.js +++ b/webpack/redux/reducers/RedHatRepositories/__tests__/repositorySetRepositories.test.js @@ -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); }); diff --git a/webpack/redux/reducers/RedHatRepositories/repositorySetRepositories.js b/webpack/redux/reducers/RedHatRepositories/repositorySetRepositories.js index 7c8068c588b..0630da21172 100644 --- a/webpack/redux/reducers/RedHatRepositories/repositorySetRepositories.js +++ b/webpack/redux/reducers/RedHatRepositories/repositorySetRepositories.js @@ -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,