3

I have a problem with serverspec. I'm trying to check installed package version on ubuntu.

I use this code:

describe 'java packages' do it 'package openjdk-9-jre should be installed with the correct version' do expect(package('openjdk-9-jre')).to be_installed.with_version('9~b114-0ubuntu1') end end 

Serverspec run dpkg-query command to check package but escapes tilda character and it doesn't work. serverspec runs:

dpkg-query -f '${Status} ${Version}' -W openjdk-9-jre | grep -E '^(install|hold) ok installed 9\\~b114-0ubuntu1$' 

instead of

dpkg-query -f '${Status} ${Version}' -W openjdk-9-jre | grep -E '^(install|hold) ok installed 9~b114-0ubuntu1$' 

How can I fix this problem?

1 Answer 1

4

The problem is here: https://github.com/mizzy/specinfra/blob/92ccc19714ead956589127c40e3cd65faf38cb8b/lib/specinfra/command/debian/base/package.rb#L6.

Specinfra is escaping the characters in the with_version chain as #{Regexp.escape(escape(version))} instead of #{Regexp.escape(version)). This would require a PR to Specinfra to fix due to the Specinfra/Serverspec contribution policy. I can put this on my list of things to do and notify you when finished, since I keep an up-to-date Specinfra fork around and am a contributor to both so I know the codebase.

In the meantime, you would have to do a command matcher workaround.

describe 'java packages' do it 'package openjdk-9-jre should be installed with the correct version' do describe command("dpkg-query -f '${Status} ${Version}' -W openjdk-9-jre") do its(:stdout) { is_expected.to match('^(install|hold) ok installed 9\~b114\-0ubuntu1$') } end end end 

Specinfra PR: https://github.com/mizzy/specinfra/pull/608

Sign up to request clarification or add additional context in comments.

4 Comments

Good, thanks It will be grat if this will be fixed. :)
It looks like this was fixed in github.com/mizzy/serverspec/pull/316/files in ServerSpec and appears to be working for me. Not sure if it's possible to do a >= or if it only supports > or <.
@dragon788 Please note the link in the answer to the PR where I fixed it.
Aha, I knew I saw it somewhere! It also works with cmp in InSpec. It's a shame that fuzzy versions aren't fully supported in all the Chef package resources yet.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.