ohai 8.0.1 → 8.1.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 (37) hide show
  1. checksums.yaml +13 -5
  2. data/lib/ohai/loader.rb +1 -1
  3. data/lib/ohai/mixin/gce_metadata.rb +2 -1
  4. data/lib/ohai/plugins/cloud.rb +56 -6
  5. data/lib/ohai/plugins/cloud_v2.rb +29 -1
  6. data/lib/ohai/plugins/cloudstack.rb +7 -0
  7. data/lib/ohai/plugins/digital_ocean.rb +81 -0
  8. data/lib/ohai/plugins/elixir.rb +32 -0
  9. data/lib/ohai/plugins/linode.rb +1 -0
  10. data/lib/ohai/plugins/linux/block_device.rb +5 -0
  11. data/lib/ohai/plugins/linux/cpu.rb +21 -1
  12. data/lib/ohai/plugins/linux/filesystem.rb +1 -1
  13. data/lib/ohai/plugins/linux/network.rb +6 -2
  14. data/lib/ohai/plugins/linux/platform.rb +2 -0
  15. data/lib/ohai/plugins/linux/virtualization.rb +14 -3
  16. data/lib/ohai/plugins/php.rb +13 -6
  17. data/lib/ohai/plugins/ruby.rb +10 -10
  18. data/lib/ohai/plugins/rust.rb +32 -0
  19. data/lib/ohai/plugins/ssh_host_key.rb +6 -0
  20. data/lib/ohai/util/ip_helper.rb +52 -0
  21. data/lib/ohai/version.rb +1 -1
  22. data/spec/data/plugins/php.output +16 -0
  23. data/spec/unit/plugins/cloud_spec.rb +63 -9
  24. data/spec/unit/plugins/cloud_v2_spec.rb +123 -25
  25. data/spec/unit/plugins/cloudstack_spec.rb +1 -1
  26. data/spec/unit/plugins/digital_ocean_spec.rb +211 -0
  27. data/spec/unit/plugins/elixir_spec.rb +46 -0
  28. data/spec/unit/plugins/linux/cpu_spec.rb +112 -35
  29. data/spec/unit/plugins/linux/filesystem_spec.rb +7 -7
  30. data/spec/unit/plugins/linux/network_spec.rb +63 -4
  31. data/spec/unit/plugins/linux/platform_spec.rb +13 -0
  32. data/spec/unit/plugins/linux/virtualization_spec.rb +146 -21
  33. data/spec/unit/plugins/php_spec.rb +37 -3
  34. data/spec/unit/plugins/rust_spec.rb +43 -0
  35. data/spec/unit/plugins/ssh_host_keys_spec.rb +11 -0
  36. data/spec/unit/util/ip_helper_spec.rb +128 -0
  37. metadata +49 -41
@@ -138,7 +138,7 @@ EOM
138
138
  expect(ohai_data['cloudstack']['service_offering']).to eq("2vCPU, 1GHz, 2GB RAM")
139
139
  end
140
140
  it "reads the public ipv4 from the metadata service" do
141
- expect(ohai_data['cloudstack']['public_ipv4']).to eq("10.235.34.23")
141
+ expect(ohai_data['cloudstack']['router_ipv4']).to eq("10.235.34.23")
142
142
  end
143
143
  it "reads the vm id from the metadata service" do
144
144
  expect(ohai_data['cloudstack']['vm_id']).to eq("8983fb85-fb7f-46d6-8af1-c1b6666fec39")
@@ -0,0 +1,211 @@
1
+ #
2
+ # Author:: Stafford Brunk (<stafford.brunk@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 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 'ipaddress'
19
+ require 'spec_helper'
20
+
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' }
24
+ let(:digitalocean_path) { '/etc/digitalocean' }
25
+ 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
+ }'
37
+ }
38
+
39
+ before do
40
+ @plugin = get_plugin("digital_ocean")
41
+ @plugin[:network] = {
42
+ "interfaces"=> {
43
+ "eth0"=> {
44
+ "addresses"=> {
45
+ "1.2.3.4"=> {
46
+ "netmask"=> "255.255.255.0"
47
+ },
48
+ "2400:6180:0000:00d0:0000:0000:0009:7001"=> {}
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ allow(File).to receive(:exist?).with(hint_path_nix).and_return(true)
55
+ allow(File).to receive(:read).with(hint_path_nix).and_return(hint)
56
+ allow(File).to receive(:exist?).with(hint_path_win).and_return(true)
57
+ allow(File).to receive(:read).with(hint_path_win).and_return(hint)
58
+ end
59
+
60
+
61
+ shared_examples_for "!digital_ocean" do
62
+ before(:each) do
63
+ @plugin.run
64
+ end
65
+
66
+ it "does not create the digital_ocean mash" do
67
+ expect(@plugin[:digital_ocean]).to be_nil
68
+ end
69
+ end
70
+
71
+ shared_examples_for "digital_ocean_networking" do
72
+ it "creates the networks attribute" do
73
+ expect(@plugin[:digital_ocean][:networks]).not_to be_nil
74
+ end
75
+
76
+ it "pulls ip addresses from the network interfaces" do
77
+ expect(@plugin[:digital_ocean][:networks][:v4]).to eq([{"ip_address" => "1.2.3.4",
78
+ "type" => "public",
79
+ "netmask" => "255.255.255.0"}])
80
+ expect(@plugin[:digital_ocean][:networks][:v6]).to eq([{"ip_address"=>"2400:6180:0000:00d0:0000:0000:0009:7001",
81
+ "type"=>"public",
82
+ "cidr"=>128}])
83
+ end
84
+ end
85
+
86
+ shared_examples_for "digital_ocean" do
87
+ before(:each) do
88
+ @plugin.run
89
+ end
90
+
91
+ it "creates a digital_ocean mash" do
92
+ expect(@plugin[:digital_ocean]).not_to be_nil
93
+ end
94
+
95
+ it "has all hint attributes" do
96
+ expect(@plugin[:digital_ocean][:droplet_id]).not_to be_nil
97
+ expect(@plugin[:digital_ocean][:name]).not_to be_nil
98
+ expect(@plugin[:digital_ocean][:image_id]).not_to be_nil
99
+ expect(@plugin[:digital_ocean][:size_id]).not_to be_nil
100
+ expect(@plugin[:digital_ocean][:region_id]).not_to be_nil
101
+ end
102
+
103
+ it "skips the ip_addresses hint attribute" do
104
+ expect(@plugin[:digital_ocean][:ip_addresses]).to be_nil
105
+ end
106
+
107
+ it "has correct values for all hint attributes" do
108
+ expect(@plugin[:digital_ocean][:droplet_id]).to eq(12345678)
109
+ expect(@plugin[:digital_ocean][:name]).to eq("example.com")
110
+ expect(@plugin[:digital_ocean][:image_id]).to eq(3240036)
111
+ expect(@plugin[:digital_ocean][:size_id]).to eq(66)
112
+ expect(@plugin[:digital_ocean][:region_id]).to eq(4)
113
+ end
114
+
115
+ include_examples 'digital_ocean_networking'
116
+ end
117
+
118
+ describe "with digital_ocean hint file" do
119
+ before do
120
+ allow(File).to receive(:exist?).with(hint_path_nix).and_return(true)
121
+ allow(File).to receive(:exist?).with(hint_path_win).and_return(true)
122
+ end
123
+
124
+ context "without private networking enabled" do
125
+ it_should_behave_like "digital_ocean"
126
+ end
127
+
128
+ context "with private networking enabled" do
129
+ before do
130
+ @plugin[:network][:interfaces][:eth1] = {
131
+ "addresses"=> {
132
+ "10.128.142.89" => {
133
+ "netmask" => "255.255.255.0"
134
+ },
135
+ "fdf8:f53b:82e4:0000:0000:0000:0000:0053" => {}
136
+ }
137
+ }
138
+
139
+ @plugin.run
140
+ end
141
+
142
+ it "should extract the private networking ips" do
143
+ expect(@plugin[:digital_ocean][:networks][:v4]).to eq([{"ip_address" => "1.2.3.4",
144
+ "type" => "public",
145
+ "netmask" => "255.255.255.0"},
146
+ {"ip_address" => "10.128.142.89",
147
+ "type" => "private",
148
+ "netmask" => "255.255.255.0"}])
149
+ expect(@plugin[:digital_ocean][:networks][:v6]).to eq([{"ip_address"=>"2400:6180:0000:00d0:0000:0000:0009:7001",
150
+ "type"=>"public",
151
+ "cidr"=>128},
152
+ {"ip_address"=>"fdf8:f53b:82e4:0000:0000:0000:0000:0053",
153
+ "type"=>"private",
154
+ "cidr"=>128}])
155
+ end
156
+ end
157
+ end
158
+
159
+ describe "without digital_ocean hint file" do
160
+ before do
161
+ allow(File).to receive(:exist?).with(hint_path_nix).and_return(false)
162
+ allow(File).to receive(:exist?).with(hint_path_win).and_return(false)
163
+ end
164
+
165
+
166
+ describe "with the /etc/digitalocean file" do
167
+ before do
168
+ allow(File).to receive(:exist?).with(digitalocean_path).and_return(true)
169
+ @plugin.run
170
+ end
171
+ it_should_behave_like "digital_ocean_networking"
172
+ end
173
+
174
+ describe "without the /etc/digitalocean file" do
175
+ before do
176
+ allow(File).to receive(:exist?).with(digitalocean_path).and_return(false)
177
+ end
178
+ it_should_behave_like "!digital_ocean"
179
+ end
180
+ end
181
+
182
+ context "with ec2 hint file" do
183
+ let(:ec2_hint_path_nix) { '/etc/chef/ohai/hints/ec2.json' }
184
+ let(:ec2_hint_path_win) { 'C:\chef\ohai\hints/ec2.json' }
185
+
186
+ before do
187
+ allow(File).to receive(:exist?).with(hint_path_nix).and_return(false)
188
+ allow(File).to receive(:exist?).with(hint_path_win).and_return(false)
189
+
190
+ allow(File).to receive(:exist?).with(ec2_hint_path_nix).and_return(true)
191
+ allow(File).to receive(:read).with(ec2_hint_path_nix).and_return('')
192
+ allow(File).to receive(:exist?).with(ec2_hint_path_win).and_return(true)
193
+ allow(File).to receive(:read).with(ec2_hint_path_win).and_return('')
194
+ end
195
+
196
+ describe "with the /etc/digitalocean file" do
197
+ before do
198
+ allow(File).to receive(:exist?).with(digitalocean_path).and_return(true)
199
+ @plugin.run
200
+ end
201
+ it_should_behave_like "digital_ocean_networking"
202
+ end
203
+
204
+ describe "without the /etc/digitalocean file" do
205
+ before do
206
+ allow(File).to receive(:exist?).with(digitalocean_path).and_return(false)
207
+ end
208
+ it_should_behave_like "!digital_ocean"
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,46 @@
1
+ # Author:: Christopher M Luciano (<cmlucian@us.ibm.com>)
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language elixirverning permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb'))
18
+
19
+ describe Ohai::System, "plugin elixir" do
20
+
21
+ 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, ""))
26
+ end
27
+
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
31
+ end
32
+
33
+ it "should set languages[:elixir][:version]" do
34
+ @plugin.run
35
+ expect(@plugin.languages[:elixir][:version]).to eql("1.0.2")
36
+ end
37
+
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)
43
+ end
44
+
45
+ end
46
+
@@ -19,7 +19,48 @@
19
19
 
20
20
  require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
21
21
 
22
- describe Ohai::System, "Linux cpu plugin" do
22
+ shared_examples "Common cpu info" do |total_cpu, real_cpu|
23
+ describe "cpu" do
24
+ it "has cpu[:total] equals to #{total_cpu}" do
25
+ @plugin.run
26
+ expect(@plugin[:cpu][:total]).to eq(total_cpu)
27
+ end
28
+
29
+ it "has cpu[:real] equals to #{real_cpu}" do
30
+ @plugin.run
31
+ expect(@plugin[:cpu][:real]).to eq(real_cpu)
32
+ end
33
+
34
+ it "has a cpu 0" do
35
+ @plugin.run
36
+ expect(@plugin[:cpu]).to have_key("0")
37
+ end
38
+ end
39
+ end
40
+
41
+ shared_examples "S390 processor info" do |cpu_no, version, identification, machine|
42
+ describe "S390 processor" do
43
+ it "has a version for cpu #{cpu_no}" do
44
+ @plugin.run
45
+ expect(@plugin[:cpu]["#{cpu_no}"]).to have_key("version")
46
+ expect(@plugin[:cpu]["#{cpu_no}"]["version"]).to eql(version)
47
+ end
48
+
49
+ it "has a identification for cpu #{cpu_no}" do
50
+ @plugin.run
51
+ expect(@plugin[:cpu]["#{cpu_no}"]).to have_key("identification")
52
+ expect(@plugin[:cpu]["#{cpu_no}"]["identification"]).to eql(identification)
53
+ end
54
+
55
+ it "has a machine for cpu #{cpu_no}" do
56
+ @plugin.run
57
+ expect(@plugin[:cpu]["#{cpu_no}"]).to have_key("machine")
58
+ expect(@plugin[:cpu]["#{cpu_no}"]["machine"]).to eql(machine)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe Ohai::System, "General Linux cpu plugin" do
23
64
  before(:each) do
24
65
  @plugin = get_plugin("linux/cpu")
25
66
  allow(@plugin).to receive(:collect_os).and_return(:linux)
@@ -47,81 +88,117 @@ describe Ohai::System, "Linux cpu plugin" do
47
88
  allow(File).to receive(:open).with("/proc/cpuinfo").and_return(@double_file)
48
89
  end
49
90
 
50
- it "should set cpu[:total] to 1" do
51
- @plugin.run
52
- expect(@plugin[:cpu][:total]).to eq(1)
53
- end
54
-
55
- it "should set cpu[:real] to 0" do
56
- @plugin.run
57
- expect(@plugin[:cpu][:real]).to eq(0)
58
- end
59
-
60
- it "should have a cpu 0" do
91
+ it_behaves_like "Common cpu info", 1, 0
92
+
93
+ it "doesn't have a cpu 1" do
61
94
  @plugin.run
62
- expect(@plugin[:cpu]).to have_key("0")
95
+ expect(@plugin[:cpu]).not_to have_key("1")
63
96
  end
64
-
65
- it "should have a vendor_id for cpu 0" do
97
+
98
+ it "has a vendor_id for cpu 0" do
66
99
  @plugin.run
67
100
  expect(@plugin[:cpu]["0"]).to have_key("vendor_id")
68
101
  expect(@plugin[:cpu]["0"]["vendor_id"]).to eql("GenuineIntel")
69
102
  end
70
-
71
- it "should have a family for cpu 0" do
103
+
104
+ it "has a family for cpu 0" do
72
105
  @plugin.run
73
106
  expect(@plugin[:cpu]["0"]).to have_key("family")
74
107
  expect(@plugin[:cpu]["0"]["family"]).to eql("6")
75
108
  end
76
-
77
- it "should have a model for cpu 0" do
109
+
110
+ it "has a model for cpu 0" do
78
111
  @plugin.run
79
112
  expect(@plugin[:cpu]["0"]).to have_key("model")
80
113
  expect(@plugin[:cpu]["0"]["model"]).to eql("23")
81
114
  end
82
-
83
- it "should have a stepping for cpu 0" do
115
+
116
+ it "has a stepping for cpu 0" do
84
117
  @plugin.run
85
118
  expect(@plugin[:cpu]["0"]).to have_key("stepping")
86
119
  expect(@plugin[:cpu]["0"]["stepping"]).to eql("6")
87
120
  end
88
-
89
- it "should not have a phyiscal_id for cpu 0" do
121
+
122
+ it "doesn't have a phyiscal_id for cpu 0" do
90
123
  @plugin.run
91
124
  expect(@plugin[:cpu]["0"]).not_to have_key("physical_id")
92
125
  end
93
-
94
- it "should not have a core_id for cpu 0" do
126
+
127
+ it "doesn't have a core_id for cpu 0" do
95
128
  @plugin.run
96
129
  expect(@plugin[:cpu]["0"]).not_to have_key("core_id")
97
130
  end
98
-
99
- it "should not have a cores for cpu 0" do
131
+
132
+ it "doesn't have a cores for cpu 0" do
100
133
  @plugin.run
101
134
  expect(@plugin[:cpu]["0"]).not_to have_key("cores")
102
135
  end
103
-
104
- it "should have a model name for cpu 0" do
136
+
137
+ it "has a model name for cpu 0" do
105
138
  @plugin.run
106
139
  expect(@plugin[:cpu]["0"]).to have_key("model_name")
107
140
  expect(@plugin[:cpu]["0"]["model_name"]).to eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz")
108
141
  end
109
-
110
- it "should have a mhz for cpu 0" do
142
+
143
+ it "has a mhz for cpu 0" do
111
144
  @plugin.run
112
145
  expect(@plugin[:cpu]["0"]).to have_key("mhz")
113
146
  expect(@plugin[:cpu]["0"]["mhz"]).to eql("1968.770")
114
147
  end
115
-
116
- it "should have a cache_size for cpu 0" do
148
+
149
+ it "has a cache_size for cpu 0" do
117
150
  @plugin.run
118
151
  expect(@plugin[:cpu]["0"]).to have_key("cache_size")
119
152
  expect(@plugin[:cpu]["0"]["cache_size"]).to eql("64 KB")
120
153
  end
121
-
122
- it "should have flags for cpu 0" do
154
+
155
+ it "has flags for cpu 0" do
123
156
  @plugin.run
124
157
  expect(@plugin[:cpu]["0"]).to have_key("flags")
125
158
  expect(@plugin[:cpu]["0"]["flags"]).to eq(%w{fpu pse tsc msr mce cx8 sep mtrr pge cmov})
126
159
  end
127
160
  end
161
+
162
+ describe Ohai::System, "S390 linux cpu plugin" do
163
+ before(:each) do
164
+ @plugin = get_plugin("linux/cpu")
165
+ allow(@plugin).to receive(:collect_os).and_return(:linux)
166
+ @double_file = double("/proc/cpuinfo")
167
+ allow(@double_file).to receive(:each).
168
+ and_yield("vendor_id : IBM/S390").
169
+ and_yield("# processors : 2").
170
+ and_yield("bogomips per cpu: 9328.00").
171
+ and_yield("features : esan3 zarch stfle msa ldisp eimm dfp etf3eh highgprs").
172
+ and_yield("processor 0: version = EE, identification = 06E276, machine = 2717").
173
+ and_yield("processor 1: version = FF, identification = 06E278, machine = 2818")
174
+ allow(File).to receive(:open).with("/proc/cpuinfo").and_return(@double_file)
175
+ end
176
+
177
+ it_behaves_like "Common cpu info", 2, 0
178
+
179
+ it "has a cpu 1" do
180
+ @plugin.run
181
+ expect(@plugin[:cpu]).to have_key("1")
182
+ end
183
+
184
+ it "has a vendor_id" do
185
+ @plugin.run
186
+ expect(@plugin[:cpu]).to have_key("vendor_id")
187
+ expect(@plugin[:cpu]["vendor_id"]).to eql("IBM/S390")
188
+ end
189
+
190
+ it "has a bogomips per cpu" do
191
+ @plugin.run
192
+ expect(@plugin[:cpu]).to have_key("bogomips_per_cpu")
193
+ expect(@plugin[:cpu]["bogomips_per_cpu"]).to eql("9328.00")
194
+ end
195
+
196
+ it "has features" do
197
+ @plugin.run
198
+ expect(@plugin[:cpu]).to have_key("features")
199
+ expect(@plugin[:cpu]["features"]).to eq(%w{esan3 zarch stfle msa ldisp eimm dfp etf3eh highgprs})
200
+ end
201
+
202
+ it_behaves_like "S390 processor info", 0, "EE", "06E276", "2717"
203
+ it_behaves_like "S390 processor info", 1, "FF", "06E278", "2818"
204
+ end