ohai 7.2.0 → 7.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ohai/plugins/linux/filesystem.rb +46 -7
- data/lib/ohai/version.rb +1 -1
- data/spec/unit/plugins/linux/filesystem_spec.rb +133 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4329545c173368396f653fe483a8c05a0bbfcbf7
|
4
|
+
data.tar.gz: 82c031fc26ba2f9fd0a1c0a91d68eb344c3d44f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eece99b024c9d7e9ee89cd3eaa6213f92bc39586a520e914226e9127f3368edf1c3b11c3d5756c14533742e778f2c0cc80cf951dc1632fe9616615274f140071
|
7
|
+
data.tar.gz: 9c681cd6d5f724a472e8181d4924265edf463a7bc99ccf71f200fc9ca53c4208062e25a40d0f8f890eb6fdce31a423fc0a18e24d14506ceb08f3e5e50293b7c4
|
@@ -19,8 +19,22 @@
|
|
19
19
|
Ohai.plugin(:Filesystem) do
|
20
20
|
provides "filesystem"
|
21
21
|
|
22
|
+
def get_blk_cmd(attr, have_lsblk)
|
23
|
+
if have_lsblk
|
24
|
+
attr = 'FSTYPE' if attr == 'TYPE'
|
25
|
+
"lsblk -r -n -o NAME,#{attr}"
|
26
|
+
else
|
27
|
+
"blkid -s #{attr}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_blk_regex(attr, have_lsblk)
|
32
|
+
have_lsblk ? /^(\S+) (\S+)/ : /^(\S+): #{attr}="(\S+)"/
|
33
|
+
end
|
34
|
+
|
22
35
|
collect_data(:linux) do
|
23
36
|
fs = Mash.new
|
37
|
+
have_lsblk = File.executable?('/bin/lsblk')
|
24
38
|
|
25
39
|
# Grab filesystem data from df
|
26
40
|
so = shell_out("df -P")
|
@@ -68,10 +82,14 @@ Ohai.plugin(:Filesystem) do
|
|
68
82
|
end
|
69
83
|
end
|
70
84
|
|
85
|
+
have_lsblk = File.exists?('/bin/lsblk')
|
86
|
+
|
71
87
|
# Gather more filesystem types via libuuid, even devices that's aren't mounted
|
72
|
-
|
88
|
+
cmd = get_blk_cmd('TYPE', have_lsblk)
|
89
|
+
regex = get_blk_regex('TYPE', have_lsblk)
|
90
|
+
so = shell_out(cmd)
|
73
91
|
so.stdout.lines do |line|
|
74
|
-
if line =~
|
92
|
+
if line =~ regex
|
75
93
|
filesystem = $1
|
76
94
|
fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
|
77
95
|
fs[filesystem][:fs_type] = $2
|
@@ -79,9 +97,11 @@ Ohai.plugin(:Filesystem) do
|
|
79
97
|
end
|
80
98
|
|
81
99
|
# Gather device UUIDs via libuuid
|
82
|
-
|
100
|
+
cmd = get_blk_cmd('UUID', have_lsblk)
|
101
|
+
regex = get_blk_regex('UUID', have_lsblk)
|
102
|
+
so = shell_out(cmd)
|
83
103
|
so.stdout.lines do |line|
|
84
|
-
if line =~
|
104
|
+
if line =~ regex
|
85
105
|
filesystem = $1
|
86
106
|
fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
|
87
107
|
fs[filesystem][:uuid] = $2
|
@@ -89,9 +109,11 @@ Ohai.plugin(:Filesystem) do
|
|
89
109
|
end
|
90
110
|
|
91
111
|
# Gather device labels via libuuid
|
92
|
-
|
112
|
+
cmd = get_blk_cmd('LABEL', have_lsblk)
|
113
|
+
regex = get_blk_regex('LABEL', have_lsblk)
|
114
|
+
so = shell_out(cmd)
|
93
115
|
so.stdout.lines do |line|
|
94
|
-
if line =~
|
116
|
+
if line =~ regex
|
95
117
|
filesystem = $1
|
96
118
|
fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
|
97
119
|
fs[filesystem][:label] = $2
|
@@ -100,7 +122,24 @@ Ohai.plugin(:Filesystem) do
|
|
100
122
|
|
101
123
|
# Grab any missing mount information from /proc/mounts
|
102
124
|
if File.exists?('/proc/mounts')
|
103
|
-
|
125
|
+
mounts = ''
|
126
|
+
# Due to https://tickets.opscode.com/browse/OHAI-196
|
127
|
+
# we have to non-block read dev files. Ew.
|
128
|
+
f = File.open('/proc/mounts')
|
129
|
+
loop do
|
130
|
+
begin
|
131
|
+
data = f.read_nonblock(4096)
|
132
|
+
mounts << data
|
133
|
+
# We should just catch EOFError, but the kernel had a period of
|
134
|
+
# bugginess with reading virtual files, so we're being extra
|
135
|
+
# cautious here, catching all exceptions, and then we'll read
|
136
|
+
# whatever data we might have
|
137
|
+
rescue Exception
|
138
|
+
break
|
139
|
+
end
|
140
|
+
end
|
141
|
+
f.close
|
142
|
+
mounts.each_line do |line|
|
104
143
|
if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/
|
105
144
|
filesystem = $1
|
106
145
|
next if fs.has_key?(filesystem)
|
data/lib/ohai/version.rb
CHANGED
@@ -26,10 +26,18 @@ describe Ohai::System, "Linux filesystem plugin" do
|
|
26
26
|
@plugin.stub(:shell_out).with("df -P").and_return(mock_shell_out(0, "", ""))
|
27
27
|
@plugin.stub(:shell_out).with("df -i").and_return(mock_shell_out(0, "", ""))
|
28
28
|
@plugin.stub(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
|
29
|
+
File.stub(:exists?).with("/bin/lsblk").and_return(false)
|
29
30
|
@plugin.stub(:shell_out).with("blkid -s TYPE").and_return(mock_shell_out(0, "", ""))
|
30
31
|
@plugin.stub(:shell_out).with("blkid -s UUID").and_return(mock_shell_out(0, "", ""))
|
31
32
|
@plugin.stub(:shell_out).with("blkid -s LABEL").and_return(mock_shell_out(0, "", ""))
|
32
33
|
|
34
|
+
@plugin.stub(:shell_out).with("lsblk -r -n -o NAME,FSTYPE").
|
35
|
+
and_return(mock_shell_out(0, "", ""))
|
36
|
+
@plugin.stub(:shell_out).with("lsblk -r -n -o NAME,UUID").
|
37
|
+
and_return(mock_shell_out(0, "", ""))
|
38
|
+
@plugin.stub(:shell_out).with("lsblk -r -n -o NAME,LABEL").
|
39
|
+
and_return(mock_shell_out(0, "", ""))
|
40
|
+
|
33
41
|
File.stub(:exists?).with("/proc/mounts").and_return(false)
|
34
42
|
end
|
35
43
|
|
@@ -154,7 +162,7 @@ MOUNT
|
|
154
162
|
describe "when gathering filesystem type data from blkid" do
|
155
163
|
before(:each) do
|
156
164
|
@stdout = <<-BLKID_TYPE
|
157
|
-
dev/sdb1: TYPE=\"linux_raid_member\"
|
165
|
+
/dev/sdb1: TYPE=\"linux_raid_member\"
|
158
166
|
/dev/sdb2: TYPE=\"linux_raid_member\"
|
159
167
|
/dev/sda1: TYPE=\"linux_raid_member\"
|
160
168
|
/dev/sda2: TYPE=\"linux_raid_member\"
|
@@ -181,6 +189,39 @@ BLKID_TYPE
|
|
181
189
|
end
|
182
190
|
end
|
183
191
|
|
192
|
+
describe "when gathering filesystem type data from lsblk" do
|
193
|
+
before(:each) do
|
194
|
+
File.stub(:exists?).with("/bin/lsblk").and_return(true)
|
195
|
+
@stdout = <<-BLKID_TYPE
|
196
|
+
/dev/sdb1 linux_raid_member
|
197
|
+
/dev/sdb2 linux_raid_member
|
198
|
+
/dev/sda1 linux_raid_member
|
199
|
+
/dev/sda2 linux_raid_member
|
200
|
+
/dev/md0 ext3
|
201
|
+
/dev/md1 LVM2_member
|
202
|
+
/dev/mapper/sys.vg-root.lv ext4
|
203
|
+
/dev/mapper/sys.vg-swap.lv swap
|
204
|
+
/dev/mapper/sys.vg-tmp.lv ext4
|
205
|
+
/dev/mapper/sys.vg-usr.lv ext4
|
206
|
+
/dev/mapper/sys.vg-var.lv ext4
|
207
|
+
/dev/mapper/sys.vg-home.lv xfs
|
208
|
+
BLKID_TYPE
|
209
|
+
@plugin.stub(:shell_out).with("lsblk -r -n -o NAME,FSTYPE").
|
210
|
+
and_return(mock_shell_out(0, @stdout, ""))
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should run lsblk -r -n -o NAME,FSTYPE" do
|
214
|
+
@plugin.should_receive(:shell_out).with("lsblk -r -n -o NAME,FSTYPE").
|
215
|
+
and_return(mock_shell_out(0, @stdout, ""))
|
216
|
+
@plugin.run
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should set kb_size to value from lsblk -r -n -o NAME,FSTYPE" do
|
220
|
+
@plugin.run
|
221
|
+
@plugin[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
184
225
|
describe "when gathering filesystem uuid data from blkid" do
|
185
226
|
before(:each) do
|
186
227
|
@stdout = <<-BLKID_UUID
|
@@ -211,6 +252,40 @@ BLKID_UUID
|
|
211
252
|
end
|
212
253
|
end
|
213
254
|
|
255
|
+
describe "when gathering filesystem uuid data from lsblk" do
|
256
|
+
before(:each) do
|
257
|
+
File.stub(:exists?).with("/bin/lsblk").and_return(true)
|
258
|
+
@stdout = <<-BLKID_UUID
|
259
|
+
/dev/sdb1 bd1197e0-6997-1f3a-e27e-7801388308b5
|
260
|
+
/dev/sdb2 e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa
|
261
|
+
/dev/sda1 bd1197e0-6997-1f3a-e27e-7801388308b5
|
262
|
+
/dev/sda2 e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa
|
263
|
+
/dev/md0 37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32
|
264
|
+
/dev/md1 YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK
|
265
|
+
/dev/mapper/sys.vg-root.lv 7742d14b-80a3-4e97-9a32-478be9ea9aea
|
266
|
+
/dev/mapper/sys.vg-swap.lv 9bc2e515-8ddc-41c3-9f63-4eaebde9ce96
|
267
|
+
/dev/mapper/sys.vg-tmp.lv 74cf7eb9-428f-479e-9a4a-9943401e81e5
|
268
|
+
/dev/mapper/sys.vg-usr.lv 26ec33c5-d00b-4f88-a550-492def013bbc
|
269
|
+
/dev/mapper/sys.vg-var.lv 6b559c35-7847-4ae2-b512-c99012d3f5b3
|
270
|
+
/dev/mapper/sys.vg-home.lv d6efda02-1b73-453c-8c74-7d8dee78fa5e
|
271
|
+
BLKID_UUID
|
272
|
+
@plugin.stub(:shell_out).with("lsblk -r -n -o NAME,UUID").
|
273
|
+
and_return(mock_shell_out(0, @stdout, ""))
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should run lsblk -r -n -o NAME,UUID" do
|
277
|
+
@plugin.should_receive(:shell_out).with("lsblk -r -n -o NAME,UUID").
|
278
|
+
and_return(mock_shell_out(0, @stdout, ""))
|
279
|
+
@plugin.run
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should set kb_size to value from lsblk -r -n -o NAME,UUID" do
|
283
|
+
@plugin.run
|
284
|
+
@plugin[:filesystem]["/dev/sda2"][:uuid].should be ==
|
285
|
+
"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
214
289
|
describe "when gathering filesystem label data from blkid" do
|
215
290
|
before(:each) do
|
216
291
|
@stdout = <<-BLKID_LABEL
|
@@ -239,28 +314,67 @@ BLKID_LABEL
|
|
239
314
|
end
|
240
315
|
end
|
241
316
|
|
317
|
+
describe "when gathering filesystem label data from lsblk" do
|
318
|
+
before(:each) do
|
319
|
+
File.stub(:exists?).with("/bin/lsblk").and_return(true)
|
320
|
+
@stdout = <<-BLKID_LABEL
|
321
|
+
/dev/sda1 fuego:0
|
322
|
+
/dev/sda2 fuego:1
|
323
|
+
/dev/sdb1 fuego:0
|
324
|
+
/dev/sdb2 fuego:1
|
325
|
+
/dev/md0 /boot
|
326
|
+
/dev/mapper/sys.vg-root.lv /
|
327
|
+
/dev/mapper/sys.vg-tmp.lv /tmp
|
328
|
+
/dev/mapper/sys.vg-usr.lv /usr
|
329
|
+
/dev/mapper/sys.vg-var.lv /var
|
330
|
+
/dev/mapper/sys.vg-home.lv /home
|
331
|
+
BLKID_LABEL
|
332
|
+
@plugin.stub(:shell_out).with("lsblk -r -n -o NAME,LABEL").
|
333
|
+
and_return(mock_shell_out(0, @stdout, ""))
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should run blkid -s LABEL" do
|
337
|
+
@plugin.should_receive(:shell_out).with("lsblk -r -n -o NAME,LABEL").
|
338
|
+
and_return(mock_shell_out(0, @stdout, ""))
|
339
|
+
@plugin.run
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should set kb_size to value from blkid -s LABEL" do
|
343
|
+
@plugin.run
|
344
|
+
@plugin[:filesystem]["/dev/md0"][:label].should be == "/boot"
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
|
242
349
|
describe "when gathering data from /proc/mounts" do
|
243
350
|
before(:each) do
|
244
351
|
File.stub(:exists?).with("/proc/mounts").and_return(true)
|
245
352
|
@double_file = double("/proc/mounts")
|
246
|
-
@
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
353
|
+
@mounts = <<-MOUNTS
|
354
|
+
rootfs / rootfs rw 0 0
|
355
|
+
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
|
356
|
+
none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
|
357
|
+
none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0
|
358
|
+
none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
|
359
|
+
/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0
|
360
|
+
tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0
|
361
|
+
tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
|
362
|
+
/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0
|
363
|
+
/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0
|
364
|
+
/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0
|
365
|
+
/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0
|
366
|
+
/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0
|
367
|
+
/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0
|
368
|
+
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
|
369
|
+
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
|
370
|
+
MOUNTS
|
371
|
+
@counter = 0
|
372
|
+
@double_file.stub(:read_nonblock) do
|
373
|
+
@counter += 1
|
374
|
+
raise EOFError if @counter == 2
|
375
|
+
@mounts
|
376
|
+
end
|
377
|
+
@double_file.stub(:close)
|
264
378
|
File.stub(:open).with("/proc/mounts").and_return(@double_file)
|
265
379
|
end
|
266
380
|
|
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: 7.2.
|
4
|
+
version: 7.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|