如何在 rspec-puppet 测试中禁用 Hiera 调试输出

How to disable Hiera debug output in rspec-puppet test

我有以下规范文件

require 'spec_helper'

describe 'PLC', :type => 'class' do

  let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
  hiera = Hiera.new({ :config => 'spec/fixtures/hiera/hiera.yaml' })

  abc = hiera.lookup('PLC::PLC_LINE',nil,nil)

  let(:hiera_data) {{
    :PLC_LINE => abc
  }}

  it{ should contain_file('/test/rspec/etc/PLC').with(
        'ensure'  => 'file',
        'owner'   => 'root',
        'group'   => 'root',
        'mode'    => '0644',
        'require' => 'File[/test/rspec/etc]') }

  it{ should contain_file('/test/rspec/etc/PLC').with_PLC_LINE(abc)}


end

下面是我的/hiera/fixtures/plc.yaml

plc : puppetlab

当我 运行 rake spec 时,会打印以下消息:

DEBUG: Wed Jul 08 07:11:55 -0400 2015: Hiera YAML backend starting
DEBUG: Wed Jul 08 07:11:55 -0400 2015: Looking up plc::plc_LINE in YAML backend
DEBUG: Wed Jul 08 07:11:55 -0400 2015: Looking for data source plc

如何抑制这个输出?

只需放入例如spec_helper.rb 以下:

Puppet::Util::Log.level = :warning

在客户端您可以轻松查看 log_level:

puppet config print log_level --section agent

您可以在例如/etc/puppet/puppet.conf(取决于您的配置路径):

[agent]
log_level = info