【问题标题】:Chef spec tests with not_if guard使用 not_if 保护的 Chef 规范测试
【发布时间】:2018-04-18 10:57:23
【问题描述】:

我有以下厨师资源

  rpm_package 'Install BESAgent' do
    source node['besclient']['package_url']
    action :install
    not_if { "rpm -qa | grep -qx 'BESAgent-9.5.9.62-rhe6.x86_64'" || "rpm -qa | grep -qx 'BESAgent-9.5.9.62-sle11.x86_64'" }
  end

与此相对应,我有以下厨师规格测试

it 'installs rpm_package for BES Client' do
  expect(chef_run).to install_rpm_package('Install BESAgent').with(source: 'http://software.bigfix.com/download/bes/95/BESAgent-9.5.9.62-rhe6.x86_64.rpm' , not_if: '{ \"rpm -qa | grep -qx \'BESAgent-9.5.9.62-rhe6.x86_64\'\" || \"rpm -qa | grep -qx \'BESAgent-9.5.9.62-sle11.x86_64\'\"}'))
end

给出警告

[2018-04-17T21:18:03+05:30] WARN: not_if block for rpm_package[Install BESAgent]
returned "rpm -qa | grep -qx 'BESAgent-9.5.9.62-rhe6.x86_64'", did you mean to
run a command? If so use 'not_if "rpm -qa | grep -qx 'BESAgent-9.5.9.62-rhe6.x86_64'"' in your code. 

还有以下错误

  1) besclient::linux redhat 6.8: when all attributes are default installs rpm_
ackage for BES Client
     Failure/Error: expect(chef_run).to install_rpm_package('Install BESAgent')
with(source: 'http://software.bigfix.com/download/bes/95/BESAgent-9.5.9.62-rhe6
x86_64.rpm', not_if: '{ \"rpm -qa | grep -qx \'BESAgent-9.5.9.62-rhe6.x86_64\'\
 || \"rpm -qa | grep -qx \'BESAgent-9.5.9.62-sle11.x86_64\'\"}')
       expected "rpm_package[Install BESAgent]" actions [] to include :install

【问题讨论】:

  • 您可以在node['packages'] Mash 中查找包,而不是生成子shell。

标签: chef-recipe recipe


【解决方案1】:

当你在not_if 块中使用命令时,你不需要使用花括号。您可以简单地使用双引号或单引号

not_if "rpm -qa | grep -qx 'BESAgent-9.5.9.62-rhe6.x86_64'" || "rpm -qa | grep -qx 'BESAgent-9.5.9.62-sle11.x86_64'"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 2015-01-17
    相关资源
    最近更新 更多