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,510 points
65 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
• 40,460 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,280 points
292 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,810 points
3,410 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,280 points
26 views
0 votes
2 answers
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
152 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
• 40,460 points
38 views