Rspec:无法分析环境rp_env

Rspec:无法分析环境rp_env,rspec,puppet,rspec-puppet,Rspec,Puppet,Rspec Puppet,我是rspec puppet的新手,我从测试写作开始: 我写了这段代码: describe 'rcjenkins' do let(:facts) do { :osfamily => 'RedHat' } end let(:pre_condition) do "$facts = #{facts}" end let(:params) do { :host => "127.0.0.1", :githu

我是rspec puppet的新手,我从测试写作开始:

我写了这段代码:

describe 'rcjenkins' do
  let(:facts) do
    {
      :osfamily => 'RedHat'
    }
  end
  let(:pre_condition) do
    "$facts = #{facts}"
  end

  let(:params) do
    {
      :host => "127.0.0.1",
      :github_token => "valor",

    }
  end
  it do
    is_expected.to contain_class('rcjenkins::nginx')
  end
end
哪些应该测试:

class rcjenkins($host, $github_token) {
  include rcjenkins::package

  class { 'nginx': }

  nginx::resource::upstream { 'jenkins':
    members => [
      'localhost:8080'
    ]
  }

  nginx::resource::vhost { $host:
    proxy => 'http://jenkins'
  }

  nginx::resource::location { 'jenkins_root':
    ensure         => present,
    vhost          => $host,
    location       => '/status',
    location_alias => '/usr/share/nginx/html'
  }
这更像是一个“测试中的测试”,但事情总是失败。 我得到:

  1) rcjenkins Treco should contain Class[rcjenkins::nginx]
     Failure/Error: is_expected.to contain_class('rcjenkins::nginx')

     Puppet::ParseErrorWithIssue:
       Could not parse for environment rp_env: Syntax error at ':' at line 1:11 on node localhost.localdomain
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser_support.rb:127:in `on_error'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/lexer2.rb:712:in `scan'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser_support.rb:240:in `_parse'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser_support.rb:134:in `parse_string'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/evaluating_parser.rb:28:in `parse_string'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/e4_parser_adapter.rb:29:in `parse'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/node/environment.rb:507:in `perform_initial_import'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/node/environment.rb:247:in `known_resource_types'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:767:in `block in initvars'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/context.rb:65:in `override'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet.rb:293:in `override'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:765:in `initvars'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:422:in `initialize'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:33:in `new'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:33:in `compile'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:266:in `block (2 levels) in compile'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util/profiler.rb:51:in `profile'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:264:in `block in compile'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util.rb:223:in `block in benchmark'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util.rb:222:in `benchmark'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:262:in `compile'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:53:in `find'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/indirection.rb:194:in `find'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/adapters.rb:74:in `catalog'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/adapters.rb:148:in `catalog'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:203:in `build_catalog_without_cache'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:212:in `block in build_catalog'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/cache.rb:17:in `call'is_expected.to contain_class('rcjenkins::nginx')
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/cache.rb:17:in `get'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:211:in `build_catalog'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:30:in `block in load_catalogue'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:178:in `with_vardir'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:19:in `load_catalogue'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/example/class_example_group.rb:7:in `catalogue'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:11:in `block in subject'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `call'
     # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `matches?'
     # ./spec/classes/rcjenkins_spec.rb:39:in `block (3 levels) in <top (required)>'
1)rcjenkins Treco应该包含类[rcjenkins::nginx]
失败/错误:应为\u。应包含\u类('rcjenkins::nginx')
Puppet::ParseErrorWithIssue:
无法分析节点localhost.localdomain上第1:11行“:”处的环境rp_env:语法错误
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser\u support.rb:127:in'on\u error'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/lexer2.rb:712:in'scan'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser\u support.rb:240:in`\u parse'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser\u support.rb:134:in'parse\u string'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/evaluation_parser.rb:28:in'parse_string'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/e4_parser_adapter.rb:29:in'parse'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/node/environment.rb:507:in“执行初始导入”
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/node/environment.rb:247:在“已知资源类型”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:767:in`block in initvars'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/context.rb:65:在“覆盖”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet.rb:293:in'override'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:765:in`initvars'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:422:in'initialize'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:33:in`new'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:33:in'compile'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:266:in `编译中的块(2级)'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util/profiler/around_profiler.rb:58:in“profile”
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util/profiler.rb:51:in'profile'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:264:在“编译中的块”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util.rb:223:在“基准中的块”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util.rb:222:in `基准'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:262:in'compile'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:53:in'find'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/indirection.rb:194:in'find'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/adapters.rb:74:在“目录”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/adapters.rb:148:在“目录”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:203:在“构建目录”中没有缓存
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:212:在“构建中的块目录”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec puppet/cache.rb:17:in'call'应包含类('rcjenkins::nginx'))
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/cache.rb:17:in'get'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:211:在“构建目录”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:30:in“加载中的块目录”
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:178:in“with_vardir”
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:19:in“加载目录”
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/example/class\u example\u group.rb:7:在“目录”中
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:11:in“主体中的块”
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/matchers/create_generic.rb:82:in'call'
#/home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/matchers/create_generic.rb:82:in‘matches?’
#./spec/classes/rcjenkins_spec.rb:39:in'block(3层)in'
第39行应包含类('rcjenkins::nginx')。有人知道发生了什么吗

编辑:
我也注意到,我改变测试的任何内容都会给我同样的错误。我错过了什么?什么是rp_env?

删除或修复您的前置条件,它不会生成有效的傀儡清单:

let(:pre_condition) do
  "$facts = #{facts}"
end
如果Ruby变量
facts
{:osfamily=>'RedHat'}
,则会生成一个如下的傀儡清单:

$facts = {:osfamily=>'RedHat'}
osfamily哈希键前面的冒号在Puppet清单中无效(它必须是字符串,例如,
“osfamily”


我认为没有任何理由在这里设置
pre\u条件,你的
let(:facts)
应该足够了。

OP还询问了
rp\e