-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4896c7a
commit c494807
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
# nomad_node_id.rb | ||
# | ||
Facter.add(:nomad_node_id) do | ||
confine do | ||
File.readable?('/var/lib/nomad/server/node-id') | ||
end | ||
setcode do | ||
File.read('/var/lib/nomad/server/node-id').chomp | ||
rescue StandardError | ||
nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper_acceptance' | ||
|
||
describe 'nomad class' do | ||
context 'facts' do | ||
pp = <<-EOS | ||
class { 'nomad': | ||
config_hash => { | ||
region => 'us-west', | ||
datacenter => 'ptk', | ||
log_level => 'INFO', | ||
bind_addr => "0.0.0.0", | ||
data_dir => "/var/lib/nomad", | ||
server => { | ||
enabled => true, | ||
bootstrap_expect => 1 | ||
} | ||
} | ||
} | ||
EOS | ||
|
||
fact_notices = <<-EOS | ||
notify{"nomad_node_id: ${facts['nomad_node_id']}":} | ||
notify{"nomad_version: ${facts['nomad_version']}":} | ||
EOS | ||
|
||
# rubocop:disable RSpec/RepeatedExample | ||
it 'outputs nomad facts when not installed' do | ||
apply_manifest(fact_notices, catch_failures: true) do |r| | ||
expect(r.stdout).to match(%r{nomad_node_id: \S+}) | ||
expect(r.stdout).to match(%r{nomad_version: \S+}) | ||
end | ||
end | ||
|
||
it 'sets up nomad' do | ||
apply_manifest(pp, catch_failures: true) | ||
end | ||
|
||
it 'outputs nomad facts when installed' do | ||
apply_manifest(fact_notices, catch_failures: true) do |r| | ||
expect(r.stdout).to match(%r{nomad_node_id: \S+}) | ||
expect(r.stdout).to match(%r{nomad_version: \S+}) | ||
end | ||
end | ||
# rubocop:enable RSpec/RepeatedExample | ||
end | ||
end |