ohai 8.14.0 → 8.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -153,17 +153,17 @@ describe Ohai::System, "plugin c" do
153
153
  end
154
154
 
155
155
  #glibc
156
- it "gets the glibc x.x.x version from running /lib/libc.so.6" do
156
+ it "gets the glibc x.x.x version from running /lib/libc.so.6", :unix_only do
157
157
  expect(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_3_4, ""))
158
158
  plugin.run
159
159
  end
160
160
 
161
- it "sets languages[:c][:glibc][:version]" do
161
+ it "sets languages[:c][:glibc][:version]", :unix_only do
162
162
  plugin.run
163
163
  expect(plugin.languages[:c][:glibc][:version]).to eql("2.3.4")
164
164
  end
165
165
 
166
- it "sets languages[:c][:glibc][:description]" do
166
+ it "sets languages[:c][:glibc][:description]", :unix_only do
167
167
  plugin.run
168
168
  expect(plugin.languages[:c][:glibc][:description]).to eql(C_GLIBC_2_3_4.split($/).first)
169
169
  end
@@ -183,7 +183,7 @@ describe Ohai::System, "plugin c" do
183
183
  expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
184
184
  end
185
185
 
186
- it "gets the glibc x.x version from running /lib/libc.so.6" do
186
+ it "gets the glibc x.x version from running /lib/libc.so.6", :unix_only do
187
187
  allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_5, ""))
188
188
  expect(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_5, ""))
189
189
  plugin.run
@@ -19,26 +19,24 @@ require "ipaddress"
19
19
  require "spec_helper"
20
20
 
21
21
  describe Ohai::System, "plugin digital_ocean" do
22
- let(:hint_path_nix) { "/etc/chef/ohai/hints/digital_ocean.json" }
23
- let(:hint_path_win) { 'C:\chef\ohai\hints/digital_ocean.json' }
22
+ let(:plugin) { get_plugin("digital_ocean") }
24
23
  let(:digitalocean_path) { "/etc/digitalocean" }
25
24
  let(:hint) {
26
- '{
27
- "droplet_id": 12345678,
28
- "name": "example.com",
29
- "image_id": 3240036,
30
- "size_id": 66,
31
- "region_id": 4,
32
- "ip_addresses": {
33
- "public": "1.2.3.4",
34
- "private": "5.6.7.8"
35
- }
36
- }'
25
+ {
26
+ "droplet_id" => 12345678,
27
+ "name" => "example.com",
28
+ "image_id" => 3240036,
29
+ "size_id" => 66,
30
+ "region_id" => 4,
31
+ "ip_addresses" => {
32
+ "public" => "1.2.3.4",
33
+ "private" => "5.6.7.8",
34
+ },
35
+ }
37
36
  }
38
37
 
39
38
  before do
40
- @plugin = get_plugin("digital_ocean")
41
- @plugin[:network] = {
39
+ plugin[:network] = {
42
40
  "interfaces" => {
43
41
  "eth0" => {
44
42
  "addresses" => {
@@ -54,64 +52,61 @@ describe Ohai::System, "plugin digital_ocean" do
54
52
  },
55
53
  }
56
54
 
57
- allow(File).to receive(:exist?).with(hint_path_nix).and_return(true)
58
- allow(File).to receive(:read).with(hint_path_nix).and_return(hint)
59
- allow(File).to receive(:exist?).with(hint_path_win).and_return(true)
60
- allow(File).to receive(:read).with(hint_path_win).and_return(hint)
55
+ allow(plugin).to receive(:hint?).with("digital_ocean").and_return(hint)
61
56
  end
62
57
 
63
58
  shared_examples_for "!digital_ocean" do
64
59
  before(:each) do
65
- @plugin.run
60
+ plugin.run
66
61
  end
67
62
 
68
63
  it "does not create the digital_ocean mash" do
69
- expect(@plugin[:digital_ocean]).to be_nil
64
+ expect(plugin[:digital_ocean]).to be_nil
70
65
  end
71
66
  end
72
67
 
73
68
  shared_examples_for "digital_ocean_networking" do
74
69
  it "creates the networks attribute" do
75
- expect(@plugin[:digital_ocean][:networks]).not_to be_nil
70
+ expect(plugin[:digital_ocean][:networks]).not_to be_nil
76
71
  end
77
72
 
78
73
  it "pulls ip addresses from the network interfaces" do
79
- expect(@plugin[:digital_ocean][:networks][:v4]).to eq([{ "ip_address" => "1.2.3.4",
80
- "type" => "public",
81
- "netmask" => "255.255.255.0" }])
82
- expect(@plugin[:digital_ocean][:networks][:v6]).to eq([{ "ip_address" => "2400:6180:0000:00d0:0000:0000:0009:7001",
83
- "type" => "public",
84
- "cidr" => 128 }])
74
+ expect(plugin[:digital_ocean][:networks][:v4]).to eq([{ "ip_address" => "1.2.3.4",
75
+ "type" => "public",
76
+ "netmask" => "255.255.255.0" }])
77
+ expect(plugin[:digital_ocean][:networks][:v6]).to eq([{ "ip_address" => "2400:6180:0000:00d0:0000:0000:0009:7001",
78
+ "type" => "public",
79
+ "cidr" => 128 }])
85
80
  end
86
81
  end
87
82
 
88
83
  shared_examples_for "digital_ocean" do
89
84
  before(:each) do
90
- @plugin.run
85
+ plugin.run
91
86
  end
92
87
 
93
88
  it "creates a digital_ocean mash" do
94
- expect(@plugin[:digital_ocean]).not_to be_nil
89
+ expect(plugin[:digital_ocean]).not_to be_nil
95
90
  end
96
91
 
97
92
  it "has all hint attributes" do
98
- expect(@plugin[:digital_ocean][:droplet_id]).not_to be_nil
99
- expect(@plugin[:digital_ocean][:name]).not_to be_nil
100
- expect(@plugin[:digital_ocean][:image_id]).not_to be_nil
101
- expect(@plugin[:digital_ocean][:size_id]).not_to be_nil
102
- expect(@plugin[:digital_ocean][:region_id]).not_to be_nil
93
+ expect(plugin[:digital_ocean][:droplet_id]).not_to be_nil
94
+ expect(plugin[:digital_ocean][:name]).not_to be_nil
95
+ expect(plugin[:digital_ocean][:image_id]).not_to be_nil
96
+ expect(plugin[:digital_ocean][:size_id]).not_to be_nil
97
+ expect(plugin[:digital_ocean][:region_id]).not_to be_nil
103
98
  end
104
99
 
105
100
  it "skips the ip_addresses hint attribute" do
106
- expect(@plugin[:digital_ocean][:ip_addresses]).to be_nil
101
+ expect(plugin[:digital_ocean][:ip_addresses]).to be_nil
107
102
  end
108
103
 
109
104
  it "has correct values for all hint attributes" do
110
- expect(@plugin[:digital_ocean][:droplet_id]).to eq(12345678)
111
- expect(@plugin[:digital_ocean][:name]).to eq("example.com")
112
- expect(@plugin[:digital_ocean][:image_id]).to eq(3240036)
113
- expect(@plugin[:digital_ocean][:size_id]).to eq(66)
114
- expect(@plugin[:digital_ocean][:region_id]).to eq(4)
105
+ expect(plugin[:digital_ocean][:droplet_id]).to eq(12345678)
106
+ expect(plugin[:digital_ocean][:name]).to eq("example.com")
107
+ expect(plugin[:digital_ocean][:image_id]).to eq(3240036)
108
+ expect(plugin[:digital_ocean][:size_id]).to eq(66)
109
+ expect(plugin[:digital_ocean][:region_id]).to eq(4)
115
110
  end
116
111
 
117
112
  include_examples "digital_ocean_networking"
@@ -119,17 +114,16 @@ describe Ohai::System, "plugin digital_ocean" do
119
114
 
120
115
  describe "with digital_ocean hint file" do
121
116
  before do
122
- allow(File).to receive(:exist?).with(hint_path_nix).and_return(true)
123
- allow(File).to receive(:exist?).with(hint_path_win).and_return(true)
117
+ allow(plugin).to receive(:hint?).with("digital_ocean").and_return(hint)
124
118
  end
125
119
 
126
120
  context "without private networking enabled" do
127
- it_should_behave_like "digital_ocean"
121
+ it_behaves_like "digital_ocean"
128
122
  end
129
123
 
130
124
  context "with private networking enabled" do
131
125
  before do
132
- @plugin[:network][:interfaces][:eth1] = {
126
+ plugin[:network][:interfaces][:eth1] = {
133
127
  "addresses" => {
134
128
  "10.128.142.89" => {
135
129
  "netmask" => "255.255.255.0",
@@ -138,19 +132,19 @@ describe Ohai::System, "plugin digital_ocean" do
138
132
  },
139
133
  }
140
134
 
141
- @plugin.run
135
+ plugin.run
142
136
  end
143
137
 
144
- it "should extract the private networking ips" do
145
- expect(@plugin[:digital_ocean][:networks][:v4]).to eq([{ "ip_address" => "1.2.3.4",
146
- "type" => "public",
147
- "netmask" => "255.255.255.0" },
138
+ it "extracts the private networking ips" do
139
+ expect(plugin[:digital_ocean][:networks][:v4]).to eq([{ "ip_address" => "1.2.3.4",
140
+ "type" => "public",
141
+ "netmask" => "255.255.255.0" },
148
142
  { "ip_address" => "10.128.142.89",
149
143
  "type" => "private",
150
144
  "netmask" => "255.255.255.0" }])
151
- expect(@plugin[:digital_ocean][:networks][:v6]).to eq([{ "ip_address" => "2400:6180:0000:00d0:0000:0000:0009:7001",
152
- "type" => "public",
153
- "cidr" => 128 },
145
+ expect(plugin[:digital_ocean][:networks][:v6]).to eq([{ "ip_address" => "2400:6180:0000:00d0:0000:0000:0009:7001",
146
+ "type" => "public",
147
+ "cidr" => 128 },
154
148
  { "ip_address" => "fdf8:f53b:82e4:0000:0000:0000:0000:0053",
155
149
  "type" => "private",
156
150
  "cidr" => 128 }])
@@ -160,53 +154,22 @@ describe Ohai::System, "plugin digital_ocean" do
160
154
 
161
155
  describe "without digital_ocean hint file" do
162
156
  before do
163
- allow(File).to receive(:exist?).with(hint_path_nix).and_return(false)
164
- allow(File).to receive(:exist?).with(hint_path_win).and_return(false)
165
- end
166
-
167
- describe "with the /etc/digitalocean file" do
168
- before do
169
- allow(File).to receive(:exist?).with(digitalocean_path).and_return(true)
170
- @plugin.run
171
- end
172
- it_should_behave_like "digital_ocean_networking"
173
- end
174
-
175
- describe "without the /etc/digitalocean file" do
176
- before do
177
- allow(File).to receive(:exist?).with(digitalocean_path).and_return(false)
178
- end
179
- it_should_behave_like "!digital_ocean"
180
- end
181
- end
182
-
183
- context "with ec2 hint file" do
184
- let(:ec2_hint_path_nix) { "/etc/chef/ohai/hints/ec2.json" }
185
- let(:ec2_hint_path_win) { 'C:\chef\ohai\hints/ec2.json' }
186
-
187
- before do
188
- allow(File).to receive(:exist?).with(hint_path_nix).and_return(false)
189
- allow(File).to receive(:exist?).with(hint_path_win).and_return(false)
190
-
191
- allow(File).to receive(:exist?).with(ec2_hint_path_nix).and_return(true)
192
- allow(File).to receive(:read).with(ec2_hint_path_nix).and_return("")
193
- allow(File).to receive(:exist?).with(ec2_hint_path_win).and_return(true)
194
- allow(File).to receive(:read).with(ec2_hint_path_win).and_return("")
157
+ allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false)
195
158
  end
196
159
 
197
160
  describe "with the /etc/digitalocean file" do
198
161
  before do
199
162
  allow(File).to receive(:exist?).with(digitalocean_path).and_return(true)
200
- @plugin.run
163
+ plugin.run
201
164
  end
202
- it_should_behave_like "digital_ocean_networking"
165
+ it_behaves_like "digital_ocean_networking"
203
166
  end
204
167
 
205
168
  describe "without the /etc/digitalocean file" do
206
169
  before do
207
170
  allow(File).to receive(:exist?).with(digitalocean_path).and_return(false)
208
171
  end
209
- it_should_behave_like "!digital_ocean"
172
+ it_behaves_like "!digital_ocean"
210
173
  end
211
174
  end
212
175
  end
@@ -24,8 +24,7 @@ require "base64"
24
24
  describe Ohai::System, "plugin ec2" do
25
25
 
26
26
  before(:each) do
27
- allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/ec2.json").and_return(false)
28
- allow(File).to receive(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
27
+ allow(plugin).to receive(:hint?).with("ec2").and_return(false)
29
28
  allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(false)
30
29
  end
31
30
 
@@ -132,13 +131,7 @@ describe Ohai::System, "plugin ec2" do
132
131
 
133
132
  context "with ec2_iam hint file" do
134
133
  before do
135
- if windows?
136
- allow(File).to receive(:exist?).with('C:\chef\ohai\hints/iam.json').and_return(true)
137
- allow(File).to receive(:read).with('C:\chef\ohai\hints/iam.json').and_return("")
138
- else
139
- allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/iam.json").and_return(true)
140
- allow(File).to receive(:read).with("/etc/chef/ohai/hints/iam.json").and_return("")
141
- end
134
+ allow(plugin).to receive(:hint?).with("iam").and_return(true)
142
135
  end
143
136
 
144
137
  it "parses ec2 iam/ directory and collect iam/security-credentials/" do
@@ -168,11 +161,7 @@ describe Ohai::System, "plugin ec2" do
168
161
 
169
162
  context "without ec2_iam hint file" do
170
163
  before do
171
- if windows?
172
- allow(File).to receive(:exist?).with('C:\chef\ohai\hints/iam.json').and_return(false)
173
- else
174
- allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/iam.json").and_return(false)
175
- end
164
+ allow(plugin).to receive(:hint?).with("iam").and_return(false)
176
165
  end
177
166
 
178
167
  it "parses ec2 iam/ directory and NOT collect iam/security-credentials/" do
@@ -296,33 +285,14 @@ describe Ohai::System, "plugin ec2" do
296
285
  it_behaves_like "ec2"
297
286
 
298
287
  before(:each) do
299
- if windows?
300
- expect(File).to receive(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
301
- allow(File).to receive(:read).with('C:\chef\ohai\hints/ec2.json').and_return("")
302
- else
303
- expect(File).to receive(:exist?).with("/etc/chef/ohai/hints/ec2.json").and_return(true)
304
- allow(File).to receive(:read).with("/etc/chef/ohai/hints/ec2.json").and_return("")
305
- end
306
- end
307
- end
308
-
309
- describe "with rackspace hint file" do
310
- it_behaves_like "!ec2"
311
-
312
- before(:each) do
313
- allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/rackspace.json").and_return(true)
314
- allow(File).to receive(:read).with("/etc/chef/ohai/hints/rackspace.json").and_return("")
315
- allow(File).to receive(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
316
- allow(File).to receive(:read).with('C:\chef\ohai\hints/rackspace.json').and_return("")
288
+ allow(plugin).to receive(:hint?).with("ec2").and_return({})
317
289
  end
318
290
  end
319
-
320
291
  describe "without any hints that it is an ec2 system" do
321
292
  it_behaves_like "!ec2"
322
293
 
323
294
  before(:each) do
324
- allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/ec2.json").and_return(false)
325
- allow(File).to receive(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
295
+ allow(plugin).to receive(:hint?).with("ec2").and_return(false)
326
296
  plugin[:dmi] = nil
327
297
  end
328
298
  end
@@ -17,29 +17,39 @@
17
17
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb"))
18
18
 
19
19
  describe Ohai::System, "plugin elixir" do
20
+ let(:plugin) { get_plugin("elixir") }
20
21
 
21
22
  before(:each) do
22
- @plugin = get_plugin("elixir")
23
- @plugin[:languages] = Mash.new
24
- @stdout = "Elixir 1.0.2"
25
- allow(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, @stdout, ""))
23
+ plugin[:languages] = Mash.new
26
24
  end
27
25
 
28
- it "should get the elixir version" do
29
- expect(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, @stdout, ""))
30
- @plugin.run
26
+ it "should shellout to elixir -v" do
27
+ expect(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, "Elixir 1.0.2", ""))
28
+ plugin.run
31
29
  end
32
30
 
33
- it "should set languages[:elixir][:version]" do
34
- @plugin.run
35
- expect(@plugin.languages[:elixir][:version]).to eql("1.0.2")
31
+ it "sets languages[:elixir][:version] on older elixir" do
32
+ allow(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, "Elixir 1.0.2", ""))
33
+ plugin.run
34
+ expect(plugin.languages[:elixir][:version]).to eql("1.0.2")
36
35
  end
37
36
 
38
- it "should not set the languages[:elixir] if elixir command fails" do
39
- @stdout = "Elixir 1.0.2\n"
40
- allow(@plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(1, @stdout, ""))
41
- @plugin.run
42
- expect(@plugin.languages).not_to have_key(:elixir)
37
+ it "sets languages[:elixir][:version] on newer elixir" do
38
+ new_stdout = "Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]\n\nElixir 1.2.4\n"
39
+ allow(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, new_stdout, ""))
40
+ plugin.run
41
+ expect(plugin.languages[:elixir][:version]).to eql("1.2.4")
43
42
  end
44
43
 
44
+ it "does not set languages[:elixir] if elixir command fails" do
45
+ allow(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(1, "", ""))
46
+ plugin.run
47
+ expect(plugin.languages).not_to have_key(:elixir)
48
+ end
49
+
50
+ it "does not set languages[:elixir] if elixir command doesn't exist" do
51
+ allow(plugin).to receive(:shell_out).and_raise(Ohai::Exceptions::Exec)
52
+ plugin.run
53
+ expect(plugin.languages).not_to have_key(:elixir)
54
+ end
45
55
  end
@@ -20,41 +20,47 @@
20
20
  require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
21
21
 
22
22
  describe Ohai::System, "plugin erlang" do
23
+ let(:plugin) { get_plugin("erlang") }
23
24
 
24
25
  before(:each) do
25
- @plugin = get_plugin("erlang")
26
- @plugin[:languages] = Mash.new
27
- @stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"
28
- allow(@plugin).to receive(:shell_out).with("erl +V").and_return(mock_shell_out(0, "", @stderr))
26
+ plugin[:languages] = Mash.new
27
+ erl_v_output = "Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 7.3\n"
28
+ erl_systeminfo_output = "\"18\"\r\n\"7.3\"\r\n\"2.10\"\r\n"
29
+ allow(plugin).to receive(:shell_out).with("erl +V")
30
+ .and_return(mock_shell_out(0, "", erl_v_output))
31
+ allow(plugin).to receive(:shell_out).with("erl -eval 'erlang:display(erlang:system_info(otp_release)), erlang:display(erlang:system_info(version)), erlang:display(erlang:system_info(nif_version)), halt().' -noshell")
32
+ .and_return(mock_shell_out(0, erl_systeminfo_output, ""))
29
33
  end
30
34
 
31
- it "should get the erlang version from erl +V" do
32
- expect(@plugin).to receive(:shell_out).with("erl +V").and_return(mock_shell_out(0, "", @stderr))
33
- @plugin.run
35
+ it "sets languages[:erlang][:options]" do
36
+ plugin.run
37
+ expect(plugin.languages[:erlang][:options]).to eql(%w{SMP ASYNC_THREADS HIPE})
34
38
  end
35
39
 
36
- it "should set languages[:erlang][:version]" do
37
- @plugin.run
38
- expect(@plugin.languages[:erlang][:version]).to eql("5.6.2")
40
+ it "sets languages[:erlang][:emulator]" do
41
+ plugin.run
42
+ expect(plugin.languages[:erlang][:emulator]).to eql("BEAM")
39
43
  end
40
44
 
41
- it "should set languages[:erlang][:options]" do
42
- @plugin.run
43
- expect(@plugin.languages[:erlang][:options]).to eql(%w{ASYNC_THREADS SMP HIPE})
45
+ it "sets languages[:erlang][:version]" do
46
+ plugin.run
47
+ expect(plugin.languages[:erlang][:version]).to eql("18")
44
48
  end
45
49
 
46
- it "should set languages[:erlang][:emulator]" do
47
- @plugin.run
48
- expect(@plugin.languages[:erlang][:emulator]).to eql("BEAM")
50
+ it "sets languages[:erlang][:erts_version]" do
51
+ plugin.run
52
+ expect(plugin.languages[:erlang][:erts_version]).to eql("7.3")
49
53
  end
50
54
 
51
- it "should not set the languages[:erlang] tree up if erlang command fails" do
52
- @status = 1
53
- @stdin = ""
54
- @stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"
55
- allow(@plugin).to receive(:shell_out).with("erl +V").and_return(mock_shell_out(1, "", @stderr))
56
- @plugin.run
57
- expect(@plugin.languages).not_to have_key(:erlang)
55
+ it "sets languages[:erlang][:nif_version]" do
56
+ plugin.run
57
+ expect(plugin.languages[:erlang][:nif_version]).to eql("2.10")
58
+ end
59
+
60
+ it "does not set languages[:erlang] if the erl commands fails" do
61
+ allow(plugin).to receive(:shell_out).and_raise(Ohai::Exceptions::Exec)
62
+ plugin.run
63
+ expect(plugin.languages).not_to have_key(:erlang)
58
64
  end
59
65
 
60
66
  end