Skip to content

Commit

Permalink
CV Rake Task to run a list of druids in a csv
Browse files Browse the repository at this point in the history
Rake task to Rakefile: cv_druid_list which takes a file_path
parameter.

Checksum.validate_list_of_druids method which iterates over each
druid in the csv and invokes the already written method:
Checksum.validate_druid

RSpec test where Checksum.validate_druid is called once per druid

Update README with usage information and assumptions
  • Loading branch information
SaravShah committed Jun 6, 2018
1 parent 24c6a07 commit a5a4138
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,19 @@ RAILS_ENV=production bundle exec rake cv_all_endpoints[profile]
```
this will generate a log at, for example, `log/profile_cv_validate_disk_all_endpoints2018-01-01T14:25:31-flat.txt`

### One druid at a time
#### Single Druid
- Without profiling:
```sh
RAILS_ENV=production bundle exec rake cv_druid[bz514sm9647]
```

#### Druid List
- Give the file path of the csv as the parameter. The first column of the csv should contain druids, without the prefix, and contain no headers.
- Without profiling:
```sh
RAILS_ENV=production bundle exec rake cv_druid_list[/file/path/to/your/csv/druid_list.csv]

```
## Development

### Running Tests
Expand Down
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,11 @@ task :cv_druid, [:druid] => [:environment] do |_t, args|
# exit with non-zero status if any of the pres copies failed checksum validation
exit 1 if cv_results_lists.detect { |aud_res| !aud_res.contains_result_code?(AuditResults::MOAB_CHECKSUM_VALID) }
end

desc "Fire off checksum validation on a list of druids"
task :cv_druid_list, [:file_path] => [:environment] do |_t, args|
druid_list_file_path = args[:file_path]
puts "#{Time.now.utc.iso8601} Checksum Validation on the list of druids from #{druid_list_file_path} has started"
Checksum.validate_list_of_druids(druid_list_file_path)
puts "#{Time.now.utc.iso8601} Checksum Validation on the list of druids from #{druid_list_file_path} has finished."
end
8 changes: 8 additions & 0 deletions lib/audit/checksum.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'profiler.rb'
require 'csv'

# Checksum validator code
class Checksum
Expand Down Expand Up @@ -57,4 +58,11 @@ def self.validate_druid(druid)
ensure
logger.info "#{Time.now.utc.iso8601} CV validate_druid ended for #{druid}"
end

# assumes that the list of druids is in column 1, and has no header.
def self.validate_list_of_druids(druid_list_file_path)
CSV.foreach(druid_list_file_path) do |druid|
Checksum.validate_druid(druid.join)
end
end
end
13 changes: 13 additions & 0 deletions spec/lib/audit/checksum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,17 @@
expect(checksum_results.contains_result_code?(AuditResults::MOAB_CHECKSUM_VALID)).to eq true
end
end

describe ".validate_list_of_druids" do
include_context 'fixture moabs in db'

it 'calls Checksum.validate_druid once per druid' do
csv_file_path = 'spec/fixtures/druid_list.csv'
CSV.foreach(csv_file_path) do |row|
expect(described_class).to receive(:validate_druid).with(row.first)
end
described_class.validate_list_of_druids(csv_file_path)
end
end

end

0 comments on commit a5a4138

Please sign in to comment.