ohai 13.3.0 → 13.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ohai/mixin/azure_metadata.rb +53 -0
  3. data/lib/ohai/plugins/aix/uptime.rb +25 -10
  4. data/lib/ohai/plugins/azure.rb +68 -8
  5. data/lib/ohai/plugins/cloud.rb +4 -2
  6. data/lib/ohai/plugins/digital_ocean.rb +3 -3
  7. data/lib/ohai/plugins/dragonflybsd/os.rb +1 -2
  8. data/lib/ohai/plugins/ec2.rb +24 -16
  9. data/lib/ohai/plugins/eucalyptus.rb +4 -4
  10. data/lib/ohai/plugins/freebsd/os.rb +1 -2
  11. data/lib/ohai/plugins/gce.rb +3 -3
  12. data/lib/ohai/plugins/hostname.rb +3 -3
  13. data/lib/ohai/plugins/linux/cpu.rb +33 -2
  14. data/lib/ohai/plugins/linux/filesystem.rb +47 -39
  15. data/lib/ohai/plugins/linux/systemd_paths.rb +3 -4
  16. data/lib/ohai/plugins/linux/virtualization.rb +6 -2
  17. data/lib/ohai/plugins/network.rb +2 -3
  18. data/lib/ohai/plugins/openstack.rb +2 -3
  19. data/lib/ohai/plugins/os.rb +1 -2
  20. data/lib/ohai/plugins/packages.rb +28 -2
  21. data/lib/ohai/plugins/passwd.rb +1 -2
  22. data/lib/ohai/plugins/rackspace.rb +1 -2
  23. data/lib/ohai/plugins/shard.rb +1 -2
  24. data/lib/ohai/plugins/softlayer.rb +1 -2
  25. data/lib/ohai/plugins/solaris2/virtualization.rb +1 -2
  26. data/lib/ohai/plugins/uptime.rb +1 -2
  27. data/lib/ohai/version.rb +1 -1
  28. data/spec/data/plugins/pacman.output +51 -0
  29. data/spec/unit/mixin/azure_metadata_spec.rb +67 -0
  30. data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
  31. data/spec/unit/plugins/aix/uptime_spec.rb +7 -9
  32. data/spec/unit/plugins/azure_spec.rb +81 -0
  33. data/spec/unit/plugins/cloud_spec.rb +37 -5
  34. data/spec/unit/plugins/ec2_spec.rb +34 -12
  35. data/spec/unit/plugins/linux/cpu_spec.rb +123 -87
  36. data/spec/unit/plugins/linux/filesystem_spec.rb +12 -0
  37. data/spec/unit/plugins/linux/virtualization_spec.rb +11 -0
  38. data/spec/unit/plugins/packages_spec.rb +37 -0
  39. metadata +6 -3
@@ -16,13 +16,12 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "ohai/util/file_helper"
20
-
21
- include Ohai::Util::FileHelper
22
-
23
19
  Ohai.plugin(:SystemdPaths) do
24
20
  provides "systemd_paths"
25
21
 
22
+ require "ohai/util/file_helper"
23
+ include Ohai::Util::FileHelper
24
+
26
25
  collect_data(:linux) do
27
26
  systemd_path_path = which("systemd-path")
28
27
  if systemd_path_path
@@ -16,9 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "ohai/mixin/dmi_decode"
20
-
21
19
  Ohai.plugin(:Virtualization) do
20
+ require "ohai/mixin/dmi_decode"
22
21
  include Ohai::Mixin::DmiDecode
23
22
  provides "virtualization"
24
23
 
@@ -186,6 +185,11 @@ Ohai.plugin(:Virtualization) do
186
185
  virtualization[:system] = $1
187
186
  virtualization[:role] = "guest"
188
187
  virtualization[:systems][$1.to_sym] = "guest"
188
+ elsif File.read("/proc/1/environ") =~ /container=lxc/
189
+ Ohai::Log.debug("Plugin Virtualization: /proc/1/environ indicates lxc container. Detecting as lxc guest")
190
+ virtualization[:system] = "lxc"
191
+ virtualization[:role] = "guest"
192
+ virtualization[:systems][:lxc] = "guest"
189
193
  elsif lxc_version_exists? && File.read("/proc/self/cgroup") =~ %r{\d:[^:]+:/$}
190
194
  # lxc-version shouldn't be installed by default
191
195
  # Even so, it is likely we are on an LXC capable host that is not being used as such
@@ -16,10 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "ipaddress"
20
- require "ohai/mixin/network_constants"
21
-
22
19
  Ohai.plugin(:NetworkAddresses) do
20
+ require "ipaddress"
21
+ require "ohai/mixin/network_constants"
23
22
  include Ohai::Mixin::NetworkConstants
24
23
 
25
24
  provides "ipaddress", "ip6address", "macaddress"
@@ -16,10 +16,9 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
- require "ohai/mixin/ec2_metadata"
20
- require "ohai/mixin/http_helper"
21
-
22
19
  Ohai.plugin(:Openstack) do
20
+ require "ohai/mixin/ec2_metadata"
21
+ require "ohai/mixin/http_helper"
23
22
  include Ohai::Mixin::Ec2Metadata
24
23
  include Ohai::Mixin::HttpHelper
25
24
 
@@ -16,9 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "ohai/mixin/os"
20
-
21
19
  Ohai.plugin(:OS) do
20
+ require "ohai/mixin/os"
22
21
  provides "os", "os_version"
23
22
  depends "kernel"
24
23
 
@@ -32,7 +32,8 @@ Ohai.plugin(:Packages) do
32
32
 
33
33
  collect_data(:linux) do
34
34
  packages Mash.new
35
- if %w{debian}.include? platform_family
35
+ case platform_family
36
+ when "debian"
36
37
  format = '${Package}\t${Version}\t${Architecture}\n'
37
38
  so = shell_out("dpkg-query -W -f='#{format}'")
38
39
  pkgs = so.stdout.lines
@@ -42,7 +43,7 @@ Ohai.plugin(:Packages) do
42
43
  packages[name] = { "version" => version, "arch" => arch }
43
44
  end
44
45
 
45
- elsif %w{rhel fedora suse pld}.include? platform_family
46
+ when "rhel", "fedora", "suse", "pld"
46
47
  format = '%{NAME}\t%|EPOCH?{%{EPOCH}}:{0}|\t%{VERSION}\t%{RELEASE}\t%{INSTALLTIME}\t%{ARCH}\n'
47
48
  so = shell_out("rpm -qa --qf '#{format}'")
48
49
  pkgs = so.stdout.lines
@@ -51,6 +52,31 @@ Ohai.plugin(:Packages) do
51
52
  name, epoch, version, release, installdate, arch = pkg.split
52
53
  packages[name] = { "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch }
53
54
  end
55
+
56
+ when "arch"
57
+ require "date"
58
+
59
+ # Set LANG=C to force an easy to parse date format
60
+ so = shell_out("LANG=C pacman -Qi")
61
+
62
+ so.stdout.split("\n\n").each do |record|
63
+ pacman_info = {}
64
+ record.lines.each do |line|
65
+ if line =~ /\A(.*?)\s+:\s(.*)\z/m
66
+ key, value = Regexp.last_match[1..2]
67
+ key = key.strip.downcase.gsub(/\s+/, "")
68
+ pacman_info[key] = value.strip
69
+ end
70
+ end
71
+
72
+ name = pacman_info["name"]
73
+ installdate = DateTime.strptime(pacman_info["installdate"], "%Ec").strftime("%s")
74
+ packages[name] = {
75
+ "version" => pacman_info["version"],
76
+ "installdate" => installdate,
77
+ "arch" => pacman_info["architecture"],
78
+ }
79
+ end
54
80
  end
55
81
  end
56
82
 
@@ -1,7 +1,6 @@
1
1
 
2
- require "etc"
3
-
4
2
  Ohai.plugin(:Passwd) do
3
+ require "etc"
5
4
  provides "etc", "current_user"
6
5
 
7
6
  def fix_encoding(str)
@@ -14,9 +14,8 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "resolv"
18
-
19
17
  Ohai.plugin(:Rackspace) do
18
+ require "resolv"
20
19
  provides "rackspace"
21
20
 
22
21
  depends "kernel", "network/interfaces"
@@ -16,9 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "digest/md5"
20
-
21
19
  Ohai.plugin(:ShardSeed) do
20
+ require "digest/md5"
22
21
  depends "hostname", "dmi", "machine_id", "machinename"
23
22
  provides "shard_seed"
24
23
 
@@ -18,9 +18,8 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
 
21
- require "ohai/mixin/softlayer_metadata"
22
-
23
21
  Ohai.plugin(:Softlayer) do
22
+ require "ohai/mixin/softlayer_metadata"
24
23
  include ::Ohai::Mixin::SoftlayerMetadata
25
24
 
26
25
  provides "softlayer"
@@ -18,9 +18,8 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require "ohai/mixin/dmi_decode"
22
-
23
21
  Ohai.plugin(:Virtualization) do
22
+ require "ohai/mixin/dmi_decode"
24
23
  include Ohai::Mixin::DmiDecode
25
24
  provides "virtualization"
26
25
 
@@ -24,9 +24,8 @@
24
24
  # limitations under the License.
25
25
  #
26
26
 
27
- require "ohai/mixin/seconds_to_human"
28
-
29
27
  Ohai.plugin(:Uptime) do
28
+ require "ohai/mixin/seconds_to_human"
30
29
  provides "uptime", "uptime_seconds"
31
30
  provides "idletime", "idletime_seconds" # linux only
32
31
  depends "platform_version"
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "13.3.0"
21
+ VERSION = "13.4.0"
22
22
  end
@@ -0,0 +1,51 @@
1
+ Name : acl
2
+ Version : 2.2.52-3
3
+ Description : Access control list utilities, libraries and headers
4
+ Architecture : x86_64
5
+ URL : http://savannah.nongnu.org/projects/acl
6
+ Licenses : LGPL
7
+ Groups : None
8
+ Provides : xfsacl
9
+ Depends On : attr>=2.4.46
10
+ Optional Deps : None
11
+ Required By : coreutils gettext libarchive logrotate sed shadow systemd tar
12
+ Optional For : None
13
+ Conflicts With : xfsacl
14
+ Replaces : xfsacl
15
+ Installed Size : 290.00 KiB
16
+ Packager : Bartlomiej Piotrowski <bpiotrowski@archlinux.org>
17
+ Build Date : Sun Nov 6 14:03:46 2016
18
+ Install Date : Sun Jul 23 03:25:45 2017
19
+ Install Reason : Installed as a dependency for another package
20
+ Install Script : No
21
+ Validated By : Signature
22
+
23
+ Name : abcde
24
+ Version : 2.8.1-2
25
+ 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
26
+ Architecture : any
27
+ URL : https://abcde.einval.com/
28
+ Licenses : GPL
29
+ Groups : None
30
+ Provides : None
31
+ Depends On : bash cd-discid wget vorbis-tools python2-eyed3
32
+ Optional Deps : cdparanoia: Paranoia ripping support [installed]
33
+ cdrkit: icedax ripping support [installed]
34
+ flac: FLAC encoding support [installed]
35
+ id3: ID3 v1 tag support
36
+ lame: MP3 encoding support [installed]
37
+ mp3gain: MP3 normalization support [installed]
38
+ perl-musicbrainz-discid: musicbrainz support (AUR)
39
+ perl-webservice-musicbrainz: musicbrainz support (AUR)
40
+ vorbisgain: Ogg Vorbis normalization support [installed]
41
+ Required By : None
42
+ Optional For : None
43
+ Conflicts With : None
44
+ Replaces : None
45
+ Installed Size : 334.00 KiB
46
+ Packager : Alexander Rødseth <rodseth@gmail.com>
47
+ Build Date : Wed Apr 26 02:04:21 2017
48
+ Install Date : Fri May 5 15:36:23 2017
49
+ Install Reason : Explicitly installed
50
+ Install Script : No
51
+ Validated By : Signature
@@ -0,0 +1,67 @@
1
+ #
2
+ # Author:: Tim Smith <tsmith@chef.io>
3
+ # Copyright:: 2017 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDIT"Net::HTTP Response"NS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require_relative "../../spec_helper.rb"
20
+ require "ohai/mixin/azure_metadata"
21
+
22
+ describe Ohai::Mixin::AzureMetadata do
23
+ let(:mixin) do
24
+ mixin = Object.new.extend(::Ohai::Mixin::AzureMetadata)
25
+ mixin
26
+ end
27
+
28
+ describe "#http_get" do
29
+ it "gets the passed URI" do
30
+ http_mock = double("http")
31
+ allow(http_mock).to receive(:read_timeout=)
32
+ allow(Net::HTTP).to receive(:start).with("169.254.169.254").and_return(http_mock)
33
+
34
+ expect(http_mock).to receive(:get).with("http://www.chef.io", initheader = { "Metadata" => "true" })
35
+ mixin.http_get("http://www.chef.io")
36
+ end
37
+ end
38
+
39
+ describe "#fetch_metadata" do
40
+ it "returns an empty hash given a non-200 response" do
41
+ http_mock = double("http", { :code => "500" })
42
+ allow(mixin).to receive(:http_get).and_return(http_mock)
43
+
44
+ expect(Ohai::Log).to receive(:warn)
45
+ vals = mixin.fetch_metadata
46
+ expect(vals).to eq(nil)
47
+ end
48
+
49
+ it "returns an empty hash given invalid JSON response" do
50
+ http_mock = double("http", { :code => "200", :body => '{ "foo" "bar"}' })
51
+ allow(mixin).to receive(:http_get).and_return(http_mock)
52
+
53
+ expect(Ohai::Log).to receive(:warn)
54
+ vals = mixin.fetch_metadata
55
+ expect(vals).to eq(nil)
56
+ end
57
+
58
+ it "returns a populated hash given valid JSON response" do
59
+ http_mock = double("http", { :code => "200", :body => '{ "foo": "bar"}' })
60
+ allow(mixin).to receive(:http_get).and_return(http_mock)
61
+
62
+ expect(Ohai::Log).not_to receive(:warn)
63
+ vals = mixin.fetch_metadata
64
+ expect(vals).to eq({ "foo" => "bar" })
65
+ end
66
+ end
67
+ end
@@ -36,7 +36,7 @@ describe ::Ohai::Mixin::SoftlayerMetadata do
36
36
  end
37
37
 
38
38
  context "fetch_metadata" do
39
- it "riases error if softlayer api query results with error" do
39
+ it "raises error if softlayer api query results with error" do
40
40
  http_mock = double("http", { :ssl_version= => true, :use_ssl= => true, :ca_file= => true })
41
41
  allow(http_mock).to receive(:get).and_raise(StandardError.new("API return fake error"))
42
42
  allow(::Net::HTTP).to receive(:new).with("api.service.softlayer.com", 443).and_return(http_mock)
@@ -23,19 +23,17 @@ describe Ohai::System, "Aix plugin uptime" do
23
23
  before(:each) do
24
24
  @plugin = get_plugin("aix/uptime")
25
25
  allow(@plugin).to receive(:collect_os).and_return(:aix)
26
- allow(Time).to receive_message_chain(:now, :to_i).and_return(1412072511)
27
- allow(Time).to receive_message_chain(:now, :zone).and_return("IST")
28
- allow(DateTime).to receive_message_chain(:parse, :strftime, :to_i).and_return(1411561320)
29
- allow(@plugin).to receive(:shell_out).with("who -b").and_return(mock_shell_out(0, " . system boot Sep 24 17:52", nil))
30
-
26
+ allow(@plugin).to receive(:shell_out).and_call_original
27
+ allow(Time).to receive_message_chain(:now, :to_i).and_return(1504287957)
28
+ allow(@plugin).to receive(:shell_out).with("LC_ALL=POSIX ps -o etime= -p 1").and_return(mock_shell_out(0, "1148-20:54:50", nil))
31
29
  @plugin.run
32
30
  end
33
31
 
34
- it "should set uptime_seconds to uptime" do
35
- expect(@plugin[:uptime_seconds]).to eq(511191)
32
+ it "should set uptime_seconds to uptime with days" do
33
+ expect(@plugin[:uptime_seconds]).to eq(1405025467)
36
34
  end
37
35
 
38
- it "should set uptime to a human readable date" do
39
- expect(@plugin[:uptime]).to eq("5 days 21 hours 59 minutes 51 seconds")
36
+ it "should set uptime to a human readable date with days" do
37
+ expect(@plugin[:uptime]).to eq("1148 days 20 hours 54 minutes 50 seconds")
40
38
  end
41
39
  end
@@ -31,6 +31,33 @@ describe Ohai::System, "plugin azure" do
31
31
  }
32
32
  end
33
33
 
34
+ let(:response_data) do
35
+ { "compute" => { "location" => "westus",
36
+ "name" => "timtest",
37
+ "offer" => "UbuntuServer",
38
+ "osType" => "Linux",
39
+ "platformFaultDomain" => "0",
40
+ "platformUpdateDomain" => "0",
41
+ "publisher" => "Canonical",
42
+ "sku" => "16.04-LTS",
43
+ "version" => "16.04.201707270",
44
+ "vmId" => "f78151b3-da8b-4bd8-a592-d9ce8a57ea65",
45
+ "vmSize" => "Standard_DS2_v2" },
46
+ "network" => { "interface" => [ { "ipv4" =>
47
+ { "ipAddress" => [{ "privateIpAddress" => "10.0.1.6", "publicIpAddress" => "40.118.212.225" }],
48
+ "subnet" => [{ "address" => "10.0.1.0", "prefix" => "24" }] },
49
+ "ipv6" =>
50
+ { "ipAddress" => [] },
51
+ "macAddress" => "000D3A37F080" }] } }
52
+ end
53
+
54
+ before do
55
+ # skips all the metadata logic unless we want to test it
56
+ allow(plugin).to receive(:can_socket_connect?).
57
+ with(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80).
58
+ and_return(false)
59
+ end
60
+
34
61
  shared_examples_for "!azure" do
35
62
  it "does not set the azure attribute" do
36
63
  plugin.run
@@ -42,6 +69,7 @@ describe Ohai::System, "plugin azure" do
42
69
  it "sets the azure attribute" do
43
70
  plugin.run
44
71
  expect(plugin[:azure]).to be_truthy
72
+ expect(plugin[:azure]).to have_key(:metadata)
45
73
  end
46
74
  end
47
75
 
@@ -159,4 +187,57 @@ describe Ohai::System, "plugin azure" do
159
187
  it_behaves_like "azure"
160
188
  end
161
189
 
190
+ describe "with non-responsive metadata endpoint" do
191
+ before(:each) do
192
+ allow(plugin).to receive(:hint?).with("azure").and_return({})
193
+ end
194
+
195
+ it "does not return metadata information" do
196
+ allow(plugin).to receive(:can_socket_connect?).
197
+ with(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80).
198
+ and_return(true)
199
+ allow(plugin).to receive(:fetch_metadata).and_return(nil)
200
+
201
+ plugin.run
202
+ expect(plugin[:azure]).to have_key(:metadata)
203
+ expect(plugin[:azure][:metadata]).to be_nil
204
+ end
205
+ end
206
+
207
+ describe "with responsive metadata endpoint" do
208
+ before(:each) do
209
+ allow(plugin).to receive(:hint?).with("azure").and_return({})
210
+ allow(plugin).to receive(:can_socket_connect?).
211
+ with(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80).
212
+ and_return(true)
213
+ allow(plugin).to receive(:fetch_metadata).and_return(response_data)
214
+ plugin.run
215
+ end
216
+
217
+ it "returns metadata compute information" do
218
+ expect(plugin[:azure][:metadata][:compute][:location]).to eq("westus")
219
+ expect(plugin[:azure][:metadata][:compute][:name]).to eq("timtest")
220
+ expect(plugin[:azure][:metadata][:compute][:offer]).to eq("UbuntuServer")
221
+ expect(plugin[:azure][:metadata][:compute][:osType]).to eq("Linux")
222
+ expect(plugin[:azure][:metadata][:compute][:platformFaultDomain]).to eq("0")
223
+ expect(plugin[:azure][:metadata][:compute][:platformUpdateDomain]).to eq("0")
224
+ expect(plugin[:azure][:metadata][:compute][:publisher]).to eq("Canonical")
225
+ expect(plugin[:azure][:metadata][:compute][:sku]).to eq("16.04-LTS")
226
+ expect(plugin[:azure][:metadata][:compute][:version]).to eq("16.04.201707270")
227
+ expect(plugin[:azure][:metadata][:compute][:vmId]).to eq("f78151b3-da8b-4bd8-a592-d9ce8a57ea65")
228
+ expect(plugin[:azure][:metadata][:compute][:vmSize]).to eq("Standard_DS2_v2")
229
+ end
230
+
231
+ it "returns metadata network information" do
232
+ expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:mac]).to eq("000D3A37F080")
233
+ expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:public_ipv6]).to eq([])
234
+ expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:public_ipv4]).to eq(["40.118.212.225"])
235
+ expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:local_ipv6]).to eq([])
236
+ expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:local_ipv4]).to eq(["10.0.1.6"])
237
+ expect(plugin[:azure][:metadata][:network][:public_ipv6]).to eq([])
238
+ expect(plugin[:azure][:metadata][:network][:public_ipv4]).to eq(["40.118.212.225"])
239
+ expect(plugin[:azure][:metadata][:network][:local_ipv6]).to eq([])
240
+ expect(plugin[:azure][:metadata][:network][:local_ipv4]).to eq(["10.0.1.6"])
241
+ end
242
+ end
162
243
  end