1

I have this serverspec test:

  describe package("python-pip") do
    it { should be_installed.with_version("6.1.1") }
  end

It was failing and I noticed in the output that serverspec was checking packages installed with rpm default. Then I noticed in the serverspec docs that you can use by() to specify a package manager, so I tried this:

  describe package("python-pip") do
    it { should be_installed.by("yum").with_version("6.1.1") }
  end

However, this also failed, with this error:

check_is_installed_by_yum is not implemented in Specinfra::Command::Redhat::Base::Package

I checked the docs for that class here and noticed this list, which doesn't include yum:

check_is_installed_by_cpan, check_is_installed_by_gem, check_is_installed_by_npm, check_is_installed_by_pear, check_is_installed_by_pecl, check_is_installed_by_pip, check_is_installed_by_rvm

So now I'm having to fall back to describe command rather than describe package:

  describe command("yum list installed | grep python27-pip") do
    its(:exit_status) { should eq 0 }
  end

This feels hacky since serverspec seems to have the functionality I'm looking for already. Is there something I'm missing?

EDIT

Matt's answer has helped me understand some things better, like how rpm -q and yum list installed work and how serverspec's by() was meant to be used (I thought rpm -q only showed packages installed by rpm and same with yum list but it appears they both list all installed packages). Knowing that, I have gotten my test to pass by changing it to this:

  describe package("python27-pip-6.1.1-1.21.amzn1.noarch") do
    it { should be_installed }
  end

python27-pip-6.1.1-1.21.amzn1.noarch is the name of the package as printed out when I use rpm -qa or yum list installed. However, it seems a bit cumbersome to have to know that entire name and use it here. I'm hoping there's a way to do this similar to how I was trying to do it above using the with_version() method.

EDIT 2

So now I know I can write the test this way:

  describe package("python27-pip") do
    it { should be_installed.with_version("6.1.1-1.21.amzn1.noarch") }
  end

So there were a few Linux-y things I didn't understand that I think are what led to this question needing to be asked. With that being the case, when Matt pointed out that searching the system packages with rpm is the same as with yum, it pretty much explained what I really needed to know.

So I realize this isn't a great question but am not sure if I should delete it since maybe it could help someone else but also because I appreciate the help I've gotten and want to reward it with points.

sixty4bit
  • 7,422
  • 7
  • 33
  • 57
  • I think the reason that the `with_version("6.1.1")` did not work and the `with_version("6.1.1-1.21.amzn1.noarch")` did work is due to some kind of malformatted rpm tag for version/release/epoch/arch in the spec file. `rpm -q` normally is able to work with just the `6.1.1`, so something may be off with the rpm itself. – Matthew Schuchard Jun 17 '16 at 13:36
  • I can check it again, but it may be because I never tried the combination of `package("python27-pip")` with `with_version("6.1.1")`. I had only tried the latter when calling the package `python-pip`. – sixty4bit Jun 17 '16 at 14:38
  • Oh I completely missed that. Yeah, that probably was the problem. – Matthew Schuchard Jun 17 '16 at 17:24

1 Answers1

1

For starters, take a look here (assuming you are using RHEL/CentOS/SL/OL since you said yum and not zypper or dnf):

https://github.com/mizzy/specinfra/blob/master/lib/specinfra/command/redhat/base/package.rb

It was a good idea to check the docs, but there are a bunch of other provider chains available that I happen to know about because I contribute to specinfra/serverspec. Unfortunately, none are yum.

Since there is essentially no difference in the version checking chain with_version between rpm and yum, specinfra does not have a command for the yum provider chain.

If you literally require that it be installed by yum and not rpm, and want to use a chain to the package method, then this is going to require a PR to specinfra. I am already going to be doing a PR to specinfra for an issue discovered in another stackoverflow question so I can always bang this one out too.

Finally, your block here:

describe package("python-pip") do
  it { should be_installed.with_version("6.1.1") }
end

should absolutely work as intended (checks if version 6.1.1 of python-pip is installed). If it is not, then either there is a problem with the test, your server configuration, or specinfra/serverspec. I recommend adding the output from that test since that is also a worthwhile avenue to explore.

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
  • Thanks Matt. Your answer has helped clarify some things. I've edited the original question with where things stand for me now and would be interested in your thoughts if you have a moment. Basically it has to do with what you said about how my test (as written) "should absolutely work." I've found out that the system has a much longer package name than `python-pip` (I just assumed that because it's what you use when installing with `yum`). – sixty4bit Jun 16 '16 at 20:43