Skip to content

Commit

Permalink
[rspec] Adopt Hiera v3 lookups with RSpec tests
Browse files Browse the repository at this point in the history
To satisfy Hiera lookups (as opposed to purely 'fact' based references)
RSpec tests now have their own respective Hiera hierarchy defined at:
'site/profiles/fixtures/hiera.yaml'. All existing (and future) RSpec tests
will now perform "Automatic Parameter Lookups" only falling back to
in-class default values should the corresponding key not be found.

The 'datadir' path to the RSpec test directory is relative to the
'Profiles' module's 'root' directory: 'site/profiles'. As of this commit
the "data-in-module" pattern is not currently utilised and consequently
dedicated RSpec specific Hiera data files are consumed.

The 'ghoneycutt-ssh' community module utilises a deprecated Hiera
function, 'hiera_hash', for performing a "deep" merge of an explicit
key: 'ssh::keys'. This is addressed in the same manner as:
c3a17e3e896ad24599d6f9274cc8f37a45844e41.

Unfortunately Hiera v3 had to be adopted as the Ruby gem 'rspec-puppet'
utilised by `pdk` is unable to parse Hiera v5 configuration file syntax.

Related links regarding Hiera v3 & puppet-rspec limitations:

* rodjek/rspec-puppet#762

* rodjek/rspec-puppet#551

* https://tickets.puppetlabs.com/browse/HI-598
  • Loading branch information
penguinspiral committed Dec 28, 2020
1 parent a9ec5fe commit 2cbe0a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions site/profiles/spec/fixtures/data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
profiles::ssh::keys:
'raft.com':
user: 'debian'
type: 'ssh-rsa'
key: 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCvgu7p7cM17pL41bfJu+9VbH5t+APGnqxHQRdG2qlAr2TTKzlCxVslau7a5tay2lGJ757dNE6mrGVGwVDMorTADU9eqlA2ajwVTQpDtmblUSVzXDutKop/KPyDCnh8I+1mIgGp4jm1Fa0AP0LqJziY8WtS9waNphwMFjw+xCAGxI+a8dt49QrtmGonMouxMyRRB5pjzKjAPfVazsK4mCtWGvHX5m0Q+PCjd0DZPRflD1OuBvTG7KFoDVGxwDJqOIjAZ4vBkF/wO7wpsoKS9K2uNEhPEysR4JFbZbCyVgVXp6vint11025YOTjSHldQSZcEwbfgZOAfl09Qb8Um03ET'
ssh::keys: "%{alias('profiles::ssh::keys')}"
7 changes: 7 additions & 0 deletions site/profiles/spec/fixtures/hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
:backends:
- yaml
:yaml:
:datadir: './spec/fixtures/data'
:hierarchy:
- 'common'
1 change: 1 addition & 0 deletions site/profiles/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
Puppet.settings[:strict_variables] = true
end
c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT']
c.hiera_config = File.expand_path(File.join(__FILE__, '../fixtures/hiera.yaml'))
c.after(:suite) do
end
end
Expand Down

0 comments on commit 2cbe0a0

Please sign in to comment.