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.