ohai 6.16.0 → 6.18.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Nathan L Smith (<nlloyds@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013 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
+
20
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
21
+
22
+ describe Ohai::System, "Darwin cpu plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "darwin"
27
+ @ohai.stub(:from).with("sysctl -n hw.physicalcpu").and_return("1")
28
+ @ohai.stub(:from).with("sysctl -n hw.logicalcpu").and_return("2")
29
+ end
30
+
31
+ it "should set cpu[:total] to 2" do
32
+ @ohai._require_plugin("darwin::cpu")
33
+ @ohai[:cpu][:total].should == 2
34
+ end
35
+
36
+ it "should set cpu[:real] to 1" do
37
+ @ohai._require_plugin("darwin::cpu")
38
+ @ohai[:cpu][:real].should == 1
39
+ end
40
+ end
@@ -42,21 +42,24 @@ describe Ohai::System, "plugin ec2" do
42
42
  t = mock("connection")
43
43
  t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS)
44
44
  Socket.stub!(:new).and_return(t)
45
+ @http_client.should_receive(:get).
46
+ with("/").twice.
47
+ and_return(mock("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
45
48
  end
46
49
 
47
50
  it "should recursively fetch all the ec2 metadata" do
48
51
  @http_client.should_receive(:get).
49
52
  with("/2012-01-12/meta-data/").
50
- and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups"))
53
+ and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200"))
51
54
  @http_client.should_receive(:get).
52
55
  with("/2012-01-12/meta-data/instance_type").
53
- and_return(mock("Net::HTTP Response", :body => "c1.medium"))
56
+ and_return(mock("Net::HTTP Response", :body => "c1.medium", :code => "200"))
54
57
  @http_client.should_receive(:get).
55
58
  with("/2012-01-12/meta-data/ami_id").
56
- and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934"))
59
+ and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200"))
57
60
  @http_client.should_receive(:get).
58
61
  with("/2012-01-12/meta-data/security-groups").
59
- and_return(mock("Net::HTTP Response", :body => "group1\ngroup2"))
62
+ and_return(mock("Net::HTTP Response", :body => "group1\ngroup2", :code => "200"))
60
63
  @http_client.should_receive(:get).
61
64
  with("/2012-01-12/user-data/").
62
65
  and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
@@ -71,22 +74,22 @@ describe Ohai::System, "plugin ec2" do
71
74
  it "should parse ec2 network/ directory as a multi-level hash" do
72
75
  @http_client.should_receive(:get).
73
76
  with("/2012-01-12/meta-data/").
74
- and_return(mock("Net::HTTP Response", :body => "network/"))
77
+ and_return(mock("Net::HTTP Response", :body => "network/", :code => "200"))
75
78
  @http_client.should_receive(:get).
76
79
  with("/2012-01-12/meta-data/network/").
77
- and_return(mock("Net::HTTP Response", :body => "interfaces/"))
80
+ and_return(mock("Net::HTTP Response", :body => "interfaces/", :code => "200"))
78
81
  @http_client.should_receive(:get).
79
82
  with("/2012-01-12/meta-data/network/interfaces/").
80
- and_return(mock("Net::HTTP Response", :body => "macs/"))
83
+ and_return(mock("Net::HTTP Response", :body => "macs/", :code => "200"))
81
84
  @http_client.should_receive(:get).
82
85
  with("/2012-01-12/meta-data/network/interfaces/macs/").
83
- and_return(mock("Net::HTTP Response", :body => "12:34:56:78:9a:bc/"))
86
+ and_return(mock("Net::HTTP Response", :body => "12:34:56:78:9a:bc/", :code => "200"))
84
87
  @http_client.should_receive(:get).
85
88
  with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/").
86
- and_return(mock("Net::HTTP Response", :body => "public_hostname"))
89
+ and_return(mock("Net::HTTP Response", :body => "public_hostname", :code => "200"))
87
90
  @http_client.should_receive(:get).
88
91
  with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/public_hostname").
89
- and_return(mock("Net::HTTP Response", :body => "server17.opscode.com"))
92
+ and_return(mock("Net::HTTP Response", :body => "server17.opscode.com", :code => "200"))
90
93
  @ohai._require_plugin("ec2")
91
94
 
92
95
  @ohai[:ec2].should_not be_nil
@@ -96,16 +99,16 @@ describe Ohai::System, "plugin ec2" do
96
99
  it "should parse ec2 iam/ directory and its JSON files properly" do
97
100
  @http_client.should_receive(:get).
98
101
  with("/2012-01-12/meta-data/").
99
- and_return(mock("Net::HTTP Response", :body => "iam/"))
102
+ and_return(mock("Net::HTTP Response", :body => "iam/", :code => "200"))
100
103
  @http_client.should_receive(:get).
101
104
  with("/2012-01-12/meta-data/iam/").
102
- and_return(mock("Net::HTTP Response", :body => "security-credentials/"))
105
+ and_return(mock("Net::HTTP Response", :body => "security-credentials/", :code => "200"))
103
106
  @http_client.should_receive(:get).
104
107
  with("/2012-01-12/meta-data/iam/security-credentials/").
105
- and_return(mock("Net::HTTP Response", :body => "MyRole"))
108
+ and_return(mock("Net::HTTP Response", :body => "MyRole", :code => "200"))
106
109
  @http_client.should_receive(:get).
107
110
  with("/2012-01-12/meta-data/iam/security-credentials/MyRole").
108
- and_return(mock("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}"))
111
+ and_return(mock("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
109
112
  @ohai._require_plugin("ec2")
110
113
 
111
114
  @ohai[:ec2].should_not be_nil
@@ -116,7 +119,7 @@ describe Ohai::System, "plugin ec2" do
116
119
  it "should ignore \"./\" and \"../\" on ec2 metadata paths to avoid infinity loops" do
117
120
  @http_client.should_receive(:get).
118
121
  with("/2012-01-12/meta-data/").
119
- and_return(mock("Net::HTTP Response", :body => ".\n./\n..\n../\npath1/.\npath2/./\npath3/..\npath4/../"))
122
+ and_return(mock("Net::HTTP Response", :body => ".\n./\n..\n../\npath1/.\npath2/./\npath3/..\npath4/../", :code => "200"))
120
123
 
121
124
  @http_client.should_not_receive(:get).
122
125
  with("/2012-01-12/meta-data/.")
@@ -131,16 +134,16 @@ describe Ohai::System, "plugin ec2" do
131
134
 
132
135
  @http_client.should_receive(:get).
133
136
  with("/2012-01-12/meta-data/path1/").
134
- and_return(mock("Net::HTTP Response", :body => ""))
137
+ and_return(mock("Net::HTTP Response", :body => "", :code => "200"))
135
138
  @http_client.should_receive(:get).
136
139
  with("/2012-01-12/meta-data/path2/").
137
- and_return(mock("Net::HTTP Response", :body => ""))
140
+ and_return(mock("Net::HTTP Response", :body => "", :code => "200"))
138
141
  @http_client.should_receive(:get).
139
142
  with("/2012-01-12/meta-data/path3/").
140
- and_return(mock("Net::HTTP Response", :body => ""))
143
+ and_return(mock("Net::HTTP Response", :body => "", :code => "200"))
141
144
  @http_client.should_receive(:get).
142
145
  with("/2012-01-12/meta-data/path4/").
143
- and_return(mock("Net::HTTP Response", :body => ""))
146
+ and_return(mock("Net::HTTP Response", :body => "", :code => "200"))
144
147
 
145
148
  @ohai._require_plugin("ec2")
146
149
 
@@ -164,7 +167,7 @@ describe Ohai::System, "plugin ec2" do
164
167
  @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"}
165
168
  end
166
169
  end
167
-
170
+
168
171
  describe "with ec2 cloud file" do
169
172
  it_should_behave_like "ec2"
170
173
 
@@ -178,16 +181,16 @@ describe Ohai::System, "plugin ec2" do
178
181
 
179
182
  describe "without cloud file" do
180
183
  it_should_behave_like "!ec2"
181
-
184
+
182
185
  before(:each) do
183
186
  File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(false)
184
187
  File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
185
188
  end
186
189
  end
187
-
190
+
188
191
  describe "with rackspace cloud file" do
189
192
  it_should_behave_like "!ec2"
190
-
193
+
191
194
  before(:each) do
192
195
  File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
193
196
  File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
@@ -195,5 +198,5 @@ describe Ohai::System, "plugin ec2" do
195
198
  File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
196
199
  end
197
200
  end
198
-
201
+
199
202
  end
@@ -38,18 +38,21 @@ describe Ohai::System, "plugin eucalyptus" do
38
38
  @http_client = mock("Net::HTTP client")
39
39
  @ohai.stub!(:http_client).and_return(@http_client)
40
40
 
41
+ @http_client.should_receive(:get).
42
+ with("/").twice.
43
+ and_return(mock("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
41
44
  @http_client.should_receive(:get).
42
45
  with("/2012-01-12/meta-data/").
43
- and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups"))
46
+ and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200"))
44
47
  @http_client.should_receive(:get).
45
48
  with("/2012-01-12/meta-data/instance_type").
46
- and_return(mock("Net::HTTP Response", :body => "c1.medium"))
49
+ and_return(mock("Net::HTTP Response", :body => "c1.medium", :code => "200"))
47
50
  @http_client.should_receive(:get).
48
51
  with("/2012-01-12/meta-data/ami_id").
49
- and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934"))
52
+ and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200"))
50
53
  @http_client.should_receive(:get).
51
54
  with("/2012-01-12/meta-data/security-groups").
52
- and_return(mock("Net::HTTP Response", :body => "group1\ngroup2"))
55
+ and_return(mock("Net::HTTP Response", :body => "group1\ngroup2", :code => "200"))
53
56
  @http_client.should_receive(:get).
54
57
  with("/2012-01-12/user-data/").
55
58
  and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
@@ -84,7 +87,7 @@ describe Ohai::System, "plugin eucalyptus" do
84
87
  @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
85
88
  end
86
89
  end
87
-
90
+
88
91
  describe "with eucalyptus cloud file" do
89
92
  it_should_behave_like "eucalyptus"
90
93
 
@@ -98,16 +101,16 @@ describe Ohai::System, "plugin eucalyptus" do
98
101
 
99
102
  describe "without cloud file" do
100
103
  it_should_behave_like "!eucalyptus"
101
-
104
+
102
105
  before(:each) do
103
106
  File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false)
104
107
  File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false)
105
108
  end
106
109
  end
107
-
110
+
108
111
  describe "with ec2 cloud file" do
109
112
  it_should_behave_like "!eucalyptus"
110
-
113
+
111
114
  before(:each) do
112
115
  File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
113
116
  File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
@@ -115,5 +118,5 @@ describe Ohai::System, "plugin eucalyptus" do
115
118
  File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
116
119
  end
117
120
  end
118
-
121
+
119
122
  end
@@ -0,0 +1,130 @@
1
+ #
2
+ # Author:: Ranjib Dey (dey.ranjib@gmail.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 CONDIT"Net::HTTP Response"NS 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.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
19
+ require 'open-uri'
20
+
21
+ describe Ohai::System, "plugin gce" do
22
+ before(:each) do
23
+ @ohai = Ohai::System.new
24
+ @ohai.stub!(:require_plugin).and_return(true)
25
+ end
26
+
27
+ shared_examples_for "!gce" do
28
+ it "should NOT attempt to fetch the gce metadata" do
29
+ @ohai.should_not_receive(:http_client)
30
+ @ohai._require_plugin("gce")
31
+ end
32
+ end
33
+
34
+ shared_examples_for "gce" do
35
+ before(:each) do
36
+ @http_client = mock("Net::HTTP client")
37
+ @ohai.stub!(:http_client).and_return(@http_client)
38
+ IO.stub!(:select).and_return([[],[1],[]])
39
+ t = mock("connection")
40
+ t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS)
41
+ Socket.stub!(:new).and_return(t)
42
+ Socket.stub!(:pack_sockaddr_in).and_return(nil)
43
+ end
44
+
45
+ it "should recursively fetch metadata" do
46
+ @http_client.should_receive(:get).
47
+ with("/0.1/meta-data/").
48
+ and_return(mock("Net::HTTPOK",
49
+ :body => "domain\nhostname\ndescription", :code=>"200"))
50
+ @http_client.should_receive(:get).
51
+ with("/0.1/meta-data/domain").
52
+ and_return(mock("Net::HTTPOK", :body => "test-domain", :code=>"200"))
53
+ @http_client.should_receive(:get).
54
+ with("/0.1/meta-data/hostname").
55
+ and_return(mock("Net::HTTPOK", :body => "test-host", :code=>"200"))
56
+ @http_client.should_receive(:get).
57
+ with("/0.1/meta-data/description").
58
+ and_return(mock("Net::HTTPOK", :body => "test-description", :code=>"200"))
59
+
60
+ @ohai._require_plugin("gce")
61
+
62
+ @ohai[:gce].should_not be_nil
63
+ @ohai[:gce]['hostname'].should == "test-host"
64
+ @ohai[:gce]['domain'].should == "test-domain"
65
+ @ohai[:gce]['description'].should == "test-description"
66
+ end
67
+
68
+ it "should properly parse json metadata" do
69
+ @http_client.should_receive(:get).
70
+ with("/0.1/meta-data/").
71
+ and_return(mock("Net::HTTP Response", :body => "attached-disks\n", :code=>"200"))
72
+ @http_client.should_receive(:get).
73
+ with("/0.1/meta-data/attached-disks").
74
+ and_return(mock("Net::HTTP Response", :body => '{"disks":[{"deviceName":"boot",
75
+ "index":0,"mode":"READ_WRITE","type":"EPHEMERAL"}]}', :code=>"200"))
76
+
77
+ @ohai._require_plugin("gce")
78
+
79
+ @ohai[:gce].should_not be_nil
80
+ @ohai[:gce]['attached_disks'].should eq({"disks"=>[{"deviceName"=>"boot",
81
+ "index"=>0,"mode"=>"READ_WRITE",
82
+ "type"=>"EPHEMERAL"}]})
83
+ end
84
+ end
85
+
86
+ describe "with dmi and metadata address connected" do
87
+ it_should_behave_like "gce"
88
+ before(:each) do
89
+ File.should_receive(:read).with('/sys/firmware/dmi/entries/1-0/raw').and_return('Google')
90
+ end
91
+ end
92
+
93
+ describe "without dmi and metadata address connected" do
94
+ it_should_behave_like "!gce"
95
+ before(:each) do
96
+ File.should_receive(:read).with('/sys/firmware/dmi/entries/1-0/raw').and_return('Test')
97
+ end
98
+ end
99
+
100
+ describe "with hint file" do
101
+ it_should_behave_like "gce"
102
+
103
+ before(:each) do
104
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/gce.json').and_return(true)
105
+ File.stub!(:read).with('/etc/chef/ohai/hints/gce.json').and_return('')
106
+ File.stub!(:exist?).with('C:\chef\ohai\hints/gce.json').and_return(true)
107
+ File.stub!(:read).with('C:\chef\ohai\hints/gce.json').and_return('')
108
+ end
109
+ end
110
+
111
+ describe "without hint file" do
112
+ it_should_behave_like "!gce"
113
+
114
+ before(:each) do
115
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/gce.json').and_return(false)
116
+ File.stub!(:exist?).with('C:\chef\ohai\hints/gce.json').and_return(false)
117
+ end
118
+ end
119
+
120
+ describe "with ec2 cloud file" do
121
+ it_should_behave_like "!gce"
122
+
123
+ before(:each) do
124
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
125
+ File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
126
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
127
+ File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
128
+ end
129
+ end
130
+ end
@@ -72,6 +72,12 @@ describe Ohai::System, "Linux plugin platform" do
72
72
  @ohai[:platform].should == "linuxmint"
73
73
  @ohai[:platform_family].should == "debian"
74
74
  end
75
+ it "should set platform to gcel and platform_family to debian [:lsb][:id] contains GCEL" do
76
+ @ohai[:lsb][:id] = "GCEL"
77
+ @ohai._require_plugin("linux::platform")
78
+ @ohai[:platform].should == "gcel"
79
+ @ohai[:platform_family].should == "debian"
80
+ end
75
81
  it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do
76
82
  @ohai[:lsb][:id] = "Debian"
77
83
  @ohai._require_plugin("linux::platform")
@@ -378,12 +384,11 @@ describe Ohai::System, "Linux plugin platform" do
378
384
  @ohai[:lsb][:id] = "SUSE LINUX"
379
385
  end
380
386
 
381
- it "should read the platform as suse" do
387
+ it "should read the platform as opensuse on openSUSE" do
382
388
  @ohai[:lsb][:release] = "12.1"
383
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
389
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
384
390
  @ohai._require_plugin("linux::platform")
385
- @ohai[:platform].should == "suse"
386
- @ohai[:platform_version].should == "12.1"
391
+ @ohai[:platform].should == "opensuse"
387
392
  @ohai[:platform_family].should == "suse"
388
393
  end
389
394
  end
@@ -421,28 +426,32 @@ describe Ohai::System, "Linux plugin platform" do
421
426
  end
422
427
 
423
428
  it "[OHAI-272] should read the version as 11.3" do
424
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
429
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
425
430
  @ohai._require_plugin("linux::platform")
426
- @ohai[:platform].should == "suse"
427
431
  @ohai[:platform_version].should == "11.3"
428
432
  @ohai[:platform_family].should == "suse"
429
433
  end
430
434
 
431
435
  it "[OHAI-272] should read the version as 9.1" do
432
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
436
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
433
437
  @ohai._require_plugin("linux::platform")
434
- @ohai[:platform].should == "suse"
435
438
  @ohai[:platform_version].should == "9.1"
436
439
  @ohai[:platform_family].should == "suse"
437
440
  end
438
441
 
439
442
  it "[OHAI-272] should read the version as 11.4" do
440
- File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
443
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
441
444
  @ohai._require_plugin("linux::platform")
442
- @ohai[:platform].should == "suse"
443
445
  @ohai[:platform_version].should == "11.4"
444
446
  @ohai[:platform_family].should == "suse"
445
447
  end
448
+
449
+ it "should read the platform as opensuse on openSUSE" do
450
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n")
451
+ @ohai._require_plugin("linux::platform")
452
+ @ohai[:platform].should == "opensuse"
453
+ @ohai[:platform_family].should == "suse"
454
+ end
446
455
  end
447
456
  end
448
457
 
@@ -194,7 +194,8 @@ describe Ohai::System, "Network Plugin" do
194
194
  end
195
195
 
196
196
  it "informs about this setup" do
197
- Ohai::Log.should_receive(:info).with(/^ipaddress and ip6address are set from different interfaces/)
197
+ Ohai::Log.should_receive(:debug).with(/^ipaddress and ip6address are set from different interfaces/)
198
+ Ohai::Log.should_receive(:debug).any_number_of_times
198
199
  @ohai._require_plugin("network")
199
200
  end
200
201
  end
@@ -223,7 +224,8 @@ describe Ohai::System, "Network Plugin" do
223
224
  end
224
225
 
225
226
  it "informs about this setup" do
226
- Ohai::Log.should_receive(:info).with(/^ipaddress and ip6address are set from different interfaces/)
227
+ Ohai::Log.should_receive(:debug).with(/^ipaddress and ip6address are set from different interfaces/)
228
+ Ohai::Log.should_receive(:debug).any_number_of_times
227
229
  @ohai._require_plugin("network")
228
230
  end
229
231
  end
@@ -238,20 +240,38 @@ describe Ohai::System, "Network Plugin" do
238
240
 
239
241
  it_does_not_fail
240
242
 
241
- it "doesn't detect {ip,ip6,mac}address" do
243
+ it "picks {ip,ip6,mac}address" do
242
244
  Ohai::Log.should_receive(:warn).any_number_of_times
243
245
  @ohai._require_plugin("network")
244
- @ohai["ipaddress"].should be_nil
245
- @ohai["macaddress"].should be_nil
246
- @ohai["ip6address"].should be_nil
246
+ @ohai["ipaddress"].should == "192.168.99.11"
247
+ @ohai["macaddress"].should == "00:16:3E:2F:36:80"
248
+ @ohai["ip6address"].should == "3ffe:1111:3333::1"
247
249
  end
248
250
 
249
251
  it "warns about this conflict" do
250
252
  Ohai::Log.should_receive(:warn).with(/^\[inet\] no ipaddress\/mask on eth1/).once
251
- Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
252
- Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
253
253
  Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ipaddress\/mask on eth1/).once
254
- Ohai::Log.should_receive(:warn).with(/^unable to detect ip6address/).once
254
+ @ohai._require_plugin("network")
255
+ end
256
+ end
257
+
258
+ describe "there's a default gateway, none of the configured ip/mask theorically allows to reach it" do
259
+ before do
260
+ @ohai["network"]["default_gateway"] = "172.16.12.42"
261
+ @ohai["network"]["default_inet6_gateway"] = "3ffe:12:42::7070"
262
+ end
263
+
264
+ it "picks {ip,ip6,mac}address" do
265
+ Ohai::Log.should_receive(:warn).any_number_of_times
266
+ @ohai._require_plugin("network")
267
+ @ohai["ipaddress"].should == "192.168.66.33"
268
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
269
+ @ohai["ip6address"].should == "3ffe:1111:2222::33"
270
+ end
271
+
272
+ it "warns about this conflict" do
273
+ Ohai::Log.should_receive(:warn).with(/^\[inet\] no ipaddress\/mask on eth0/).once
274
+ Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ipaddress\/mask on eth0/).once
255
275
  @ohai._require_plugin("network")
256
276
  end
257
277
  end
@@ -274,9 +294,9 @@ describe Ohai::System, "Network Plugin" do
274
294
  it "warns about this conflict" do
275
295
  Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
276
296
  Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
277
- Ohai::Log.should_receive(:warn).with(/^\[inet\] no ip on eth0/).once
297
+ Ohai::Log.should_receive(:warn).with(/^\[inet\] no ip address on eth0/).once
278
298
  Ohai::Log.should_receive(:warn).with(/^unable to detect ip6address/).once
279
- Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ip on eth0/).once
299
+ Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ip address on eth0/).once
280
300
  @ohai._require_plugin("network")
281
301
  end
282
302
  end
@@ -455,8 +475,9 @@ describe Ohai::System, "Network Plugin" do
455
475
  it_does_not_fail
456
476
 
457
477
  it "picks {ip,mac,ip6}address from the first interface" do
458
- Ohai::Log.should_receive(:info).with(/^\[inet\] no default interface/).once
459
- Ohai::Log.should_receive(:info).with(/^\[inet6\] no default interface/).once
478
+ Ohai::Log.should_receive(:debug).with(/^\[inet\] no default interface/).once
479
+ Ohai::Log.should_receive(:debug).with(/^\[inet6\] no default interface/).once
480
+ Ohai::Log.should_receive(:debug).any_number_of_times
460
481
  @ohai._require_plugin("network")
461
482
  @ohai["ipaddress"].should == "192.168.99.11"
462
483
  @ohai["macaddress"].should == "00:16:3E:2F:36:80"
@@ -477,8 +498,9 @@ describe Ohai::System, "Network Plugin" do
477
498
  it_does_not_fail
478
499
 
479
500
  it "prefers global scope addressses to set {ip,mac,ip6}address" do
480
- Ohai::Log.should_receive(:info).with(/^\[inet\] no default interface/).once
481
- Ohai::Log.should_receive(:info).with(/^\[inet6\] no default interface/).once
501
+ Ohai::Log.should_receive(:debug).with(/^\[inet\] no default interface/).once
502
+ Ohai::Log.should_receive(:debug).with(/^\[inet6\] no default interface/).once
503
+ Ohai::Log.should_receive(:debug).any_number_of_times
482
504
  @ohai._require_plugin("network")
483
505
  @ohai["ipaddress"].should == "192.168.99.11"
484
506
  @ohai["macaddress"].should == "00:16:3E:2F:36:80"
@@ -619,8 +641,8 @@ describe Ohai::System, "Network Plugin" do
619
641
  end
620
642
 
621
643
  it "informs about macaddress being set using the ipv6 setup" do
622
- Ohai::Log.should_receive(:warn).any_number_of_times
623
- Ohai::Log.should_receive(:info).with(/^macaddress set to 00:16:3E:2F:36:79 from the ipv6 setup/).once
644
+ Ohai::Log.should_receive(:debug).with(/^macaddress set to 00:16:3E:2F:36:79 from the ipv6 setup/).once
645
+ Ohai::Log.should_receive(:debug).any_number_of_times
624
646
  @ohai._require_plugin("network")
625
647
  end
626
648
  end