Skip to content

Commit

Permalink
add some real hiera methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Sep 7, 2015
1 parent f3bd548 commit 842a11a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/hieracles/hiera.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,17 @@ def datadir
parampath
end

def hierarchy
@loaded[:hierarchy]
end

def hierarchy_short
hierarchy.select { |x| !x[/common/] }
end

def params
hierarchy.join(',').scan(/%\{([^\}]*)\}/).flatten.uniq
end

end
end
54 changes: 52 additions & 2 deletions spec/lib/hiera_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
end
end


describe '.datadir' do
context 'hiera file do not have a yaml backend' do
let(:hierafile) { File.expand_path('../../files/hiera_no_yamlbackend.yaml', __FILE__) }
Expand All @@ -43,7 +42,58 @@
expect(hiera.datadir).to eq parampath
end
end

end

describe '.hierarchy' do
let(:hierafile) { File.expand_path('../../files/hiera.yaml', __FILE__) }
let(:hiera) { Hieracles::Hiera.new hierafile }
let(:expected) { [
'nodes/%{fqdn}',
'farm_datacenter/%{farm}_%{datacenter}',
'farm/%{farm}',
'room/%{room}',
'datacenter/%{datacenter}',
'country/%{country}',
'os/%{operatingsystem}-%{lsbdistcodename}',
'common/common'
]}
it "extracts the hierarchy accoding to the hierfile" do
expect(hiera.hierarchy).to eq expected
end
end

describe '.hierarchy_short' do
let(:hierafile) { File.expand_path('../../files/hiera.yaml', __FILE__) }
let(:hiera) { Hieracles::Hiera.new hierafile }
let(:expected) { [
'nodes/%{fqdn}',
'farm_datacenter/%{farm}_%{datacenter}',
'farm/%{farm}',
'room/%{room}',
'datacenter/%{datacenter}',
'country/%{country}',
'os/%{operatingsystem}-%{lsbdistcodename}'
]}
it "extracts the hierarchy accoding to the hierfile" do
expect(hiera.hierarchy_short).to eq expected
end
end

describe '.params' do
let(:hierafile) { File.expand_path('../../files/hiera.yaml', __FILE__) }
let(:hiera) { Hieracles::Hiera.new hierafile }
let(:expected) { [
'fqdn',
'farm',
'datacenter',
'room',
'country',
'operatingsystem',
'lsbdistcodename'
]}
it 'extracts hiera parameters from the hierarchy' do
expect(hiera.params).to eq expected
end
end

end

0 comments on commit 842a11a

Please sign in to comment.