用puppetlabs-spec-helper使用hiera的正确方法是什么?

我正在尝试为我的模块写一些rspectesting。 他们中的大多数现在使用hiera。

我有一个.fixures.yml:

fixtures: repositories: stdlib: https://github.com/puppetlabs/puppetlabs-stdlib.git hiera-puppet: https://github.com/puppetlabs/hiera-puppet.git symlinks: mongodb: "#{source_dir}" 

和一个spec / classes / mongodb_spec.rb:

 require 'spec_helper' describe 'mongodb', :type => 'class' do context "On an Ubuntu install, admin and single user" do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Ubuntu', :operatingsystemrelease => '12.04' } end it { should contain_user('XXXX').with( { 'uid' => '***' } ) should contain_group('XXXX').with( { 'gid' => '***' } ) should contain_package('mongodb').with( { 'name' => 'mongodb' } ) should contain_service('mongodb').with( { 'name' => 'mongodb' } ) } end end 

但是当我运行spectesting时,我得到:

 # rake spec /usr/bin/ruby1.8 -S rspec spec/classes/mongodb_spec.rb --color F Failures: 1) mongodb On an Ubuntu install, admin and single user Failure/Error: should contain_user('XXXX').with( { 'uid' => '***' } ) LoadError: no such file to load -- hiera_puppet # ./spec/fixtures/modules/hiera-puppet/lib/puppet/parser/functions/hiera.rb:3:in `function_hiera' # ./spec/classes/mongodb_spec.rb:15 Finished in 0.05415 seconds 1 example, 1 failure Failed examples: rspec ./spec/classes/mongodb_spec.rb:14 # mongodb On an Ubuntu install, admin and single user rake aborted! /usr/bin/ruby1.8 -S rspec spec/classes/mongodb_spec.rb --color failed Tasks: TOP => spec_standalone (See full trace by running task with --trace) 

模块testing是相对较新的,和hiera一样。 到目前为止,我一直无法find合适的解决scheme。 (在傀儡开发来回是有趣的,但没有帮助)。

我需要做些什么才能使其发挥作用? 由于企业的政策,从gem安装木偶并侵入rubylib并不是一个可行的解决scheme。

我使用的是Ubuntu 12.04 LTS + Puppet 2.7.17 + hiera 0.3.0。

rspec-hiera-puppetgem

https://github.com/amfranz/rspec-hiera-puppet

在你的Gemfile中:

 gem 'puppet' gem 'rspec-puppet' gem 'rspec-hiera-puppet' gem 'puppetlabs_spec_helper' gem 'hiera' gem 'hiera-puppet' 

在你的spec_helper.rb :`require'rspec-hiera-puppet'

spec/shared_context.rb

 require 'rspec-hiera-puppet' shared_context "hieradata" do let :hiera_config do { # this specifies that rspec overrides what's been defined in `riak::params` :backends => ['rspec', 'puppet'], :hierarchy => ['%{location}', '%{environment}', '%{calling_module}'], :puppet => { :datasource => 'params' }, :rspec => respond_to?(:hiera_data) ? send(:hiera_data) : {} } end end 

我在这里使用它:

https://github.com/haf/puppet-riak

随意去看看。

不幸的是puppetlabs_spec_helper目前不支持hiera。 我希望不久之后,Puppet中的某个人或社区中的某个人将有一个很好的解决scheme。 我知道很多人使用Hiera,我真的希望他们能够使用我们用于testing模块的工具。

正式的,hiera不支持2.7版本的puppetlabs_spec_helper,并且可以在将来的3.x兼容版本中使用。

非正式地, 木偶开发者邮件列表告诉我有一个“hackish” 补丁可以应用到puppetlabs_spec_helper,这将允许规范testing写与hiera支持。 不利的一面是,它可能会打破/需要一些重写,等3.0终于出来。