ohai 6.14.0 → 6.16.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohai/mixin/ec2_metadata.rb +61 -6
- data/lib/ohai/plugins/cloud.rb +69 -5
- data/lib/ohai/plugins/darwin/system_profiler.rb +44 -7
- data/lib/ohai/plugins/freebsd/virtualization.rb +16 -0
- data/lib/ohai/plugins/java.rb +1 -1
- data/lib/ohai/plugins/kernel.rb +1 -0
- data/lib/ohai/plugins/linode.rb +53 -0
- data/lib/ohai/plugins/linux/platform.rb +6 -2
- data/lib/ohai/plugins/network.rb +130 -44
- data/lib/ohai/plugins/{aix/ssh_host_key.rb → nodejs.rb} +15 -7
- data/lib/ohai/plugins/openstack.rb +46 -0
- data/lib/ohai/plugins/rackspace.rb +35 -1
- data/lib/ohai/plugins/solaris2/filesystem.rb +1 -1
- data/lib/ohai/plugins/solaris2/network.rb +2 -1
- data/lib/ohai/plugins/solaris2/platform.rb +2 -2
- data/lib/ohai/plugins/ssh_host_key.rb +63 -0
- data/lib/ohai/plugins/virtualization.rb +1 -1
- data/lib/ohai/plugins/windows/cpu.rb +20 -3
- data/lib/ohai/plugins/windows/kernel.rb +0 -19
- data/lib/ohai/plugins/windows/kernel_devices.rb +39 -0
- data/lib/ohai/system.rb +3 -2
- data/lib/ohai/version.rb +1 -1
- data/spec/spec_helper.rb +14 -1
- data/spec/support/platform_helpers.rb +31 -0
- data/spec/{ohai → unit}/mixin/command_spec.rb +0 -0
- data/spec/{ohai → unit}/mixin/from_file_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/c_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/chef_spec.rb +20 -12
- data/spec/unit/plugins/cloud_spec.rb +159 -0
- data/spec/{ohai → unit}/plugins/darwin/hostname_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/darwin/kernel_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/darwin/network_spec.rb +4 -2
- data/spec/{ohai → unit}/plugins/darwin/platform_spec.rb +0 -0
- data/spec/unit/plugins/darwin/system_profiler_output.rb +79525 -0
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +48 -0
- data/spec/{ohai → unit}/plugins/dmi_spec.rb +0 -0
- data/spec/unit/plugins/ec2_spec.rb +199 -0
- data/spec/{ohai → unit}/plugins/erlang_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/eucalyptus_spec.rb +5 -5
- data/spec/{ohai → unit}/plugins/fail_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/freebsd/hostname_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/freebsd/kernel_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/freebsd/platform_spec.rb +0 -0
- data/spec/unit/plugins/freebsd/virtualization_spec.rb +99 -0
- data/spec/{ohai → unit}/plugins/groovy_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/hostname_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/java_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/kernel_spec.rb +0 -0
- data/spec/unit/plugins/linode_spec.rb +156 -0
- data/spec/{ohai → unit}/plugins/linux/cpu_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/linux/filesystem_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/linux/hostname_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/linux/kernel_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/linux/lsb_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/linux/network_spec.rb +3 -60
- data/spec/{ohai → unit}/plugins/linux/platform_spec.rb +10 -0
- data/spec/{ohai → unit}/plugins/linux/uptime_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/linux/virtualization_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/lua_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/mono_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/netbsd/hostname_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/netbsd/kernel_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/netbsd/platform_spec.rb +0 -0
- data/spec/unit/plugins/network_spec.rb +829 -0
- data/spec/unit/plugins/nodejs_spec.rb +51 -0
- data/spec/{ohai → unit}/plugins/ohai_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/ohai_time_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/openbsd/hostname_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/openbsd/kernel_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/openbsd/platform_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/os_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/passwd_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/perl_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/php_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/platform_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/python_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/rackspace_spec.rb +26 -0
- data/spec/{ohai → unit}/plugins/ruby_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/sigar/network_route_spec.rb +1 -0
- data/spec/{ohai → unit}/plugins/solaris2/hostname_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/solaris2/kernel_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/solaris2/network_spec.rb +8 -1
- data/spec/{ohai → unit}/plugins/solaris2/platform_spec.rb +0 -0
- data/spec/{ohai → unit}/plugins/solaris2/virtualization_spec.rb +0 -0
- data/spec/unit/plugins/ssh_host_keys_spec.rb +77 -0
- data/spec/{ohai → unit}/system_spec.rb +0 -0
- metadata +221 -184
- data/lib/ohai/plugins/darwin/ssh_host_key.rb +0 -25
- data/lib/ohai/plugins/freebsd/ssh_host_key.rb +0 -26
- data/lib/ohai/plugins/hpux/ssh_host_key.rb +0 -26
- data/lib/ohai/plugins/linux/ssh_host_key.rb +0 -26
- data/lib/ohai/plugins/netbsd/ssh_host_key.rb +0 -26
- data/lib/ohai/plugins/openbsd/ssh_host_key.rb +0 -26
- data/lib/ohai/plugins/solaris2/ssh_host_key.rb +0 -26
- data/spec/ohai/plugins/cloud_spec.rb +0 -113
- data/spec/ohai/plugins/ec2_spec.rb +0 -120
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Paul Mooring (<paul@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 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
|
+
require File.expand_path("#{File.dirname(__FILE__)}/system_profiler_output.rb")
|
21
|
+
|
22
|
+
begin
|
23
|
+
require 'plist'
|
24
|
+
rescue LoadError => e
|
25
|
+
puts "The darwin systemprofile plugin spec tests will fail without the 'plist' library/gem.\n\n"
|
26
|
+
raise e
|
27
|
+
end
|
28
|
+
|
29
|
+
describe Ohai::System, "Darwin system_profiler plugin", :unix_only do
|
30
|
+
before(:each) do
|
31
|
+
@ohai = Ohai::System.new
|
32
|
+
|
33
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return the right serial number" do
|
37
|
+
mini_cmd = "system_profiler -xml -detailLevel mini SPParallelATAData SPAudioData SPBluetoothData"
|
38
|
+
mini_cmd += " SPCardReaderData SPDiagnosticsData SPDiscBurningData SPEthernetData SPFibreChannelData"
|
39
|
+
mini_cmd += " SPFireWireData SPDisplaysData SPHardwareRAIDData SPMemoryData SPModemData SPNetworkData"
|
40
|
+
mini_cmd += " SPPCIData SPParallelSCSIData SPPrintersSoftwareData SPPrintersData SPSASData SPSerialATAData"
|
41
|
+
mini_cmd += " SPSoftwareData SPThunderboltData SPUSBData SPWWANData SPAirPortData"
|
42
|
+
full_cmd = "system_profiler -xml -detailLevel full SPHardwareDataType"
|
43
|
+
@ohai.stub!(:popen4).with(full_cmd).and_yield(nil, StringIO.new, StringIO.new(SystemProfilerOutput::Full), nil)
|
44
|
+
@ohai.stub!(:popen4).with(mini_cmd).and_yield(nil, StringIO.new, StringIO.new(SystemProfilerOutput::Mini), nil)
|
45
|
+
@ohai._require_plugin("darwin::system_profiler")
|
46
|
+
@ohai['system_profile'][18]["_items"][0]["serial_number"].should == 'ABCDEFG12345'
|
47
|
+
end
|
48
|
+
end
|
File without changes
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Tim Dysinger (<tim@dysinger.net>)
|
3
|
+
# Author:: Christopher Brown (cb@opscode.com)
|
4
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDIT"Net::HTTP Response"NS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
|
21
|
+
require 'open-uri'
|
22
|
+
|
23
|
+
describe Ohai::System, "plugin ec2" do
|
24
|
+
before(:each) do
|
25
|
+
@ohai = Ohai::System.new
|
26
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
27
|
+
@ohai[:network] = {:interfaces => {:eth0 => {} } }
|
28
|
+
end
|
29
|
+
|
30
|
+
shared_examples_for "!ec2" do
|
31
|
+
it "should NOT attempt to fetch the ec2 metadata" do
|
32
|
+
@ohai.should_not_receive(:http_client)
|
33
|
+
@ohai._require_plugin("ec2")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
shared_examples_for "ec2" do
|
38
|
+
before(:each) do
|
39
|
+
@http_client = mock("Net::HTTP client")
|
40
|
+
@ohai.stub!(:http_client).and_return(@http_client)
|
41
|
+
IO.stub!(:select).and_return([[],[1],[]])
|
42
|
+
t = mock("connection")
|
43
|
+
t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS)
|
44
|
+
Socket.stub!(:new).and_return(t)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should recursively fetch all the ec2 metadata" do
|
48
|
+
@http_client.should_receive(:get).
|
49
|
+
with("/2012-01-12/meta-data/").
|
50
|
+
and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups"))
|
51
|
+
@http_client.should_receive(:get).
|
52
|
+
with("/2012-01-12/meta-data/instance_type").
|
53
|
+
and_return(mock("Net::HTTP Response", :body => "c1.medium"))
|
54
|
+
@http_client.should_receive(:get).
|
55
|
+
with("/2012-01-12/meta-data/ami_id").
|
56
|
+
and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934"))
|
57
|
+
@http_client.should_receive(:get).
|
58
|
+
with("/2012-01-12/meta-data/security-groups").
|
59
|
+
and_return(mock("Net::HTTP Response", :body => "group1\ngroup2"))
|
60
|
+
@http_client.should_receive(:get).
|
61
|
+
with("/2012-01-12/user-data/").
|
62
|
+
and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
|
63
|
+
@ohai._require_plugin("ec2")
|
64
|
+
|
65
|
+
@ohai[:ec2].should_not be_nil
|
66
|
+
@ohai[:ec2]['instance_type'].should == "c1.medium"
|
67
|
+
@ohai[:ec2]['ami_id'].should == "ami-5d2dc934"
|
68
|
+
@ohai[:ec2]['security_groups'].should eql ['group1', 'group2']
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should parse ec2 network/ directory as a multi-level hash" do
|
72
|
+
@http_client.should_receive(:get).
|
73
|
+
with("/2012-01-12/meta-data/").
|
74
|
+
and_return(mock("Net::HTTP Response", :body => "network/"))
|
75
|
+
@http_client.should_receive(:get).
|
76
|
+
with("/2012-01-12/meta-data/network/").
|
77
|
+
and_return(mock("Net::HTTP Response", :body => "interfaces/"))
|
78
|
+
@http_client.should_receive(:get).
|
79
|
+
with("/2012-01-12/meta-data/network/interfaces/").
|
80
|
+
and_return(mock("Net::HTTP Response", :body => "macs/"))
|
81
|
+
@http_client.should_receive(:get).
|
82
|
+
with("/2012-01-12/meta-data/network/interfaces/macs/").
|
83
|
+
and_return(mock("Net::HTTP Response", :body => "fe:ff:ff:ff:ff:ff/"))
|
84
|
+
@http_client.should_receive(:get).
|
85
|
+
with("/2012-01-12/meta-data/network/interfaces/macs/fe:ff:ff:ff:ff:ff/").
|
86
|
+
and_return(mock("Net::HTTP Response", :body => "public_hostname"))
|
87
|
+
@http_client.should_receive(:get).
|
88
|
+
with("/2012-01-12/meta-data/network/interfaces/macs/fe:ff:ff:ff:ff:ff/public_hostname").
|
89
|
+
and_return(mock("Net::HTTP Response", :body => "server17.opscode.com"))
|
90
|
+
@ohai._require_plugin("ec2")
|
91
|
+
|
92
|
+
@ohai[:ec2].should_not be_nil
|
93
|
+
@ohai[:ec2]['network_interfaces_macs']['fe:ff:ff:ff:ff:ff']['public_hostname'].should eql('server17.opscode.com')
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should parse ec2 iam/ directory and its JSON files properly" do
|
97
|
+
@http_client.should_receive(:get).
|
98
|
+
with("/2012-01-12/meta-data/").
|
99
|
+
and_return(mock("Net::HTTP Response", :body => "iam/"))
|
100
|
+
@http_client.should_receive(:get).
|
101
|
+
with("/2012-01-12/meta-data/iam/").
|
102
|
+
and_return(mock("Net::HTTP Response", :body => "security-credentials/"))
|
103
|
+
@http_client.should_receive(:get).
|
104
|
+
with("/2012-01-12/meta-data/iam/security-credentials/").
|
105
|
+
and_return(mock("Net::HTTP Response", :body => "MyRole"))
|
106
|
+
@http_client.should_receive(:get).
|
107
|
+
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}"))
|
109
|
+
@ohai._require_plugin("ec2")
|
110
|
+
|
111
|
+
@ohai[:ec2].should_not be_nil
|
112
|
+
@ohai[:ec2]['iam']['security-credentials']['MyRole']['Code'].should eql 'Success'
|
113
|
+
@ohai[:ec2]['iam']['security-credentials']['MyRole']['Token'].should eql '12345678'
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should ignore \"./\" and \"../\" on ec2 metadata paths to avoid infinity loops" do
|
117
|
+
@http_client.should_receive(:get).
|
118
|
+
with("/2012-01-12/meta-data/").
|
119
|
+
and_return(mock("Net::HTTP Response", :body => ".\n./\n..\n../\npath1/.\npath2/./\npath3/..\npath4/../"))
|
120
|
+
|
121
|
+
@http_client.should_not_receive(:get).
|
122
|
+
with("/2012-01-12/meta-data/.")
|
123
|
+
@http_client.should_not_receive(:get).
|
124
|
+
with("/2012-01-12/meta-data/./")
|
125
|
+
@http_client.should_not_receive(:get).
|
126
|
+
with("/2012-01-12/meta-data/..")
|
127
|
+
@http_client.should_not_receive(:get).
|
128
|
+
with("/2012-01-12/meta-data/../")
|
129
|
+
@http_client.should_not_receive(:get).
|
130
|
+
with("/2012-01-12/meta-data/path1/..")
|
131
|
+
|
132
|
+
@http_client.should_receive(:get).
|
133
|
+
with("/2012-01-12/meta-data/path1/").
|
134
|
+
and_return(mock("Net::HTTP Response", :body => ""))
|
135
|
+
@http_client.should_receive(:get).
|
136
|
+
with("/2012-01-12/meta-data/path2/").
|
137
|
+
and_return(mock("Net::HTTP Response", :body => ""))
|
138
|
+
@http_client.should_receive(:get).
|
139
|
+
with("/2012-01-12/meta-data/path3/").
|
140
|
+
and_return(mock("Net::HTTP Response", :body => ""))
|
141
|
+
@http_client.should_receive(:get).
|
142
|
+
with("/2012-01-12/meta-data/path4/").
|
143
|
+
and_return(mock("Net::HTTP Response", :body => ""))
|
144
|
+
|
145
|
+
@ohai._require_plugin("ec2")
|
146
|
+
|
147
|
+
@ohai[:ec2].should_not be_nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "with ec2 mac and metadata address connected" do
|
152
|
+
it_should_behave_like "ec2"
|
153
|
+
|
154
|
+
before(:each) do
|
155
|
+
IO.stub!(:select).and_return([[],[1],[]])
|
156
|
+
@ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "without ec2 mac and metadata address connected" do
|
161
|
+
it_should_behave_like "!ec2"
|
162
|
+
|
163
|
+
before(:each) do
|
164
|
+
@ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"}
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "with ec2 cloud file" do
|
169
|
+
it_should_behave_like "ec2"
|
170
|
+
|
171
|
+
before(:each) do
|
172
|
+
File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
|
173
|
+
File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
|
174
|
+
File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
|
175
|
+
File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "without cloud file" do
|
180
|
+
it_should_behave_like "!ec2"
|
181
|
+
|
182
|
+
before(:each) do
|
183
|
+
File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(false)
|
184
|
+
File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "with rackspace cloud file" do
|
189
|
+
it_should_behave_like "!ec2"
|
190
|
+
|
191
|
+
before(:each) do
|
192
|
+
File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
|
193
|
+
File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
|
194
|
+
File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
|
195
|
+
File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
File without changes
|
@@ -39,19 +39,19 @@ describe Ohai::System, "plugin eucalyptus" do
|
|
39
39
|
@ohai.stub!(:http_client).and_return(@http_client)
|
40
40
|
|
41
41
|
@http_client.should_receive(:get).
|
42
|
-
with("/
|
42
|
+
with("/2012-01-12/meta-data/").
|
43
43
|
and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups"))
|
44
44
|
@http_client.should_receive(:get).
|
45
|
-
with("/
|
45
|
+
with("/2012-01-12/meta-data/instance_type").
|
46
46
|
and_return(mock("Net::HTTP Response", :body => "c1.medium"))
|
47
47
|
@http_client.should_receive(:get).
|
48
|
-
with("/
|
48
|
+
with("/2012-01-12/meta-data/ami_id").
|
49
49
|
and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934"))
|
50
50
|
@http_client.should_receive(:get).
|
51
|
-
with("/
|
51
|
+
with("/2012-01-12/meta-data/security-groups").
|
52
52
|
and_return(mock("Net::HTTP Response", :body => "group1\ngroup2"))
|
53
53
|
@http_client.should_receive(:get).
|
54
|
-
with("/
|
54
|
+
with("/2012-01-12/user-data/").
|
55
55
|
and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
|
56
56
|
end
|
57
57
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan <btm@opscode.com>
|
3
|
+
# Copyright:: Copyright (c) 2012 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, "FreeBSD virtualization plugin" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@ohai[:os] = "freebsd"
|
27
|
+
@stderr = StringIO.new
|
28
|
+
@stdin = StringIO.new
|
29
|
+
@status = 0
|
30
|
+
@pid = 42
|
31
|
+
@ohai.stub(:popen4).with("/sbin/kldstat")
|
32
|
+
@ohai.stub(:from)
|
33
|
+
end
|
34
|
+
|
35
|
+
context "jails" do
|
36
|
+
it "detects we are in a jail" do
|
37
|
+
@ohai.stub(:from).with("sysctl -n security.jail.jailed").and_return("1")
|
38
|
+
@ohai._require_plugin("freebsd::virtualization")
|
39
|
+
@ohai[:virtualization][:system].should == "jail"
|
40
|
+
@ohai[:virtualization][:role].should == "guest"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "detects we are hosing jails" do
|
44
|
+
@ohai.stub(:from).with("jls -n \| wc -l").and_return("1")
|
45
|
+
@ohai._require_plugin("freebsd::virtualization")
|
46
|
+
@ohai[:virtualization][:system].should == "jail"
|
47
|
+
@ohai[:virtualization][:role].should == "host"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
context "when on a virtualbox guest" do
|
53
|
+
before do
|
54
|
+
@stdout = StringIO.new(<<-OUT)
|
55
|
+
Id Refs Address Size Name
|
56
|
+
1 40 0xffffffff80100000 d20428 kernel
|
57
|
+
7 3 0xffffffff81055000 41e88 vboxguest.ko
|
58
|
+
OUT
|
59
|
+
@ohai.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "detects we are a guest" do
|
63
|
+
@ohai._require_plugin("freebsd::virtualization")
|
64
|
+
@ohai[:virtualization][:system].should == "vbox"
|
65
|
+
@ohai[:virtualization][:role].should == "guest"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when on a virtualbox host" do
|
70
|
+
before do
|
71
|
+
@stdout = StringIO.new(<<-OUT)
|
72
|
+
Id Refs Address Size Name
|
73
|
+
1 40 0xffffffff80100000 d20428 kernel
|
74
|
+
7 3 0xffffffff81055000 41e88 vboxdrv.ko
|
75
|
+
OUT
|
76
|
+
@ohai.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "detects we are a host" do
|
80
|
+
@ohai._require_plugin("freebsd::virtualization")
|
81
|
+
@ohai[:virtualization][:system].should == "vbox"
|
82
|
+
@ohai[:virtualization][:role].should == "host"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when on a QEMU guest" do
|
87
|
+
it "detects we are a guest" do
|
88
|
+
@ohai.stub(:from).with("sysctl -n hw.model").and_return('QEMU Virtual CPU version (cpu64-rhel6) ("GenuineIntel" 686-class)')
|
89
|
+
@ohai._require_plugin("freebsd::virtualization")
|
90
|
+
@ohai[:virtualization][:system].should == "kvm"
|
91
|
+
@ohai[:virtualization][:role].should == "guest"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# TODO upfactor tests from linux virtualization plugin for dmidecode
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,156 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Aaron Kalin (<akalin@martinisoftware.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.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
|
19
|
+
|
20
|
+
describe Ohai::System, "plugin linode" do
|
21
|
+
let(:hint_path_nix) { '/etc/chef/ohai/hints/linode.json' }
|
22
|
+
let(:hint_path_win) { 'C:\chef\ohai\hints/linode.json' }
|
23
|
+
|
24
|
+
before do
|
25
|
+
@ohai = Ohai::System.new
|
26
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
27
|
+
@ohai[:network] = {
|
28
|
+
"interfaces"=> {
|
29
|
+
"eth0"=> {
|
30
|
+
"addresses"=> {
|
31
|
+
"1.2.3.4"=> {
|
32
|
+
"broadcast"=> "67.23.20.255",
|
33
|
+
"netmask"=> "255.255.255.0",
|
34
|
+
"family"=> "inet"
|
35
|
+
},
|
36
|
+
"fe80::4240:95ff:fe47:6eed"=> {
|
37
|
+
"scope"=> "Link",
|
38
|
+
"prefixlen"=> "64",
|
39
|
+
"family"=> "inet6"
|
40
|
+
},
|
41
|
+
"40:40:95:47:6E:ED" => {
|
42
|
+
"family" => "lladdr"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
shared_examples_for "!linode" do
|
51
|
+
it "does not create the linode mash" do
|
52
|
+
@ohai._require_plugin("linode")
|
53
|
+
@ohai[:linode].should be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
shared_examples_for "linode" do
|
58
|
+
it "creates a linode mash" do
|
59
|
+
@ohai._require_plugin("linode")
|
60
|
+
@ohai[:linode].should_not be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "has all required attributes" do
|
64
|
+
@ohai._require_plugin("linode")
|
65
|
+
@ohai[:linode][:public_ip].should_not be_nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it "has correct values for all attributes" do
|
69
|
+
@ohai._require_plugin("linode")
|
70
|
+
@ohai[:linode][:public_ip].should == "1.2.3.4"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
context "without linode kernel" do
|
76
|
+
before do
|
77
|
+
@ohai[:kernel] = { "release" => "3.5.2-x86_64" }
|
78
|
+
end
|
79
|
+
|
80
|
+
it_should_behave_like "!linode"
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with linode kernel" do
|
84
|
+
before do
|
85
|
+
@ohai[:kernel] = { "release" => "3.5.2-x86_64-linode24" }
|
86
|
+
end
|
87
|
+
|
88
|
+
it_should_behave_like "linode"
|
89
|
+
|
90
|
+
# This test is an interface created according to this guide by Linode
|
91
|
+
# http://library.linode.com/networking/configuring-static-ip-interfaces
|
92
|
+
context "with configured private ip address as suggested by linode" do
|
93
|
+
before do
|
94
|
+
@ohai[:network][:interfaces]["eth0:1"] = {
|
95
|
+
"addresses" => {
|
96
|
+
"5.6.7.8"=> {
|
97
|
+
"broadcast"=> "10.176.191.255",
|
98
|
+
"netmask"=> "255.255.224.0",
|
99
|
+
"family"=> "inet"
|
100
|
+
},
|
101
|
+
"fe80::4240:f5ff:feab:2836" => {
|
102
|
+
"scope"=> "Link",
|
103
|
+
"prefixlen"=> "64",
|
104
|
+
"family"=> "inet6"
|
105
|
+
},
|
106
|
+
"40:40:F5:AB:28:36" => {
|
107
|
+
"family"=> "lladdr"
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
it "detects and sets the private ip" do
|
114
|
+
@ohai._require_plugin("linode")
|
115
|
+
@ohai[:linode][:private_ip].should_not be_nil
|
116
|
+
@ohai[:linode][:private_ip].should == "5.6.7.8"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "with linode cloud file" do
|
123
|
+
before do
|
124
|
+
File.stub!(:exist?).with(hint_path_nix).and_return(true)
|
125
|
+
File.stub!(:read).with(hint_path_nix).and_return('')
|
126
|
+
File.stub!(:exist?).with(hint_path_win).and_return(true)
|
127
|
+
File.stub!(:read).with(hint_path_win).and_return('')
|
128
|
+
end
|
129
|
+
|
130
|
+
it_should_behave_like "linode"
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "without cloud file" do
|
134
|
+
before do
|
135
|
+
File.stub!(:exist?).with(hint_path_nix).and_return(false)
|
136
|
+
File.stub!(:exist?).with(hint_path_win).and_return(false)
|
137
|
+
end
|
138
|
+
|
139
|
+
it_should_behave_like "!linode"
|
140
|
+
end
|
141
|
+
|
142
|
+
context "with ec2 cloud file" do
|
143
|
+
let(:hint_path_nix) { '/etc/chef/ohai/hints/ec2.json' }
|
144
|
+
let(:hint_path_win) { 'C:\chef\ohai\hints/ec2.json' }
|
145
|
+
|
146
|
+
before do
|
147
|
+
File.stub!(:exist?).with(hint_path_nix).and_return(true)
|
148
|
+
File.stub!(:read).with(hint_path_nix).and_return('')
|
149
|
+
File.stub!(:exist?).with(hint_path_win).and_return(true)
|
150
|
+
File.stub!(:read).with(hint_path_win).and_return('')
|
151
|
+
end
|
152
|
+
|
153
|
+
it_should_behave_like "!linode"
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|