ohai 0.6.12 → 0.6.14.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -66,10 +66,10 @@ describe Ohai::System, "Linux plugin platform" do
66
66
  @ohai[:platform].should == "ubuntu"
67
67
  @ohai[:platform_family].should == "debian"
68
68
  end
69
- it "should set platform to mint and platform_family to debian [:lsb][:id] contains Mint" do
70
- @ohai[:lsb][:id] = "Mint"
69
+ it "should set platform to linuxmint and platform_family to debian [:lsb][:id] contains LinuxMint" do
70
+ @ohai[:lsb][:id] = "LinuxMint"
71
71
  @ohai._require_plugin("linux::platform")
72
- @ohai[:platform].should == "mint"
72
+ @ohai[:platform].should == "linuxmint"
73
73
  @ohai[:platform_family].should == "debian"
74
74
  end
75
75
  it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do
@@ -354,59 +354,79 @@ describe Ohai::System, "Linux plugin platform" do
354
354
 
355
355
  describe "on suse" do
356
356
  before(:each) do
357
- @ohai.lsb = nil
358
357
  File.should_receive(:exists?).with("/etc/SuSE-release").and_return(true)
359
358
  end
360
-
361
- it "should check for the existance of SuSE-release" do
362
- @ohai._require_plugin("linux::platform")
363
- end
364
-
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")
367
- @ohai._require_plugin("linux::platform")
368
- @ohai[:platform].should == "suse"
369
- @ohai[:platform_family].should == "suse"
370
- end
371
-
372
- it "should read the version as 10.1 for bogus SLES 10" do
373
- File.should_receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 10 (i586)\nVERSION = 10\nPATCHLEVEL = 1\n")
374
- @ohai._require_plugin("linux::platform")
375
- @ohai[:platform].should == "suse"
376
- @ohai[:platform_version].should == "10.1"
377
- @ohai[:platform_family].should == "suse"
378
- end
379
-
380
- it "should read the version as 11.2" do
381
- File.should_receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
382
- @ohai._require_plugin("linux::platform")
383
- @ohai[:platform].should == "suse"
384
- @ohai[:platform_version].should == "11.2"
385
- @ohai[:platform_family].should == "suse"
386
- end
387
-
388
- it "[OHAI-272] should read the version as 11.3" do
389
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
390
- @ohai._require_plugin("linux::platform")
391
- @ohai[:platform].should == "suse"
392
- @ohai[:platform_version].should == "11.3"
393
- @ohai[:platform_family].should == "suse"
394
- end
395
-
396
- it "[OHAI-272] should read the version as 9.1" do
397
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
398
- @ohai._require_plugin("linux::platform")
399
- @ohai[:platform].should == "suse"
400
- @ohai[:platform_version].should == "9.1"
401
- @ohai[:platform_family].should == "suse"
359
+
360
+ describe "with lsb_release results" do
361
+ before(:each) do
362
+ @ohai[:lsb][:id] = "SUSE LINUX"
363
+ end
364
+
365
+ it "should read the platform as suse" do
366
+ @ohai[:lsb][:release] = "12.1"
367
+ File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
368
+ @ohai._require_plugin("linux::platform")
369
+ @ohai[:platform].should == "suse"
370
+ @ohai[:platform_version].should == "12.1"
371
+ @ohai[:platform_family].should == "suse"
372
+ end
402
373
  end
403
-
404
- it "[OHAI-272] should read the version as 11.4" do
405
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
406
- @ohai._require_plugin("linux::platform")
407
- @ohai[:platform].should == "suse"
408
- @ohai[:platform_version].should == "11.4"
409
- @ohai[:platform_family].should == "suse"
374
+
375
+ describe "without lsb_release results" do
376
+ before(:each) do
377
+ @ohai.lsb = nil
378
+ end
379
+
380
+ it "should check for the existance of SuSE-release" do
381
+ @ohai._require_plugin("linux::platform")
382
+ end
383
+
384
+ it "should set platform and platform_family to suse and bogus verion to 10.0" do
385
+ File.should_receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
386
+ @ohai._require_plugin("linux::platform")
387
+ @ohai[:platform].should == "suse"
388
+ @ohai[:platform_family].should == "suse"
389
+ end
390
+
391
+ it "should read the version as 10.1 for bogus SLES 10" do
392
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 10 (i586)\nVERSION = 10\nPATCHLEVEL = 1\n")
393
+ @ohai._require_plugin("linux::platform")
394
+ @ohai[:platform].should == "suse"
395
+ @ohai[:platform_version].should == "10.1"
396
+ @ohai[:platform_family].should == "suse"
397
+ end
398
+
399
+ it "should read the version as 11.2" do
400
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
401
+ @ohai._require_plugin("linux::platform")
402
+ @ohai[:platform].should == "suse"
403
+ @ohai[:platform_version].should == "11.2"
404
+ @ohai[:platform_family].should == "suse"
405
+ end
406
+
407
+ it "[OHAI-272] should read the version as 11.3" do
408
+ File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
409
+ @ohai._require_plugin("linux::platform")
410
+ @ohai[:platform].should == "suse"
411
+ @ohai[:platform_version].should == "11.3"
412
+ @ohai[:platform_family].should == "suse"
413
+ end
414
+
415
+ it "[OHAI-272] should read the version as 9.1" do
416
+ File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
417
+ @ohai._require_plugin("linux::platform")
418
+ @ohai[:platform].should == "suse"
419
+ @ohai[:platform_version].should == "9.1"
420
+ @ohai[:platform_family].should == "suse"
421
+ end
422
+
423
+ it "[OHAI-272] should read the version as 11.4" do
424
+ File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
425
+ @ohai._require_plugin("linux::platform")
426
+ @ohai[:platform].should == "suse"
427
+ @ohai[:platform_version].should == "11.4"
428
+ @ohai[:platform_family].should == "suse"
429
+ end
410
430
  end
411
431
  end
412
432
 
@@ -32,7 +32,8 @@ describe Ohai::System, "Linux virtualization platform" do
32
32
  File.stub!(:exists?).with("/proc/cpuinfo").and_return(false)
33
33
  File.stub!(:exists?).with("/usr/sbin/dmidecode").and_return(false)
34
34
  File.stub!(:exists?).with("/proc/self/status").and_return(false)
35
- File.stub!(:exists?).with("/proc/user_beancounters").and_return(false)
35
+ File.stub!(:exists?).with("/proc/bc/0").and_return(false)
36
+ File.stub!(:exists?).with("/proc/vz").and_return(false)
36
37
  end
37
38
 
38
39
  describe "when we are checking for xen" do
@@ -216,24 +217,24 @@ VMWARE
216
217
  end
217
218
  end
218
219
  describe "when we are checking for openvz" do
219
- it "should set openvz host if /proc/user_beancounters contains 0:" do
220
- File.should_receive(:exists?).with("/proc/user_beancounters").and_return(true)
221
- File.stub!(:read).with("/proc/user_beancounters").and_return("\n 0: ")
220
+ it "should set openvz host if /proc/bc/0 exists" do
221
+ File.should_receive(:exists?).with("/proc/bc/0").and_return(true)
222
222
  @ohai._require_plugin("linux::virtualization")
223
- @ohai[:virtualization][:emulator].should == "openvz"
223
+ @ohai[:virtualization][:system].should == "openvz"
224
224
  @ohai[:virtualization][:role].should == "host"
225
225
  end
226
226
 
227
- it "should set openvz guest if /proc/user_beancounters doesn't contain 0:" do
228
- File.should_receive(:exists?).with("/proc/user_beancounters").and_return(true)
229
- File.stub!(:read).with("/proc/user_beancounters").and_return("101:")
227
+ it "should set openvz guest if /proc/bc/0 doesn't exist and /proc/vz exists" do
228
+ File.should_receive(:exists?).with("/proc/bc/0").and_return(false)
229
+ File.should_receive(:exists?).with("/proc/vz").and_return(true)
230
230
  @ohai._require_plugin("linux::virtualization")
231
- @ohai[:virtualization][:emulator].should == "openvz"
231
+ @ohai[:virtualization][:system].should == "openvz"
232
232
  @ohai[:virtualization][:role].should == "guest"
233
233
  end
234
234
 
235
235
  it "should not set virtualization if openvz isn't there" do
236
- File.should_receive(:exists?).at_least(:once).and_return(false)
236
+ File.should_receive(:exists?).with("/proc/bc/0").and_return(false)
237
+ File.should_receive(:exists?).with("/proc/vz").and_return(false)
237
238
  @ohai._require_plugin("linux::virtualization")
238
239
  @ohai[:virtualization].should == {}
239
240
  end
@@ -72,4 +72,15 @@ describe Ohai::System, "plugin os" do
72
72
  @ohai[:os].should == "solaris2"
73
73
  end
74
74
  end
75
+
76
+ describe "on something we have never seen before, but ruby has" do
77
+ before do
78
+ ::RbConfig::CONFIG['host_os'] = "tron"
79
+ end
80
+
81
+ it "sets the os to the ruby 'host_os'" do
82
+ @ohai._require_plugin("os")
83
+ @ohai[:os].should == "tron"
84
+ end
85
+ end
75
86
  end
@@ -35,7 +35,7 @@ describe Ohai::System, "plugin platform" do
35
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
+ @ohai[:platform_family].should eql("monkey")
39
39
  end
40
40
 
41
41
  it "should not set the platform to the os if it was set earlier" do
@@ -48,14 +48,14 @@ describe Ohai::System, "plugin platform" do
48
48
  @ohai[:platform] = 'lars'
49
49
  @ohai[:platform_family] = 'jack'
50
50
  @ohai._require_plugin("platform")
51
- @ohai[:platform_family].should eql ("jack")
51
+ @ohai[:platform_family].should eql("jack")
52
52
  end
53
53
 
54
54
  it "should not set the platform_family if the platform_family was set earlier." do
55
55
  @ohai[:platform] = 'lars'
56
56
  @ohai._require_plugin("platform")
57
57
  @ohai[:platform].should eql("lars")
58
- @ohai[:platform_family].should eql ("lars")
58
+ @ohai[:platform_family].should eql("lars")
59
59
  end
60
60
 
61
61
  it "should set the platform_version to the os_version if it was not set earlier" do
@@ -22,38 +22,38 @@ describe Ohai::System, "plugin rackspace" do
22
22
  @ohai = Ohai::System.new
23
23
  @ohai.stub!(:require_plugin).and_return(true)
24
24
  @ohai[:network] = {:interfaces => {:eth0 => {"addresses"=> {
25
- "1.2.3.4"=> {
26
- "broadcast"=> "67.23.20.255",
27
- "netmask"=> "255.255.255.0",
28
- "family"=> "inet"
29
- },
30
- "fe80::4240:95ff:fe47:6eed"=> {
31
- "scope"=> "Link",
32
- "prefixlen"=> "64",
33
- "family"=> "inet6"
34
- },
35
- "40:40:95:47:6E:ED"=> {
36
- "family"=> "lladdr"
37
- }
38
- }}
25
+ "1.2.3.4"=> {
26
+ "broadcast"=> "67.23.20.255",
27
+ "netmask"=> "255.255.255.0",
28
+ "family"=> "inet"
29
+ },
30
+ "fe80::4240:95ff:fe47:6eed"=> {
31
+ "scope"=> "Link",
32
+ "prefixlen"=> "64",
33
+ "family"=> "inet6"
34
+ },
35
+ "40:40:95:47:6E:ED"=> {
36
+ "family"=> "lladdr"
39
37
  }
38
+ }}
40
39
  }
41
-
42
- @ohai[:network][:interfaces][:eth1] = {:addresses => {
43
- "fe80::4240:f5ff:feab:2836" => {
44
- "scope"=> "Link",
45
- "prefixlen"=> "64",
46
- "family"=> "inet6"
47
- },
48
- "5.6.7.8"=> {
49
- "broadcast"=> "10.176.191.255",
50
- "netmask"=> "255.255.224.0",
51
- "family"=> "inet"
52
- },
53
- "40:40:F5:AB:28:36" => {
54
- "family"=> "lladdr"
55
- }
56
- }}
40
+ }
41
+
42
+ @ohai[:network][:interfaces][:eth1] = {:addresses => {
43
+ "fe80::4240:f5ff:feab:2836" => {
44
+ "scope"=> "Link",
45
+ "prefixlen"=> "64",
46
+ "family"=> "inet6"
47
+ },
48
+ "5.6.7.8"=> {
49
+ "broadcast"=> "10.176.191.255",
50
+ "netmask"=> "255.255.224.0",
51
+ "family"=> "inet"
52
+ },
53
+ "40:40:F5:AB:28:36" => {
54
+ "family"=> "lladdr"
55
+ }
56
+ }}
57
57
  end
58
58
 
59
59
  shared_examples_for "!rackspace" do
@@ -84,32 +84,63 @@ describe Ohai::System, "plugin rackspace" do
84
84
 
85
85
  end
86
86
 
87
- describe "with rackspace mac and hostname" do
88
- it_should_behave_like "rackspace"
87
+ describe "with rackspace mac and hostname" do
88
+ it_should_behave_like "rackspace"
89
89
 
90
- before(:each) do
91
- IO.stub!(:select).and_return([[],[1],[]])
92
- @ohai[:hostname] = "slice74976"
93
- @ohai[:network][:interfaces][:eth0][:arp] = {"67.23.20.1" => "00:00:0c:07:ac:01"}
94
- end
90
+ before(:each) do
91
+ IO.stub!(:select).and_return([[],[1],[]])
92
+ @ohai[:hostname] = "slice74976"
93
+ @ohai[:network][:interfaces][:eth0][:arp] = {"67.23.20.1" => "00:00:0c:07:ac:01"}
95
94
  end
95
+ end
96
96
 
97
- describe "without rackspace mac" do
98
- it_should_behave_like "!rackspace"
97
+ describe "without rackspace mac" do
98
+ it_should_behave_like "!rackspace"
99
99
 
100
- before(:each) do
101
- @ohai[:hostname] = "slice74976"
102
- @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"}
103
- end
100
+ before(:each) do
101
+ @ohai[:hostname] = "slice74976"
102
+ @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"}
104
103
  end
104
+ end
105
+
106
+ describe "without rackspace hostname" do
107
+ it_should_behave_like "rackspace"
105
108
 
106
- describe "without rackspace hostname" do
107
- it_should_behave_like "rackspace"
109
+ before(:each) do
110
+ @ohai[:hostname] = "bubba"
111
+ @ohai[:network][:interfaces][:eth0][:arp] = {"67.23.20.1" => "00:00:0c:07:ac:01"}
112
+ end
113
+ end
114
+
115
+ describe "with rackspace cloud file" do
116
+ it_should_behave_like "rackspace"
117
+
118
+ before(:each) do
119
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
120
+ File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
121
+ File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
122
+ File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
123
+ end
124
+ end
108
125
 
109
- before(:each) do
110
- @ohai[:hostname] = "bubba"
111
- @ohai[:network][:interfaces][:eth0][:arp] = {"67.23.20.1" => "00:00:0c:07:ac:01"}
112
- end
126
+ describe "without cloud file" do
127
+ it_should_behave_like "!rackspace"
128
+
129
+ before(:each) do
130
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false)
131
+ File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false)
113
132
  end
133
+ end
134
+
135
+ describe "with ec2 cloud file" do
136
+ it_should_behave_like "!rackspace"
137
+
138
+ before(:each) do
139
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
140
+ File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
141
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
142
+ File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
143
+ end
144
+ end
114
145
 
115
146
  end
@@ -0,0 +1,77 @@
1
+ #
2
+ # Author:: Trevor O (<trevoro@joyent.com>)
3
+ # Copyright:: Copyright (c) 2009 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, "Solaris plugin platform" do
22
+ before(:each) do
23
+ @ohai = Ohai::System.new
24
+ @ohai.extend(SimpleFromFile)
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "solaris2"
27
+ @ohai.stub!(:popen4).with("/sbin/uname -X")
28
+ end
29
+
30
+ describe "on SmartOS" do
31
+ before(:each) do
32
+ uname_x = <<-UNAME_X
33
+ System = SunOS
34
+ Node = node.example.com
35
+ Release = 5.11
36
+ KernelID = joyent_20120130T201844Z
37
+ Machine = i86pc
38
+ BusType = <unknown>
39
+ Serial = <unknown>
40
+ Users = <unknown>
41
+ OEM# = 0
42
+ Origin# = 1
43
+ NumCPU = 16
44
+ UNAME_X
45
+ @stdin = mock("STDIN", { :close => true })
46
+ @pid = 10
47
+ @stderr = mock("STDERR")
48
+ @status = 0
49
+
50
+ @uname_x_lines = uname_x.split("\n")
51
+
52
+ File.stub!(:exists?).with("/sbin/uname").and_return(true)
53
+ @ohai.stub(:popen4).with("/sbin/uname -X").and_yield(@pid, @stdin, @uname_x_lines, @stderr).and_return(@status)
54
+
55
+ @release = StringIO.new(" SmartOS 20120130T201844Z x86_64\n")
56
+ @mock_file.stub!(:close).and_return(0)
57
+ File.stub!(:open).with("/etc/release").and_yield(@release)
58
+ end
59
+
60
+ it "should run uname and set platform and build" do
61
+ @ohai._require_plugin("solaris2::platform")
62
+ @ohai[:platform_build].should == "joyent_20120130T201844Z"
63
+ end
64
+
65
+ it "should set the platform" do
66
+ @ohai._require_plugin("solaris2::platform")
67
+ @ohai[:platform].should == "smartos"
68
+ end
69
+
70
+ it "should set the platform_version" do
71
+ @ohai._require_plugin("solaris2::platform")
72
+ @ohai[:platform_version].should == "20120130T201844Z"
73
+ end
74
+
75
+ end
76
+
77
+ end