首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果变量可以传递给木偶中的类,则运行Rspec失败

如果变量可以传递给木偶中的类,则运行Rspec失败
EN

Stack Overflow用户
提问于 2015-03-27 20:06:31
回答 1查看 617关注 0票数 1

问题

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

代码语言:javascript
复制
class module_name (
  $variable='hello_world'
) {
  package { 'package_name': }
}

如果运行rspec,则会失败,即:

代码语言:javascript
复制
[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'

主要问题

代码语言:javascript
复制
Error from DataBinding while looking up FileSystem implementation expected Pathname, 
got: 'Hash' on node

配置

版本

代码语言:javascript
复制
[vagrant@vm-one opsview]$ puppet --version
3.7.5
[vagrant@vm-one opsview]$ rspec --version
3.2.2

Spec_helper

代码语言:javascript
复制
[vagrant@vm-one opsview]$ cat spec/spec_helper.rb
require 'rspec-puppet'
require 'hiera-puppet-helper'

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))

RSpec.configure do |c|
  c.module_path = File.join(fixture_path, 'modules')
  c.manifest_dir = File.join(fixture_path, 'manifests')
  c.hiera_config = '/etc/puppet/hiera.yaml'
end

at_exit { RSpec::Puppet::Coverage.report! }

尝试

  1. 这个问答称,是hiera-puppet-helper造成了这一问题。Rspec-傀儡似乎支持测试hiera和‘hiera-木偶助手’可以被取代。好的,也许这解决了这个问题,但是是什么导致了这个问题呢?
  2. 这个职位包含相同的问题,但没有解决这个问题的解决方案。
  3. 这个职位表示删除类参数解决了这个问题,但是这个类被多个模块使用,因此这不是一个解决方案。
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-15 13:47:28

hiera_config有一个问题,应该是:

代码语言:javascript
复制
c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'

假设您的目录结构如下:

代码语言:javascript
复制
  \spec
    \fixtures
      \hiera
        hiera.yaml
        default.yaml

hiera.yaml

代码语言:javascript
复制
---
:backends:
  - yaml
:hierarchy:
  - '%{::clientcert}'
  - default
:yaml:
  :datadir: './spec/fixtures/hiera'

hiera-puppet-helper gem确实不是必需的,实际上它不应该存在。我建议使用加雷瑟骨架生成模块结构,它已经包含了Hiera的工作设置,可以节省大量时间。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29309341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档