ohai 13.6.0 → 13.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f877e6723a132a880743b84ab9a9d6a0ede623eb
4
- data.tar.gz: 7bb2833e7c7d12bc8207608bf14f93b266e48371
3
+ metadata.gz: 29f7dbc2f6ba160d4cc5a90e112804e12338cb76
4
+ data.tar.gz: 1a6a50e9261b97ea92348d64cbf3e2bdc97717ab
5
5
  SHA512:
6
- metadata.gz: b7b5ff8c56d7f071ac3278e345c91bd8df4f9a5e4e07fd4aec0a714833f1debaabc02a588d6ca2b5c43595d8799662410d6ec95cca4b9fb84a641358ccfb4c06
7
- data.tar.gz: d062c3f9b9595a699be681be9d3b1a8bb6513e61fefc7662fbc3e88f0f5063dbe2b640997e4957e0ff4667b79023e4016e114ba68c34d288b6c2e27479b22e40
6
+ metadata.gz: 35f52d079c7a4dc1b0dfaf70c8977b808c11d36d3069888a4967973d14d70326581a22539a7f3fee2b85345b325bfd78a91cfeb52792d64c5e98bcc30f8ace74
7
+ data.tar.gz: 85006bb7724517c6edeed48cabffbb806b8d5e638fa5481d7f354965159e19c28778185bd282a184fa1f6e2498fdf566ed2a0319adfc1d89176f853e56fed58f
data/bin/ohai CHANGED
@@ -19,23 +19,8 @@
19
19
  # limitations under the License.
20
20
  #
21
21
 
22
- begin
23
- require "rubygems"
24
- rescue LoadError
25
- # must be debian! ;)
26
- missing_rubygems = true
27
- end
28
- begin
29
- # if we're in a source code checkout, we want to run the code from that.
30
- # have to do this *after* rubygems is loaded.
31
- $:.unshift File.expand_path("../../lib", __FILE__)
32
- require "ohai/application"
33
- rescue LoadError
34
- if missing_rubygems
35
- STDERR.puts "rubygems previously failed to load - is it installed?"
36
- end
37
-
38
- raise
39
- end
22
+ # if we're in a source code checkout, we want to run the code from that.
23
+ $:.unshift File.expand_path("../../lib", __FILE__)
24
+ require "ohai/application"
40
25
 
41
26
  Ohai::Application.new.run
@@ -44,7 +44,7 @@ module Ohai
44
44
  nil
45
45
  end
46
46
  else
47
- Ohai::Log.warn("Mixin AzureMetadata: Received resonse code #{response.code} requesting metadata")
47
+ Ohai::Log.warn("Mixin AzureMetadata: Received response code #{response.code} requesting metadata")
48
48
  nil
49
49
  end
50
50
  end
@@ -35,7 +35,7 @@ module Ohai
35
35
  parser = FFI_Yajl::Parser.new
36
36
  parser.parse(response.body)
37
37
  when "404"
38
- Ohai::Log.debug("Mixin DOMetadata: Encountered 404 response retreiving Digital Ocean metadata: #{uri} ; continuing.")
38
+ Ohai::Log.debug("Mixin DOMetadata: Encountered 404 response retrieving Digital Ocean metadata: #{uri} ; continuing.")
39
39
  {}
40
40
  else
41
41
  raise "Mixin DOMetadata: Encountered error retrieving Digital Ocean metadata (#{uri} returned #{response.code} response)"
@@ -94,7 +94,7 @@ module Ohai
94
94
  when "200"
95
95
  response.body
96
96
  when "404"
97
- Ohai::Log.debug("Mixin EC2: Encountered 404 response retreiving EC2 metadata path: #{path} ; continuing.")
97
+ Ohai::Log.debug("Mixin EC2: Encountered 404 response retrieving EC2 metadata path: #{path} ; continuing.")
98
98
  nil
99
99
  else
100
100
  raise "Mixin EC2: Encountered error retrieving EC2 metadata (#{path} returned #{response.code} response)"
@@ -134,6 +134,7 @@ Ohai.plugin(:C) do
134
134
  end
135
135
  end
136
136
  rescue Ohai::Exceptions::Exec
137
+ Ohai::Log.debug("Plugin C: 'xlc' binary could not be found. Skipping data.")
137
138
  end
138
139
 
139
140
  def collect_sunpro
@@ -298,7 +298,7 @@ Ohai.plugin(:Cloud) do
298
298
  collect_data do
299
299
  require "ipaddr"
300
300
 
301
- @cloud_attr_obj = CloudAttrs.new()
301
+ @cloud_attr_obj = CloudAttrs.new
302
302
 
303
303
  get_gce_values if on_gce?
304
304
  get_ec2_values if on_ec2?
@@ -21,7 +21,8 @@
21
21
  # How we detect EC2 from easiest to hardest & least reliable
22
22
  # 1. Ohai ec2 hint exists. This always works
23
23
  # 2. Xen hypervisor UUID starts with 'ec2'. This catches Linux HVM & paravirt instances
24
- # 3. DMI data mentions amazon. This catches HVM instances in a VPC
24
+ # 3. DMI bios version data mentions amazon. This catches HVM instances in a VPC on the Xen based hypervisor
25
+ # 3. DMI bios vendor data mentions amazon. This catches HVM instances in a VPC on the non-Xen based hypervisor
25
26
  # 4. Kernel data mentioned Amazon. This catches Windows HVM & paravirt instances
26
27
 
27
28
  Ohai.plugin(:EC2) do
@@ -33,32 +34,43 @@ Ohai.plugin(:EC2) do
33
34
  include Ohai::Mixin::HttpHelper
34
35
 
35
36
  provides "ec2"
36
- depends "dmi"
37
37
 
38
- # look for amazon string in dmi bios data
38
+ # look for amazon string in dmi vendor bios data within the sys tree.
39
+ # this works even if the system lacks dmidecode use by the Dmi plugin
40
+ # this gets us detection of new Xen-less HVM instances that are within a VPC
41
+ # @return [Boolean] do we have Amazon DMI data?
42
+ def has_ec2_amazon_dmi?
43
+ # detect a version of '4.2.amazon'
44
+ if file_val_if_exists("/sys/class/dmi/id/bios_vendor") =~ /Amazon/
45
+ Ohai::Log.debug("Plugin EC2: has_ec2_amazon_dmi? == true")
46
+ true
47
+ else
48
+ Ohai::Log.debug("Plugin EC2: has_ec2_amazon_dmi? == false")
49
+ false
50
+ end
51
+ end
52
+
53
+ # look for amazon string in dmi bios version data within the sys tree.
54
+ # this works even if the system lacks dmidecode use by the Dmi plugin
39
55
  # this gets us detection of HVM instances that are within a VPC
40
56
  # @return [Boolean] do we have Amazon DMI data?
41
- def has_ec2_dmi?
57
+ def has_ec2_xen_dmi?
42
58
  # detect a version of '4.2.amazon'
43
- if get_attribute(:dmi, :bios, :all_records, 0, :Version) =~ /amazon/
44
- Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == true")
59
+ if file_val_if_exists("/sys/class/dmi/id/bios_version") =~ /amazon/
60
+ Ohai::Log.debug("Plugin EC2: has_ec2_xen_dmi? == true")
45
61
  true
46
62
  else
47
- Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == false")
63
+ Ohai::Log.debug("Plugin EC2: has_ec2_xen_dmi? == false")
48
64
  false
49
65
  end
50
66
  end
51
67
 
52
- # looks for a xen UUID that starts with ec2
53
- # uses the sys tree on Linux and a WMI query on windows
54
- # this gets us detection of HVM and Paravirt hosts
68
+ # looks for a xen UUID that starts with ec2 from within the Linux sys tree
55
69
  # @return [Boolean] do we have a Xen UUID or not?
56
70
  def has_ec2_xen_uuid?
57
- if ::File.exist?("/sys/hypervisor/uuid")
58
- if ::File.read("/sys/hypervisor/uuid") =~ /^ec2/
59
- Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == true")
60
- return true
61
- end
71
+ if file_val_if_exists("/sys/hypervisor/uuid") =~ /^ec2/
72
+ Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == true")
73
+ return true
62
74
  end
63
75
  Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == false")
64
76
  false
@@ -82,13 +94,22 @@ Ohai.plugin(:EC2) do
82
94
  end
83
95
  end
84
96
 
97
+ # return the contents of a file if the file exists
98
+ # @param path[String] abs path to the file
99
+ # @return [String] contents of the file if it exists
100
+ def file_val_if_exists(path)
101
+ if ::File.exist?(path)
102
+ ::File.read(path)
103
+ end
104
+ end
105
+
85
106
  # a single check that combines all the various detection methods for EC2
86
107
  # @return [Boolean] Does the system appear to be on EC2
87
108
  def looks_like_ec2?
88
109
  return true if hint?("ec2")
89
110
 
90
111
  # Even if it looks like EC2 try to connect first
91
- if has_ec2_xen_uuid? || has_ec2_dmi? || has_ec2_identifying_number?
112
+ if has_ec2_xen_uuid? || has_ec2_amazon_dmi? || has_ec2_xen_dmi? || has_ec2_identifying_number?
92
113
  return true if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
93
114
  end
94
115
  end
@@ -64,10 +64,35 @@ Ohai.plugin(:Mdadm) do
64
64
  # unless the array is inactive, in which case you don't get a raid
65
65
  # level.
66
66
  members = pieces.drop_while { |x| !x.start_with?("raid", "inactive") }
67
- # drop the 'raid' too
68
-
67
+ # and drop that too
69
68
  members.shift unless members.empty?
70
- devices[device] = members.map { |s| s.match(/(.+)\[\d\]/)[1] }
69
+ devices[device] = {
70
+ "active" => [],
71
+ "spare" => [],
72
+ "journal" => nil,
73
+ }
74
+ members.each do |member|
75
+ # We want to match the device, and optionally the type
76
+ # most entries will look like:
77
+ # sdc1[5]
78
+ # but some will look like:
79
+ # sdc1[5](J)
80
+ # where the format is:
81
+ # <device>[<number in array>](<type>)
82
+ # Type can be things like "J" for a journal device, or "S" for
83
+ # a spare device.
84
+ m = member.match(/(.+)\[\d+\](?:\((\w)\))?/)
85
+ member_device = m[1]
86
+ member_type = m[2]
87
+ case member_type
88
+ when "J"
89
+ devices[device]["journal"] = member_device
90
+ when "S"
91
+ devices[device]["spare"] << member_device
92
+ else
93
+ devices[device]["active"] << member_device
94
+ end
95
+ end
71
96
  end
72
97
  end
73
98
 
@@ -82,7 +107,9 @@ Ohai.plugin(:Mdadm) do
82
107
 
83
108
  # if the mdadm command was sucessful pass so.stdout to create_raid_device_mash to grab the tidbits we want
84
109
  mdadm[device] = create_raid_device_mash(so.stdout) if so.stdout
85
- mdadm[device]["members"] = devices[device]
110
+ mdadm[device]["members"] = devices[device]["active"]
111
+ mdadm[device]["spares"] = devices[device]["spare"]
112
+ mdadm[device]["journal"] = devices[device]["journal"]
86
113
  end
87
114
  end
88
115
  end
@@ -30,6 +30,8 @@ Ohai.plugin(:Memory) do
30
30
  memory[:total] = "#{$1}#{$2}"
31
31
  when /^MemFree:\s+(\d+) (.+)$/
32
32
  memory[:free] = "#{$1}#{$2}"
33
+ when /^MemAvailable:\s+(\d+) (.+)$/
34
+ memory[:available] = "#{$1}#{$2}"
33
35
  when /^Buffers:\s+(\d+) (.+)$/
34
36
  memory[:buffers] = "#{$1}#{$2}"
35
37
  when /^Cached:\s+(\d+) (.+)$/
@@ -249,7 +249,7 @@ Ohai.plugin(:Platform) do
249
249
  platform_version `uname -r`.strip
250
250
  elsif File.exist?("/etc/alpine-release")
251
251
  platform "alpine"
252
- platform_version File.read("/etc/alpine-release").strip()
252
+ platform_version File.read("/etc/alpine-release").strip
253
253
  elsif File.exist?("/usr/lib/os-release")
254
254
  contents = File.read("/usr/lib/os-release")
255
255
  if /Clear Linux/ =~ contents
@@ -159,7 +159,7 @@ Ohai.plugin(:Virtualization) do
159
159
  end
160
160
  end
161
161
 
162
- # Detect LXC/Docker
162
+ # Detect LXC/Docker/Nspawn
163
163
  #
164
164
  # /proc/self/cgroup will look like this inside a docker container:
165
165
  # <index #>:<subsystem>:/lxc/<hexadecimal container id>
@@ -190,6 +190,11 @@ Ohai.plugin(:Virtualization) do
190
190
  virtualization[:system] = "lxc"
191
191
  virtualization[:role] = "guest"
192
192
  virtualization[:systems][:lxc] = "guest"
193
+ elsif File.read("/proc/1/environ") =~ /container=systemd-nspawn/
194
+ Ohai::Log.debug("Plugin Virtualization: /proc/1/environ indicates nspawn container. Detecting as nspawn guest")
195
+ virtualization[:system] = "nspawn"
196
+ virtualization[:role] = "guest"
197
+ virtualization[:systems][:nspawn] = "guest"
193
198
  elsif lxc_version_exists? && File.read("/proc/self/cgroup") =~ %r{\d:[^:]+:/$}
194
199
  # lxc-version shouldn't be installed by default
195
200
  # Even so, it is likely we are on an LXC capable host that is not being used as such
@@ -62,7 +62,7 @@ module Ohai
62
62
  @loader = Ohai::Loader.new(self)
63
63
  @runner = Ohai::Runner.new(self, true)
64
64
 
65
- Ohai::Hints.refresh_hints()
65
+ Ohai::Hints.refresh_hints
66
66
 
67
67
  # Remove the previously defined plugins
68
68
  recursive_remove_constants(Ohai::NamedPlugin)
@@ -193,7 +193,7 @@ module Ohai
193
193
  # This method takes a naive approach to v6 plugins: it simply re-runs all
194
194
  # of them whenever called.
195
195
  def refresh_plugins(attribute_filter = nil)
196
- Ohai::Hints.refresh_hints()
196
+ Ohai::Hints.refresh_hints
197
197
  @provides_map.all_plugins(attribute_filter).each do |plugin|
198
198
  plugin.reset!
199
199
  end
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "13.6.0"
21
+ VERSION = "13.7.0"
22
22
  end
@@ -39,7 +39,7 @@ describe "CloudAttrs object" do
39
39
  end
40
40
 
41
41
  it "populates cloud mash" do
42
- @cloud_attr_obj = ::CloudAttrs.new()
42
+ @cloud_attr_obj = ::CloudAttrs.new
43
43
  @cloud_attr_obj.add_ipv4_addr("1.2.3.1", :public)
44
44
  @cloud_attr_obj.add_ipv4_addr("1.2.4.1", :private)
45
45
  @cloud_attr_obj.add_ipv6_addr("3ffe:505:2::1", :public)
@@ -51,22 +51,22 @@ describe "CloudAttrs object" do
51
51
  end
52
52
 
53
53
  it "throws exception with a bad ipv4 address" do
54
- @cloud_attr_obj = ::CloudAttrs.new()
54
+ @cloud_attr_obj = ::CloudAttrs.new
55
55
  expect { @cloud_attr_obj.add_ipv6_addr("somebogusstring", :public) }.to raise_error(RuntimeError)
56
56
  end
57
57
 
58
58
  it "throws exception with a bad ipv6 address" do
59
- @cloud_attr_obj = ::CloudAttrs.new()
59
+ @cloud_attr_obj = ::CloudAttrs.new
60
60
  expect { @cloud_attr_obj.add_ipv6_addr("FEED:B0B:DEAD:BEEF", :public) }.to raise_error(RuntimeError)
61
61
  end
62
62
 
63
63
  it "throws exception with ipv6 address passed to ipv4" do
64
- @cloud_attr_obj = ::CloudAttrs.new()
64
+ @cloud_attr_obj = ::CloudAttrs.new
65
65
  expect { @cloud_attr_obj.add_ipv4_addr("3ffe:506:2::1", :public) }.to raise_error(RuntimeError)
66
66
  end
67
67
 
68
68
  it "throws exception with ipv4 address passed to ipv6" do
69
- @cloud_attr_obj = ::CloudAttrs.new()
69
+ @cloud_attr_obj = ::CloudAttrs.new
70
70
  expect { @cloud_attr_obj.add_ipv6_addr("1.2.3.4", :public) }.to raise_error(RuntimeError)
71
71
  end
72
72
 
@@ -28,6 +28,8 @@ describe Ohai::System, "plugin ec2" do
28
28
  before(:each) do
29
29
  allow(plugin).to receive(:hint?).with("ec2").and_return(false)
30
30
  allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(false)
31
+ allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(false)
32
+ allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(false)
31
33
  end
32
34
 
33
35
  shared_examples_for "!ec2" do
@@ -332,11 +334,39 @@ describe Ohai::System, "plugin ec2" do
332
334
  end
333
335
  end # shared examples for ec2
334
336
 
335
- describe "with ec2 dmi data" do
337
+ describe "with amazon dmi bios version data" do
336
338
  it_behaves_like "ec2"
337
339
 
338
340
  before(:each) do
339
- plugin[:dmi] = { :bios => { :all_records => [ { :Version => "4.2.amazon" } ] } }
341
+ allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
342
+ allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("4.2.amazon\n")
343
+ end
344
+ end
345
+
346
+ describe "with non-amazon dmi bios version data" do
347
+ it_behaves_like "!ec2"
348
+
349
+ before(:each) do
350
+ allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
351
+ allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("1.0\n")
352
+ end
353
+ end
354
+
355
+ describe "with amazon dmi bios vendor data" do
356
+ it_behaves_like "ec2"
357
+
358
+ before(:each) do
359
+ allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
360
+ allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Amazon EC2\n")
361
+ end
362
+ end
363
+
364
+ describe "with non-amazon dmi bios vendor data" do
365
+ it_behaves_like "!ec2"
366
+
367
+ before(:each) do
368
+ allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
369
+ allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Xen\n")
340
370
  end
341
371
  end
342
372
 
@@ -345,7 +375,7 @@ describe Ohai::System, "plugin ec2" do
345
375
 
346
376
  before(:each) do
347
377
  allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
348
- allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8")
378
+ allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
349
379
  end
350
380
  end
351
381
 
@@ -354,7 +384,7 @@ describe Ohai::System, "plugin ec2" do
354
384
 
355
385
  before(:each) do
356
386
  allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
357
- allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8")
387
+ allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
358
388
  end
359
389
  end
360
390
 
@@ -106,6 +106,20 @@ MD
106
106
  )
107
107
  end
108
108
 
109
+ it "should detect member devices even if there are multi-digit numbers" do
110
+ new_mdstat = double("/proc/mdstat2")
111
+ allow(new_mdstat).to receive(:each).
112
+ and_yield("Personalities : [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid10]").
113
+ and_yield("md0 : active raid10 sdj[2010] sdi[99] sdh[5] sdg[4] sdf[3] sde[2] sdd[1] sdc[0]").
114
+ and_yield(" 2929893888 blocks super 1.2 256K chunks 2 near-copies [6/6] [UUUUUU]")
115
+ allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat)
116
+
117
+ @plugin.run
118
+ expect(@plugin[:mdadm][:md0][:members].sort).to eq(
119
+ %w{sdc sdd sde sdf sdg sdh sdi sdj}
120
+ )
121
+ end
122
+
109
123
  it "should detect member devices even if mdstat has extra entries" do
110
124
  new_mdstat = double("/proc/mdstat2")
111
125
  allow(new_mdstat).to receive(:each).
@@ -128,8 +142,29 @@ MD
128
142
  allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat)
129
143
 
130
144
  @plugin.run
131
- expect(@plugin[:mdadm][:md0][:members].sort).to eq(%w{nvme2n1p3})
145
+ expect(@plugin[:mdadm][:md0][:spares]).to eq(%w{nvme2n1p3})
132
146
  end
133
- end
134
147
 
148
+ it "should report journal devices" do
149
+ new_mdstat = double("/proc/mdstat_journal")
150
+ allow(new_mdstat).to receive(:each).
151
+ and_yield("Personalies : [raid6]").
152
+ and_yield("md0 : active (somecraphere) <morestuff raid6 sdbc1[7] sdd1[6] sde1[5] sdd1[4] sde1[3] sdf1[2] sdg1[1] nvme2n1p3[0](J)")
153
+ allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat)
154
+
155
+ @plugin.run
156
+ expect(@plugin[:mdadm][:md0][:journal]).to eq("nvme2n1p3")
157
+ end
158
+
159
+ it "should report spare devices" do
160
+ new_mdstat = double("/proc/mdstat_spare")
161
+ allow(new_mdstat).to receive(:each).
162
+ and_yield("Personalies : [raid6]").
163
+ and_yield("md0 : active (somecraphere) <morestuff raid6 sdbc1[7] sdd1[6] sde1[5] sdd1[4] sde1[3] sdf1[2] sdg1[1] sdh1[0](S)")
164
+ allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat)
165
+
166
+ @plugin.run
167
+ expect(@plugin[:mdadm][:md0][:spares]).to eq(%w{sdh1})
168
+ end
169
+ end
135
170
  end
@@ -24,6 +24,7 @@ describe Ohai::System, "Linux memory plugin" do
24
24
  allow(@double_file).to receive(:each).
25
25
  and_yield("MemTotal: 131932120 kB").
26
26
  and_yield("MemFree: 2269032 kB").
27
+ and_yield("MemAvailable: 9208922 kB").
27
28
  and_yield("Buffers: 646368 kB").
28
29
  and_yield("Cached: 32346556 kB").
29
30
  and_yield("SwapCached: 312 kB").
@@ -68,6 +69,11 @@ describe Ohai::System, "Linux memory plugin" do
68
69
  expect(@plugin[:memory][:free]).to eql("2269032kB")
69
70
  end
70
71
 
72
+ it "should get available memory" do
73
+ @plugin.run
74
+ expect(@plugin[:memory][:available]).to eql("9208922kB")
75
+ end
76
+
71
77
  it "should get memory used for file buffers" do
72
78
  @plugin.run
73
79
  expect(@plugin[:memory][:buffers]).to eql("646368kB")
@@ -40,6 +40,7 @@ describe Ohai::System, "Linux virtualization platform" do
40
40
  allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(false)
41
41
  allow(File).to receive(:exist?).with("/dev/lxd/sock").and_return(false)
42
42
  allow(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(false)
43
+ allow(File).to receive(:exist?).with("/proc/1/environ").and_return(false)
43
44
 
44
45
  # default the which wrappers to nil
45
46
  allow(plugin).to receive(:which).with("lxc-version").and_return(nil)
@@ -627,6 +628,18 @@ CGROUP
627
628
  end
628
629
  end
629
630
 
631
+ describe "when we are checking for systemd-nspawn" do
632
+ it "sets nspawn guest if /proc/1/environ has nspawn string in it" do
633
+ allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
634
+ one_environ = "container=systemd-nspawn_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3".chomp
635
+ allow(File).to receive(:read).with("/proc/1/environ").and_return(one_environ)
636
+ allow(File).to receive(:read).with("/proc/self/cgroup").and_return("")
637
+ plugin.run
638
+ expect(plugin[:virtualization][:system]).to eq("nspawn")
639
+ expect(plugin[:virtualization][:role]).to eq("guest")
640
+ end
641
+ end
642
+
630
643
  describe "when we are checking for docker" do
631
644
  it "sets docker guest if /proc/self/cgroup exist and there are /docker/<hexadecimal> mounts" do
632
645
  self_cgroup = <<-CGROUP
@@ -45,7 +45,7 @@ PSRemotingProtocolVersion 2.2
45
45
  END
46
46
  compat_version_array = ["1.0", "2.0", "3.0", "4.0"]
47
47
 
48
- allow(plugin).to receive(:shell_out).with(anything()).and_return(mock_shell_out(0, v4_output, ""))
48
+ allow(plugin).to receive(:shell_out).with(anything).and_return(mock_shell_out(0, v4_output, ""))
49
49
  allow(plugin).to receive(:parse_compatible_versions).and_return(compat_version_array)
50
50
  plugin.run
51
51
  expect(plugin.languages[:powershell][:version]).to eql("4.0")
@@ -79,12 +79,12 @@ describe "Ohai::System" do
79
79
  log_level = :debug
80
80
  Ohai.config[:log_level] = log_level
81
81
  expect(Ohai::Log).not_to receive(:level=).with(log_level)
82
- Ohai::System.new()
82
+ Ohai::System.new
83
83
  end
84
84
 
85
85
  it "does not resolve log_level when set to :auto" do
86
86
  expect(Ohai::Log).not_to receive(:level=).with(:info)
87
- Ohai::System.new()
87
+ Ohai::System.new
88
88
  end
89
89
  end
90
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.6.0
4
+ version: 13.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-24 00:00:00.000000000 Z
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: systemu