summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Justice <jjustice6@bloomberg.net>2019-06-03 14:52:47 -0400
committerJoshua Justice <jjustice6@bloomberg.net>2019-07-10 15:28:38 -0400
commit0736be5bfe26792d48d3905144920cd28899da82 (patch)
tree81c36dae894668939e96d3334343226a625ee03a
parentf5eed7c04a407b5ee138125000860b29325e1f21 (diff)
downloadohai-0736be5bfe26792d48d3905144920cd28899da82.tar.gz
Add other_versions subfield for RPM packages.
Signed-off-by: Joshua Justice <jjustice6@bloomberg.net>
-rw-r--r--lib/ohai/plugins/packages.rb11
-rw-r--r--spec/data/plugins/rpmquery.output2
-rw-r--r--spec/unit/plugins/packages_spec.rb14
3 files changed, 26 insertions, 1 deletions
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb
index 04c19e96..a7a74f7d 100644
--- a/lib/ohai/plugins/packages.rb
+++ b/lib/ohai/plugins/packages.rb
@@ -48,7 +48,16 @@ Ohai.plugin(:Packages) do
pkgs.each do |pkg|
name, epoch, version, release, installdate, arch = pkg.split
- packages[name] = { "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch }
+ if packages[name]
+ # We have more than one package with this exact name!
+ # Create an "other_versions" array for tracking all versions of packages with this name.
+ # The top-level package information will be the first one returned by rpm -qa,
+ # all others go in this list, with the same information they'd normally have.
+ packages[name]["other_versions"] = [] unless packages[name]["other_versions"]
+ packages[name]["other_versions"] << Mash.new({ "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch })
+ else
+ packages[name] = { "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch }
+ end
end
when "arch"
diff --git a/spec/data/plugins/rpmquery.output b/spec/data/plugins/rpmquery.output
index 02de1a61..ada89595 100644
--- a/spec/data/plugins/rpmquery.output
+++ b/spec/data/plugins/rpmquery.output
@@ -3,3 +3,5 @@ tzdata 0 2016d 1.el7 1463486618 noarch
nss-softokn-freebl 0 3.16.2.3 14.2.el7_2 1463486619 x86_64
glibc 0 2.17 106.el7_2.6 1463486666 x86_64
libstdc++ 0 4.8.5 4.el7 1463486669 x86_64
+kernel 0 3.10.0 862.2.3.el7 1526310781 x86_64
+kernel 0 3.10.0 862.el7 1521745632 x86_64
diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb
index a031ef79..60fe7ed9 100644
--- a/spec/unit/plugins/packages_spec.rb
+++ b/spec/unit/plugins/packages_spec.rb
@@ -100,6 +100,20 @@ describe Ohai::System, "plugin packages" do
expect(plugin[:packages]["tzdata"][:installdate]).to eq("1463486618")
expect(plugin[:packages]["tzdata"][:arch]).to eq("noarch")
end
+
+ it "handles multiple packages with the same name" do
+ expect(plugin[:packages]["kernel"][:version]).to eq("3.10.0")
+ expect(plugin[:packages]["kernel"][:release]).to eq("862.2.3.el7")
+ expect(plugin[:packages]["kernel"][:epoch]).to eq("0")
+ expect(plugin[:packages]["kernel"][:installdate]).to eq("1526310781")
+ expect(plugin[:packages]["kernel"][:arch]).to eq("x86_64")
+ # and now the "other" version installed:
+ expect(plugin[:packages]["kernel"]["other_versions"].first[:version]).to eq("3.10.0")
+ expect(plugin[:packages]["kernel"]["other_versions"].first[:release]).to eq("862.el7")
+ expect(plugin[:packages]["kernel"]["other_versions"].first[:epoch]).to eq("0")
+ expect(plugin[:packages]["kernel"]["other_versions"].first[:installdate]).to eq("1521745632")
+ expect(plugin[:packages]["kernel"]["other_versions"].first[:arch]).to eq("x86_64")
+ end
end
context "on arch" do