ohai 0.6.10 → 0.6.12.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohai/plugins/linux/filesystem.rb +39 -13
- data/lib/ohai/plugins/linux/network.rb +193 -69
- data/lib/ohai/plugins/linux/platform.rb +36 -8
- data/lib/ohai/plugins/openbsd/uptime.rb +3 -3
- data/lib/ohai/plugins/os.rb +4 -4
- data/lib/ohai/plugins/platform.rb +6 -3
- data/lib/ohai/plugins/sigar/network_route.rb +5 -2
- data/lib/ohai/plugins/windows/platform.rb +1 -0
- data/lib/ohai/version.rb +1 -1
- data/spec/ohai/plugins/linux/filesystem_spec.rb +289 -0
- data/spec/ohai/plugins/linux/network_spec.rb +285 -0
- data/spec/ohai/plugins/linux/platform_spec.rb +164 -9
- data/spec/ohai/plugins/os_spec.rb +5 -5
- data/spec/ohai/plugins/platform_spec.rb +17 -2
- data/spec/ohai/plugins/ruby_spec.rb +11 -5
- data/spec/ohai/plugins/sigar/network_route_spec.rb +120 -106
- metadata +16 -10
data/lib/ohai/plugins/os.rb
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -22,7 +22,7 @@ require 'rbconfig'
|
|
22
22
|
|
23
23
|
require_plugin 'kernel'
|
24
24
|
|
25
|
-
case ::
|
25
|
+
case ::RbConfig::CONFIG['host_os']
|
26
26
|
when /aix(.+)$/
|
27
27
|
os "aix"
|
28
28
|
when /darwin(.+)$/
|
@@ -47,7 +47,7 @@ when /mswin|mingw32|windows/
|
|
47
47
|
# subsystems.
|
48
48
|
os "windows"
|
49
49
|
else
|
50
|
-
|
50
|
+
Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG['host_os']
|
51
51
|
end
|
52
52
|
|
53
53
|
os_version kernel[:release]
|
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -16,10 +16,13 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
provides "platform", "platform_version"
|
19
|
+
provides "platform", "platform_version", "platform_family"
|
20
20
|
|
21
21
|
require_plugin "#{os}::platform"
|
22
22
|
|
23
23
|
platform os unless attribute?("platform")
|
24
24
|
|
25
25
|
platform_version os_version unless attribute?("platform_version")
|
26
|
+
|
27
|
+
platform_family platform unless attribute?("platform_family")
|
28
|
+
|
@@ -35,12 +35,15 @@ def flags(flags)
|
|
35
35
|
f
|
36
36
|
end
|
37
37
|
|
38
|
+
# From sigar: include/sigar.h sigar_net_route_t
|
39
|
+
SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname]
|
40
|
+
|
38
41
|
sigar=Sigar.new
|
39
42
|
sigar.net_route_list.each do |route|
|
40
43
|
next unless network[:interfaces][route.ifname] # this should never happen
|
41
44
|
network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
|
42
45
|
route_data={}
|
43
|
-
|
46
|
+
SIGAR_ROUTE_METHODS.each do |m|
|
44
47
|
if(m == :flags)
|
45
48
|
route_data[m]=flags(route.send(m))
|
46
49
|
else
|
@@ -48,4 +51,4 @@ sigar.net_route_list.each do |route|
|
|
48
51
|
end
|
49
52
|
end
|
50
53
|
network[:interfaces][route.ifname][:route][route.destination] = route_data
|
51
|
-
end
|
54
|
+
end
|
data/lib/ohai/version.rb
CHANGED
@@ -0,0 +1,289 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matthew Kent (<mkent@magoazul.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, 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 CONDITIONS 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 File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
|
20
|
+
|
21
|
+
describe Ohai::System, "Linux filesystem plugin" do
|
22
|
+
before(:each) do
|
23
|
+
@ohai = Ohai::System.new
|
24
|
+
@ohai[:os] = "linux"
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@ohai.extend(SimpleFromFile)
|
27
|
+
|
28
|
+
@ohai.stub!(:popen4).with("df -P").and_return(false)
|
29
|
+
@ohai.stub!(:popen4).with("mount").and_return(false)
|
30
|
+
@ohai.stub!(:popen4).with("blkid -s TYPE").and_return(false)
|
31
|
+
@ohai.stub!(:popen4).with("blkid -s UUID").and_return(false)
|
32
|
+
@ohai.stub!(:popen4).with("blkid -s LABEL").and_return(false)
|
33
|
+
|
34
|
+
File.stub!(:exists?).with("/proc/mounts").and_return(false)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "when gathering filesystem usage data from df" do
|
38
|
+
before(:each) do
|
39
|
+
@stdin = mock("STDIN", { :close => true })
|
40
|
+
@pid = 10
|
41
|
+
@stderr = mock("STDERR")
|
42
|
+
@stdout = mock("STDOUT")
|
43
|
+
@status = 0
|
44
|
+
|
45
|
+
@stdout.stub!(:each).
|
46
|
+
and_yield("Filesystem 1024-blocks Used Available Capacity Mounted on").
|
47
|
+
and_yield("/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /").
|
48
|
+
and_yield("tmpfs 2030944 0 2030944 0% /lib/init/rw").
|
49
|
+
and_yield("udev 2025576 228 2025348 1% /dev").
|
50
|
+
and_yield("tmpfs 2030944 2960 2027984 1% /dev/shm").
|
51
|
+
and_yield("/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home").
|
52
|
+
and_yield("/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special").
|
53
|
+
and_yield("/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp").
|
54
|
+
and_yield("/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr").
|
55
|
+
and_yield("/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var").
|
56
|
+
and_yield("/dev/md0 960492 36388 875312 4% /boot")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should run df -P" do
|
60
|
+
@ohai.should_receive(:popen4).with("df -P").and_return(true)
|
61
|
+
@ohai._require_plugin("linux::filesystem")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should set kb_size to value from df -P" do
|
65
|
+
@ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
66
|
+
@ohai._require_plugin("linux::filesystem")
|
67
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_size].should be == "97605057"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set kb_used to value from df -P" do
|
71
|
+
@ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
72
|
+
@ohai._require_plugin("linux::filesystem")
|
73
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_used].should be == "53563253"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set kb_available to value from df -P" do
|
77
|
+
@ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
78
|
+
@ohai._require_plugin("linux::filesystem")
|
79
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_available].should be == "44041805"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should set percent_used to value from df -P" do
|
83
|
+
@ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
84
|
+
@ohai._require_plugin("linux::filesystem")
|
85
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:percent_used].should be == "56%"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should set mount to value from df -P" do
|
89
|
+
@ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
90
|
+
@ohai._require_plugin("linux::filesystem")
|
91
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "when gathering mounted filesystem data from mount" do
|
96
|
+
before(:each) do
|
97
|
+
@stdin = mock("STDIN", { :close => true })
|
98
|
+
@pid = 10
|
99
|
+
@stderr = mock("STDERR")
|
100
|
+
@stdout = mock("STDOUT")
|
101
|
+
@status = 0
|
102
|
+
|
103
|
+
@stdout.stub!(:each).
|
104
|
+
and_yield("/dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro)").
|
105
|
+
and_yield("tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)").
|
106
|
+
and_yield("proc on /proc type proc (rw,noexec,nosuid,nodev)").
|
107
|
+
and_yield("sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)").
|
108
|
+
and_yield("udev on /dev type tmpfs (rw,mode=0755)").
|
109
|
+
and_yield("tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)").
|
110
|
+
and_yield("devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)").
|
111
|
+
and_yield("/dev/mapper/sys.vg-home.lv on /home type xfs (rw,noatime)").
|
112
|
+
and_yield("/dev/mapper/sys.vg-special.lv on /special type xfs (ro,noatime)").
|
113
|
+
and_yield("/dev/mapper/sys.vg-tmp.lv on /tmp type ext4 (rw,noatime)").
|
114
|
+
and_yield("/dev/mapper/sys.vg-usr.lv on /usr type ext4 (rw,noatime)").
|
115
|
+
and_yield("/dev/mapper/sys.vg-var.lv on /var type ext4 (rw,noatime)").
|
116
|
+
and_yield("/dev/md0 on /boot type ext3 (rw,noatime,errors=remount-ro)").
|
117
|
+
and_yield("fusectl on /sys/fs/fuse/connections type fusectl (rw)").
|
118
|
+
and_yield("binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)")
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should run mount" do
|
122
|
+
@ohai.should_receive(:popen4).with("mount").and_return(true)
|
123
|
+
@ohai._require_plugin("linux::filesystem")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should set mount to value from mount" do
|
127
|
+
@ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
128
|
+
@ohai._require_plugin("linux::filesystem")
|
129
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should set fs_type to value from mount" do
|
133
|
+
@ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
134
|
+
@ohai._require_plugin("linux::filesystem")
|
135
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should set mount_options to an array of values from mount" do
|
139
|
+
@ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
140
|
+
@ohai._require_plugin("linux::filesystem")
|
141
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime" ]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "when gathering filesystem type data from blkid" do
|
146
|
+
before(:each) do
|
147
|
+
@stdin = mock("STDIN", { :close => true })
|
148
|
+
@pid = 10
|
149
|
+
@stderr = mock("STDERR")
|
150
|
+
@stdout = mock("STDOUT")
|
151
|
+
@status = 0
|
152
|
+
|
153
|
+
@stdout.stub!(:each).
|
154
|
+
and_yield("/dev/sdb1: TYPE=\"linux_raid_member\" ").
|
155
|
+
and_yield("/dev/sdb2: TYPE=\"linux_raid_member\" ").
|
156
|
+
and_yield("/dev/sda1: TYPE=\"linux_raid_member\" ").
|
157
|
+
and_yield("/dev/sda2: TYPE=\"linux_raid_member\" ").
|
158
|
+
and_yield("/dev/md0: TYPE=\"ext3\" ").
|
159
|
+
and_yield("/dev/md1: TYPE=\"LVM2_member\" ").
|
160
|
+
and_yield("/dev/mapper/sys.vg-root.lv: TYPE=\"ext4\" ").
|
161
|
+
and_yield("/dev/mapper/sys.vg-swap.lv: TYPE=\"swap\" ").
|
162
|
+
and_yield("/dev/mapper/sys.vg-tmp.lv: TYPE=\"ext4\" ").
|
163
|
+
and_yield("/dev/mapper/sys.vg-usr.lv: TYPE=\"ext4\" ").
|
164
|
+
and_yield("/dev/mapper/sys.vg-var.lv: TYPE=\"ext4\" ").
|
165
|
+
and_yield("/dev/mapper/sys.vg-home.lv: TYPE=\"xfs\" ")
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should run blkid -s TYPE" do
|
169
|
+
@ohai.should_receive(:popen4).with("blkid -s TYPE").and_return(true)
|
170
|
+
@ohai._require_plugin("linux::filesystem")
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should set kb_size to value from blkid -s TYPE" do
|
174
|
+
@ohai.stub!(:popen4).with("blkid -s TYPE").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
175
|
+
@ohai._require_plugin("linux::filesystem")
|
176
|
+
@ohai[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "when gathering filesystem uuid data from blkid" do
|
181
|
+
before(:each) do
|
182
|
+
@stdin = mock("STDIN", { :close => true })
|
183
|
+
@pid = 10
|
184
|
+
@stderr = mock("STDERR")
|
185
|
+
@stdout = mock("STDOUT")
|
186
|
+
@status = 0
|
187
|
+
|
188
|
+
@stdout.stub!(:each).
|
189
|
+
and_yield("/dev/sdb1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" ").
|
190
|
+
and_yield("/dev/sdb2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" ").
|
191
|
+
and_yield("/dev/sda1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" ").
|
192
|
+
and_yield("/dev/sda2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" ").
|
193
|
+
and_yield("/dev/md0: UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" ").
|
194
|
+
and_yield("/dev/md1: UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" ").
|
195
|
+
and_yield("/dev/mapper/sys.vg-root.lv: UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" ").
|
196
|
+
and_yield("/dev/mapper/sys.vg-swap.lv: UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" ").
|
197
|
+
and_yield("/dev/mapper/sys.vg-tmp.lv: UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" ").
|
198
|
+
and_yield("/dev/mapper/sys.vg-usr.lv: UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" ").
|
199
|
+
and_yield("/dev/mapper/sys.vg-var.lv: UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" ").
|
200
|
+
and_yield("/dev/mapper/sys.vg-home.lv: UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" ")
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should run blkid -s UUID" do
|
204
|
+
@ohai.should_receive(:popen4).with("blkid -s UUID").and_return(true)
|
205
|
+
@ohai._require_plugin("linux::filesystem")
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should set kb_size to value from blkid -s UUID" do
|
209
|
+
@ohai.stub!(:popen4).with("blkid -s UUID").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
210
|
+
@ohai._require_plugin("linux::filesystem")
|
211
|
+
@ohai[:filesystem]["/dev/sda2"][:uuid].should be == "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "when gathering filesystem label data from blkid" do
|
216
|
+
before(:each) do
|
217
|
+
@stdin = mock("STDIN", { :close => true })
|
218
|
+
@pid = 10
|
219
|
+
@stderr = mock("STDERR")
|
220
|
+
@stdout = mock("STDOUT")
|
221
|
+
@status = 0
|
222
|
+
|
223
|
+
@stdout.stub!(:each).
|
224
|
+
and_yield("/dev/sda1: LABEL=\"fuego:0\" ").
|
225
|
+
and_yield("/dev/sda2: LABEL=\"fuego:1\" ").
|
226
|
+
and_yield("/dev/sdb1: LABEL=\"fuego:0\" ").
|
227
|
+
and_yield("/dev/sdb2: LABEL=\"fuego:1\" ").
|
228
|
+
and_yield("/dev/md0: LABEL=\"/boot\" ").
|
229
|
+
and_yield("/dev/mapper/sys.vg-root.lv: LABEL=\"/\" ").
|
230
|
+
and_yield("/dev/mapper/sys.vg-tmp.lv: LABEL=\"/tmp\" ").
|
231
|
+
and_yield("/dev/mapper/sys.vg-usr.lv: LABEL=\"/usr\" ").
|
232
|
+
and_yield("/dev/mapper/sys.vg-var.lv: LABEL=\"/var\" ").
|
233
|
+
and_yield("/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" ")
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should run blkid -s LABEL" do
|
237
|
+
@ohai.should_receive(:popen4).with("blkid -s LABEL").and_return(true)
|
238
|
+
@ohai._require_plugin("linux::filesystem")
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should set kb_size to value from blkid -s LABEL" do
|
242
|
+
@ohai.stub!(:popen4).with("blkid -s LABEL").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
243
|
+
@ohai._require_plugin("linux::filesystem")
|
244
|
+
@ohai[:filesystem]["/dev/md0"][:label].should be == "/boot"
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe "when gathering data from /proc/mounts" do
|
249
|
+
before(:each) do
|
250
|
+
File.stub!(:exists?).with("/proc/mounts").and_return(true)
|
251
|
+
@mock_file = mock("/proc/mounts")
|
252
|
+
@mock_file.stub!(:read_nonblock).and_return(@mock_file)
|
253
|
+
@mock_file.stub!(:each_line).
|
254
|
+
and_yield("rootfs / rootfs rw 0 0").
|
255
|
+
and_yield("none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0").
|
256
|
+
and_yield("none /proc proc rw,nosuid,nodev,noexec,relatime 0 0").
|
257
|
+
and_yield("none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0").
|
258
|
+
and_yield("none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0").
|
259
|
+
and_yield("/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0").
|
260
|
+
and_yield("tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0").
|
261
|
+
and_yield("tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0").
|
262
|
+
and_yield("/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0").
|
263
|
+
and_yield("/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0").
|
264
|
+
and_yield("/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0").
|
265
|
+
and_yield("/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0").
|
266
|
+
and_yield("/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0").
|
267
|
+
and_yield("/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0").
|
268
|
+
and_yield("fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0").
|
269
|
+
and_yield("binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0")
|
270
|
+
File.stub!(:open).with("/proc/mounts").and_return(@mock_file)
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should set mount to value from /proc/mounts" do
|
274
|
+
@ohai._require_plugin("linux::filesystem")
|
275
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should set fs_type to value from /proc/mounts" do
|
279
|
+
@ohai._require_plugin("linux::filesystem")
|
280
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should set mount_options to an array of values from /proc/mounts" do
|
284
|
+
@ohai._require_plugin("linux::filesystem")
|
285
|
+
@ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime", "attr2", "noquota" ]
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Caleb Tennis <caleb.tennis@gmail.com>
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, 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 CONDITIONS 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 File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
|
20
|
+
|
21
|
+
describe Ohai::System, "Linux Network Plugin" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
linux_ifconfig = <<-ENDIFCONFIG
|
25
|
+
eth0 Link encap:Ethernet HWaddr 12:31:3D:02:BE:A2
|
26
|
+
inet addr:10.116.201.76 Bcast:10.116.201.255 Mask:255.255.255.0
|
27
|
+
inet6 addr: fe80::1031:3dff:fe02:bea2/64 Scope:Link
|
28
|
+
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
29
|
+
RX packets:2659966 errors:0 dropped:0 overruns:0 frame:0
|
30
|
+
TX packets:1919690 errors:0 dropped:0 overruns:0 carrier:0
|
31
|
+
collisions:0 txqueuelen:1000
|
32
|
+
RX bytes:1392844460 (1.2 GiB) TX bytes:691785313 (659.7 MiB)
|
33
|
+
Interrupt:16
|
34
|
+
|
35
|
+
lo Link encap:Local Loopback
|
36
|
+
inet addr:127.0.0.1 Mask:255.0.0.0
|
37
|
+
inet6 addr: ::1/128 Scope:Host
|
38
|
+
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
39
|
+
RX packets:524 errors:0 dropped:0 overruns:0 frame:0
|
40
|
+
TX packets:524 errors:0 dropped:0 overruns:0 carrier:0
|
41
|
+
collisions:0 txqueuelen:0
|
42
|
+
RX bytes:35224 (34.3 KiB) TX bytes:35224 (34.3 KiB)
|
43
|
+
ENDIFCONFIG
|
44
|
+
|
45
|
+
linux_ip_addr = <<-IP_ADDR
|
46
|
+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
|
47
|
+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
48
|
+
inet 127.0.0.1/8 scope host lo
|
49
|
+
inet6 ::1/128 scope host
|
50
|
+
valid_lft forever preferred_lft forever
|
51
|
+
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
|
52
|
+
link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff
|
53
|
+
inet 10.116.201.76/24 brd 10.116.201.255 scope global eth0
|
54
|
+
inet6 fe80::1031:3dff:fe02:bea2/64 scope link
|
55
|
+
valid_lft forever preferred_lft forever
|
56
|
+
IP_ADDR
|
57
|
+
|
58
|
+
linux_ip_link_s = <<-IP_LINK_S
|
59
|
+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
|
60
|
+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
61
|
+
RX: bytes packets errors dropped overrun mcast
|
62
|
+
35224 524 0 0 0 0
|
63
|
+
TX: bytes packets errors dropped carrier collsns
|
64
|
+
35224 524 0 0 0 0
|
65
|
+
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
|
66
|
+
link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff
|
67
|
+
RX: bytes packets errors dropped overrun mcast
|
68
|
+
1392844460 2659966 0 0 0 0
|
69
|
+
TX: bytes packets errors dropped carrier collsns
|
70
|
+
691785313 1919690 0 0 0 0
|
71
|
+
IP_LINK_S
|
72
|
+
|
73
|
+
linux_route_n = <<-ROUTE_N
|
74
|
+
Kernel IP routing table
|
75
|
+
Destination Gateway Genmask Flags Metric Ref Use Iface
|
76
|
+
10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
|
77
|
+
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
|
78
|
+
0.0.0.0 10.116.201.1 0.0.0.0 UG 0 0 0 eth0
|
79
|
+
ROUTE_N
|
80
|
+
|
81
|
+
linux_arp_an = <<-ARP_AN
|
82
|
+
? (10.116.201.1) at fe:ff:ff:ff:ff:ff [ether] on eth0
|
83
|
+
ARP_AN
|
84
|
+
|
85
|
+
linux_ip_neighbor_show = <<-NEIGHBOR_SHOW
|
86
|
+
10.116.201.1 dev eth0 lladdr fe:ff:ff:ff:ff:ff REACHABLE
|
87
|
+
NEIGHBOR_SHOW
|
88
|
+
|
89
|
+
linux_ip_route_show_exact = <<-IP_ROUTE
|
90
|
+
default via 10.116.201.1 dev eth0
|
91
|
+
IP_ROUTE
|
92
|
+
|
93
|
+
@stdin_ifconfig = StringIO.new
|
94
|
+
@stdin_arp = StringIO.new
|
95
|
+
@stdin_ipaddr = StringIO.new
|
96
|
+
@stdin_iplink = StringIO.new
|
97
|
+
@stdin_ipneighbor = StringIO.new
|
98
|
+
|
99
|
+
@ifconfig_lines = linux_ifconfig.split("\n")
|
100
|
+
@route_lines = linux_route_n.split("\n")
|
101
|
+
@arp_lines = linux_arp_an.split("\n")
|
102
|
+
@ipaddr_lines = linux_ip_addr.split("\n")
|
103
|
+
@iplink_lines = linux_ip_link_s.split("\n")
|
104
|
+
@ipneighbor_lines = linux_ip_neighbor_show.split("\n")
|
105
|
+
@iproute_lines = linux_ip_route_show_exact
|
106
|
+
|
107
|
+
@ohai = Ohai::System.new
|
108
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
109
|
+
|
110
|
+
@ohai.stub(:popen4).with("ifconfig -a")
|
111
|
+
@ohai.stub(:popen4).with("arp -an")
|
112
|
+
end
|
113
|
+
|
114
|
+
["ifconfig","iproute2"].each do |network_method|
|
115
|
+
|
116
|
+
describe "gathering IP layer address info via #{network_method}" do
|
117
|
+
before do
|
118
|
+
File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
|
119
|
+
@ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
|
120
|
+
@ohai.stub!(:from).with("ip route show exact 0.0.0.0/0").and_return(@iproute_lines)
|
121
|
+
@ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
|
122
|
+
@ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
|
123
|
+
@ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
|
124
|
+
@ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
|
125
|
+
@ohai.stub!(:popen4).with("ip link -s").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
|
126
|
+
@ohai._require_plugin("network")
|
127
|
+
@ohai._require_plugin("linux::network")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "completes the run" do
|
131
|
+
@ohai['network'].should_not be_nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it "detects the interfaces" do
|
135
|
+
@ohai['network']['interfaces'].keys.sort.should == ["eth0", "lo"]
|
136
|
+
end
|
137
|
+
|
138
|
+
it "detects the ipv4 addresses of the ethernet interface" do
|
139
|
+
@ohai['network']['interfaces']['eth0']['addresses'].keys.should include('10.116.201.76')
|
140
|
+
@ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['netmask'].should == '255.255.255.0'
|
141
|
+
@ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['broadcast'].should == '10.116.201.255'
|
142
|
+
@ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['family'].should == 'inet'
|
143
|
+
end
|
144
|
+
|
145
|
+
it "detects the ipv6 addresses of the ethernet interface" do
|
146
|
+
@ohai['network']['interfaces']['eth0']['addresses'].keys.should include('fe80::1031:3dff:fe02:bea2')
|
147
|
+
@ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['scope'].should == 'Link'
|
148
|
+
@ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['prefixlen'].should == '64'
|
149
|
+
@ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['family'].should == 'inet6'
|
150
|
+
end
|
151
|
+
|
152
|
+
it "detects the mac addresses of the ethernet interface" do
|
153
|
+
@ohai['network']['interfaces']['eth0']['addresses'].keys.should include('12:31:3D:02:BE:A2')
|
154
|
+
@ohai['network']['interfaces']['eth0']['addresses']['12:31:3D:02:BE:A2']['family'].should == 'lladdr'
|
155
|
+
end
|
156
|
+
|
157
|
+
it "detects the encapsulation type of the ethernet interface" do
|
158
|
+
@ohai['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet'
|
159
|
+
end
|
160
|
+
|
161
|
+
it "detects the flags of the ethernet interface" do
|
162
|
+
if network_method == "ifconfig"
|
163
|
+
@ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP']
|
164
|
+
else
|
165
|
+
@ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','LOWER_UP','MULTICAST','UP']
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
it "detects the number of the ethernet interface" do
|
170
|
+
@ohai['network']['interfaces']['eth0']['number'].should == "0"
|
171
|
+
end
|
172
|
+
|
173
|
+
it "detects the mtu of the ethernet interface" do
|
174
|
+
@ohai['network']['interfaces']['eth0']['mtu'].should == "1500"
|
175
|
+
end
|
176
|
+
|
177
|
+
it "detects the ipv4 addresses of the loopback interface" do
|
178
|
+
@ohai['network']['interfaces']['lo']['addresses'].keys.should include('127.0.0.1')
|
179
|
+
@ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0'
|
180
|
+
@ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['family'].should == 'inet'
|
181
|
+
end
|
182
|
+
|
183
|
+
it "detects the ipv6 addresses of the loopback interface" do
|
184
|
+
@ohai['network']['interfaces']['lo']['addresses'].keys.should include('::1')
|
185
|
+
@ohai['network']['interfaces']['lo']['addresses']['::1']['scope'].should == 'Node'
|
186
|
+
@ohai['network']['interfaces']['lo']['addresses']['::1']['prefixlen'].should == '128'
|
187
|
+
@ohai['network']['interfaces']['lo']['addresses']['::1']['family'].should == 'inet6'
|
188
|
+
end
|
189
|
+
|
190
|
+
it "detects the encapsulation type of the loopback interface" do
|
191
|
+
@ohai['network']['interfaces']['lo']['encapsulation'].should == 'Loopback'
|
192
|
+
end
|
193
|
+
|
194
|
+
it "detects the flags of the ethernet interface" do
|
195
|
+
if network_method == "ifconfig"
|
196
|
+
@ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP']
|
197
|
+
else
|
198
|
+
@ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','LOWER_UP','UP']
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
it "detects the mtu of the loopback interface" do
|
204
|
+
@ohai['network']['interfaces']['lo']['mtu'].should == "16436"
|
205
|
+
end
|
206
|
+
|
207
|
+
it "detects the arp entries" do
|
208
|
+
@ohai['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff'
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "gathering interface counters via #{network_method}" do
|
214
|
+
before do
|
215
|
+
File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
|
216
|
+
@ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
|
217
|
+
@ohai.stub!(:from).with("ip route show exact 0.0.0.0/0").and_return(@iproute_lines)
|
218
|
+
@ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
|
219
|
+
@ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
|
220
|
+
@ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
|
221
|
+
@ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
|
222
|
+
@ohai.stub!(:popen4).with("ip link -s").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
|
223
|
+
@ohai._require_plugin("network")
|
224
|
+
@ohai._require_plugin("linux::network")
|
225
|
+
end
|
226
|
+
|
227
|
+
it "detects the ethernet counters" do
|
228
|
+
@ohai['counters']['network']['interfaces']['eth0']['tx']['bytes'].should == "691785313"
|
229
|
+
@ohai['counters']['network']['interfaces']['eth0']['tx']['packets'].should == "1919690"
|
230
|
+
@ohai['counters']['network']['interfaces']['eth0']['tx']['collisions'].should == "0"
|
231
|
+
@ohai['counters']['network']['interfaces']['eth0']['tx']['queuelen'].should == "1000"
|
232
|
+
@ohai['counters']['network']['interfaces']['eth0']['tx']['errors'].should == "0"
|
233
|
+
@ohai['counters']['network']['interfaces']['eth0']['tx']['carrier'].should == "0"
|
234
|
+
@ohai['counters']['network']['interfaces']['eth0']['tx']['drop'].should == "0"
|
235
|
+
|
236
|
+
@ohai['counters']['network']['interfaces']['eth0']['rx']['bytes'].should == "1392844460"
|
237
|
+
@ohai['counters']['network']['interfaces']['eth0']['rx']['packets'].should == "2659966"
|
238
|
+
@ohai['counters']['network']['interfaces']['eth0']['rx']['errors'].should == "0"
|
239
|
+
@ohai['counters']['network']['interfaces']['eth0']['rx']['overrun'].should == "0"
|
240
|
+
@ohai['counters']['network']['interfaces']['eth0']['rx']['drop'].should == "0"
|
241
|
+
end
|
242
|
+
|
243
|
+
it "detects the loopback counters" do
|
244
|
+
@ohai['counters']['network']['interfaces']['lo']['tx']['bytes'].should == "35224"
|
245
|
+
@ohai['counters']['network']['interfaces']['lo']['tx']['packets'].should == "524"
|
246
|
+
@ohai['counters']['network']['interfaces']['lo']['tx']['collisions'].should == "0"
|
247
|
+
@ohai['counters']['network']['interfaces']['lo']['tx']['errors'].should == "0"
|
248
|
+
@ohai['counters']['network']['interfaces']['lo']['tx']['carrier'].should == "0"
|
249
|
+
@ohai['counters']['network']['interfaces']['lo']['tx']['drop'].should == "0"
|
250
|
+
|
251
|
+
@ohai['counters']['network']['interfaces']['lo']['rx']['bytes'].should == "35224"
|
252
|
+
@ohai['counters']['network']['interfaces']['lo']['rx']['packets'].should == "524"
|
253
|
+
@ohai['counters']['network']['interfaces']['lo']['rx']['errors'].should == "0"
|
254
|
+
@ohai['counters']['network']['interfaces']['lo']['rx']['overrun'].should == "0"
|
255
|
+
@ohai['counters']['network']['interfaces']['lo']['rx']['drop'].should == "0"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
describe "setting the node's default IP address attribute with #{network_method}" do
|
260
|
+
before do
|
261
|
+
File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
|
262
|
+
@ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
|
263
|
+
@ohai.stub!(:from).with("ip route show exact 0.0.0.0/0").and_return(@iproute_lines)
|
264
|
+
@ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
|
265
|
+
@ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
|
266
|
+
@ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
|
267
|
+
@ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
|
268
|
+
@ohai.stub!(:popen4).with("ip link -s").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
|
269
|
+
@ohai._require_plugin("network")
|
270
|
+
@ohai._require_plugin("linux::network")
|
271
|
+
end
|
272
|
+
|
273
|
+
it "finds the default interface by asking which iface has the default route" do
|
274
|
+
@ohai['network'][:default_interface].should == 'eth0'
|
275
|
+
end
|
276
|
+
|
277
|
+
it "finds the default interface by asking which iface has the default route" do
|
278
|
+
@ohai['network'][:default_gateway].should == '10.116.201.1'
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|