Serverspec doesn t check package version correctly

0 votes

I am having trouble in serverspec. I'm trying to check installed package version on ubuntu.

I am using 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$'

I don't know how to fix this?

Can anyone help me with this?

Thanks

Jul 3, 2018 in DevOps Tools by Damon Salvatore
• 5,980 points
1,032 views

1 answer to this question.

0 votes

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.

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
answered Aug 2, 2018 by Kalgi
• 52,360 points

Related Questions In DevOps Tools

0 votes
1 answer

How to download the latest minor version of nexus artifact using REST?

If you're using nexus 2.x, you can ...READ MORE

answered Jun 27, 2018 in DevOps Tools by ajs3033
• 7,300 points
3,126 views
+1 vote
3 answers

How do I check and export sonarqube analysis reports in embedded db?

Browse to sonarqube web instance to access ...READ MORE

answered Jul 2, 2018 in DevOps Tools by DareDev
• 6,890 points
27,494 views
0 votes
1 answer

Error saying "client and server don't have same version (client : 1.19, server: 1.18)"

As of docker-compose 1.4 you can now ...READ MORE

answered Jul 19, 2018 in DevOps Tools by Kalgi
• 2,680 points
1,630 views
0 votes
1 answer

Set variable on specific package installation in CFEngine

Try using packagesmatching to get the version ...READ MORE

answered Aug 8, 2018 in DevOps Tools by ajs3033
• 7,300 points
385 views
0 votes
2 answers
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,520 views
0 votes
2 answers
0 votes
1 answer

IBM Cloud DevOps - Eclipse Orion IDE not working correctly

follow these steps Step 1- open dev-tools Step 2- ...READ MORE

answered Aug 3, 2018 in DevOps Tools by Kalgi
• 52,360 points
489 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP