Skip to content

Commit

Permalink
Trap for Errno::ENOENT
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
mjgiarlo committed Dec 13, 2019
1 parent 178f50c commit eee0465
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/services/moab_validation_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/audit/catalog_to_moab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit eee0465

Please sign in to comment.