Testing 如果变量可以传递给Puppet中的类,则运行Rspec将失败

Testing 如果变量可以传递给Puppet中的类,则运行Rspec将失败,testing,rspec,tdd,puppet,Testing,Rspec,Tdd,Puppet,问题 如果变量可以传递给Puppet类,例如: class module_name ( $variable='hello_world' ) { package { 'package_name': } } 如果失败,则运行rspec,即: [user@host module_name]$ rspec ...............................FFFFFFFFFFFF.......................................... Failures

问题

如果变量可以传递给Puppet类,例如:

class module_name (
  $variable='hello_world'
) {
  package { 'package_name': }
}
如果失败,则运行
rspec
,即:

[user@host module_name]$ rspec
...............................FFFFFFFFFFFF..........................................

Failures:

  1) opsview should contain Class[module_name]
     Failure/Error: it { should contain_class('module_name') }
     Puppet::Error:
       Error from DataBinding 'hiera' while looking up 'module_name::variable': 
       FileSystem implementation expected Pathname, got: 'Hash' on node host
     # /usr/share/ruby/vendor_ruby/puppet/resource.rb:393:
         in `rescue in lookup_with_databinding'
     # /usr/share/ruby/vendor_ruby/puppet/resource.rb:387:
         in `lookup_with_databinding'
     # /usr/share/ruby/vendor_ruby/puppet/resource.rb:381:
         in `lookup_external_default_for'
主要问题

配置

版本

特殊助手

尝试

  • 根据
    hiera puppet helper
    引起 问题Rspec傀儡似乎支持测试hiera和 “hiera puppet helper”可以替换。好吧,也许这解决了问题,但问题的根源是什么
  • 包含相同的问题,但不是要解决的解决方案 问题
  • 指示删除类参数可以解决此问题,但该类由多个模块使用,因此这不是解决方案

  • hiera_配置有问题,应该是:

    c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
    
    假设您有如下目录结构:

      \spec
        \fixtures
          \hiera
            hiera.yaml
            default.yaml
    
    hiera.yaml

    ---
    :backends:
      - yaml
    :hierarchy:
      - '%{::clientcert}'
      - default
    :yaml:
      :datadir: './spec/fixtures/hiera'
    

    确实不需要
    hiera puppet helper
    gem,事实上它不应该在那里。我建议您使用已包含Hiera工作设置的模块结构生成模块结构,这样可以节省大量时间。

    因此,使用
    c.Hiera\u config='/etc/puppet/Hiera.yaml'
    ,您是在告诉
    rspec puppet
    使用高效的Hiera数据进行测试吗?这不危险吗?rspec puppet内置了hiera支持。不需要
    hiera木偶助手
    。查看有关hiera集成的部分。@FelixFrank是否可以为每个环境使用单独的hiera.yaml,例如/etc/puppet/environments/production/hiera.yaml和/etc/puppet/environments/dev/hiera.yaml?目前,hieradata在每个环境中是不同的,并且位于/etc/puppet/environments/production和/etc/puppet/environments中/dev@ptierno你是对的。我现在正在使用它,问题已经解决,不再使用hiera puppet helper。我只是好奇为什么hiera puppet helper会引起这个问题。也许你可以解释一下,并把它作为一个答案贴出来。
    c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
    
      \spec
        \fixtures
          \hiera
            hiera.yaml
            default.yaml
    
    ---
    :backends:
      - yaml
    :hierarchy:
      - '%{::clientcert}'
      - default
    :yaml:
      :datadir: './spec/fixtures/hiera'