From eee04650b2a51bab470f5f662a7d457d5477b35f Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Thu, 12 Dec 2019 15:58:59 -0800 Subject: [PATCH] Trap for `Errno::ENOENT` Fixes #1184 This branch includes the following pieces: * Trap for `Errno::ENOENT` on first call to `moab_validation_errors` * When the trap triggers, add a `MOAB_NOT_FOUND` result and update the status to `online_moab_not_found` Also include: * Prefer appending arrays of values to iterating and shoveling in `MoabValidationHandler` --- app/services/moab_validation_handler.rb | 12 ++++++++++-- spec/lib/audit/catalog_to_moab_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/services/moab_validation_handler.rb b/app/services/moab_validation_handler.rb index 19bee4505..f2bcef808 100644 --- a/app/services/moab_validation_handler.rb +++ b/app/services/moab_validation_handler.rb @@ -36,7 +36,7 @@ def moab_validation_errors if moab_errors.any? moab_error_msgs = [] moab_errors.each do |error_hash| - error_hash.each_value { |msg| moab_error_msgs << msg } + moab_error_msgs += error_hash.values end results.add_result(AuditResults::INVALID_MOAB, moab_error_msgs) end @@ -68,7 +68,15 @@ def update_status(new_status) # @param [Boolean] found_expected_version # @return [void] def set_status_as_seen_on_disk(found_expected_version) - return update_status('invalid_moab') if moab_validation_errors.any? + begin + return update_status('invalid_moab') if moab_validation_errors.any? + rescue Errno::ENOENT + results.add_result(AuditResults::MOAB_NOT_FOUND, + db_created_at: complete_moab.created_at.iso8601, + db_updated_at: complete_moab.updated_at.iso8601) + return update_status('online_moab_not_found') + end + return update_status('unexpected_version_on_storage') unless found_expected_version # NOTE: subclasses which override this method should NOT perform checksum validation inside of this method! diff --git a/spec/lib/audit/catalog_to_moab_spec.rb b/spec/lib/audit/catalog_to_moab_spec.rb index d1aa755f0..fde2c2dec 100644 --- a/spec/lib/audit/catalog_to_moab_spec.rb +++ b/spec/lib/audit/catalog_to_moab_spec.rb @@ -329,6 +329,27 @@ expect(new_status).to eq 'unexpected_version_on_storage' end + context 'moab not found' do + before do + allow(mock_sov).to receive(:validation_errors).and_raise(Errno::ENOENT) + allow(Stanford::StorageObjectValidator).to receive(:new).and_return(mock_sov) + end + + it 'sets status to online_moab_not_found' do + orig = comp_moab.status + c2m.check_catalog_version + new_status = comp_moab.reload.status + expect(new_status).not_to eq orig + expect(new_status).to eq 'online_moab_not_found' + end + + it 'adds a MOAB_NOT_FOUND result' do + c2m.instance_variable_set(:@results, results_double) + expect(c2m.results).to receive(:add_result).with(AuditResults::MOAB_NOT_FOUND, anything) + c2m.check_catalog_version + end + end + context 'invalid moab' do before do allow(mock_sov).to receive(:validation_errors).and_return([foo: 'error message'])