ohai 8.13.0 → 8.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/ohai/common/dmi.rb +1 -1
  4. data/lib/ohai/config.rb +2 -2
  5. data/lib/ohai/dsl/plugin.rb +1 -1
  6. data/lib/ohai/loader.rb +1 -1
  7. data/lib/ohai/mixin/command.rb +18 -5
  8. data/lib/ohai/mixin/ec2_metadata.rb +1 -1
  9. data/lib/ohai/plugins/aix/os.rb +1 -1
  10. data/lib/ohai/plugins/c.rb +49 -67
  11. data/lib/ohai/plugins/darwin/memory.rb +1 -1
  12. data/lib/ohai/plugins/darwin/network.rb +3 -3
  13. data/lib/ohai/plugins/darwin/platform.rb +1 -1
  14. data/lib/ohai/plugins/darwin/system_profiler.rb +1 -1
  15. data/lib/ohai/plugins/digital_ocean.rb +1 -1
  16. data/lib/ohai/plugins/ec2.rb +42 -41
  17. data/lib/ohai/plugins/erlang.rb +1 -1
  18. data/lib/ohai/plugins/ip_scopes.rb +1 -1
  19. data/lib/ohai/plugins/kernel.rb +1 -1
  20. data/lib/ohai/plugins/linux/network.rb +2 -2
  21. data/lib/ohai/plugins/linux/platform.rb +6 -1
  22. data/lib/ohai/plugins/mono.rb +1 -1
  23. data/lib/ohai/plugins/network.rb +2 -2
  24. data/lib/ohai/plugins/packages.rb +59 -46
  25. data/lib/ohai/plugins/python.rb +2 -2
  26. data/lib/ohai/plugins/rackspace.rb +4 -4
  27. data/lib/ohai/plugins/sigar/network.rb +1 -1
  28. data/lib/ohai/plugins/sigar/network_route.rb +1 -1
  29. data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
  30. data/lib/ohai/plugins/solaris2/network.rb +25 -8
  31. data/lib/ohai/plugins/ssh_host_key.rb +1 -1
  32. data/lib/ohai/plugins/windows/network.rb +5 -5
  33. data/lib/ohai/provides_map.rb +2 -2
  34. data/lib/ohai/system.rb +1 -1
  35. data/lib/ohai/version.rb +1 -1
  36. data/spec/functional/loader_spec.rb +1 -1
  37. data/spec/unit/mixin/command_spec.rb +118 -0
  38. data/spec/unit/plugins/aix/os_spec.rb +6 -5
  39. data/spec/unit/plugins/c_spec.rb +169 -118
  40. data/spec/unit/plugins/digital_ocean_spec.rb +7 -7
  41. data/spec/unit/plugins/dmi_spec.rb +4 -4
  42. data/spec/unit/plugins/ec2_spec.rb +64 -69
  43. data/spec/unit/plugins/linode_spec.rb +6 -6
  44. data/spec/unit/plugins/linux/platform_spec.rb +7 -0
  45. data/spec/unit/plugins/linux/sessions_spec.rb +2 -2
  46. data/spec/unit/plugins/network_spec.rb +16 -16
  47. data/spec/unit/plugins/openstack_spec.rb +1 -1
  48. data/spec/unit/plugins/packages_spec.rb +165 -191
  49. data/spec/unit/plugins/rackspace_spec.rb +203 -130
  50. data/spec/unit/plugins/solaris2/filesystem.rb +2 -2
  51. data/spec/unit/plugins/solaris2/network_spec.rb +36 -5
  52. metadata +3 -3
@@ -171,7 +171,7 @@ EOM
171
171
 
172
172
  expect_get_response(
173
173
  URI.parse("#{openstack_metadata_endpoint}#{openstack_metadata_version}/meta_data.json"),
174
- openstack_metadata_values,
174
+ openstack_metadata_values
175
175
  )
176
176
 
177
177
  openstack_plugin.run
@@ -20,252 +20,226 @@
20
20
  require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
21
21
 
22
22
  describe Ohai::System, "plugin packages" do
23
- context "when the packages plugin is disabled" do
24
- before do
25
- Ohai.config[:plugin][:packages][:enabled] = false
26
- allow(plugin).to receive(:collect_os).and_return(platform_family.to_s)
27
- plugin.run
28
- end
29
-
23
+ context "on debian" do
30
24
  let(:plugin) do
31
25
  get_plugin("packages").tap do |plugin|
32
- plugin[:platform_family] = platform_family
26
+ plugin[:platform_family] = "debian"
33
27
  end
34
28
  end
35
29
 
36
- [:debian, :fedora, :windows, :aix, :solaris2].each do |os|
37
- context "on #{os}" do
38
- let(:platform_family) { os }
39
-
40
- it "does not enumerate the packages" do
41
- expect(plugin[:packages]).to eq(nil)
42
- end
43
- end
30
+ let(:stdout) do
31
+ File.read(File.join(SPEC_PLUGIN_PATH, "dpkg-query.output"))
44
32
  end
45
- end
46
33
 
47
- context "when the packages plugin is enabled" do
48
- before do
49
- Ohai.config[:plugin][:packages][:enabled] = true
34
+ before(:each) do
35
+ allow(plugin).to receive(:collect_os).and_return(:linux)
36
+ allow(plugin).to receive(:shell_out)
37
+ .with("dpkg-query -W")
38
+ .and_return(mock_shell_out(0, stdout, ""))
39
+ plugin.run
50
40
  end
51
41
 
52
- context "on debian" do
53
- let(:plugin) do
54
- get_plugin("packages").tap do |plugin|
55
- plugin[:platform_family] = "debian"
56
- end
57
- end
42
+ it "calls dpkg query" do
43
+ expect(plugin).to receive(:shell_out)
44
+ .with("dpkg-query -W")
45
+ .and_return(mock_shell_out(0, stdout, ""))
46
+ plugin.run
47
+ end
58
48
 
59
- let(:stdout) do
60
- File.read(File.join(SPEC_PLUGIN_PATH, "dpkg-query.output"))
61
- end
49
+ it "gets packages and versions" do
50
+ expect(plugin[:packages]["vim-common"][:version]).to eq("2:7.4.052-1ubuntu3")
51
+ end
52
+ end
62
53
 
63
- before(:each) do
64
- allow(plugin).to receive(:collect_os).and_return(:linux)
65
- allow(plugin).to receive(:shell_out)
66
- .with("dpkg-query -W")
67
- .and_return(mock_shell_out(0, stdout, ""))
68
- plugin.run
54
+ context "on fedora" do
55
+ let(:plugin) do
56
+ get_plugin("packages").tap do |plugin|
57
+ plugin[:platform_family] = "fedora"
69
58
  end
59
+ end
70
60
 
71
- it "calls dpkg query" do
72
- expect(plugin).to receive(:shell_out)
73
- .with("dpkg-query -W")
74
- .and_return(mock_shell_out(0, stdout, ""))
75
- plugin.run
76
- end
61
+ let(:format) { Shellwords.escape '%{NAME}\t%{VERSION}\t%{RELEASE}\n' }
77
62
 
78
- it "gets packages and versions" do
79
- expect(plugin[:packages]["vim-common"][:version]).to eq("2:7.4.052-1ubuntu3")
80
- end
63
+ let(:stdout) do
64
+ File.read(File.join(SPEC_PLUGIN_PATH, "rpmquery.output"))
81
65
  end
82
66
 
83
- context "on fedora" do
84
- let(:plugin) do
85
- get_plugin("packages").tap do |plugin|
86
- plugin[:platform_family] = "fedora"
87
- end
88
- end
67
+ before(:each) do
68
+ allow(plugin).to receive(:collect_os).and_return(:linux)
69
+ allow(plugin).to receive(:shell_out).with("rpm -qa --queryformat #{format}").and_return(mock_shell_out(0, stdout, ""))
70
+ plugin.run
71
+ end
89
72
 
90
- let(:format) { Shellwords.escape '%{NAME}\t%{VERSION}\t%{RELEASE}\n' }
73
+ it "calls rpm -qa" do
74
+ expect(plugin).to receive(:shell_out)
75
+ .with("rpm -qa --queryformat #{format}")
76
+ .and_return(mock_shell_out(0, stdout, ""))
77
+ plugin.run
78
+ end
91
79
 
92
- let(:stdout) do
93
- File.read(File.join(SPEC_PLUGIN_PATH, "rpmquery.output"))
94
- end
80
+ it "gets packages and versions/release" do
81
+ expect(plugin[:packages]["vim-common"][:version]).to eq("7.2.411")
82
+ expect(plugin[:packages]["vim-common"][:release]).to eq("1.8.el6")
83
+ end
84
+ end
95
85
 
96
- before(:each) do
97
- allow(plugin).to receive(:collect_os).and_return(:linux)
98
- allow(plugin).to receive(:shell_out).with("rpm -qa --queryformat #{format}").and_return(mock_shell_out(0, stdout, ""))
99
- plugin.run
100
- end
86
+ context "on windows", :windows_only do
101
87
 
102
- it "calls rpm -qa" do
103
- expect(plugin).to receive(:shell_out)
104
- .with("rpm -qa --queryformat #{format}")
105
- .and_return(mock_shell_out(0, stdout, ""))
106
- plugin.run
88
+ let(:plugin) do
89
+ get_plugin("packages").tap do |plugin|
90
+ plugin[:platform_family] = "windows"
107
91
  end
92
+ end
108
93
 
109
- it "gets packages and versions/release" do
110
- expect(plugin[:packages]["vim-common"][:version]).to eq("7.2.411")
111
- expect(plugin[:packages]["vim-common"][:release]).to eq("1.8.el6")
112
- end
94
+ let(:win_reg_double) do
95
+ instance_double("Win32::Registry")
113
96
  end
114
97
 
115
- context "on windows", :windows_only do
116
- require "wmi-lite"
98
+ let(:win_reg_keys) do
99
+ [ "{22FA28AB-3C1B-438B-A8B5-E23892C8B567}",
100
+ "{0D4BCDCD-6225-4BA5-91A3-54AFCECC281E}" ]
101
+ end
117
102
 
118
- let(:plugin) do
119
- get_plugin("packages").tap do |plugin|
120
- plugin[:platform_family] = "windows"
121
- end
122
- end
103
+ let(:i386_reg_type) do
104
+ Win32::Registry::KEY_READ | 0x100
105
+ end
123
106
 
124
- let(:win32_product_output) do
125
- [{ "assignmenttype" => 0,
126
- "caption" => "NXLOG-CE",
127
- "description" => "NXLOG-CE",
128
- "helplink" => nil,
129
- "helptelephone" => nil,
130
- "identifyingnumber" => "{22FA28AB-3C1B-438B-A8B5-E23892C8B567}",
131
- "installdate" => "20150511",
132
- "installdate2" => nil,
133
- "installlocation" => nil,
134
- "installsource" => 'C:\\chef\\cache\\',
135
- "installstate" => 5,
136
- "language" => "1033",
137
- "localpackage" => 'C:\\Windows\\Installer\\30884.msi',
138
- "name" => "NXLOG-CE",
139
- "packagecache" => 'C:\\Windows\\Installer\\30884.msi',
140
- "packagecode" => "{EC3A13C4-4634-47FC-9662-DC293CB96F9F}",
141
- "packagename" => "nexlog-ce-2.8.1248.msi",
142
- "productid" => nil,
143
- "regcompany" => nil,
144
- "regowner" => nil,
145
- "skunumber" => nil,
146
- "transforms" => nil,
147
- "urlinfoabout" => nil,
148
- "urlupdateinfo" => nil,
149
- "vendor" => "nxsec.com",
150
- "version" => "2.8.1248",
151
- "wordcount" => 2 },
152
- { "assignmenttype" => 1,
153
- "caption" => "Chef Development Kit v0.7.0",
154
- "description" => "Chef Development Kit v0.7.0",
155
- "helplink" => "http://www.getchef.com/support/",
156
- "helptelephone" => nil,
157
- "identifyingnumber" => "{90754A33-404C-4172-8F3B-7F04CE98011C}",
158
- "installdate" => "20150925", "installdate2" => nil,
159
- "installlocation" => nil,
160
- "installsource" => 'C:\\Users\\skhajamohid1\\Downloads\\',
161
- "installstate" => 5, "language" => "1033",
162
- "localpackage" => 'C:\\WINDOWS\\Installer\\d9e1ca7.msi',
163
- "name" => "Chef Development Kit v0.7.0",
164
- "packagecache" => 'C:\\WINDOWS\\Installer\\d9e1ca7.msi',
165
- "packagecode" => "{9B82FB86-40AE-4CDF-9DE8-97574F9395B9}",
166
- "packagename" => "chefdk-0.7.0-1 (2).msi",
167
- "productid" => nil,
168
- "regcompany" => nil,
169
- "regowner" => nil,
170
- "skunumber" => nil,
171
- "transforms" => nil,
172
- "urlinfoabout" => nil,
173
- "urlupdateinfo" => nil,
174
- "vendor" => "\"Chef Software, Inc. <maintainers@chef.io>\"",
175
- "version" => "0.7.0.1",
176
- "wordcount" => 2 }]
177
- end
107
+ let(:x86_64_reg_type) do
108
+ Win32::Registry::KEY_READ | 0x200
109
+ end
178
110
 
179
- before(:each) do
180
- allow(plugin).to receive(:collect_os).and_return(:windows)
181
- expect_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with("Win32_Product").and_return(win32_product_output)
182
- plugin.run
183
- end
111
+ let(:win_reg_output) do
112
+ [{ "DisplayName" => "NXLOG-CE",
113
+ "DisplayVersion" => "2.8.1248",
114
+ "Publisher" => "nxsec.com",
115
+ "InstallDate" => "20150511",
116
+ },
117
+ { "DisplayName" => "Chef Development Kit v0.7.0",
118
+ "DisplayVersion" => "0.7.0.1",
119
+ "Publisher" => "\"Chef Software, Inc. <maintainers@chef.io>\"",
120
+ "InstallDate" => "20150925" }]
121
+ end
184
122
 
123
+ shared_examples "windows_package_plugin" do
185
124
  it "gets package info" do
125
+ plugin.run
186
126
  expect(plugin[:packages]["Chef Development Kit v0.7.0"][:version]).to eq("0.7.0.1")
187
- expect(plugin[:packages]["Chef Development Kit v0.7.0"][:vendor]).to eq("\"Chef Software, Inc. <maintainers@chef.io>\"")
127
+ expect(plugin[:packages]["Chef Development Kit v0.7.0"][:publisher]).to eq("\"Chef Software, Inc. <maintainers@chef.io>\"")
188
128
  expect(plugin[:packages]["Chef Development Kit v0.7.0"][:installdate]).to eq("20150925")
189
129
 
190
130
  expect(plugin[:packages]["NXLOG-CE"][:version]).to eq("2.8.1248")
191
- expect(plugin[:packages]["NXLOG-CE"][:vendor]).to eq("nxsec.com")
131
+ expect(plugin[:packages]["NXLOG-CE"][:publisher]).to eq("nxsec.com")
192
132
  expect(plugin[:packages]["NXLOG-CE"][:installdate]).to eq("20150511")
193
133
  end
194
134
  end
195
135
 
196
- context "on aix" do
197
- let(:plugin) { get_plugin("packages") }
136
+ before(:each) do
137
+ allow(plugin).to receive(:collect_os).and_return(:windows)
138
+ allow(win_reg_double).to receive(:open).with(win_reg_keys[0]).and_return(win_reg_output[0])
139
+ allow(win_reg_double).to receive(:open).with(win_reg_keys[1]).and_return(win_reg_output[1])
140
+ allow(win_reg_double).to receive(:each_key).and_yield(win_reg_keys[0], 0).and_yield(win_reg_keys[1], 1)
141
+ end
198
142
 
199
- let(:stdout) do
200
- File.read(File.join(SPEC_PLUGIN_PATH, "lslpp.output"))
143
+ describe "on 32 bit ruby" do
144
+ before do
145
+ stub_const("::RbConfig::CONFIG", { "target_cpu" => "i386" } )
146
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Microsoft\Windows\CurrentVersion\Uninstall', i386_reg_type).and_yield(win_reg_double)
147
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall', i386_reg_type).and_yield(win_reg_double)
201
148
  end
149
+ it_behaves_like "windows_package_plugin"
150
+ end
202
151
 
203
- before(:each) do
204
- allow(plugin).to receive(:collect_os).and_return(:aix)
205
- allow(plugin).to receive(:shell_out).with("lslpp -L -q -c").and_return(mock_shell_out(0, stdout, ""))
206
- plugin.run
152
+ describe "on 64 bit ruby" do
153
+ before do
154
+ stub_const("::RbConfig::CONFIG", { "target_cpu" => "x86_64" } )
155
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Microsoft\Windows\CurrentVersion\Uninstall', x86_64_reg_type).and_yield(win_reg_double)
156
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall', x86_64_reg_type).and_yield(win_reg_double)
207
157
  end
158
+ it_behaves_like "windows_package_plugin"
159
+ end
208
160
 
209
- it "calls lslpp -L -q -c" do
210
- expect(plugin).to receive(:shell_out)
211
- .with("lslpp -L -q -c")
212
- .and_return(mock_shell_out(0, stdout, ""))
213
- plugin.run
161
+ describe "on unknown ruby" do
162
+ before do
163
+ stub_const("::RbConfig::CONFIG", { "target_cpu" => nil } )
164
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Microsoft\Windows\CurrentVersion\Uninstall', Win32::Registry::KEY_READ).and_yield(win_reg_double)
165
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall', Win32::Registry::KEY_READ).and_yield(win_reg_double)
214
166
  end
167
+ it_behaves_like "windows_package_plugin"
168
+ end
169
+ end
215
170
 
216
- it "gets packages with version" do
217
- expect(plugin[:packages]["chef"][:version]).to eq("12.5.1.1")
218
- end
171
+ context "on aix" do
172
+ let(:plugin) { get_plugin("packages") }
173
+
174
+ let(:stdout) do
175
+ File.read(File.join(SPEC_PLUGIN_PATH, "lslpp.output"))
219
176
  end
220
177
 
221
- context "on solaris2" do
222
- let(:plugin) { get_plugin("packages") }
178
+ before(:each) do
179
+ allow(plugin).to receive(:collect_os).and_return(:aix)
180
+ allow(plugin).to receive(:shell_out).with("lslpp -L -q -c").and_return(mock_shell_out(0, stdout, ""))
181
+ plugin.run
182
+ end
223
183
 
224
- let(:pkglist_output) do
225
- File.read(File.join(SPEC_PLUGIN_PATH, "pkglist.output"))
226
- end
184
+ it "calls lslpp -L -q -c" do
185
+ expect(plugin).to receive(:shell_out)
186
+ .with("lslpp -L -q -c")
187
+ .and_return(mock_shell_out(0, stdout, ""))
188
+ plugin.run
189
+ end
227
190
 
228
- let(:pkginfo_output) do
229
- File.read(File.join(SPEC_PLUGIN_PATH, "pkginfo.output"))
230
- end
191
+ it "gets packages with version" do
192
+ expect(plugin[:packages]["chef"][:version]).to eq("12.5.1.1")
193
+ end
194
+ end
231
195
 
232
- before(:each) do
233
- allow(plugin).to receive(:collect_os).and_return(:solaris2)
234
- allow(plugin).to receive(:shell_out).with("pkg list -H").and_return(mock_shell_out(0, pkglist_output, ""))
235
- allow(plugin).to receive(:shell_out).with("pkginfo -l").and_return(mock_shell_out(0, pkginfo_output, ""))
236
- plugin.run
237
- end
196
+ context "on solaris2" do
197
+ let(:plugin) { get_plugin("packages") }
238
198
 
239
- it "calls pkg list -H" do
240
- expect(plugin).to receive(:shell_out)
241
- .with("pkg list -H")
242
- .and_return(mock_shell_out(0, pkglist_output, ""))
243
- plugin.run
244
- end
199
+ let(:pkglist_output) do
200
+ File.read(File.join(SPEC_PLUGIN_PATH, "pkglist.output"))
201
+ end
245
202
 
246
- it "calls pkginfo -l" do
247
- expect(plugin).to receive(:shell_out)
248
- .with("pkginfo -l")
249
- .and_return(mock_shell_out(0, pkginfo_output, ""))
250
- plugin.run
251
- end
203
+ let(:pkginfo_output) do
204
+ File.read(File.join(SPEC_PLUGIN_PATH, "pkginfo.output"))
205
+ end
252
206
 
253
- it "gets ips packages with version" do
254
- expect(plugin[:packages]["chef"][:version]).to eq("12.5.1")
255
- end
207
+ before(:each) do
208
+ allow(plugin).to receive(:collect_os).and_return(:solaris2)
209
+ allow(plugin).to receive(:shell_out).with("pkg list -H").and_return(mock_shell_out(0, pkglist_output, ""))
210
+ allow(plugin).to receive(:shell_out).with("pkginfo -l").and_return(mock_shell_out(0, pkginfo_output, ""))
211
+ plugin.run
212
+ end
256
213
 
257
- it "gets ips packages with version and publisher" do
258
- expect(plugin[:packages]["system/EMCpower"][:version]).to eq("6.0.0.1.0-3")
259
- expect(plugin[:packages]["system/EMCpower"][:publisher]).to eq("emc.com")
260
- end
214
+ it "calls pkg list -H" do
215
+ expect(plugin).to receive(:shell_out)
216
+ .with("pkg list -H")
217
+ .and_return(mock_shell_out(0, pkglist_output, ""))
218
+ plugin.run
219
+ end
261
220
 
262
- it "gets sysv packages with version" do
263
- expect(plugin[:packages]["chef"][:version]).to eq("12.5.1")
264
- end
221
+ it "calls pkginfo -l" do
222
+ expect(plugin).to receive(:shell_out)
223
+ .with("pkginfo -l")
224
+ .and_return(mock_shell_out(0, pkginfo_output, ""))
225
+ plugin.run
226
+ end
265
227
 
266
- it "gets sysv packages with version" do
267
- expect(plugin[:packages]["mqm"][:version]).to eq("7.0.1.4")
268
- end
228
+ it "gets ips packages with version" do
229
+ expect(plugin[:packages]["chef"][:version]).to eq("12.5.1")
230
+ end
231
+
232
+ it "gets ips packages with version and publisher" do
233
+ expect(plugin[:packages]["system/EMCpower"][:version]).to eq("6.0.0.1.0-3")
234
+ expect(plugin[:packages]["system/EMCpower"][:publisher]).to eq("emc.com")
235
+ end
236
+
237
+ it "gets sysv packages with version" do
238
+ expect(plugin[:packages]["chef"][:version]).to eq("12.5.1")
239
+ end
240
+
241
+ it "gets sysv packages with version" do
242
+ expect(plugin[:packages]["mqm"][:version]).to eq("7.0.1.4")
269
243
  end
270
244
  end
271
245
  end
@@ -20,110 +20,118 @@ require "resolv"
20
20
  require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
21
21
 
22
22
  describe Ohai::System, "plugin rackspace" do
23
+ let(:plugin) { get_plugin("rackspace") }
24
+
23
25
  before(:each) do
24
26
  allow(Resolv).to receive(:getname).and_return("1.2.3.4")
25
- @plugin = get_plugin("rackspace")
26
- @plugin[:hostname] = "katie"
27
- @plugin[:network] = { :interfaces => { :eth0 => { "addresses" => {
28
- "1.2.3.4" => {
29
- "broadcast" => "67.23.20.255",
30
- "netmask" => "255.255.255.0",
31
- "family" => "inet",
32
- },
33
- "2a00:1a48:7805:111:e875:efaf:ff08:75" => {
34
- "family" => "inet6",
35
- "prefixlen" => "64",
36
- "scope" => "Global",
37
- },
38
- "fe80::4240:95ff:fe47:6eed" => {
39
- "scope" => "Link",
40
- "prefixlen" => "64",
41
- "family" => "inet6",
42
- },
43
- "40:40:95:47:6E:ED" => {
44
- "family" => "lladdr"
27
+
28
+ plugin[:hostname] = "katie"
29
+
30
+ plugin[:network] = {
31
+ :interfaces => {
32
+ :eth0 => {
33
+ "addresses" => {
34
+ "1.2.3.4" => {
35
+ "broadcast" => "67.23.20.255",
36
+ "netmask" => "255.255.255.0",
37
+ "family" => "inet",
38
+ },
39
+ "2a00:1a48:7805:111:e875:efaf:ff08:75" => {
40
+ "family" => "inet6",
41
+ "prefixlen" => "64",
42
+ "scope" => "Global",
43
+ },
44
+ "fe80::4240:95ff:fe47:6eed" => {
45
+ "scope" => "Link",
46
+ "prefixlen" => "64",
47
+ "family" => "inet6",
48
+ },
49
+ "40:40:95:47:6E:ED" => {
50
+ "family" => "lladdr",
51
+ },
52
+ },
53
+ },
45
54
  },
46
- } }
47
55
  }
48
- }
49
56
 
50
- @plugin[:network][:interfaces][:eth1] = { :addresses => {
51
- "fe80::4240:f5ff:feab:2836" => {
52
- "scope" => "Link",
53
- "prefixlen" => "64",
54
- "family" => "inet6",
55
- },
56
- "5.6.7.8" => {
57
- "broadcast" => "10.176.191.255",
58
- "netmask" => "255.255.224.0",
59
- "family" => "inet",
60
- },
61
- "40:40:F5:AB:28:36" => {
62
- "family" => "lladdr"
57
+ plugin[:network][:interfaces][:eth1] = {
58
+ :addresses => {
59
+ "fe80::4240:f5ff:feab:2836" => {
60
+ "scope" => "Link",
61
+ "prefixlen" => "64",
62
+ "family" => "inet6",
63
+ },
64
+ "5.6.7.8" => {
65
+ "broadcast" => "10.176.191.255",
66
+ "netmask" => "255.255.224.0",
67
+ "family" => "inet",
68
+ },
69
+ "40:40:F5:AB:28:36" => {
70
+ "family" => "lladdr",
71
+ },
63
72
  },
64
- } }
73
+ }
65
74
 
66
75
  # In olden days we could detect rackspace by a -rscloud suffix on the kernel
67
76
  # This is here to make #has_rackspace_kernel? fail until we remove that check
68
- @plugin[:kernel] = { :release => "1.2.13-not-rackspace" }
77
+ plugin[:kernel] = { :release => "1.2.13-not-rackspace" }
69
78
 
70
79
  # We need a generic stub here for the later stubs with arguments to work
71
80
  # Because, magic.
72
- allow(@plugin).to receive(:shell_out).and_return(mock_shell_out(1, "", ""))
81
+ allow(plugin).to receive(:shell_out).and_return(mock_shell_out(1, "", ""))
73
82
  end
74
83
 
75
84
  shared_examples_for "!rackspace" do
76
- it "should NOT create rackspace" do
77
- @plugin.run
78
- expect(@plugin[:rackspace]).to be_nil
85
+ it "does not create rackspace" do
86
+ plugin.run
87
+ expect(plugin[:rackspace]).to be_nil
79
88
  end
80
89
  end
81
90
 
82
91
  shared_examples_for "rackspace" do
83
-
84
- it "should create rackspace" do
85
- @plugin.run
86
- expect(@plugin[:rackspace]).not_to be_nil
92
+ it "creates rackspace" do
93
+ plugin.run
94
+ expect(plugin[:rackspace]).not_to be_nil
87
95
  end
88
96
 
89
- it "should have all required attributes" do
90
- @plugin.run
91
- expect(@plugin[:rackspace][:public_ip]).not_to be_nil
92
- expect(@plugin[:rackspace][:private_ip]).not_to be_nil
93
- expect(@plugin[:rackspace][:public_ipv4]).not_to be_nil
94
- expect(@plugin[:rackspace][:local_ipv4]).not_to be_nil
95
- expect(@plugin[:rackspace][:public_ipv6]).not_to be_nil
96
- expect(@plugin[:rackspace][:local_ipv6]).to be_nil
97
- expect(@plugin[:rackspace][:local_hostname]).not_to be_nil
98
- expect(@plugin[:rackspace][:public_hostname]).not_to be_nil
97
+ it "has all required attributes" do
98
+ plugin.run
99
+ expect(plugin[:rackspace][:public_ip]).not_to be_nil
100
+ expect(plugin[:rackspace][:private_ip]).not_to be_nil
101
+ expect(plugin[:rackspace][:public_ipv4]).not_to be_nil
102
+ expect(plugin[:rackspace][:local_ipv4]).not_to be_nil
103
+ expect(plugin[:rackspace][:public_ipv6]).not_to be_nil
104
+ expect(plugin[:rackspace][:local_ipv6]).to be_nil
105
+ expect(plugin[:rackspace][:local_hostname]).not_to be_nil
106
+ expect(plugin[:rackspace][:public_hostname]).not_to be_nil
99
107
  end
100
108
 
101
- it "should resolve hostname if reverse dns is set" do
109
+ it "resolves hostname if reverse dns is set" do
102
110
  allow(Resolv).to receive(:getname).and_return("1234.resolved.com")
103
- @plugin.run
104
- expect(@plugin[:rackspace][:public_hostname]).to eq("1234.resolved.com")
111
+ plugin.run
112
+ expect(plugin[:rackspace][:public_hostname]).to eq("1234.resolved.com")
105
113
  end
106
114
 
107
115
  [Resolv::ResolvError, Resolv::ResolvTimeout].each do |exception|
108
- it "should return ip address when reverse dns returns exception: #{exception}" do
116
+ it "returns ip address when reverse dns returns exception: #{exception}" do
109
117
  allow(Resolv).to receive(:getname).and_raise(exception)
110
- @plugin.run
111
- expect(@plugin[:rackspace][:public_hostname]).to eq("1.2.3.4")
118
+ plugin.run
119
+ expect(plugin[:rackspace][:public_hostname]).to eq("1.2.3.4")
112
120
  end
113
121
  end
114
122
 
115
- it "should have correct values for all attributes" do
116
- @plugin.run
117
- expect(@plugin[:rackspace][:public_ip]).to eq("1.2.3.4")
118
- expect(@plugin[:rackspace][:private_ip]).to eq("5.6.7.8")
119
- expect(@plugin[:rackspace][:public_ipv4]).to eq("1.2.3.4")
120
- expect(@plugin[:rackspace][:local_ipv4]).to eq("5.6.7.8")
121
- expect(@plugin[:rackspace][:public_ipv6]).to eq("2a00:1a48:7805:111:e875:efaf:ff08:75")
122
- expect(@plugin[:rackspace][:local_hostname]).to eq("katie")
123
- expect(@plugin[:rackspace][:public_hostname]).to eq("1.2.3.4")
123
+ it "has correct values for all attributes" do
124
+ plugin.run
125
+ expect(plugin[:rackspace][:public_ip]).to eq("1.2.3.4")
126
+ expect(plugin[:rackspace][:private_ip]).to eq("5.6.7.8")
127
+ expect(plugin[:rackspace][:public_ipv4]).to eq("1.2.3.4")
128
+ expect(plugin[:rackspace][:local_ipv4]).to eq("5.6.7.8")
129
+ expect(plugin[:rackspace][:public_ipv6]).to eq("2a00:1a48:7805:111:e875:efaf:ff08:75")
130
+ expect(plugin[:rackspace][:local_hostname]).to eq("katie")
131
+ expect(plugin[:rackspace][:public_hostname]).to eq("1.2.3.4")
124
132
  end
125
133
 
126
- it "should capture region information" do
134
+ it "captures region information" do
127
135
  provider_data = <<-OUT
128
136
  provider = "Rackspace"
129
137
  service_type = "cloudServers"
@@ -131,21 +139,53 @@ server_id = "21301000"
131
139
  created_at = "2012-12-06T22:08:16Z"
132
140
  region = "dfw"
133
141
  OUT
134
- allow(@plugin).to receive(:shell_out).with("xenstore-ls vm-data/provider_data").and_return(mock_shell_out(0, provider_data, ""))
135
- @plugin.run
136
- expect(@plugin[:rackspace][:region]).to eq("dfw")
142
+ allow(plugin).to receive(:shell_out).with("xenstore-ls vm-data/provider_data").and_return(mock_shell_out(0, provider_data, ""))
143
+ plugin.run
144
+ expect(plugin[:rackspace][:region]).to eq("dfw")
145
+ end
146
+
147
+ it "logs a debug message when region info cannot be collected" do
148
+ expect(plugin).
149
+ to receive(:shell_out).
150
+ with("xenstore-ls vm-data/provider_data").
151
+ and_raise(Ohai::Exceptions::Exec)
152
+
153
+ expect(Ohai::Log).
154
+ to receive(:debug).
155
+ with("rackspace plugin: Unable to find xenstore-ls, cannot capture " \
156
+ "region information for Rackspace cloud")
157
+
158
+ plugin.run
159
+
160
+ expect(plugin[:rackspace]).not_to have_key(:region)
137
161
  end
138
162
 
139
- it "should capture instance ID information" do
163
+ it "captures instance ID information" do
140
164
  provider_data = "instance-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
141
- allow(@plugin).to receive(:shell_out).with("xenstore-read name").and_return(mock_shell_out(0, provider_data, ""))
142
- @plugin.run
143
- expect(@plugin[:rackspace][:instance_id]).to eq("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
165
+ allow(plugin).to receive(:shell_out).with("xenstore-read name").and_return(mock_shell_out(0, provider_data, ""))
166
+ plugin.run
167
+ expect(plugin[:rackspace][:instance_id]).to eq("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
168
+ end
169
+
170
+ it "logs error if instance id cannot be found" do
171
+ expect(plugin).
172
+ to receive(:shell_out).
173
+ with("xenstore-read name").
174
+ and_raise(Ohai::Exceptions::Exec)
175
+
176
+ expect(Ohai::Log).
177
+ to receive(:debug).
178
+ with("rackspace plugin: Unable to find xenstore-read, cannot capture " \
179
+ "instance ID information for Rackspace cloud")
180
+
181
+ plugin.run
182
+
183
+ expect(plugin[:rackspace]).not_to have_key(:instance_id)
144
184
  end
145
185
  end
146
186
 
147
187
  describe "with rackspace cloud file" do
148
- it_should_behave_like "rackspace"
188
+ it_behaves_like "rackspace"
149
189
 
150
190
  before(:each) do
151
191
  allow(Resolv).to receive(:getname).and_raise(Resolv::ResolvError)
@@ -160,34 +200,34 @@ OUT
160
200
  describe "with no public interfaces (empty eth0)" do
161
201
  before do
162
202
  # unset public (eth0) addresses
163
- @plugin[:network][:interfaces][:eth0]["addresses"] = {}
203
+ plugin[:network][:interfaces][:eth0]["addresses"] = {}
164
204
  end
165
205
 
166
- it "should have all required attributes" do
167
- @plugin.run
206
+ it "has all required attributes" do
207
+ plugin.run
168
208
  # expliticly nil
169
- expect(@plugin[:rackspace][:public_ip]).to be_nil
170
- expect(@plugin[:rackspace][:public_ipv4]).to be_nil
171
- expect(@plugin[:rackspace][:public_ipv6]).to be_nil
172
- expect(@plugin[:rackspace][:public_hostname]).to be_nil
209
+ expect(plugin[:rackspace][:public_ip]).to be_nil
210
+ expect(plugin[:rackspace][:public_ipv4]).to be_nil
211
+ expect(plugin[:rackspace][:public_ipv6]).to be_nil
212
+ expect(plugin[:rackspace][:public_hostname]).to be_nil
173
213
  # per normal
174
- expect(@plugin[:rackspace][:private_ip]).not_to be_nil
175
- expect(@plugin[:rackspace][:local_ipv4]).not_to be_nil
176
- expect(@plugin[:rackspace][:local_ipv6]).to be_nil
177
- expect(@plugin[:rackspace][:local_hostname]).not_to be_nil
214
+ expect(plugin[:rackspace][:private_ip]).not_to be_nil
215
+ expect(plugin[:rackspace][:local_ipv4]).not_to be_nil
216
+ expect(plugin[:rackspace][:local_ipv6]).to be_nil
217
+ expect(plugin[:rackspace][:local_hostname]).not_to be_nil
178
218
  end
179
219
 
180
- it "should have correct values for all attributes" do
181
- @plugin.run
182
- expect(@plugin[:rackspace][:private_ip]).to eq("5.6.7.8")
183
- expect(@plugin[:rackspace][:local_ipv4]).to eq("5.6.7.8")
184
- expect(@plugin[:rackspace][:local_hostname]).to eq("katie")
220
+ it "has correct values for all attributes" do
221
+ plugin.run
222
+ expect(plugin[:rackspace][:private_ip]).to eq("5.6.7.8")
223
+ expect(plugin[:rackspace][:local_ipv4]).to eq("5.6.7.8")
224
+ expect(plugin[:rackspace][:local_hostname]).to eq("katie")
185
225
  end
186
226
  end
187
227
  end
188
228
 
189
229
  describe "without cloud file" do
190
- it_should_behave_like "!rackspace"
230
+ it_behaves_like "!rackspace"
191
231
 
192
232
  before(:each) do
193
233
  allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/rackspace.json").and_return(false)
@@ -196,7 +236,7 @@ OUT
196
236
  end
197
237
 
198
238
  describe "with ec2 cloud file" do
199
- it_should_behave_like "!rackspace"
239
+ it_behaves_like "!rackspace"
200
240
 
201
241
  before(:each) do
202
242
  allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/ec2.json").and_return(true)
@@ -210,29 +250,60 @@ OUT
210
250
  end
211
251
 
212
252
  describe "xenstore provider returns rackspace" do
213
- it_should_behave_like "rackspace"
253
+ it_behaves_like "rackspace"
214
254
 
215
255
  before(:each) do
216
256
  stdout = "Rackspace\n"
217
- allow(@plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
257
+ allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
218
258
  end
219
259
  end
220
260
 
221
261
  describe "xenstore provider does not return rackspace" do
222
- it_should_behave_like "!rackspace"
262
+ it_behaves_like "!rackspace"
223
263
 
224
264
  before(:each) do
225
265
  stdout = "cumulonimbus\n"
226
- allow(@plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
266
+ allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
267
+ end
268
+ end
269
+
270
+ describe "xenstore provider does not exist" do
271
+ it_behaves_like "!rackspace"
272
+
273
+ before(:each) do
274
+ allow(plugin).
275
+ to receive(:shell_out).
276
+ with("xenstore-read vm-data/provider_data/provider").
277
+ and_raise(Ohai::Exceptions::Exec)
278
+ end
279
+ end
280
+
281
+ describe "when private networks shell out fails" do
282
+ it "logs an error and does not collect private_networks" do
283
+ allow(plugin).to receive(:hint?).with("rackspace").and_return(true)
284
+
285
+ expect(plugin).
286
+ to receive(:shell_out).
287
+ with("xenstore-ls vm-data/networking").
288
+ and_raise(Ohai::Exceptions::Exec)
289
+
290
+ expect(Ohai::Log).
291
+ to receive(:debug).
292
+ with("rackspace plugin: Unable to capture custom private networking " \
293
+ "information for Rackspace cloud")
294
+
295
+ plugin.run
296
+
297
+ expect(plugin[:rackspace]).not_to have_key(:private_networks)
227
298
  end
228
299
  end
229
300
 
230
301
  describe "does not have private networks" do
231
302
  before do
232
303
  stdout = 'BC764E20422B = "{"label": "public"}"\n'
233
- allow(@plugin).to receive(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
304
+ allow(plugin).to receive(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
234
305
  stdout = '{"label": "public", "broadcast": "9.10.11.255", "ips": [{"ip": "9.10.11.12", "netmask": "255.255.255.0", "enabled": "1", "gateway": null}], "mac": "BC:76:4E:20:42:2B", "dns": ["69.20.0.164", "69.20.0.196"], "gateway": null}'
235
- allow(@plugin).to receive(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
306
+ allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
236
307
 
237
308
  allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/rackspace.json").and_return(true)
238
309
  allow(File).to receive(:read).with("/etc/chef/ohai/hints/rackspace.json").and_return("")
@@ -240,33 +311,35 @@ OUT
240
311
  allow(File).to receive(:read).with('C:\chef\ohai\hints/rackspace.json').and_return("")
241
312
  end
242
313
 
243
- it "should not have private_networks object" do
244
- @plugin.run
245
- expect(@plugin[:rackspace][:private_networks]).to eq([])
314
+ it "does not have private_networks object" do
315
+ plugin.run
316
+ expect(plugin[:rackspace][:private_networks]).to eq([])
246
317
  end
247
318
  end
248
319
 
249
320
  describe "has private networks" do
250
321
  before do
251
- @plugin[:network][:interfaces][:eth2] = { :addresses => {
252
- "fe80::be76:4eff:fe20:422b" => {
253
- "scope" => "Link",
254
- "prefixlen" => "64",
255
- "family" => "inet6",
256
- },
257
- "9.10.11.12" => {
258
- "broadcast" => "9.10.11.255",
259
- "netmask" => "255.255.255.0",
260
- "family" => "inet",
261
- },
262
- "BC:76:4E:20:42:2B" => {
263
- "family" => "lladdr"
322
+ plugin[:network][:interfaces][:eth2] = {
323
+ :addresses => {
324
+ "fe80::be76:4eff:fe20:422b" => {
325
+ "scope" => "Link",
326
+ "prefixlen" => "64",
327
+ "family" => "inet6",
328
+ },
329
+ "9.10.11.12" => {
330
+ "broadcast" => "9.10.11.255",
331
+ "netmask" => "255.255.255.0",
332
+ "family" => "inet",
333
+ },
334
+ "BC:76:4E:20:42:2B" => {
335
+ "family" => "lladdr",
336
+ },
264
337
  },
265
- } }
338
+ }
266
339
  stdout = 'BC764E20422B = "{"label": "private-network"}"\n'
267
- allow(@plugin).to receive(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
340
+ allow(plugin).to receive(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
268
341
  stdout = '{"label": "private-network", "broadcast": "9.10.11.255", "ips": [{"ip": "9.10.11.12", "netmask": "255.255.255.0", "enabled": "1", "gateway": null}], "mac": "BC:76:4E:20:42:2B", "dns": ["69.20.0.164", "69.20.0.196"], "gateway": null}'
269
- allow(@plugin).to receive(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
342
+ allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
270
343
 
271
344
  allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/rackspace.json").and_return(true)
272
345
  allow(File).to receive(:read).with("/etc/chef/ohai/hints/rackspace.json").and_return("")
@@ -274,16 +347,16 @@ OUT
274
347
  allow(File).to receive(:read).with('C:\chef\ohai\hints/rackspace.json').and_return("")
275
348
  end
276
349
 
277
- it "should private_networks object" do
278
- @plugin.run
279
- expect(@plugin[:rackspace][:private_networks]).not_to be_nil
350
+ it "has private_networks object" do
351
+ plugin.run
352
+ expect(plugin[:rackspace][:private_networks]).not_to be_nil
280
353
  end
281
354
 
282
- it "should have correct values for all attributes" do
283
- @plugin.run
284
- expect(@plugin[:rackspace][:private_networks][0][:label]).to eq("private-network")
285
- expect(@plugin[:rackspace][:private_networks][0][:broadcast]).to eq("9.10.11.255")
286
- expect(@plugin[:rackspace][:private_networks][0][:mac]).to eq("BC:76:4E:20:42:2B")
355
+ it "has correct values for all attributes" do
356
+ plugin.run
357
+ expect(plugin[:rackspace][:private_networks][0][:label]).to eq("private-network")
358
+ expect(plugin[:rackspace][:private_networks][0][:broadcast]).to eq("9.10.11.255")
359
+ expect(plugin[:rackspace][:private_networks][0][:mac]).to eq("BC:76:4E:20:42:2B")
287
360
  end
288
361
 
289
362
  end