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 2, 2018 in DevOps Tools by Damon Salvatore
• 5,270 points
35 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 35,800 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,040 points
86 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,560 points
1,520 views
0 votes
1 answer
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,040 points
18 views
0 votes
1 answer
+13 votes
2 answers
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
• 35,800 points
19 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.