Skip to content

Commit

Permalink
[rspec] Adopt Hiera v3 lookups with RSpec tests
Browse files Browse the repository at this point in the history
By design the SSH profile class, 'profiles::ssh', configures the OpenSSH
server to accept public key authentication as the *only* mechanism for
authentication. This constraint requires the user to provide either (or
both) public key(s) or explicitly enable traditional password authentication.

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 for class default
values and consequently dedicated RSpec specific Hiera data files are
consumed.

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 Jan 3, 2021
1 parent 4eb9546 commit ea02b6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions site/profiles/spec/fixtures/data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
profiles::ssh::keys:
'raft.com':
user: 'debian'
type: 'ssh-rsa'
key: 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCvgu7p7cM17pL41bfJu+9VbH5t+APGnqxHQRdG2qlAr2TTKzlCxVslau7a5tay2lGJ757dNE6mrGVGwVDMorTADU9eqlA2ajwVTQpDtmblUSVzXDutKop/KPyDCnh8I+1mIgGp4jm1Fa0AP0LqJziY8WtS9waNphwMFjw+xCAGxI+a8dt49QrtmGonMouxMyRRB5pjzKjAPfVazsK4mCtWGvHX5m0Q+PCjd0DZPRflD1OuBvTG7KFoDVGxwDJqOIjAZ4vBkF/wO7wpsoKS9K2uNEhPEysR4JFbZbCyVgVXp6vint11025YOTjSHldQSZcEwbfgZOAfl09Qb8Um03ET'
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 ea02b6a

Please sign in to comment.