summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-09-10 12:33:28 -0700
committerGitHub <noreply@github.com>2017-09-10 12:33:28 -0700
commitdccaaf9074da9109c1576d4abd54b548282cd783 (patch)
tree74f0c190be3f3a59c6af9c62627e4b32d1554411
parentc749a1f2ed714f2babd3df68fa515d475947b2ca (diff)
parent146eb904f7f86897d665ea5f9a82eb9d25762e2d (diff)
downloadohai-dccaaf9074da9109c1576d4abd54b548282cd783.tar.gz
Merge pull request #1042 from oslerw/master
Add Arch Linux support to package plugin
-rw-r--r--RELEASE_NOTES.md4
-rw-r--r--lib/ohai/plugins/packages.rb30
-rw-r--r--spec/data/plugins/pacman.output51
-rw-r--r--spec/unit/plugins/packages_spec.rb37
4 files changed, 120 insertions, 2 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 71d29c39..3bb93a73 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -7,6 +7,10 @@ Ohai now properly detects the [F5 Big-IP](https://www.f5.com/) platform and plat
- platform: bigip
- platform_family: rhel
+### Package Plugin Supports Arch Linux
+
+The Package plugin has been updated to include package information on Arch Linux systems.
+
# Ohai Release Notes 13.2:
Ohai 13.2 has been a fantastic release in terms of community involvement with new plugins, platform support, and critical bug fixes coming from community members. A huge thank you to msgarbossa, albertomurillo, jaymzh, and davide125 for their work.
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb
index f041143b..ce0c1870 100644
--- a/lib/ohai/plugins/packages.rb
+++ b/lib/ohai/plugins/packages.rb
@@ -32,7 +32,8 @@ Ohai.plugin(:Packages) do
collect_data(:linux) do
packages Mash.new
- if %w{debian}.include? platform_family
+ case platform_family
+ when "debian"
format = '${Package}\t${Version}\t${Architecture}\n'
so = shell_out("dpkg-query -W -f='#{format}'")
pkgs = so.stdout.lines
@@ -42,7 +43,7 @@ Ohai.plugin(:Packages) do
packages[name] = { "version" => version, "arch" => arch }
end
- elsif %w{rhel fedora suse pld}.include? platform_family
+ when "rhel", "fedora", "suse", "pld"
format = '%{NAME}\t%|EPOCH?{%{EPOCH}}:{0}|\t%{VERSION}\t%{RELEASE}\t%{INSTALLTIME}\t%{ARCH}\n'
so = shell_out("rpm -qa --qf '#{format}'")
pkgs = so.stdout.lines
@@ -51,6 +52,31 @@ Ohai.plugin(:Packages) do
name, epoch, version, release, installdate, arch = pkg.split
packages[name] = { "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch }
end
+
+ when "arch"
+ require "date"
+
+ # Set LANG=C to force an easy to parse date format
+ so = shell_out("LANG=C pacman -Qi")
+
+ so.stdout.split("\n\n").each do |record|
+ pacman_info = {}
+ record.lines.each do |line|
+ if line =~ /\A(.*?)\s+:\s(.*)\z/m
+ key, value = Regexp.last_match[1..2]
+ key = key.strip.downcase.gsub(/\s+/, "")
+ pacman_info[key] = value.strip
+ end
+ end
+
+ name = pacman_info["name"]
+ installdate = DateTime.strptime(pacman_info["installdate"], "%Ec").strftime("%s")
+ packages[name] = {
+ "version" => pacman_info["version"],
+ "installdate" => installdate,
+ "arch" => pacman_info["architecture"],
+ }
+ end
end
end
diff --git a/spec/data/plugins/pacman.output b/spec/data/plugins/pacman.output
new file mode 100644
index 00000000..382ed1a8
--- /dev/null
+++ b/spec/data/plugins/pacman.output
@@ -0,0 +1,51 @@
+Name : acl
+Version : 2.2.52-3
+Description : Access control list utilities, libraries and headers
+Architecture : x86_64
+URL : http://savannah.nongnu.org/projects/acl
+Licenses : LGPL
+Groups : None
+Provides : xfsacl
+Depends On : attr>=2.4.46
+Optional Deps : None
+Required By : coreutils gettext libarchive logrotate sed shadow systemd tar
+Optional For : None
+Conflicts With : xfsacl
+Replaces : xfsacl
+Installed Size : 290.00 KiB
+Packager : Bartlomiej Piotrowski <bpiotrowski@archlinux.org>
+Build Date : Sun Nov 6 14:03:46 2016
+Install Date : Sun Jul 23 03:25:45 2017
+Install Reason : Installed as a dependency for another package
+Install Script : No
+Validated By : Signature
+
+Name : abcde
+Version : 2.8.1-2
+Description : Frontend command-line utility that grabs tracks off a CD, encodes them to ogg or mp3 format, and tags them, all in one go
+Architecture : any
+URL : https://abcde.einval.com/
+Licenses : GPL
+Groups : None
+Provides : None
+Depends On : bash cd-discid wget vorbis-tools python2-eyed3
+Optional Deps : cdparanoia: Paranoia ripping support [installed]
+ cdrkit: icedax ripping support [installed]
+ flac: FLAC encoding support [installed]
+ id3: ID3 v1 tag support
+ lame: MP3 encoding support [installed]
+ mp3gain: MP3 normalization support [installed]
+ perl-musicbrainz-discid: musicbrainz support (AUR)
+ perl-webservice-musicbrainz: musicbrainz support (AUR)
+ vorbisgain: Ogg Vorbis normalization support [installed]
+Required By : None
+Optional For : None
+Conflicts With : None
+Replaces : None
+Installed Size : 334.00 KiB
+Packager : Alexander Rødseth <rodseth@gmail.com>
+Build Date : Wed Apr 26 02:04:21 2017
+Install Date : Fri May 5 15:36:23 2017
+Install Reason : Explicitly installed
+Install Script : No
+Validated By : Signature
diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb
index a97c3280..5e5d922f 100644
--- a/spec/unit/plugins/packages_spec.rb
+++ b/spec/unit/plugins/packages_spec.rb
@@ -102,6 +102,43 @@ describe Ohai::System, "plugin packages" do
end
end
+ context "on arch" do
+ let(:plugin) do
+ get_plugin("packages").tap do |plugin|
+ plugin[:platform_family] = "arch"
+ end
+ end
+
+ let(:stdout) do
+ File.read(File.join(SPEC_PLUGIN_PATH, "pacman.output"))
+ end
+
+ before(:each) do
+ allow(plugin).to receive(:collect_os).and_return(:linux)
+ allow(plugin).to receive(:shell_out).with("LANG=C pacman -Qi").and_return(mock_shell_out(0, stdout, ""))
+ plugin.run
+ end
+
+ it "calls LANG=C pacman -Qi" do
+ expect(plugin).to receive(:shell_out)
+ .with("LANG=C pacman -Qi")
+ .and_return(mock_shell_out(0, stdout, ""))
+ plugin.run
+ end
+
+ it "gets packages and versions/release - normal case" do
+ expect(plugin[:packages]["acl"][:version]).to eq("2.2.52-3")
+ expect(plugin[:packages]["acl"][:installdate]).to eq("1500780345")
+ expect(plugin[:packages]["acl"][:arch]).to eq("x86_64")
+ end
+
+ it "gets packages and versions/release - multiline optdeps" do
+ expect(plugin[:packages]["abcde"][:version]).to eq("2.8.1-2")
+ expect(plugin[:packages]["abcde"][:installdate]).to eq("1493998583")
+ expect(plugin[:packages]["abcde"][:arch]).to eq("any")
+ end
+ end
+
context "on windows", :windows_only do
let(:plugin) do