ohai 0.6.6 → 0.6.8.rc.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,17 +8,17 @@ Ohai will print out a JSON data blob for all the known data about your system. W
8
8
 
9
9
  Opscode distributes ohai as a RubyGem. This README is for developers who want to modify the Ohai source code. For users who want to write plugins for Ohai, see the wiki:
10
10
 
11
- * http://wiki.opscode.com/display/ohai/Home
11
+ * http://wiki.opscode.com/display/chef/Ohai
12
12
 
13
13
  = DEVELOPMENT:
14
14
 
15
15
  Before working on the code, if you plan to contribute your changes, you need to read the Opscode Contributing document.
16
16
 
17
- * http://wiki.opscode.com/display/opscode/Contributing
17
+ * http://wiki.opscode.com/display/chef/How+to+Contribute
18
18
 
19
19
  You will also need to set up the repository with the appropriate branches. We document the process on the Chef Wiki.
20
20
 
21
- * http://wiki.opscode.com/display/opscode/Working+with+Git
21
+ * http://wiki.opscode.com/display/chef/Working+with+git
22
22
 
23
23
  (Substitude 'ohai' for 'chef')
24
24
 
@@ -75,7 +75,7 @@ Tickets/Issues:
75
75
 
76
76
  Documentation:
77
77
 
78
- * http://wiki.opscode.com/display/ohai/Home/
78
+ * http://wiki.opscode.com/display/chef/Ohai
79
79
 
80
80
  = LICENSE:
81
81
 
@@ -66,7 +66,7 @@ popen4("ls -l /dev/disk/by-uuid/* | awk '{print $11, $9}'") do |pid, stdin, stdo
66
66
  end
67
67
 
68
68
  # Grab any missing mount information from /proc/mounts
69
- File.open('/proc/mounts').read_nonblock(4096).each do |line|
69
+ File.open('/proc/mounts').read_nonblock(4096).each_line do |line|
70
70
  if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/
71
71
  filesystem = $1
72
72
  next if fs.has_key?(filesystem)
@@ -15,6 +15,7 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
+
18
19
  def get_redhatish_platform(contents)
19
20
  contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
20
21
  end
@@ -26,8 +27,13 @@ end
26
27
  provides "platform", "platform_version"
27
28
 
28
29
  require_plugin 'linux::lsb'
30
+
31
+ # platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching
29
32
 
30
- if lsb[:id]
33
+ if lsb[:id] =~ /RedHat/i
34
+ platform "redhat"
35
+ platform_version lsb[:release]
36
+ elsif lsb[:id]
31
37
  platform lsb[:id].downcase
32
38
  platform_version lsb[:release]
33
39
  elsif File.exists?("/etc/debian_version")
@@ -22,15 +22,23 @@ virtualization Mash.new
22
22
 
23
23
  # if it is possible to detect paravirt vs hardware virt, it should be put in
24
24
  # virtualization[:mechanism]
25
- if File.exists?("/proc/xen")
26
- if File.exists?("/dev/xen/evtchn")
27
- virtualization[:system] = "xen"
25
+
26
+ ## Xen
27
+ # This file should exists on most Xen systems
28
+ if File.exists?("/proc/xen/capabilities")
29
+ virtualization[:system] = "xen"
30
+ if File.read("/proc/xen/capabilities") =~ /control_d/i
28
31
  virtualization[:role] = "host"
29
32
  else
30
- virtualization[:system] = "xen"
31
33
  virtualization[:role] = "guest"
32
34
  end
35
+ # Guests do not always have this file, but may
36
+ elsif File.exists?("/proc/sys/xen/independent_wallclock")
37
+ virtualization[:system] = "xen"
38
+ virtualization[:role] = "guest"
33
39
  end
40
+ # cpuid of guests, if we could get it, would also be a clue
41
+ # may be able to determine if under paravirt from /dev/xen/evtchn (See OHAI-253)
34
42
 
35
43
  # Detect from kernel module
36
44
  if File.exists?("/proc/modules")
data/lib/ohai/version.rb CHANGED
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = '0.6.6'
21
+ VERSION = '0.6.8.rc.0'
22
22
  end
23
23
 
@@ -19,6 +19,8 @@
19
19
 
20
20
  require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
21
21
 
22
+ # We do not alter case for lsb attributes and consume them as provided
23
+
22
24
  describe Ohai::System, "Linux lsb plugin" do
23
25
  before(:each) do
24
26
  @ohai = Ohai::System.new
@@ -64,44 +66,80 @@ describe Ohai::System, "Linux lsb plugin" do
64
66
  before(:each) do
65
67
  File.stub!(:exists?).with("/etc/lsb-release").and_return(false)
66
68
  File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(true)
67
-
69
+
68
70
  @stdin = mock("STDIN", { :close => true })
69
71
  @pid = 10
70
72
  @stderr = mock("STDERR")
71
73
  @stdout = mock("STDOUT")
72
74
  @status = 0
73
75
 
74
- @stdout.stub!(:each).
75
- and_yield("LSB Version: :core-4.0-ia32:core-4.0-noarch").
76
- and_yield("Distributor ID: Fedora").
77
- and_yield("Description: Fedora release 14 (Laughlin)").
78
- and_yield("Release: 14").
79
- and_yield("Codename: Laughlin")
80
-
81
- @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
82
-
83
- end
84
-
85
- it "should set lsb[:id]" do
86
- @ohai._require_plugin("linux::lsb")
87
- @ohai[:lsb][:id].should == "Fedora"
88
76
  end
77
+
78
+ describe "on Centos 5.4 correctly" do
79
+ before(:each) do
80
+ @stdout.stub!(:each).
81
+ and_yield("LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch").
82
+ and_yield("Distributor ID: CentOS").
83
+ and_yield("Description: CentOS release 5.4 (Final)").
84
+ and_yield("Release: 5.4").
85
+ and_yield("Codename: Final")
89
86
 
90
- it "should set lsb[:release]" do
91
- @ohai._require_plugin("linux::lsb")
92
- @ohai[:lsb][:release].should == "14"
87
+ @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
88
+ end
89
+
90
+ it "should set lsb[:id]" do
91
+ @ohai._require_plugin("linux::lsb")
92
+ @ohai[:lsb][:id].should == "CentOS"
93
+ end
94
+
95
+ it "should set lsb[:release]" do
96
+ @ohai._require_plugin("linux::lsb")
97
+ @ohai[:lsb][:release].should == "5.4"
98
+ end
99
+
100
+ it "should set lsb[:codename]" do
101
+ @ohai._require_plugin("linux::lsb")
102
+ @ohai[:lsb][:codename].should == "Final"
103
+ end
104
+
105
+ it "should set lsb[:description]" do
106
+ @ohai._require_plugin("linux::lsb")
107
+ @ohai[:lsb][:description].should == "CentOS release 5.4 (Final)"
108
+ end
93
109
  end
110
+
111
+ describe "on Fedora 14 correctly" do
112
+ before(:each) do
113
+ @stdout.stub!(:each).
114
+ and_yield("LSB Version: :core-4.0-ia32:core-4.0-noarch").
115
+ and_yield("Distributor ID: Fedora").
116
+ and_yield("Description: Fedora release 14 (Laughlin)").
117
+ and_yield("Release: 14").
118
+ and_yield("Codename: Laughlin")
94
119
 
95
- it "should set lsb[:codename]" do
96
- @ohai._require_plugin("linux::lsb")
97
- @ohai[:lsb][:codename].should == "Laughlin"
98
- end
120
+ @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
121
+ end
99
122
 
100
- it "should set lsb[:description]" do
101
- @ohai._require_plugin("linux::lsb")
102
- @ohai[:lsb][:description].should == "Fedora release 14 (Laughlin)"
123
+ it "should set lsb[:id]" do
124
+ @ohai._require_plugin("linux::lsb")
125
+ @ohai[:lsb][:id].should == "Fedora"
126
+ end
127
+
128
+ it "should set lsb[:release]" do
129
+ @ohai._require_plugin("linux::lsb")
130
+ @ohai[:lsb][:release].should == "14"
131
+ end
132
+
133
+ it "should set lsb[:codename]" do
134
+ @ohai._require_plugin("linux::lsb")
135
+ @ohai[:lsb][:codename].should == "Laughlin"
136
+ end
137
+
138
+ it "should set lsb[:description]" do
139
+ @ohai._require_plugin("linux::lsb")
140
+ @ohai[:lsb][:description].should == "Fedora release 14 (Laughlin)"
141
+ end
103
142
  end
104
-
105
143
  end
106
144
 
107
145
  it "should not set any lsb values if /etc/lsb-release or /usr/bin/lsb_release do not exist " do
@@ -119,54 +119,74 @@ describe Ohai::System, "Linux plugin platform" do
119
119
  end
120
120
 
121
121
  describe "on redhat breeds" do
122
- before(:each) do
123
- @ohai.lsb = nil
124
- File.should_receive(:exists?).with("/etc/redhat-release").and_return(true)
125
- end
126
-
127
- it "should check for the existance of redhat-release" do
128
- @ohai._require_plugin("linux::platform")
129
- end
130
-
131
- it "should read the platform as centos and version as 5.3" do
132
- File.should_receive(:read).with("/etc/redhat-release").and_return("CentOS release 5.3")
133
- @ohai._require_plugin("linux::platform")
134
- @ohai[:platform].should == "centos"
135
- end
136
-
137
- it "may be that someone munged Red Hat to be RedHat" do
138
- File.should_receive(:read).with("/etc/redhat-release").and_return("RedHat release 5.3")
139
- @ohai._require_plugin("linux::platform")
140
- @ohai[:platform].should == "redhat"
141
- @ohai[:platform_version].should == "5.3"
142
- end
143
-
144
- it "should read the platform as redhat and version as 5.3" do
145
- File.should_receive(:read).with("/etc/redhat-release").and_return("Red Hat release 5.3")
146
- @ohai._require_plugin("linux::platform")
147
- @ohai[:platform].should == "redhat"
148
- @ohai[:platform_version].should == "5.3"
122
+ describe "with lsb_release results" do
123
+ it "should set the platform to redhat even if the LSB name is something absurd but redhat like" do
124
+ @ohai[:lsb][:id] = "RedHatEnterpriseServer"
125
+ @ohai[:lsb][:release] = "6.1"
126
+ @ohai._require_plugin("linux::platform")
127
+ @ohai[:platform].should == "redhat"
128
+ @ohai[:platform_version].should == "6.1"
129
+ end
130
+
131
+ it "should set the platform to centos" do
132
+ @ohai[:lsb][:id] = "CentOS"
133
+ @ohai[:lsb][:release] = "5.4"
134
+ @ohai._require_plugin("linux::platform")
135
+ @ohai[:platform].should == "centos"
136
+ @ohai[:platform_version].should == "5.4"
137
+ end
149
138
  end
150
139
 
151
- it "should read the platform as fedora and version as 13 (rawhide)" do
152
- File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)")
153
- @ohai._require_plugin("linux::platform")
154
- @ohai[:platform].should == "fedora"
155
- @ohai[:platform_version].should == "13 (rawhide)"
156
- end
157
-
158
- it "should read the platform as fedora and version as 10" do
159
- File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 10")
160
- @ohai._require_plugin("linux::platform")
161
- @ohai[:platform].should == "fedora"
162
- @ohai[:platform_version].should == "10"
163
- end
164
-
165
- it "should read the platform as fedora and version as 13 using to_i" do
166
- File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)")
167
- @ohai._require_plugin("linux::platform")
168
- @ohai[:platform].should == "fedora"
169
- @ohai[:platform_version].to_i.should == 13
140
+ describe "without lsb_release results" do
141
+ before(:each) do
142
+ @ohai.lsb = nil
143
+ File.should_receive(:exists?).with("/etc/redhat-release").and_return(true)
144
+ end
145
+
146
+ it "should check for the existance of redhat-release" do
147
+ @ohai._require_plugin("linux::platform")
148
+ end
149
+
150
+ it "should read the platform as centos and version as 5.3" do
151
+ File.should_receive(:read).with("/etc/redhat-release").and_return("CentOS release 5.3")
152
+ @ohai._require_plugin("linux::platform")
153
+ @ohai[:platform].should == "centos"
154
+ end
155
+
156
+ it "may be that someone munged Red Hat to be RedHat" do
157
+ File.should_receive(:read).with("/etc/redhat-release").and_return("RedHat release 5.3")
158
+ @ohai._require_plugin("linux::platform")
159
+ @ohai[:platform].should == "redhat"
160
+ @ohai[:platform_version].should == "5.3"
161
+ end
162
+
163
+ it "should read the platform as redhat and version as 5.3" do
164
+ File.should_receive(:read).with("/etc/redhat-release").and_return("Red Hat release 5.3")
165
+ @ohai._require_plugin("linux::platform")
166
+ @ohai[:platform].should == "redhat"
167
+ @ohai[:platform_version].should == "5.3"
168
+ end
169
+
170
+ it "should read the platform as fedora and version as 13 (rawhide)" do
171
+ File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)")
172
+ @ohai._require_plugin("linux::platform")
173
+ @ohai[:platform].should == "fedora"
174
+ @ohai[:platform_version].should == "13 (rawhide)"
175
+ end
176
+
177
+ it "should read the platform as fedora and version as 10" do
178
+ File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 10")
179
+ @ohai._require_plugin("linux::platform")
180
+ @ohai[:platform].should == "fedora"
181
+ @ohai[:platform_version].should == "10"
182
+ end
183
+
184
+ it "should read the platform as fedora and version as 13 using to_i" do
185
+ File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)")
186
+ @ohai._require_plugin("linux::platform")
187
+ @ohai[:platform].should == "fedora"
188
+ @ohai[:platform_version].to_i.should == 13
189
+ end
170
190
  end
171
191
  end
172
192
 
@@ -26,8 +26,8 @@ describe Ohai::System, "Linux virtualization platform" do
26
26
  @ohai.extend(SimpleFromFile)
27
27
 
28
28
  # default to all requested Files not existing
29
- File.stub(:exists?).with("/proc/xen").and_return(false)
30
- File.stub(:exists?).with("/dev/xen/evtchn").and_return(false)
29
+ File.stub!(:exists?).with("/proc/xen/capabilities").and_return(false)
30
+ File.stub!(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(false)
31
31
  File.stub!(:exists?).with("/proc/modules").and_return(false)
32
32
  File.stub!(:exists?).with("/proc/cpuinfo").and_return(false)
33
33
  File.stub!(:exists?).with("/usr/sbin/dmidecode").and_return(false)
@@ -36,17 +36,24 @@ describe Ohai::System, "Linux virtualization platform" do
36
36
  end
37
37
 
38
38
  describe "when we are checking for xen" do
39
- it "should set xen host if /proc/xen " do
40
- File.should_receive(:exists?).with("/proc/xen").and_return(true)
41
- File.should_receive(:exists?).with("/dev/xen/evtchn").and_return(true)
39
+ it "should set xen host if /proc/xen/capabilities contains control_d " do
40
+ File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
41
+ File.stub!(:read).with("/proc/xen/capabilities").and_return("control_d")
42
42
  @ohai._require_plugin("linux::virtualization")
43
43
  @ohai[:virtualization][:system].should == "xen"
44
44
  @ohai[:virtualization][:role].should == "host"
45
45
  end
46
46
 
47
- it "should set xen guest if no /dev/xen/evtchn" do
48
- File.should_receive(:exists?).with("/proc/xen").and_return(true)
49
- File.should_receive(:exists?).with("/dev/xen/evtchn").and_return(false)
47
+ it "should set xen guest if /proc/xen/capabilities exists but is empty" do
48
+ File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
49
+ File.stub!(:read).with("/proc/xen/capabilities").and_return("")
50
+ @ohai._require_plugin("linux::virtualization")
51
+ @ohai[:virtualization][:system].should == "xen"
52
+ @ohai[:virtualization][:role].should == "guest"
53
+ end
54
+
55
+ it "should set xen guest if /proc/sys/xen/independent_wallclock exists" do
56
+ File.should_receive(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(true)
50
57
  @ohai._require_plugin("linux::virtualization")
51
58
  @ohai[:virtualization][:system].should == "xen"
52
59
  @ohai[:virtualization][:role].should == "guest"
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease:
4
+ hash: 15424053
5
+ prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 6
10
- version: 0.6.6
9
+ - 8
10
+ - rc
11
+ - 0
12
+ version: 0.6.8.rc.0
11
13
  platform: ruby
12
14
  authors:
13
15
  - Adam Jacob
@@ -15,7 +17,7 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-10-03 00:00:00 Z
20
+ date: 2011-10-05 00:00:00 Z
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
23
  name: yajl-ruby
@@ -355,7 +357,7 @@ files:
355
357
  - spec/rcov.opts
356
358
  - spec/ohai_spec.rb
357
359
  - bin/ohai
358
- homepage: http://wiki.opscode.com/display/ohai
360
+ homepage: http://wiki.opscode.com/display/chef/Ohai
359
361
  licenses: []
360
362
 
361
363
  post_install_message:
@@ -375,12 +377,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
375
377
  required_rubygems_version: !ruby/object:Gem::Requirement
376
378
  none: false
377
379
  requirements:
378
- - - ">="
380
+ - - ">"
379
381
  - !ruby/object:Gem::Version
380
- hash: 3
382
+ hash: 25
381
383
  segments:
382
- - 0
383
- version: "0"
384
+ - 1
385
+ - 3
386
+ - 1
387
+ version: 1.3.1
384
388
  requirements: []
385
389
 
386
390
  rubyforge_project: