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.
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
  require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
21
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
21
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
22
22
 
23
23
  describe Ohai::System, "Linux plugin platform" do
24
24
  before(:each) do
@@ -34,6 +34,8 @@ describe Ohai::System, "Linux plugin platform" do
34
34
  File.stub!(:exists?).with("/etc/arch-release").and_return(false)
35
35
  File.stub!(:exists?).with("/etc/system-release").and_return(false)
36
36
  File.stub!(:exists?).with("/etc/slackware-version").and_return(false)
37
+ File.stub!(:exists?).with("/etc/enterprise-release").and_return(false)
38
+ File.stub!(:exists?).with("/etc/oracle-release").and_return(false)
37
39
  end
38
40
 
39
41
  it "should require the lsb plugin" do
@@ -50,6 +52,7 @@ describe Ohai::System, "Linux plugin platform" do
50
52
  it "should set platform to lowercased lsb[:id]" do
51
53
  @ohai._require_plugin("linux::platform")
52
54
  @ohai[:platform].should == "ubuntu"
55
+
53
56
  end
54
57
 
55
58
  it "should set platform_version to lsb[:release]" do
@@ -57,18 +60,45 @@ describe Ohai::System, "Linux plugin platform" do
57
60
  @ohai[:platform_version].should == "8.04"
58
61
  end
59
62
 
60
- it "should set platform to redhat when [:lsb][:id] contains Redhat" do
63
+ it "should set platform to ubuntu and platform_family to debian [:lsb][:id] contains Ubuntu" do
64
+ @ohai[:lsb][:id] = "Ubuntu"
65
+ @ohai._require_plugin("linux::platform")
66
+ @ohai[:platform].should == "ubuntu"
67
+ @ohai[:platform_family].should == "debian"
68
+ end
69
+ it "should set platform to mint and platform_family to debian [:lsb][:id] contains Mint" do
70
+ @ohai[:lsb][:id] = "Mint"
71
+ @ohai._require_plugin("linux::platform")
72
+ @ohai[:platform].should == "mint"
73
+ @ohai[:platform_family].should == "debian"
74
+ end
75
+ it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do
76
+ @ohai[:lsb][:id] = "Debian"
77
+ @ohai._require_plugin("linux::platform")
78
+ @ohai[:platform].should == "debian"
79
+ @ohai[:platform_family].should == "debian"
80
+ end
81
+ it "should set platform to redhat and platform_family to rhel when [:lsb][:id] contains Redhat" do
61
82
  @ohai[:lsb][:id] = "RedHatEnterpriseServer"
62
83
  @ohai[:lsb][:release] = "5.7"
63
84
  @ohai._require_plugin("linux::platform")
64
85
  @ohai[:platform].should == "redhat"
86
+ @ohai[:platform_family].should == "rhel"
65
87
  end
66
88
 
67
- it "should set platform to amazon when [:lsb][:id] contains Amazon" do
89
+ it "should set platform to amazon and platform_family to fedora when [:lsb][:id] contains Amazon" do
68
90
  @ohai[:lsb][:id] = "AmazonAMI"
69
91
  @ohai[:lsb][:release] = "2011.09"
70
92
  @ohai._require_plugin("linux::platform")
71
93
  @ohai[:platform].should == "amazon"
94
+ @ohai[:platform_family].should == "fedora"
95
+ end
96
+
97
+ it "should set platform to scientific when [:lsb][:id] contains ScientificSL" do
98
+ @ohai[:lsb][:id] = "ScientificSL"
99
+ @ohai[:lsb][:release] = "5.7"
100
+ @ohai._require_plugin("linux::platform")
101
+ @ohai[:platform].should == "scientific"
72
102
  end
73
103
  end
74
104
 
@@ -102,9 +132,11 @@ describe Ohai::System, "Linux plugin platform" do
102
132
  File.should_receive(:exists?).with("/etc/slackware-version").and_return(true)
103
133
  end
104
134
 
105
- it "should set platform to slackware" do
135
+ it "should set platform and platform_family to slackware" do
136
+ File.should_receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
106
137
  @ohai._require_plugin("linux::platform")
107
138
  @ohai[:platform].should == "slackware"
139
+ @ohai[:platform_family].should == "slackware"
108
140
  end
109
141
  end
110
142
 
@@ -114,10 +146,12 @@ describe Ohai::System, "Linux plugin platform" do
114
146
  File.should_receive(:exists?).with("/etc/arch-release").and_return(true)
115
147
  end
116
148
 
117
- it "should set platform to arch" do
149
+ it "should set platform to arch and platform_family to arch" do
118
150
  @ohai._require_plugin("linux::platform")
119
151
  @ohai[:platform].should == "arch"
152
+ @ohai[:platform_family].should == "arch"
120
153
  end
154
+
121
155
  end
122
156
 
123
157
  describe "on gentoo" do
@@ -126,28 +160,58 @@ describe Ohai::System, "Linux plugin platform" do
126
160
  File.should_receive(:exists?).with("/etc/gentoo-release").and_return(true)
127
161
  end
128
162
 
129
- it "should set platform to gentoo" do
163
+ it "should set platform and platform_family to gentoo" do
164
+ File.should_receive(:read).with("/etc/gentoo-release").and_return("Gentoo Base System release 1.20.1.1")
130
165
  @ohai._require_plugin("linux::platform")
131
166
  @ohai[:platform].should == "gentoo"
167
+ @ohai[:platform_family].should == "gentoo"
132
168
  end
133
169
  end
134
170
 
135
171
  describe "on redhat breeds" do
136
172
  describe "with lsb_release results" do
137
- it "should set the platform to redhat even if the LSB name is something absurd but redhat like" do
173
+ it "should set the platform to redhat and platform_family to rhel even if the LSB name is something absurd but redhat like" do
138
174
  @ohai[:lsb][:id] = "RedHatEnterpriseServer"
139
175
  @ohai[:lsb][:release] = "6.1"
140
176
  @ohai._require_plugin("linux::platform")
141
177
  @ohai[:platform].should == "redhat"
142
178
  @ohai[:platform_version].should == "6.1"
179
+ @ohai[:platform_family].should == "rhel"
143
180
  end
144
181
 
145
- it "should set the platform to centos" do
182
+ it "should set the platform to centos and platform_family to rhel" do
146
183
  @ohai[:lsb][:id] = "CentOS"
147
184
  @ohai[:lsb][:release] = "5.4"
148
185
  @ohai._require_plugin("linux::platform")
149
186
  @ohai[:platform].should == "centos"
150
187
  @ohai[:platform_version].should == "5.4"
188
+ @ohai[:platform_family].should == "rhel"
189
+
190
+ end
191
+
192
+
193
+ it "should set the platform_family to rhel if the LSB name is oracle-ish" do
194
+ @ohai[:lsb][:id] = "EnterpriseEnterpriseServer"
195
+ @ohai._require_plugin("linux::platform")
196
+ @ohai[:platform_family].should == "rhel"
197
+ end
198
+
199
+ it "should set the platform_family to fedora if the LSB name is amazon-ish" do
200
+ @ohai[:lsb][:id] = "Amazon"
201
+ @ohai._require_plugin("linux::platform")
202
+ @ohai[:platform_family].should == "fedora"
203
+ end
204
+
205
+ it "should set the platform_family to fedora if the LSB name is fedora-ish" do
206
+ @ohai[:lsb][:id] = "Fedora"
207
+ @ohai._require_plugin("linux::platform")
208
+ @ohai[:platform_family].should == "fedora"
209
+ end
210
+
211
+ it "should set the platform_family to redhat if the LSB name is scientific-ish" do
212
+ @ohai[:lsb][:id] = "Scientific"
213
+ @ohai._require_plugin("linux::platform")
214
+ @ohai[:platform_family].should == "rhel"
151
215
  end
152
216
  end
153
217
 
@@ -204,6 +268,90 @@ describe Ohai::System, "Linux plugin platform" do
204
268
  end
205
269
  end
206
270
 
271
+ describe "on oracle enterprise linux" do
272
+ describe "with lsb_results" do
273
+ it "should read the platform as oracle and version as 5.7" do
274
+ @ohai[:lsb][:id] = "EnterpriseEnterpriseServer"
275
+ @ohai[:lsb][:release] = "5.7"
276
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
277
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
278
+ File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true)
279
+ File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
280
+ @ohai._require_plugin("linux::platform")
281
+ @ohai[:platform].should == "oracle"
282
+ @ohai[:platform_version].should == "5.7"
283
+ end
284
+
285
+ it "should read the platform as oracle and version as 6.1" do
286
+ @ohai[:lsb][:id] = "OracleServer"
287
+ @ohai[:lsb][:release] = "6.1"
288
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
289
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
290
+ File.should_receive(:exists?).with("/etc/oracle-release").and_return(true)
291
+ File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
292
+ @ohai._require_plugin("linux::platform")
293
+ @ohai[:platform].should == "oracle"
294
+ @ohai[:platform_version].should == "6.1"
295
+ end
296
+ end
297
+
298
+ describe "without lsb_results" do
299
+ before(:each) do
300
+ @ohai.lsb = nil
301
+ end
302
+
303
+ it "should read the platform as oracle and version as 5" do
304
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
305
+ File.stub!(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
306
+ File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true)
307
+ File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
308
+ @ohai._require_plugin("linux::platform")
309
+ @ohai[:platform].should == "oracle"
310
+ @ohai[:platform_version].should == "5"
311
+ end
312
+
313
+ it "should read the platform as oracle and version as 5.1" do
314
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
315
+ File.stub!(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
316
+ File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true)
317
+ File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
318
+ @ohai._require_plugin("linux::platform")
319
+ @ohai[:platform].should == "oracle"
320
+ @ohai[:platform_version].should == "5.1"
321
+ end
322
+
323
+ it "should read the platform as oracle and version as 5.7" do
324
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
325
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
326
+ File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true)
327
+ File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
328
+ @ohai._require_plugin("linux::platform")
329
+ @ohai[:platform].should == "oracle"
330
+ @ohai[:platform_version].should == "5.7"
331
+ end
332
+
333
+ it "should read the platform as oracle and version as 6.0" do
334
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
335
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
336
+ File.should_receive(:exists?).with("/etc/oracle-release").and_return(true)
337
+ File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0")
338
+ @ohai._require_plugin("linux::platform")
339
+ @ohai[:platform].should == "oracle"
340
+ @ohai[:platform_version].should == "6.0"
341
+ end
342
+
343
+ it "should read the platform as oracle and version as 6.1" do
344
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
345
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
346
+ File.should_receive(:exists?).with("/etc/oracle-release").and_return(true)
347
+ File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
348
+ @ohai._require_plugin("linux::platform")
349
+ @ohai[:platform].should == "oracle"
350
+ @ohai[:platform_version].should == "6.1"
351
+ end
352
+ end
353
+ end
354
+
207
355
  describe "on suse" do
208
356
  before(:each) do
209
357
  @ohai.lsb = nil
@@ -214,9 +362,11 @@ describe Ohai::System, "Linux plugin platform" do
214
362
  @ohai._require_plugin("linux::platform")
215
363
  end
216
364
 
217
- it "should set platform to suse" do
365
+ it "should set platform and platform_family to suse and bogus verion to 10.0" do
366
+ File.should_receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
218
367
  @ohai._require_plugin("linux::platform")
219
368
  @ohai[:platform].should == "suse"
369
+ @ohai[:platform_family].should == "suse"
220
370
  end
221
371
 
222
372
  it "should read the version as 10.1 for bogus SLES 10" do
@@ -224,6 +374,7 @@ describe Ohai::System, "Linux plugin platform" do
224
374
  @ohai._require_plugin("linux::platform")
225
375
  @ohai[:platform].should == "suse"
226
376
  @ohai[:platform_version].should == "10.1"
377
+ @ohai[:platform_family].should == "suse"
227
378
  end
228
379
 
229
380
  it "should read the version as 11.2" do
@@ -231,6 +382,7 @@ describe Ohai::System, "Linux plugin platform" do
231
382
  @ohai._require_plugin("linux::platform")
232
383
  @ohai[:platform].should == "suse"
233
384
  @ohai[:platform_version].should == "11.2"
385
+ @ohai[:platform_family].should == "suse"
234
386
  end
235
387
 
236
388
  it "[OHAI-272] should read the version as 11.3" do
@@ -238,6 +390,7 @@ describe Ohai::System, "Linux plugin platform" do
238
390
  @ohai._require_plugin("linux::platform")
239
391
  @ohai[:platform].should == "suse"
240
392
  @ohai[:platform_version].should == "11.3"
393
+ @ohai[:platform_family].should == "suse"
241
394
  end
242
395
 
243
396
  it "[OHAI-272] should read the version as 9.1" do
@@ -245,6 +398,7 @@ describe Ohai::System, "Linux plugin platform" do
245
398
  @ohai._require_plugin("linux::platform")
246
399
  @ohai[:platform].should == "suse"
247
400
  @ohai[:platform_version].should == "9.1"
401
+ @ohai[:platform_family].should == "suse"
248
402
  end
249
403
 
250
404
  it "[OHAI-272] should read the version as 11.4" do
@@ -252,6 +406,7 @@ describe Ohai::System, "Linux plugin platform" do
252
406
  @ohai._require_plugin("linux::platform")
253
407
  @ohai[:platform].should == "suse"
254
408
  @ohai[:platform_version].should == "11.4"
409
+ @ohai[:platform_family].should == "suse"
255
410
  end
256
411
  end
257
412
 
@@ -19,7 +19,7 @@
19
19
 
20
20
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
21
21
 
22
- ORIGINAL_CONFIG_HOST_OS = ::Config::CONFIG['host_os']
22
+ ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG['host_os']
23
23
 
24
24
  describe Ohai::System, "plugin os" do
25
25
  before(:each) do
@@ -32,7 +32,7 @@ describe Ohai::System, "plugin os" do
32
32
  end
33
33
 
34
34
  after do
35
- ::Config::CONFIG['host_os'] = ORIGINAL_CONFIG_HOST_OS
35
+ ::RbConfig::CONFIG['host_os'] = ORIGINAL_CONFIG_HOST_OS
36
36
  end
37
37
 
38
38
  it "should set os_version to kernel_release" do
@@ -42,7 +42,7 @@ describe Ohai::System, "plugin os" do
42
42
 
43
43
  describe "on linux" do
44
44
  before(:each) do
45
- ::Config::CONFIG['host_os'] = "linux"
45
+ ::RbConfig::CONFIG['host_os'] = "linux"
46
46
  end
47
47
 
48
48
  it "should set the os to linux" do
@@ -53,7 +53,7 @@ describe Ohai::System, "plugin os" do
53
53
 
54
54
  describe "on darwin" do
55
55
  before(:each) do
56
- ::Config::CONFIG['host_os'] = "darwin"
56
+ ::RbConfig::CONFIG['host_os'] = "darwin10.0"
57
57
  end
58
58
 
59
59
  it "should set the os to darwin" do
@@ -64,7 +64,7 @@ describe Ohai::System, "plugin os" do
64
64
 
65
65
  describe "on solaris" do
66
66
  before do
67
- ::Config::CONFIG['host_os'] = "solaris2.42" #heh
67
+ ::RbConfig::CONFIG['host_os'] = "solaris2.42" #heh
68
68
  end
69
69
 
70
70
  it "sets the os to solaris2" do
@@ -32,9 +32,10 @@ describe Ohai::System, "plugin platform" do
32
32
  @ohai._require_plugin("platform")
33
33
  end
34
34
 
35
- it "should set the platform to the os if it was not set earlier" do
35
+ it "should set the platform and platform family to the os if it was not set earlier" do
36
36
  @ohai._require_plugin("platform")
37
37
  @ohai[:platform].should eql("monkey")
38
+ @ohai[:platform_family].should eql ("monkey")
38
39
  end
39
40
 
40
41
  it "should not set the platform to the os if it was set earlier" do
@@ -43,6 +44,20 @@ describe Ohai::System, "plugin platform" do
43
44
  @ohai[:platform].should eql("lars")
44
45
  end
45
46
 
47
+ it "should set the platform_family to the platform if platform was set earlier but not platform_family" do
48
+ @ohai[:platform] = 'lars'
49
+ @ohai[:platform_family] = 'jack'
50
+ @ohai._require_plugin("platform")
51
+ @ohai[:platform_family].should eql ("jack")
52
+ end
53
+
54
+ it "should not set the platform_family if the platform_family was set earlier." do
55
+ @ohai[:platform] = 'lars'
56
+ @ohai._require_plugin("platform")
57
+ @ohai[:platform].should eql("lars")
58
+ @ohai[:platform_family].should eql ("lars")
59
+ end
60
+
46
61
  it "should set the platform_version to the os_version if it was not set earlier" do
47
62
  @ohai._require_plugin("platform")
48
63
  @ohai[:os_version].should eql("poop")
@@ -53,4 +68,4 @@ describe Ohai::System, "plugin platform" do
53
68
  @ohai._require_plugin("platform")
54
69
  @ohai[:platform_version].should eql("ulrich")
55
70
  end
56
- end
71
+ end
@@ -23,10 +23,17 @@ ruby_bin = File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_
23
23
 
24
24
  describe Ohai::System, "plugin ruby" do
25
25
 
26
- before(:each) do
26
+ before(:all) do
27
27
  @ohai = Ohai::System.new
28
- @ohai[:languages] = Mash.new
29
- @ohai.stub!(:require_plugin).and_return(true)
28
+ @ohai[:languages] = Mash.new
29
+
30
+ @ohai.require_plugin("ruby")
31
+
32
+ @ruby_ohai_data_pristine = @ohai[:languages][:ruby]
33
+ end
34
+
35
+ before(:each) do
36
+ @ruby_ohai_data = @ruby_ohai_data_pristine.dup
30
37
  end
31
38
 
32
39
  {
@@ -47,8 +54,7 @@ describe Ohai::System, "plugin ruby" do
47
54
  :ruby_bin => ruby_bin
48
55
  }.each do |attribute, value|
49
56
  it "should have #{attribute} set" do
50
- @ohai._require_plugin("ruby")
51
- @ohai[:languages][:ruby][attribute].should eql(value)
57
+ @ruby_ohai_data[attribute].should eql(value)
52
58
  end
53
59
  end
54
60
 
@@ -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.
@@ -17,118 +17,132 @@
17
17
  #
18
18
 
19
19
  require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
20
- require 'sigar'
20
+
21
+ sigar_available = begin
22
+ require 'sigar'
23
+ true
24
+ rescue LoadError
25
+ false
26
+ end
27
+
21
28
  require 'ohai'
22
29
 
23
30
  describe Ohai::System, "Sigar network route plugin" do
24
31
 
25
- before(:each) do
26
- @ohai = Ohai::System.new
27
- @sigar = double("Sigar")
28
- @net_info_conf={
29
- :default_gateway => "192.168.1.254",
30
- :default_gateway_interface => "eth0",
31
- :primary_dns => "192.168.1.254",
32
- :secondary_dns => "8.8.8.8",
33
- :host_name => "localhost"
34
- }
35
- net_info=double("Sigar::NetInfo")
36
- @net_info_conf.each_pair do |k,v|
37
- net_info.stub(k).and_return(v)
38
- end
39
- @net_route_conf={
40
- :destination => "192.168.1.0",
41
- :gateway => "0.0.0.0",
42
- :flags => 1,
43
- :refcnt => 0,
44
- :use => 0,
45
- :ifname => "eth0",
46
- :metric => 0,
47
- :mtu => 0,
48
- :window => 0,
49
- :irtt => 0
50
- }
51
- net_route=double("Sigar::NetRoute")
52
- @net_route_conf.each_pair do |k,v|
53
- net_route.stub(k).and_return(v)
54
- end
55
- @net_interface_conf={
56
- :flags => 2115,
57
- :destination => "192.168.1.1",
58
- :mtu => 1500,
59
- :type => "Ethernet",
60
- :hwaddr => "00:11:22:33:44:55:66",
61
- :address => "192.168.1.1",
62
- :broadcast => "192.168.1.255",
63
- :netmask => "255.255.255.0",
64
- :address6 => nil,
65
- :tx_queue_len => 1000,
66
- :prefix6_length => 0,
67
- }
68
- net_conf=double("Sigar::NetConf")
69
- @net_interface_conf.each_pair do |k,v|
70
- net_conf.stub(k).and_return(v)
71
- end
72
- @net_interface_stat={
73
- :rx_bytes=>1369035618,
74
- :rx_dropped=>0,
75
- :rx_errors=>0,
76
- :rx_frame=>0,
77
- :rx_overruns=>0,
78
- :rx_packets=>7271669,
79
- :speed=>-1,
80
- :tx_bytes=>3482843666,
81
- :tx_carrier=>0,
82
- :tx_collisions=>0,
83
- :tx_dropped=>0,
84
- :tx_errors=>0,
85
- :tx_overruns=>0,
86
- :tx_packets=>4392794
87
- }
88
- net_stat=double("Sigar::NetStat")
89
- @net_interface_stat.each_pair do |k,v|
90
- net_stat.stub(k).and_return(v)
32
+ if sigar_available
33
+
34
+ before(:each) do
35
+ @ohai = Ohai::System.new
36
+ @sigar = double("Sigar")
37
+ @net_info_conf={
38
+ :default_gateway => "192.168.1.254",
39
+ :default_gateway_interface => "eth0",
40
+ :primary_dns => "192.168.1.254",
41
+ :secondary_dns => "8.8.8.8",
42
+ :host_name => "localhost"
43
+ }
44
+ net_info=double("Sigar::NetInfo")
45
+ @net_info_conf.each_pair do |k,v|
46
+ net_info.stub(k).and_return(v)
47
+ end
48
+ @net_route_conf={
49
+ :destination => "192.168.1.0",
50
+ :gateway => "0.0.0.0",
51
+ :mask => "255.255.255.0",
52
+ :flags => 1,
53
+ :refcnt => 0,
54
+ :use => 0,
55
+ :metric => 0,
56
+ :mtu => 0,
57
+ :window => 0,
58
+ :irtt => 0,
59
+ :ifname => "eth0"
60
+ }
61
+ net_route=double("Sigar::NetRoute")
62
+ @net_route_conf.each_pair do |k,v|
63
+ net_route.stub(k).and_return(v)
64
+ end
65
+ @net_interface_conf={
66
+ :flags => 2115,
67
+ :destination => "192.168.1.1",
68
+ :mtu => 1500,
69
+ :type => "Ethernet",
70
+ :hwaddr => "00:11:22:33:44:55:66",
71
+ :address => "192.168.1.1",
72
+ :broadcast => "192.168.1.255",
73
+ :netmask => "255.255.255.0",
74
+ :address6 => nil,
75
+ :tx_queue_len => 1000,
76
+ :prefix6_length => 0,
77
+ }
78
+ net_conf=double("Sigar::NetConf")
79
+ @net_interface_conf.each_pair do |k,v|
80
+ net_conf.stub(k).and_return(v)
81
+ end
82
+ @net_interface_stat={
83
+ :rx_bytes=>1369035618,
84
+ :rx_dropped=>0,
85
+ :rx_errors=>0,
86
+ :rx_frame=>0,
87
+ :rx_overruns=>0,
88
+ :rx_packets=>7271669,
89
+ :speed=>-1,
90
+ :tx_bytes=>3482843666,
91
+ :tx_carrier=>0,
92
+ :tx_collisions=>0,
93
+ :tx_dropped=>0,
94
+ :tx_errors=>0,
95
+ :tx_overruns=>0,
96
+ :tx_packets=>4392794
97
+ }
98
+ net_stat=double("Sigar::NetStat")
99
+ @net_interface_stat.each_pair do |k,v|
100
+ net_stat.stub(k).and_return(v)
101
+ end
102
+ @net_arp_conf={
103
+ :address => "192.168.1.5",
104
+ :flags => 2,
105
+ :hwaddr => "00:15:62:96:01:D0",
106
+ :ifname => "eth0",
107
+ :type => "ether",
108
+ }
109
+ net_arp=double("Sigar::NetArp")
110
+ @net_arp_conf.each_pair do |k,v|
111
+ net_arp.stub(k).and_return(v)
112
+ end
113
+ @sigar.stub(:fqdn).and_return("localhost.localdomain")
114
+ @sigar.should_receive(:net_info).at_least(2).times.and_return(net_info)
115
+ @sigar.should_receive(:net_interface_list).once.and_return(["eth0"])
116
+ @sigar.should_receive(:net_interface_config).with("eth0").and_return(net_conf)
117
+ @sigar.should_receive(:net_interface_stat).with("eth0").and_return(net_stat)
118
+ @sigar.should_receive(:arp_list).once.and_return([net_arp])
119
+
120
+ # Since we mock net_route_list here, flags never gets called
121
+ @sigar.should_receive(:net_route_list).once.and_return([net_route])
122
+ Sigar.should_receive(:new).at_least(2).times.and_return(@sigar)
123
+ @ohai.require_plugin("os")
124
+ @ohai[:os]="sigar"
125
+ @ohai.require_plugin("network")
126
+ @ohai.require_plugin("sigar::network_route")
91
127
  end
92
- @net_arp_conf={
93
- :address => "192.168.1.5",
94
- :flags => 2,
95
- :hwaddr => "00:15:62:96:01:D0",
96
- :ifname => "eth0",
97
- :type => "ether",
98
- }
99
- net_arp=double("Sigar::NetArp")
100
- @net_arp_conf.each_pair do |k,v|
101
- net_arp.stub(k).and_return(v)
128
+
129
+ it "should set the routes" do
130
+ @ohai[:network][:interfaces][:eth0].should have_key(:route)
102
131
  end
103
- @sigar.stub(:fqdn).and_return("localhost.localdomain")
104
- @sigar.should_receive(:net_info).at_least(2).times.and_return(net_info)
105
- @sigar.should_receive(:net_interface_list).once.and_return(["eth0"])
106
- @sigar.should_receive(:net_interface_config).with("eth0").and_return(net_conf)
107
- @sigar.should_receive(:net_interface_stat).with("eth0").and_return(net_stat)
108
- @sigar.should_receive(:arp_list).once.and_return([net_arp])
109
132
 
110
- # Since we mock net_route_list here, flags never gets called
111
- @sigar.should_receive(:net_route_list).once.and_return([net_route])
112
- Sigar.should_receive(:new).at_least(2).times.and_return(@sigar)
113
- @ohai.require_plugin("os")
114
- @ohai[:os]="sigar"
115
- @ohai.require_plugin("network")
116
- @ohai.require_plugin("sigar::network_route")
117
- end
118
-
119
- it "should set the routes" do
120
- @ohai[:network][:interfaces][:eth0].should have_key(:route)
121
- end
122
-
123
- it "should set the route details" do
124
- @net_route_conf.each_pair do |k,v|
125
- # Work around the above mocking of net_route_list skipping the call to flags()
126
- if k == :flags
127
- v="U"
128
- @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v
133
+ it "should set the route details" do
134
+ @net_route_conf.each_pair do |k,v|
135
+ # Work around the above mocking of net_route_list skipping the call to flags()
136
+ if k == :flags
137
+ v="U"
138
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v
139
+ end
140
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"].should have_key(k)
141
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k].should eql(v)
129
142
  end
130
- @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"].should have_key(k)
131
- @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k].should eql(v)
132
143
  end
144
+
145
+ else
146
+ pending "Sigar not available, skipping sigar tests"
133
147
  end
134
148
  end