3

我对 serverspec 有疑问。我正在尝试检查 ubuntu 上安装的软件包版本。

我使用这段代码:

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 运行 dpkg-query 命令检查包但转义 tilda 字符并且它不起作用。serverspec 运行:

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

代替

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

我该如何解决这个问题?

4

1 回答 1

4

问题在这里:https ://github.com/mizzy/specinfra/blob/92ccc19714ead956589127c40e3cd65faf38cb8b/lib/specinfra/command/debian/base/package.rb#L6 。

Specinfra 正在转义with_version链中的字符,#{Regexp.escape(escape(version))}而不是#{Regexp.escape(version)). 由于 Specinfra/Serverspec 贡献政策,这将需要对 Specinfra 的 PR 进行修复。我可以把它放在我的待办事项清单上,并在完成后通知你,因为我保持着一个最新的 Specinfra 分支,并且是两者的贡献者,所以我知道代码库。

与此同时,您将不得不做一个command匹配器解决方法。

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 公关:https ://github.com/mizzy/specinfra/pull/608

于 2017-02-23T14:23:32.643 回答