ohai 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
2
+
3
+ describe Ohai::System, "plugin etc" do
4
+ before(:each) do
5
+ @ohai = Ohai::System.new
6
+ @ohai.stub!(:require_plugin).and_return(true)
7
+ end
8
+
9
+ PasswdEntry = Struct.new(:name, :uid, :gid, :dir, :shell, :gecos)
10
+ GroupEntry = Struct.new(:name, :gid, :mem)
11
+
12
+ it "should include a list of all users" do
13
+ Etc.should_receive(:passwd).and_yield(PasswdEntry.new("root", 1, 1, '/root', '/bin/zsh', 'BOFH')).
14
+ and_yield(PasswdEntry.new('www', 800, 800, '/var/www', '/bin/false', 'Serving the web since 1970'))
15
+ @ohai._require_plugin("passwd")
16
+ @ohai[:etc][:passwd]['root'].should == Mash.new(:shell => '/bin/zsh', :gecos => 'BOFH', :gid => 1, :uid => 1, :dir => '/root')
17
+ @ohai[:etc][:passwd]['www'].should == Mash.new(:shell => '/bin/false', :gecos => 'Serving the web since 1970', :gid => 800, :uid => 800, :dir => '/var/www')
18
+ end
19
+
20
+ it "should set the current user" do
21
+ Etc.should_receive(:getlogin).and_return('chef')
22
+ @ohai._require_plugin("passwd")
23
+ @ohai[:current_user].should == 'chef'
24
+ end
25
+
26
+ it "should set the available groups" do
27
+ Etc.should_receive(:group).and_yield(GroupEntry.new("admin", 100, ['root', 'chef'])).and_yield(GroupEntry.new('www', 800, ['www', 'deploy']))
28
+ @ohai._require_plugin("passwd")
29
+ @ohai[:etc][:group]['admin'].should == Mash.new(:gid => 100, :members => ['root', 'chef'])
30
+ @ohai[:etc][:group]['www'].should == Mash.new(:gid => 800, :members => ['www', 'deploy'])
31
+ end
32
+ end
@@ -0,0 +1,115 @@
1
+ #
2
+ # Author:: Cary Penniman (<cary@rightscale.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
19
+
20
+ describe Ohai::System, "plugin rackspace" do
21
+ before(:each) do
22
+ @ohai = Ohai::System.new
23
+ @ohai.stub!(:require_plugin).and_return(true)
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
+ }}
39
+ }
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
+ end
58
+
59
+ describe "!rackspace", :shared => true do
60
+ it "should NOT create rackspace" do
61
+ @ohai._require_plugin("rackspace")
62
+ @ohai[:rackspace].should be_nil
63
+ end
64
+ end
65
+
66
+ describe "rackspace", :shared => true do
67
+
68
+ it "should create rackspace" do
69
+ @ohai._require_plugin("rackspace")
70
+ @ohai[:rackspace].should_not be_nil
71
+ end
72
+
73
+ it "should have all required attributes" do
74
+ @ohai._require_plugin("rackspace")
75
+ @ohai[:rackspace][:public_ip].should_not be_nil
76
+ @ohai[:rackspace][:private_ip].should_not be_nil
77
+ end
78
+
79
+ it "should have correct values for all attributes" do
80
+ @ohai._require_plugin("rackspace")
81
+ @ohai[:rackspace][:public_ip].should == "1.2.3.4"
82
+ @ohai[:rackspace][:private_ip].should == "5.6.7.8"
83
+ end
84
+
85
+ end
86
+
87
+ describe "with rackspace mac and hostname" do
88
+ it_should_behave_like "rackspace"
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
95
+ end
96
+
97
+ describe "without rackspace mac" do
98
+ it_should_behave_like "!rackspace"
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
104
+ end
105
+
106
+ describe "without rackspace hostname" do
107
+ it_should_behave_like "rackspace"
108
+
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
+ end
@@ -0,0 +1,135 @@
1
+ #
2
+ # Author:: Daniel DeLeo <dan@opscode.com>
3
+ # Copyright:: Copyright (c) 2010 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.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
20
+
21
+ describe Ohai::System, "Solaris2.X network plugin" do
22
+
23
+ before do
24
+ solaris_ifconfig = <<-ENDIFCONFIG
25
+ lo0:3: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
26
+ inet 127.0.0.1 netmask ff000000
27
+ e1000g0:3: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 3
28
+ inet 72.2.115.28 netmask ffffff80 broadcast 72.2.115.127
29
+ e1000g2:1: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 4
30
+ inet 10.2.115.28 netmask ffffff80 broadcast 10.2.115.127
31
+ inet6 2001:0db8:3c4d:55:a00:20ff:fe8e:f3ad/64
32
+ ip.tun0: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
33
+ inet tunnel src 109.146.85.57 tunnel dst 109.146.85.212
34
+ tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
35
+ tunnel hop limit 60
36
+ inet6 fe80::6d92:5539/10 --> fe80::6d92:55d4
37
+ ip.tun0:1: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
38
+ inet6 2::45/128 --> 2::46
39
+ lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
40
+ inet 127.0.0.1 netmask ff000000
41
+ eri0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 \
42
+ index 2
43
+ inet 172.17.128.208 netmask ffffff00 broadcast 172.17.128.255
44
+ ip6.tun0: flags=10008d1<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST,IPv4> \
45
+ mtu 1460
46
+ index 3
47
+ inet6 tunnel src fe80::1 tunnel dst fe80::2
48
+ tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
49
+ tunnel hop limit 60 tunnel encapsulation limit 4
50
+ inet 10.0.0.208 --> 10.0.0.210 netmask ff000000
51
+ qfe1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 3
52
+ usesrc vni0
53
+ inet6 fe80::203:baff:fe17:4be0/10
54
+ ether 0:3:ba:17:4b:e0
55
+ vni0: flags=2002210041<UP,RUNNING,NOXMIT,NONUD,IPv6,VIRTUAL> mtu 0
56
+ index 5
57
+ srcof qfe1
58
+ inet6 fe80::203:baff:fe17:4444/128
59
+ ENDIFCONFIG
60
+
61
+ solaris_netstat_rn = <<-NETSTAT_RN
62
+ Routing Table: IPv4
63
+ Destination Gateway Flags Ref Use Interface
64
+ -------------------- -------------------- ----- ----- ---------- ---------
65
+ default 10.13.37.1 UG 1 0 e1000g0
66
+ 10.13.37.0 10.13.37.157 U 1 2 e1000g0
67
+ 127.0.0.1 127.0.0.1 UH 1 35 lo0
68
+
69
+ Routing Table: IPv6
70
+ Destination/Mask Gateway Flags Ref Use If
71
+ --------------------------- --------------------------- ----- --- ------- -----
72
+ fe80::/10 fe80::250:56ff:fe13:3757 U 1 0 e1000g0
73
+ ::1 ::1 UH 1 0 lo0
74
+ NETSTAT_RN
75
+
76
+ @solaris_route_get = <<-ROUTE_GET
77
+ route to: default
78
+ destination: default
79
+ mask: default
80
+ gateway: 10.13.37.1
81
+ interface: e1000g0
82
+ flags: <UP,GATEWAY,DONE,STATIC>
83
+ recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu expire
84
+ 0 0 0 0 0 0 1500 0
85
+ ROUTE_GET
86
+
87
+ @stdin = mock("STDIN", :null_object => true)
88
+ @ifconfig_lines = solaris_ifconfig.split("\n")
89
+
90
+ @ohai = Ohai::System.new
91
+ @ohai.stub!(:require_plugin).and_return(true)
92
+ @ohai[:network] = Mash.new
93
+
94
+ @ohai.stub(:popen4).with("ifconfig -a")
95
+ @ohai.stub(:popen4).with("arp -an")
96
+ end
97
+
98
+ describe "gathering IP layer address info" do
99
+ before do
100
+ @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin, @ifconfig_lines, nil)
101
+ @ohai._require_plugin("solaris2::network")
102
+ end
103
+
104
+ it "completes the run" do
105
+ @ohai['network'].should_not be_nil
106
+ end
107
+
108
+ it "detects the interfaces" do
109
+ @ohai['network']['interfaces'].keys.sort.should == ["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3", "qfe1"]
110
+ end
111
+
112
+ it "detects the ip addresses of the interfaces" do
113
+ @ohai['network']['interfaces']['e1000g0:3']['addresses'].keys.should include('72.2.115.28')
114
+ end
115
+
116
+ it "detects the encapsulation type of the interfaces" do
117
+ @ohai['network']['interfaces']['e1000g0:3']['encapsulation'].should == 'Ethernet'
118
+ end
119
+ end
120
+
121
+ # TODO: specs for the arp -an stuff, check that it correctly adds the MAC addr to the right iface, etc.
122
+
123
+ describe "setting the node's default IP address attribute" do
124
+ before do
125
+ @stdout = mock("Pipe, stdout, cmd=`route get default`", :string => @solaris_route_get)
126
+ @ohai.stub!(:popen4).with("route get default").and_yield(nil,@stdin, @stdout, nil)
127
+ @ohai._require_plugin("solaris2::network")
128
+ end
129
+
130
+ it "finds the default interface by asking which iface has the default route" do
131
+ @ohai[:network][:default_interface].should == 'e1000g0'
132
+ end
133
+ end
134
+ end
135
+
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Adam Jacob
@@ -9,59 +14,81 @@ autorequire: ohai
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-10-27 00:00:00 +13:00
17
+ date: 2010-02-28 00:00:00 -08:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
- name: extlib
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
17
30
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: extlib
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
20
36
  requirements:
21
37
  - - ">="
22
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
23
41
  version: "0"
24
- version:
42
+ type: :runtime
43
+ version_requirements: *id002
25
44
  - !ruby/object:Gem::Dependency
26
45
  name: systemu
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
30
48
  requirements:
31
49
  - - ">="
32
50
  - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
33
53
  version: "0"
34
- version:
54
+ type: :runtime
55
+ version_requirements: *id003
35
56
  - !ruby/object:Gem::Dependency
36
57
  name: mixlib-cli
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
40
60
  requirements:
41
61
  - - ">="
42
62
  - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
43
65
  version: "0"
44
- version:
66
+ type: :runtime
67
+ version_requirements: *id004
45
68
  - !ruby/object:Gem::Dependency
46
69
  name: mixlib-config
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
70
+ prerelease: false
71
+ requirement: &id005 !ruby/object:Gem::Requirement
50
72
  requirements:
51
73
  - - ">="
52
74
  - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
53
77
  version: "0"
54
- version:
78
+ type: :runtime
79
+ version_requirements: *id005
55
80
  - !ruby/object:Gem::Dependency
56
81
  name: mixlib-log
57
- type: :runtime
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
82
+ prerelease: false
83
+ requirement: &id006 !ruby/object:Gem::Requirement
60
84
  requirements:
61
85
  - - ">="
62
86
  - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
63
89
  version: "0"
64
- version:
90
+ type: :runtime
91
+ version_requirements: *id006
65
92
  description: Ohai profiles your system and emits JSON
66
93
  email: adam@opscode.com
67
94
  executables:
@@ -81,6 +108,7 @@ files:
81
108
  - lib/ohai/mixin/command.rb
82
109
  - lib/ohai/mixin/from_file.rb
83
110
  - lib/ohai/mixin/string.rb
111
+ - lib/ohai/plugins/cloud.rb
84
112
  - lib/ohai/plugins/command.rb
85
113
  - lib/ohai/plugins/darwin/filesystem.rb
86
114
  - lib/ohai/plugins/darwin/hostname.rb
@@ -148,9 +176,11 @@ files:
148
176
  - lib/ohai/plugins/openbsd/uptime.rb
149
177
  - lib/ohai/plugins/openbsd/virtualization.rb
150
178
  - lib/ohai/plugins/os.rb
179
+ - lib/ohai/plugins/passwd.rb
151
180
  - lib/ohai/plugins/perl.rb
152
181
  - lib/ohai/plugins/platform.rb
153
182
  - lib/ohai/plugins/python.rb
183
+ - lib/ohai/plugins/rackspace.rb
154
184
  - lib/ohai/plugins/ruby.rb
155
185
  - lib/ohai/plugins/solaris2/cpu.rb
156
186
  - lib/ohai/plugins/solaris2/hostname.rb
@@ -170,6 +200,7 @@ files:
170
200
  - lib/ohai.rb
171
201
  - spec/ohai/mixin/command_spec.rb
172
202
  - spec/ohai/mixin/from_file_spec.rb
203
+ - spec/ohai/plugins/cloud_spec.rb
173
204
  - spec/ohai/plugins/darwin/hostname_spec.rb
174
205
  - spec/ohai/plugins/darwin/kernel_spec.rb
175
206
  - spec/ohai/plugins/darwin/platform_spec.rb
@@ -197,12 +228,15 @@ files:
197
228
  - spec/ohai/plugins/openbsd/kernel_spec.rb
198
229
  - spec/ohai/plugins/openbsd/platform_spec.rb
199
230
  - spec/ohai/plugins/os_spec.rb
231
+ - spec/ohai/plugins/passwd_spec.rb
200
232
  - spec/ohai/plugins/perl_spec.rb
201
233
  - spec/ohai/plugins/platform_spec.rb
202
234
  - spec/ohai/plugins/python_spec.rb
235
+ - spec/ohai/plugins/rackspace_spec.rb
203
236
  - spec/ohai/plugins/ruby_spec.rb
204
237
  - spec/ohai/plugins/solaris2/hostname_spec.rb
205
238
  - spec/ohai/plugins/solaris2/kernel_spec.rb
239
+ - spec/ohai/plugins/solaris2/network_spec.rb
206
240
  - spec/ohai/system_spec.rb
207
241
  - spec/ohai_spec.rb
208
242
  - spec/rcov.opts
@@ -221,18 +255,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
255
  requirements:
222
256
  - - ">="
223
257
  - !ruby/object:Gem::Version
258
+ segments:
259
+ - 0
224
260
  version: "0"
225
- version:
226
261
  required_rubygems_version: !ruby/object:Gem::Requirement
227
262
  requirements:
228
263
  - - ">="
229
264
  - !ruby/object:Gem::Version
265
+ segments:
266
+ - 0
230
267
  version: "0"
231
- version:
232
268
  requirements: []
233
269
 
234
270
  rubyforge_project:
235
- rubygems_version: 1.3.5
271
+ rubygems_version: 1.3.6
236
272
  signing_key:
237
273
  specification_version: 3
238
274
  summary: Ohai profiles your system and emits JSON