如何从 Beaker 启用 Puppet 的调试日志级别

How to enable Puppet's debug logging level from Beaker

我有一些 beaker-rspec 验收测试涵盖了我正在创建的 Puppet 模块,并且想知道如何在底层 Puppet 调用上启用调试日志记录(例如,确切地知道当我调用 apply_manifest).我很确定我已经能够在 Beaker 本身上运行调试日志记录(export BEAKER_debug=yes?),但这似乎只能告诉我 Beaker 在做什么,不一定是人偶。

如果有帮助,这里有一些相关的文件片段:

spec/fixtures/spec_helper_acceptance.rb

require 'beaker-rspec/spec_helper'
require 'beaker-rspec/helpers/serverspec'
require 'beaker/librarian'

RSpec.configure do |c|
  module_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

  c.formatter = :documentation

  # Configure all nodes in nodeset
  c.before :suite do
    install_puppet
    install_librarian
    librarian_install_modules(module_root, 'mymodule')
  end
end

spec/acceptance/example_spec.rb

require 'spec_helper_acceptance'

apply_manifest_opts = {
  :catch_failures => true,
  # I seem to need this otherwise Puppet doesn't pick up the required modules.
  # Is this where I can also enable debug logging in Puppet? 
  :modulepath     => '/etc/puppetlabs/puppet/modules/',
}

default_pp = <<-EOS
  class { 'mymodule': }
EOS

describe 'the mymodule class' do
  describe 'given default params' do
    it 'should return successfully' do
      expect(apply_manifest(default_pp, apply_manifest_opts).exit_code).to be_zero
    end
  end
end

实际上我正在尝试找出 the mymodule class given default params should return successfully 测试失败的原因,但目前我只得到

Failure/Error: expect(apply_manifest(default_pp, apply_manifest_opts).exit_code).to be_zero
       expected `2.zero?` to return true, got false

这没什么用。你看到我的问题了吗?

我会接受直接回答我的问题的回复,或者给我一些其他方法来计算为什么退出代码不为零。

我的直觉是正确的,它只需要为 apply_manifest 提供一个额外的选项。我只是花了一些时间才弄清楚有关如何执行此操作的文档的确切位置。

apply_manifest_opts = {
  :catch_failures => true,
  # I seem to need this otherwise Puppet doesn't pick up the required modules. 
  :modulepath     => '/etc/puppetlabs/puppet/modules/',
  :debug          => true,
}

来源:

http://www.rubydoc.info/github/puppetlabs/beaker/Beaker/DSL/Helpers/PuppetHelpers#apply_manifest_on-instance_method