ohai 14.5.4 → 14.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ohai/application.rb +19 -0
  3. data/lib/ohai/exception.rb +1 -0
  4. data/lib/ohai/hints.rb +5 -0
  5. data/lib/ohai/log.rb +2 -0
  6. data/lib/ohai/plugins/cpu.rb +416 -0
  7. data/lib/ohai/plugins/darwin/hardware.rb +1 -7
  8. data/lib/ohai/plugins/darwin/system_profiler.rb +19 -19
  9. data/lib/ohai/plugins/filesystem.rb +326 -115
  10. data/lib/ohai/plugins/linux/platform.rb +1 -1
  11. data/lib/ohai/plugins/os.rb +16 -0
  12. data/lib/ohai/system.rb +12 -2
  13. data/lib/ohai/version.rb +1 -1
  14. data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
  15. data/spec/unit/plugins/aix/filesystem_spec.rb +23 -1
  16. data/spec/unit/plugins/darwin/cpu_spec.rb +3 -3
  17. data/spec/unit/plugins/freebsd/cpu_spec.rb +2 -2
  18. data/spec/unit/plugins/linux/cpu_spec.rb +3 -3
  19. data/spec/unit/plugins/linux/platform_spec.rb +2 -1
  20. data/spec/unit/plugins/os_spec.rb +33 -0
  21. data/spec/unit/plugins/solaris2/cpu_spec.rb +1 -1
  22. data/spec/unit/plugins/solaris2/filesystem.rb +355 -32
  23. data/spec/unit/plugins/windows/cpu_spec.rb +1 -1
  24. metadata +3 -18
  25. data/lib/ohai/plugins/aix/cpu.rb +0 -64
  26. data/lib/ohai/plugins/aix/filesystem.rb +0 -90
  27. data/lib/ohai/plugins/aix/os.rb +0 -30
  28. data/lib/ohai/plugins/darwin/cpu.rb +0 -50
  29. data/lib/ohai/plugins/dragonflybsd/cpu.rb +0 -58
  30. data/lib/ohai/plugins/dragonflybsd/os.rb +0 -31
  31. data/lib/ohai/plugins/freebsd/cpu.rb +0 -70
  32. data/lib/ohai/plugins/freebsd/os.rb +0 -32
  33. data/lib/ohai/plugins/linux/cpu.rb +0 -120
  34. data/lib/ohai/plugins/netbsd/cpu.rb +0 -50
  35. data/lib/ohai/plugins/openbsd/cpu.rb +0 -43
  36. data/lib/ohai/plugins/solaris2/cpu.rb +0 -70
  37. data/lib/ohai/plugins/solaris2/filesystem.rb +0 -106
  38. data/lib/ohai/plugins/windows/cpu.rb +0 -59
  39. data/spec/unit/plugins/aix/os_spec.rb +0 -35
  40. data/spec/unit/plugins/freebsd/os_spec.rb +0 -32
@@ -291,7 +291,7 @@ Ohai.plugin(:Platform) do
291
291
  # We have to do this for compatibility reasons, or older OS releases might get different
292
292
  # "platform" or "platform_version" attributes (e.g. SLES12, RHEL7).
293
293
  elsif File.exist?("/etc/os-release")
294
- platform os_release_info["ID"]
294
+ platform os_release_info["ID"] == "sles" ? "suse" : os_release_info["ID"] # SLES is wrong. We call it SUSE
295
295
  platform_version os_release_info["VERSION_ID"]
296
296
  # platform_family also does not need to be hardcoded anymore.
297
297
  # This would be the correct way, but we stick with "determine_platform_family" for compatibility reasons.
@@ -1,6 +1,9 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Author:: Isa Farnik (<isa@chef.io>)
4
+ # Author:: Richard Manyanza (<liseki@nyikacraftsmen.com>)
3
5
  # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
6
+ # Copyright:: Copyright (c) 2014 Richard Manyanza.
4
7
  # License:: Apache License, Version 2.0
5
8
  #
6
9
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +24,19 @@ Ohai.plugin(:OS) do
21
24
  provides "os", "os_version"
22
25
  depends "kernel"
23
26
 
27
+ collect_data(:aix) do
28
+ os collect_os
29
+ os_version shell_out("oslevel -s").stdout.strip
30
+ end
31
+
32
+ collect_data(:dragonflybsd, :freebsd) do
33
+ os collect_os
34
+
35
+ # This is __DragonFly_version / __FreeBSD_version. See sys/param.h or
36
+ # http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
37
+ os_version shell_out("sysctl -n kern.osreldate").stdout.split($/)[0]
38
+ end
39
+
24
40
  collect_data do
25
41
  os collect_os
26
42
  os_version kernel[:release]
@@ -32,6 +32,7 @@ require "ohai/config"
32
32
  require "ffi_yajl"
33
33
 
34
34
  module Ohai
35
+ # The class used by Ohai::Application and Chef to actually collect data
35
36
  class System
36
37
  include Ohai::Mixin::ConstantHelper
37
38
 
@@ -78,9 +79,10 @@ module Ohai
78
79
  @data[key]
79
80
  end
80
81
 
81
- # resets the system and loads then runs the plugins
82
+ # Resets the system and loads then runs the plugins. This is the primary method called
83
+ # to run the system.
82
84
  #
83
- # @param [Array<String>] attribute_filter
85
+ # @param [Array<String>] attribute_filter the attributes to run. All will be run if not specified
84
86
  # @return [void]
85
87
  def all_plugins(attribute_filter = nil)
86
88
  # Reset the system when all_plugins is called since this function
@@ -92,10 +94,18 @@ module Ohai
92
94
  run_plugins(true, attribute_filter)
93
95
  end
94
96
 
97
+ # load all plugins by calling Ohai::Loader.load_all
98
+ # @see Ohai::Loader.load_all
95
99
  def load_plugins
96
100
  @loader.load_all
97
101
  end
98
102
 
103
+ # run all plugins or those that match the attribute filter is provided
104
+ #
105
+ # @param safe [Boolean]
106
+ # @param [Array<String>] attribute_filter the attributes to run. All will be run if not specified
107
+ #
108
+ # @return [Mash]
99
109
  def run_plugins(safe = false, attribute_filter = nil)
100
110
  begin
101
111
  @provides_map.all_plugins(attribute_filter).each do |plugin|
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "14.5.4".freeze
21
+ VERSION = "14.6.2".freeze
22
22
  end
@@ -40,7 +40,7 @@ LSATTR_EL
40
40
  CPU 3 runs at 1654 MHz
41
41
  PMCYCLES_M
42
42
 
43
- @plugin = get_plugin("aix/cpu")
43
+ @plugin = get_plugin("cpu")
44
44
  allow(@plugin).to receive(:collect_os).and_return(:aix)
45
45
 
46
46
  allow(@plugin).to receive(:shell_out).with("lsdev -Cc processor").and_return(mock_shell_out(0, @lsdev_cc_processor, nil))
@@ -85,7 +85,7 @@ MOUNT
85
85
  192.168.1.11 /stage/middleware3 /stage/middleware4 nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
86
86
  MOUNT
87
87
 
88
- @plugin = get_plugin("aix/filesystem")
88
+ @plugin = get_plugin("filesystem")
89
89
  allow(@plugin).to receive(:collect_os).and_return(:aix)
90
90
  @plugin[:filesystem] = Mash.new
91
91
  end
@@ -101,22 +101,27 @@ MOUNT
101
101
 
102
102
  it "returns the filesystem block size" do
103
103
  expect(@plugin[:filesystem]["/dev/hd4"]["kb_size"]).to eq("2097152")
104
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["kb_size"]).to eq("2097152")
104
105
  end
105
106
 
106
107
  it "returns the filesystem used space in kb" do
107
108
  expect(@plugin[:filesystem]["/dev/hd4"]["kb_used"]).to eq("219796")
109
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["kb_used"]).to eq("219796")
108
110
  end
109
111
 
110
112
  it "returns the filesystem available space in kb" do
111
113
  expect(@plugin[:filesystem]["/dev/hd4"]["kb_available"]).to eq("1877356")
114
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["kb_available"]).to eq("1877356")
112
115
  end
113
116
 
114
117
  it "returns the filesystem capacity in percentage" do
115
118
  expect(@plugin[:filesystem]["/dev/hd4"]["percent_used"]).to eq("11%")
119
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["percent_used"]).to eq("11%")
116
120
  end
117
121
 
118
122
  it "returns the filesystem mounted location" do
119
123
  expect(@plugin[:filesystem]["/dev/hd4"]["mount"]).to eq("/")
124
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["mount"]).to eq("/")
120
125
  end
121
126
  end
122
127
 
@@ -124,14 +129,17 @@ MOUNT
124
129
 
125
130
  it "returns the filesystem mount location" do
126
131
  expect(@plugin[:filesystem]["/dev/hd4"]["mount"]).to eq("/")
132
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["mount"]).to eq("/")
127
133
  end
128
134
 
129
135
  it "returns the filesystem type" do
130
136
  expect(@plugin[:filesystem]["/dev/hd4"]["fs_type"]).to eq("jfs2")
137
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["fs_type"]).to eq("jfs2")
131
138
  end
132
139
 
133
140
  it "returns the filesystem mount options" do
134
141
  expect(@plugin[:filesystem]["/dev/hd4"]["mount_options"]).to eq(["rw", "log=/dev/hd8"])
142
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["mount_options"]).to eq(["rw", "log=/dev/hd8"])
135
143
  end
136
144
 
137
145
  # For entries like 192.168.1.11 /stage/middleware1 /stage/middleware2 nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
@@ -139,14 +147,17 @@ MOUNT
139
147
 
140
148
  it "returns the filesystem mount location" do
141
149
  expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware1"]["mount"]).to eq("/stage/middleware2")
150
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware1,/stage/middleware2"]["mount"]).to eq("/stage/middleware2")
142
151
  end
143
152
 
144
153
  it "returns the filesystem type" do
145
154
  expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware1"]["fs_type"]).to eq("nfs3")
155
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware1,/stage/middleware2"]["fs_type"]).to eq("nfs3")
146
156
  end
147
157
 
148
158
  it "returns the filesystem mount options" do
149
159
  expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware1"]["mount_options"]).to eq(["ro", "bg", "hard", "intr", "sec=sys"])
160
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware1,/stage/middleware2"]["mount_options"]).to eq(["ro", "bg", "hard", "intr", "sec=sys"])
150
161
  end
151
162
  end
152
163
  end
@@ -163,22 +174,27 @@ MOUNT
163
174
 
164
175
  it "returns the filesystem block size" do
165
176
  expect(@plugin[:filesystem]["Global:/"]["kb_size"]).to eq("10485760")
177
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["kb_size"]).to eq("10485760")
166
178
  end
167
179
 
168
180
  it "returns the filesystem used space in kb" do
169
181
  expect(@plugin[:filesystem]["Global:/"]["kb_used"]).to eq("130872")
182
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["kb_used"]).to eq("130872")
170
183
  end
171
184
 
172
185
  it "returns the filesystem available space in kb" do
173
186
  expect(@plugin[:filesystem]["Global:/"]["kb_available"]).to eq("10354888")
187
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["kb_available"]).to eq("10354888")
174
188
  end
175
189
 
176
190
  it "returns the filesystem capacity in percentage" do
177
191
  expect(@plugin[:filesystem]["Global:/"]["percent_used"]).to eq("2%")
192
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["percent_used"]).to eq("2%")
178
193
  end
179
194
 
180
195
  it "returns the filesystem mounted location" do
181
196
  expect(@plugin[:filesystem]["Global:/"]["mount"]).to eq("/")
197
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["mount"]).to eq("/")
182
198
  end
183
199
  end
184
200
 
@@ -186,14 +202,17 @@ MOUNT
186
202
 
187
203
  it "returns the filesystem mount location" do
188
204
  expect(@plugin[:filesystem]["Global:/"]["mount"]).to eq("/")
205
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["mount"]).to eq("/")
189
206
  end
190
207
 
191
208
  it "returns the filesystem type" do
192
209
  expect(@plugin[:filesystem]["Global:/"]["fs_type"]).to eq("jfs2")
210
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["fs_type"]).to eq("jfs2")
193
211
  end
194
212
 
195
213
  it "returns the filesystem mount options" do
196
214
  expect(@plugin[:filesystem]["Global:/"]["mount_options"]).to eq(["rw", "log=NULL"])
215
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["mount_options"]).to eq(["rw", "log=NULL"])
197
216
  end
198
217
 
199
218
  # For entries like 192.168.1.11 /stage/middleware3 /stage/middleware4 nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
@@ -201,14 +220,17 @@ MOUNT
201
220
 
202
221
  it "returns the filesystem mount location" do
203
222
  expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware3"]["mount"]).to eq("/stage/middleware4")
223
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware3,/stage/middleware4"]["mount"]).to eq("/stage/middleware4")
204
224
  end
205
225
 
206
226
  it "returns the filesystem type" do
207
227
  expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware3"]["fs_type"]).to eq("nfs3")
228
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware3,/stage/middleware4"]["fs_type"]).to eq("nfs3")
208
229
  end
209
230
 
210
231
  it "returns the filesystem mount options" do
211
232
  expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware3"]["mount_options"]).to eq(["ro", "bg", "hard", "intr", "sec=sys"])
233
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware3,/stage/middleware4"]["mount_options"]).to eq(["ro", "bg", "hard", "intr", "sec=sys"])
212
234
  end
213
235
  end
214
236
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Nathan L Smith (<nlloyds@gmail.com>)
3
- # Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
3
+ # Copyright:: Copyright (c) 2013-2018 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,7 @@ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "Darwin cpu plugin" do
22
22
  before(:each) do
23
- @plugin = get_plugin("darwin/cpu")
23
+ @plugin = get_plugin("cpu")
24
24
  @stdout = <<~CTL
25
25
  hw.ncpu: 8
26
26
  hw.byteorder: 1234
@@ -78,7 +78,7 @@ describe Ohai::System, "Darwin cpu plugin" do
78
78
  CTL
79
79
 
80
80
  allow(@plugin).to receive(:collect_os).and_return(:darwin)
81
- allow(@plugin).to receive(:shell_out).with("sysctl -a").and_return(mock_shell_out(0, @stdout, ""))
81
+ allow(@plugin).to receive(:shell_out).with("sysctl hw machdep").and_return(mock_shell_out(0, @stdout, ""))
82
82
  @plugin.run
83
83
  end
84
84
 
@@ -20,7 +20,7 @@ require_relative "../../../spec_helper.rb"
20
20
 
21
21
  describe Ohai::System, "FreeBSD cpu plugin on FreeBSD >=10.2" do
22
22
  before(:each) do
23
- @plugin = get_plugin("freebsd/cpu")
23
+ @plugin = get_plugin("cpu")
24
24
  allow(@plugin).to receive(:collect_os).and_return(:freebsd)
25
25
  @double_file = double("/var/run/dmesg.boot")
26
26
  allow(@double_file).to receive(:each)
@@ -95,7 +95,7 @@ end
95
95
 
96
96
  describe Ohai::System, "FreeBSD cpu plugin on FreeBSD <=10.1" do
97
97
  before(:each) do
98
- @plugin = get_plugin("freebsd/cpu")
98
+ @plugin = get_plugin("cpu")
99
99
  allow(@plugin).to receive(:collect_os).and_return(:freebsd)
100
100
  allow(@plugin).to receive(:shell_out).with("sysctl -n hw.ncpu").and_return(mock_shell_out(0, "2", ""))
101
101
  @double_file = double("/var/run/dmesg.boot")
@@ -77,7 +77,7 @@ shared_examples "arm64 processor info" do |cpu_no, bogomips, features|
77
77
  end
78
78
 
79
79
  describe Ohai::System, "General Linux cpu plugin" do
80
- let(:plugin) { get_plugin("linux/cpu") }
80
+ let(:plugin) { get_plugin("cpu") }
81
81
 
82
82
  let(:tempfile_handle) do
83
83
  tempfile = Tempfile.new("ohai-rspec-proc-cpuinfo")
@@ -361,7 +361,7 @@ describe Ohai::System, "General Linux cpu plugin" do
361
361
  end
362
362
 
363
363
  describe Ohai::System, "S390 linux cpu plugin" do
364
- let(:plugin) { get_plugin("linux/cpu") }
364
+ let(:plugin) { get_plugin("cpu") }
365
365
 
366
366
  before(:each) do
367
367
  allow(plugin).to receive(:collect_os).and_return(:linux)
@@ -408,7 +408,7 @@ describe Ohai::System, "S390 linux cpu plugin" do
408
408
  end
409
409
 
410
410
  describe Ohai::System, "arm64 linux cpu plugin" do
411
- let(:plugin) { get_plugin("linux/cpu") }
411
+ let(:plugin) { get_plugin("cpu") }
412
412
 
413
413
  before(:each) do
414
414
  allow(plugin).to receive(:collect_os).and_return(:linux)
@@ -709,6 +709,7 @@ CISCO_RELEASE
709
709
 
710
710
  let(:os_release_content) do
711
711
  <<~OS_RELEASE
712
+ NAME="SLES"
712
713
  VERSION="15"
713
714
  VERSION_ID="15"
714
715
  PRETTY_NAME="SUSE Linux Enterprise Server 15"
@@ -727,7 +728,7 @@ OS_RELEASE
727
728
 
728
729
  it "correctly detects SLES15" do
729
730
  @plugin.run
730
- expect(@plugin[:platform]).to eq("sles")
731
+ expect(@plugin[:platform]).to eq("suse")
731
732
  expect(@plugin[:platform_version]).to eq("15")
732
733
  expect(@plugin[:platform_family]).to eq("suse")
733
734
  end
@@ -1,6 +1,9 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Author:: Richard Manyanza (<liseki@nyikacraftsmen.com>)
4
+ # Author:: Isa Farnik (<isa@chef.io>)
3
5
  # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
6
+ # Copyright:: Copyright (c) 2014 Richard Manyanza.
4
7
  # License:: Apache License, Version 2.0
5
8
  #
6
9
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -69,6 +72,36 @@ describe Ohai::System, "plugin os" do
69
72
  end
70
73
  end
71
74
 
75
+ describe "on AIX" do
76
+ before(:each) do
77
+ @plugin = get_plugin("os")
78
+ allow(@plugin).to receive(:collect_os).and_return(:aix)
79
+ allow(@plugin).to receive(:shell_out).with("oslevel -s").and_return(mock_shell_out(0, "7200-00-01-1543\n", nil))
80
+ @plugin.run
81
+ end
82
+
83
+ it "should set the top-level os attribute" do
84
+ expect(@plugin[:os]).to eql(:aix)
85
+ end
86
+
87
+ it "should set the top-level os_level attribute" do
88
+ expect(@plugin[:os_version]).to eql("7200-00-01-1543")
89
+ end
90
+ end
91
+
92
+ describe "on FreeBSD" do
93
+ before(:each) do
94
+ @plugin = get_plugin("os")
95
+ allow(@plugin).to receive(:shell_out).with("sysctl -n kern.osreldate").and_return(mock_shell_out(0, "902001\n", ""))
96
+ allow(@plugin).to receive(:collect_os).and_return(:freebsd)
97
+ end
98
+
99
+ it "should set os_version to __FreeBSD_version" do
100
+ @plugin.run
101
+ expect(@plugin[:os_version]).to eq("902001")
102
+ end
103
+ end
104
+
72
105
  describe "on something we have never seen before, but ruby has" do
73
106
  before do
74
107
  ::RbConfig::CONFIG["host_os"] = "tron"
@@ -18,7 +18,7 @@ require_relative "../../../spec_helper.rb"
18
18
 
19
19
  describe Ohai::System, "Solaris2.X cpu plugin" do
20
20
  before(:each) do
21
- @plugin = get_plugin("solaris2/cpu")
21
+ @plugin = get_plugin("cpu")
22
22
  allow(@plugin).to receive(:collect_os).and_return("solaris2")
23
23
  end
24
24
 
@@ -18,7 +18,7 @@
18
18
  require_relative "../../../spec_helper"
19
19
 
20
20
  describe Ohai::System, "Solaris2.X filesystem plugin" do
21
- let(:plugin) { get_plugin("solaris2/filesystem") }
21
+ let(:plugin) { get_plugin("filesystem") }
22
22
 
23
23
  before(:each) do
24
24
  allow(plugin).to receive(:collect_os).and_return("solaris2")
@@ -33,51 +33,374 @@ describe Ohai::System, "Solaris2.X filesystem plugin" do
33
33
  allow(plugin).to receive(:shell_out).with("df -Pka").and_return(mock_shell_out(0, "", ""))
34
34
  allow(plugin).to receive(:shell_out).with("df -na").and_return(mock_shell_out(0, "", ""))
35
35
  allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
36
+ allow(plugin).to receive(:shell_out).with("zfs get -p -H all").and_return(mock_shell_out(0, "", ""))
37
+
38
+ @df_pka = <<~DF_PKA
39
+ Filesystem 1024-blocks Used Available Capacity Mounted on
40
+ rpool/ROOT/solaris-0 730451045 2172071 727373448 1% /
41
+ rpool/ROOT/solaris-0/var 730451045 850302 727373448 1% /var
42
+ /dev 0 0 0 0% /dev
43
+ proc 0 0 0 0% /proc
44
+ ctfs 0 0 0 0% /system/contract
45
+ mnttab 0 0 0 0% /etc/mnttab
46
+ objfs 0 0 0 0% /system/object
47
+ swap 18544280 568 18543712 1% /system/volatile
48
+ sharefs 0 0 0 0% /etc/dfs/sharetab
49
+ fd 0 0 0 0% /dev/fd
50
+ swap 18666120 122408 18543712 1% /tmp
51
+ rpool/VARSHARE 730451045 1181 727373448 1% /var/share
52
+ rpool/export 730451045 32 727373448 1% /export
53
+ rpool/export/home 730451045 182277 727373448 1% /export/home
54
+ rpool 730451045 31 727373448 1% /rpool
55
+ rpool/VARSHARE/pkg 730451045 32 727373448 1% /var/share/pkg
56
+ rpool/VARSHARE/pkg/repositories 730451045 31 727373448 1% /var/share/pkg/repositories
57
+ rpool/export/home/shian 730451045 37 727373448 1% /export/home/shain
58
+ rpool/export/home/phild 730451045 38 727373448 1% /export/home/phild
59
+ r
60
+ -hosts 0 0 0 0% /net
61
+ auto_home 0 0 0 0% /home
62
+ -fedfs 0 0 0 0% /nfs4
63
+ DF_PKA
64
+
65
+ @mount = <<~MOUNT
66
+ / on rpool/ROOT/solaris-0 read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/mountpoint=/zones/servername.chef.internal.dns/root//zone=servername.chef.internal.dns/nozonemod/sharezone=151/dev=4bd0b7e on Fri Feb 2 16:27:36 2018
67
+ /var on rpool/ROOT/solaris-0/var read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/mountpoint=/zones/servername.chef.internal.dns/root/var/zone=servername.chef.internal.dns/nozonemod/sharezone=151/dev=4bd0b7f on Fri Feb 2 16:27:36 2018
68
+ /dev on /dev read/write/setuid/devices/rstchown/zone=servername.chef.internal.dns/nozonemod/sharezone=151/dev=8f8003a on Fri Feb 2 16:27:36 2018
69
+ /proc on proc read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=8f40096 on Fri Feb 2 16:27:37 2018
70
+ /system/contract on ctfs read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=8fc0097 on Fri Feb 2 16:27:37 2018
71
+ /etc/mnttab on mnttab read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=9000097 on Fri Feb 2 16:27:37 2018
72
+ /system/object on objfs read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=9080097 on Fri Feb 2 16:27:37 2018
73
+ /system/volatile on swap read/write/setuid/nodevices/rstchown/xattr/zone=servername.chef.internal.dns/sharezone=151/dev=90406f0 on Fri Feb 2 16:27:37 2018
74
+ /etc/dfs/sharetab on sharefs read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=90c004d on Fri Feb 2 16:27:37 2018
75
+ /dev/fd on fd read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=91c007d on Fri Feb 2 16:27:44 2018
76
+ /tmp on swap read/write/setuid/nodevices/rstchown/xattr/zone=servername.chef.internal.dns/sharezone=151/dev=90406f1 on Fri Feb 2 16:27:45 2018
77
+ /var/share on rpool/VARSHARE read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b80 on Fri Feb 2 16:27:45 2018
78
+ /export on rpool/export read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b81 on Fri Feb 2 16:28:11 2018
79
+ /export/home on rpool/export/home read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b82 on Fri Feb 2 16:28:11 2018
80
+ /rpool on rpool read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b83 on Fri Feb 2 16:28:11 2018
81
+ /var/share/pkg on rpool/VARSHARE/pkg read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b84 on Fri Feb 2 16:28:12 2018
82
+ /var/share/pkg/repositories on rpool/VARSHARE/pkg/repositories read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b85 on Fri Feb 2 16:28:12 2018
83
+ /export/home/<usernameredacted> on rpool/export/home/<usernameredacted> read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b8a on Fri Feb 2 16:39:15 2018
84
+ /export/home/<usernameredacted> on rpool/export/home/<usernameredacted> read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b8b on Fri Feb 2 16:39:16 2018
85
+ MOUNT
86
+
87
+ @zfs_get = <<~ZFS_GET
88
+ data0 type filesystem -
89
+ data0 creation 1331514391 -
90
+ data0 used 7926803118480 -
91
+ data0 available 3666345412208 -
92
+ data0 referenced 60350619952 -
93
+ data0 compressratio 1.04x -
94
+ data0 mounted yes -
95
+ data0 quota 0 default
96
+ data0 reservation 0 default
97
+ data0 recordsize 131072 default
98
+ data0 mountpoint /data0 default
99
+ data0 sharenfs rw=192.168.130.0/24,rw=[2001:470:1f05:2c9::]/64,rw=[2001:470:8122:dd40::10] local
100
+ data0 checksum on default
101
+ data0 compression off local
102
+ data0 atime off local
103
+ data0 devices on default
104
+ data0 exec on default
105
+ data0 setuid on default
106
+ data0 readonly off default
107
+ data0 zoned off default
108
+ data0 snapdir hidden default
109
+ data0 aclinherit restricted default
110
+ data0 canmount on default
111
+ data0 xattr on default
112
+ data0 copies 1 default
113
+ data0 version 5 -
114
+ data0 utf8only off -
115
+ data0 normalization none -
116
+ data0 casesensitivity sensitive -
117
+ data0 vscan off default
118
+ data0 nbmand off default
119
+ data0 sharesmb off default
120
+ data0 refquota 0 default
121
+ data0 refreservation 0 default
122
+ data0 primarycache all default
123
+ data0 secondarycache all default
124
+ data0 usedbysnapshots 157243047152 -
125
+ data0 usedbydataset 60350619952 -
126
+ data0 usedbychildren 7709209451376 -
127
+ data0 usedbyrefreservation 0 -
128
+ data0 logbias latency default
129
+ data0 dedup off default
130
+ data0 mlslabel none default
131
+ data0 sync standard default
132
+ data0 refcompressratio 1.29x -
133
+ data0 written 4183965296 -
134
+ data0 logicalused 8240006744576 -
135
+ data0 logicalreferenced 75625359872 -
136
+ data0 filesystem_limit 18446744073709551615 default
137
+ data0 snapshot_limit 18446744073709551615 default
138
+ data0 filesystem_count 18446744073709551615 default
139
+ data0 snapshot_count 18446744073709551615 default
140
+ data0 snapdev hidden default
141
+ data0 acltype off default
142
+ data0 context none default
143
+ data0 fscontext none default
144
+ data0 defcontext none default
145
+ data0 rootcontext none default
146
+ data0 relatime off default
147
+ data0 redundant_metadata all default
148
+ data0 overlay off default
149
+ data0@20130228 type snapshot -
150
+ data0@20130228 creation 1362119670 -
151
+ data0@20130228 used 0 -
152
+ data0@20130228 referenced 57161787648 -
153
+ data0@20130228 compressratio 1.30x -
154
+ data0@20130228 devices on default
155
+ data0@20130228 exec on default
156
+ data0@20130228 setuid on default
157
+ data0@20130228 xattr on default
158
+ data0@20130228 version 5 -
159
+ data0@20130228 utf8only off -
160
+ data0@20130228 normalization none -
161
+ data0@20130228 casesensitivity sensitive -
162
+ data0@20130228 nbmand off default
163
+ data0@20130228 primarycache all default
164
+ data0@20130228 secondarycache all default
165
+ data0@20130228 defer_destroy off -
166
+ data0@20130228 userrefs 0 -
167
+ data0@20130228 mlslabel none default
168
+ data0@20130228 refcompressratio 1.30x -
169
+ data0@20130228 written 57161787648 -
170
+ data0@20130228 clones -
171
+ data0@20130228 logicalused 0 -
172
+ data0@20130228 logicalreferenced 72138856960 -
173
+ data0@20130228 acltype off default
174
+ data0@20130228 context none default
175
+ data0@20130228 fscontext none default
176
+ data0@20130228 defcontext none default
177
+ data0@20130228 rootcontext none default
178
+ data0@20130301 type snapshot -
179
+ data0@20130301 creation 1362122621 -
180
+ data0@20130301 used 0 -
181
+ data0@20130301 referenced 57161787648 -
182
+ data0@20130301 compressratio 1.30x -
183
+ data0@20130301 devices on default
184
+ data0@20130301 exec on default
185
+ data0@20130301 setuid on default
186
+ data0@20130301 xattr on default
187
+ data0@20130301 version 5 -
188
+ data0@20130301 utf8only off -
189
+ data0@20130301 normalization none -
190
+ data0@20130301 casesensitivity sensitive -
191
+ data0@20130301 nbmand off default
192
+ data0@20130301 primarycache all default
193
+ data0@20130301 secondarycache all default
194
+ data0@20130301 defer_destroy off -
195
+ data0@20130301 userrefs 0 -
196
+ data0@20130301 mlslabel none default
197
+ data0@20130301 refcompressratio 1.30x -
198
+ data0@20130301 written 0 -
199
+ data0@20130301 clones -
200
+ data0@20130301 logicalused 0 -
201
+ data0@20130301 logicalreferenced 72138856960 -
202
+ data0@20130301 acltype off default
203
+ data0@20130301 context none default
204
+ data0@20130301 fscontext none default
205
+ data0@20130301 defcontext none default
206
+ data0@20130301 rootcontext none default
207
+ data0@20130310 type snapshot -
208
+ data0@20130310 creation 1362955150 -
209
+ data0@20130310 used 281392 -
210
+ data0@20130310 referenced 57173475232 -
211
+ data0@20130310 compressratio 1.30x -
212
+ data0@20130310 devices on default
213
+ data0@20130310 exec on default
214
+ data0@20130310 setuid on default
215
+ data0@20130310 xattr on default
216
+ data0@20130310 version 5 -
217
+ data0@20130310 utf8only off -
218
+ data0@20130310 normalization none -
219
+ data0@20130310 casesensitivity sensitive -
220
+ data0@20130310 nbmand off default
221
+ data0@20130310 primarycache all default
222
+ data0@20130310 secondarycache all default
223
+ data0@20130310 defer_destroy off -
224
+ data0@20130310 userrefs 0 -
225
+ data0@20130310 mlslabel none default
226
+ data0@20130310 refcompressratio 1.30x -
227
+ data0@20130310 written 11968976 -
228
+ data0@20130310 clones -
229
+ data0@20130310 logicalused 0 -
230
+ data0@20130310 logicalreferenced 72164488192 -
231
+ data0@20130310 acltype off default
232
+ data0@20130310 context none default
233
+ data0@20130310 fscontext none default
234
+ data0@20130310 defcontext none default
235
+ data0@20130310 rootcontext none default
236
+ data0@20160311 type snapshot -
237
+ data0@20160311 creation 1457762233 -
238
+ data0@20160311 used 155723556528 -
239
+ data0@20160311 referenced 211890289712 -
240
+ data0@20160311 compressratio 1.24x -
241
+ data0@20160311 devices on default
242
+ data0@20160311 exec on default
243
+ data0@20160311 setuid on default
244
+ data0@20160311 xattr on default
245
+ data0@20160311 version 5 -
246
+ data0@20160311 utf8only off -
247
+ data0@20160311 normalization none -
248
+ data0@20160311 casesensitivity sensitive -
249
+ data0@20160311 nbmand off default
250
+ data0@20160311 primarycache all default
251
+ data0@20160311 secondarycache all default
252
+ data0@20160311 defer_destroy off -
253
+ data0@20160311 userrefs 0 -
254
+ data0@20160311 mlslabel none default
255
+ data0@20160311 refcompressratio 1.24x -
256
+ data0@20160311 written 156235945184 -
257
+ data0@20160311 clones -
258
+ data0@20160311 logicalused 0 -
259
+ data0@20160311 logicalreferenced 259598664192 -
260
+ data0@20160311 acltype off default
261
+ data0@20160311 context none default
262
+ data0@20160311 fscontext none default
263
+ data0@20160311 defcontext none default
264
+ data0@20160311 rootcontext none default
265
+ data0/Movies type filesystem -
266
+ data0/Movies creation 1331530217 -
267
+ data0/Movies used 642640700304 -
268
+ data0/Movies available 3666345412208 -
269
+ data0/Movies referenced 586525311344 -
270
+ data0/Movies compressratio 1.00x -
271
+ data0/Movies mounted yes -
272
+ data0/Movies quota 0 default
273
+ data0/Movies reservation 0 default
274
+ data0/Movies recordsize 131072 default
275
+ data0/Movies mountpoint /data0/Movies default
276
+ data0/Movies sharenfs sec=sys,rw=192.168.130.0/24,rw=192.168.135.0/24,rw=[2001:470:1f05:2c9::]/64,rw=[2001:470:8122::]/48,rw=[2001:470:8122:dd40::10]local
277
+ data0/Movies checksum on default
278
+ data0/Movies compression off inherited from data0
279
+ data0/Movies atime off local
280
+ data0/Movies devices on default
281
+ data0/Movies exec on default
282
+ data0/Movies setuid on default
283
+ data0/Movies readonly off default
284
+ data0/Movies zoned off default
285
+ data0/Movies snapdir hidden default
286
+ data0/Movies aclinherit restricted default
287
+ data0/Movies canmount on default
288
+ data0/Movies xattr on default
289
+ data0/Movies copies 1 default
290
+ data0/Movies version 5 -
291
+ data0/Movies utf8only off -
292
+ data0/Movies normalization none -
293
+ data0/Movies casesensitivity sensitive -
294
+ data0/Movies vscan off default
295
+ data0/Movies nbmand off default
296
+ data0/Movies sharesmb off local
297
+ data0/Movies refquota 0 default
298
+ data0/Movies refreservation 0 default
299
+ data0/Movies primarycache all default
300
+ data0/Movies secondarycache all default
301
+ data0/Movies usedbysnapshots 56115388960 -
302
+ data0/Movies usedbydataset 586525311344 -
303
+ data0/Movies usedbychildren 0 -
304
+ data0/Movies usedbyrefreservation 0 -
305
+ data0/Movies logbias latency default
306
+ data0/Movies dedup off default
307
+ data0/Movies mlslabel none default
308
+ data0/Movies sync standard default
309
+ data0/Movies refcompressratio 1.00x -
310
+ data0/Movies written 197038505024 -
311
+ data0/Movies logicalused 642795343360 -
312
+ data0/Movies logicalreferenced 586666194432 -
313
+ data0/Movies filesystem_limit 18446744073709551615 default
314
+ data0/Movies snapshot_limit 18446744073709551615 default
315
+ data0/Movies filesystem_count 18446744073709551615 default
316
+ data0/Movies snapshot_count 18446744073709551615 default
317
+ data0/Movies snapdev hidden default
318
+ data0/Movies acltype off default
319
+ data0/Movies context none default
320
+ data0/Movies fscontext none default
321
+ data0/Movies defcontext none default
322
+ data0/Movies rootcontext none default
323
+ data0/Movies relatime off default
324
+ data0/Movies redundant_metadata all default
325
+ data0/Movies overlay off default:
326
+ ZFS_GET
36
327
  end
37
328
 
38
329
  after(:each) do
39
330
  Ohai.config[:plugin] = @original_plugin_config
40
331
  end
41
332
 
42
- context "when 'zfs get' properties are not configured" do
43
- it "collects all filesystem properties" do
44
- expect(plugin).to receive(:shell_out)
45
- .with("zfs get -p -H all")
46
- .and_return(mock_shell_out(0, "", ""))
333
+ context "reports filesystem data" do
334
+ before do
335
+ allow(plugin).to receive(:shell_out)
336
+ .with("mount")
337
+ .and_return(mock_shell_out(0, @mount, nil))
338
+ allow(plugin).to receive(:shell_out)
339
+ .with("df -Pka")
340
+ .and_return(mock_shell_out(0, @df_pka, nil))
341
+ # TODO: get this output
342
+ # allow(plugin).to receive(:shell_out)
343
+ # .with("df -na")
344
+ # .and_return(mock_shell_out(0, @df_na, nil))
47
345
  plugin.run
48
346
  end
347
+
348
+ it "returns kb_used" do
349
+ expect(plugin[:filesystem]["rpool/VARSHARE"]["kb_used"]).to eq("1181")
350
+ expect(plugin[:filesystem2]["by_pair"]["rpool/VARSHARE,/var/share"]["kb_used"]).to eq("1181")
351
+ end
352
+
353
+ it "returns mount" do
354
+ expect(plugin[:filesystem]["rpool/VARSHARE"]["mount"]).to eq("/var/share")
355
+ expect(plugin[:filesystem2]["by_pair"]["rpool/VARSHARE,/var/share"]["mount"]).to eq("/var/share")
356
+ end
357
+
358
+ it "returns mount_opts" do
359
+ opts = %w{
360
+ read
361
+ write
362
+ setuid
363
+ nodevices
364
+ rstchown
365
+ nonbmand
366
+ exec
367
+ xattr
368
+ atime
369
+ zone=servername.chef.internal.dns
370
+ sharezone=151
371
+ dev=4bd0b80
372
+ }
373
+ expect(plugin[:filesystem]["rpool/VARSHARE"]["mount_options"]).to eq(opts)
374
+ expect(plugin[:filesystem2]["by_pair"]["rpool/VARSHARE,/var/share"]["mount_options"]).to eq(opts)
375
+ end
49
376
  end
50
377
 
51
- context "when 'zfs get' properties are configured" do
52
- shared_examples_for "configured zfs properties" do
53
- let(:plugin_config) do
54
- {
55
- filesystem: {
56
- zfs_properties: zfs_properties,
57
- },
58
- }
59
- end
60
-
61
- it "collects configured filesystem properties" do
62
- expect(plugin).to receive(:shell_out)
63
- .with("zfs get -p -H #{expected_cmd}")
64
- .and_return(mock_shell_out(0, "", ""))
65
- plugin.run
66
- end
378
+ context "handles zfs properties" do
379
+ before do
380
+ allow(plugin).to receive(:shell_out)
381
+ .with("zfs get -p -H all")
382
+ .and_return(mock_shell_out(0, @zfs_get, nil))
383
+ plugin.run
67
384
  end
68
385
 
69
- context "as a String" do
70
- include_examples "configured zfs properties" do
71
- let(:zfs_properties) { "mountpoint,creation,available,used" }
72
- let(:expected_cmd) { "mountpoint,creation,available,used" }
73
- end
386
+ it "returns top-level stats" do
387
+ # old API
388
+ expect(plugin[:filesystem]["data0"]["fs_type"]).to eq("zfs")
389
+ expect(plugin[:filesystem]["data0"]["mount"]).to eq("/data0")
390
+
391
+ # new API
392
+ expect(plugin[:filesystem2]["by_pair"]["data0,/data0"]["fs_type"]).to eq("zfs")
393
+ expect(plugin[:filesystem2]["by_pair"]["data0,/data0"]["mount"]).to eq("/data0")
74
394
  end
75
395
 
76
- context "as an Array" do
77
- include_examples "configured zfs properties" do
78
- let(:zfs_properties) { %w{mountpoint creation available used} }
79
- let(:expected_cmd) { "mountpoint,creation,available,used" }
80
- end
396
+ it "returns zfs-specific properties" do
397
+ # old API
398
+ expect(plugin[:filesystem]["data0"]["zfs_values"]["used"]).to eq("7926803118480")
399
+ expect(plugin[:filesystem]["data0"]["zfs_sources"]["used"]).to eq("-")
400
+
401
+ # new API
402
+ expect(plugin[:filesystem2]["by_pair"]["data0,/data0"]["zfs_properties"]["used"]["value"]).to eq("7926803118480")
403
+ expect(plugin[:filesystem2]["by_pair"]["data0,/data0"]["zfs_properties"]["used"]["source"]).to eq("-")
81
404
  end
82
405
  end
83
406
  end