Skip to content

Commit

Permalink
Add class to let us centralize shared_configs
Browse files Browse the repository at this point in the history
  • Loading branch information
tallenaz committed Mar 23, 2018
1 parent 9d2aaf5 commit 81242e2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/models/host_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Lets us consolidate shared_configs for almost identical machines
class HostSettings
# @return [Config::Options] key/value pairs of name: file_path
def self.storage_roots
@storage_roots ||= Settings.storage_root_map[parsed_hostname]
end

# @return [String] modified hostname
def self.parsed_hostname
Socket.gethostname.tr('-', '_')
end
end
8 changes: 8 additions & 0 deletions config/settings/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ moab:
fixture_sr1: 'spec/fixtures/storage_root01'
fixture_sr2: 'spec/fixtures/storage_root02'
fixture_sr3: 'spec/fixtures/checksum_root01'
storage_root_map:
preservation_catalog_prod:
fixture_sr1: 'spec/fixtures/storage_root01'
fixture_sr2: 'spec/fixtures/storage_root02'
fixture_sr3: 'spec/fixtures/checksum_root01'
preservation_catalog_prod_a:
fixture_sr1: 'spec/fixtures/storage_root01'
fixture_sr2: 'spec/fixtures/storage_root02'
workflow_services_url: 'https://sul-lyberservices-test.stanford.edu/workflow/'
11 changes: 11 additions & 0 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ moab:
fixture_sr2: 'spec/fixtures/storage_root02'
fixture_sr3: 'spec/fixtures/checksum_root01'
fixture_empty: 'spec/fixtures/empty'
storage_root_map:
default:
fixture_sr1: 'spec/fixtures/storage_root01'
fixture_sr2: 'spec/fixtures/storage_root02'
preservation_catalog_prod:
fixture_sr1: 'spec/fixtures/storage_root01'
fixture_sr2: 'spec/fixtures/storage_root02'
fixture_sr3: 'spec/fixtures/checksum_root01'
preservation_catalog_prod_a:
fixture_sr1: 'spec/fixtures/storage_root01'
fixture_sr2: 'spec/fixtures/storage_root02'
18 changes: 18 additions & 0 deletions spec/models/host_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rails_helper'

RSpec.describe HostSettings do
describe '.storage_roots' do
it 'gets the correct values' do
expect(described_class).to receive(:parsed_hostname).and_return('default')
expect(described_class.storage_roots.to_h).to eq(fixture_sr1: 'spec/fixtures/storage_root01',
fixture_sr2: 'spec/fixtures/storage_root02')
end
end

describe '.parsed_hostname' do
it 'makes hyphens into underscores' do
expect(Socket).to receive(:gethostname).and_return('preservation-catalog-prod-a')
expect(described_class.parsed_hostname).to eq('preservation_catalog_prod_a')
end
end
end

0 comments on commit 81242e2

Please sign in to comment.