0

I am trying to use the net/ssh gem to find an installed package into my Test-Kitchen instance. I do a simple recipe that reuse the build-essential cookbook.

It is my recipe:

node['my-cookbook']['packages'].each do |pkg|
  package pkg
end

And these are my attributes:

default['my-cookbook']['packages'] = %w[build-essential git bison]

These are some steps into my feature definition for cucumber.

When(/^I ask for (.*)$/) do |package|

  Net::SSH.start(@infrastructure['my-app'].ip,'vagrant', password: 'vagrant') do |ssh|
    @out = ssh.exec!("dpkg --get-selections | grep #{package}")
  end
end

Then(/^I should see (.*)$/) do |package_respond|
  puts @out
  @out.should match package_respond
end

When the instance converge, build-essential was installed and the cucumber test was succesful.

The output

puts @out

Was

grep: build-essential: No such file or directory

The test was succesful because the expresion matched. I was expecting

build-essential             install

What happened here?? When a package is not installed the console respond with an empty string.

How can I inspect if an specific package was installed into my kitchen instance using the net/ssh gem?

My kithen instance is ubuntu 12.04.

Thanks.

Robert
  • 10,403
  • 14
  • 67
  • 117

1 Answers1

0

I'm guessing there's a space in some of the packages, or something of the likes.

If that's the case, build-essential would come as the second argument of grep, and in that case, grep would try to open it as a file, which of course doesn't exist.

So I would recommend:

@out = ssh.exec!("dpkg --get-selections | grep \"#{package}\"")

diogovk
  • 2,108
  • 2
  • 19
  • 24