codec
codec

Reputation: 8836

Chef spec tests with not_if guard

I have the following chef resoutce

  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

Corresponding to this I Have the following chef spec test

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

which gives a warning

[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. 

and the following error

  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

Upvotes: 0

Views: 240

Answers (1)

slashpai
slashpai

Reputation: 1169

When you use command inside not_if block, you don't need to use curly braces. You can use simply use double or single quotes

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'"

Upvotes: 1

Related Questions