ohai 13.12.6 → 14.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -12
- data/README.md +7 -12
- data/Rakefile +16 -23
- data/docs/man/man1/ohai.1 +97 -0
- data/lib/ohai/application.rb +9 -4
- data/lib/ohai/common/dmi.rb +4 -16
- data/lib/ohai/config.rb +5 -1
- data/lib/ohai/dsl.rb +0 -1
- data/lib/ohai/dsl/plugin.rb +12 -16
- data/lib/ohai/dsl/plugin/versionvii.rb +17 -5
- data/lib/ohai/hints.rb +2 -2
- data/lib/ohai/loader.rb +21 -70
- data/lib/ohai/log.rb +1 -1
- data/lib/ohai/mixin/azure_metadata.rb +4 -4
- data/lib/ohai/mixin/command.rb +3 -3
- data/lib/ohai/mixin/dmi_decode.rb +0 -2
- data/lib/ohai/mixin/do_metadata.rb +1 -1
- data/lib/ohai/mixin/ec2_metadata.rb +8 -8
- data/lib/ohai/mixin/gce_metadata.rb +1 -5
- data/lib/ohai/mixin/http_helper.rb +3 -3
- data/lib/ohai/mixin/scaleway_metadata.rb +46 -0
- data/lib/ohai/mixin/softlayer_metadata.rb +3 -3
- data/lib/ohai/plugins/aix/filesystem.rb +1 -1
- data/lib/ohai/plugins/aix/memory.rb +1 -1
- data/lib/ohai/plugins/aix/network.rb +2 -2
- data/lib/ohai/plugins/aix/virtualization.rb +1 -1
- data/lib/ohai/plugins/azure.rb +5 -5
- data/lib/ohai/plugins/bsd/virtualization.rb +11 -11
- data/lib/ohai/plugins/c.rb +8 -8
- data/lib/ohai/plugins/chef.rb +2 -1
- data/lib/ohai/plugins/cloud.rb +0 -3
- data/lib/ohai/plugins/darwin/cpu.rb +2 -2
- data/lib/ohai/plugins/darwin/filesystem.rb +0 -2
- data/lib/ohai/plugins/darwin/hardware.rb +9 -3
- data/lib/ohai/plugins/darwin/network.rb +2 -2
- data/lib/ohai/plugins/darwin/system_profiler.rb +19 -19
- data/lib/ohai/plugins/darwin/virtualization.rb +10 -0
- data/lib/ohai/plugins/digital_ocean.rb +4 -4
- data/lib/ohai/plugins/dmi.rb +15 -14
- data/lib/ohai/plugins/docker.rb +57 -0
- data/lib/ohai/plugins/ec2.rb +11 -11
- data/lib/ohai/plugins/elixir.rb +1 -1
- data/lib/ohai/plugins/erlang.rb +2 -2
- data/lib/ohai/plugins/eucalyptus.rb +5 -5
- data/lib/ohai/plugins/gce.rb +2 -2
- data/lib/ohai/plugins/go.rb +1 -1
- data/lib/ohai/plugins/groovy.rb +1 -1
- data/lib/ohai/plugins/haskell.rb +4 -4
- data/lib/ohai/plugins/hostname.rb +6 -6
- data/lib/ohai/plugins/init_package.rb +1 -1
- data/lib/ohai/plugins/java.rb +1 -1
- data/lib/ohai/plugins/kernel.rb +109 -40
- data/lib/ohai/plugins/libvirt.rb +113 -0
- data/lib/ohai/plugins/linode.rb +4 -4
- data/lib/ohai/plugins/linux/block_device.rb +4 -4
- data/lib/ohai/plugins/linux/cpu.rb +3 -3
- data/lib/ohai/plugins/linux/filesystem.rb +4 -6
- data/lib/ohai/plugins/linux/lsb.rb +3 -3
- data/lib/ohai/plugins/linux/lspci.rb +2 -1
- data/lib/ohai/plugins/linux/machineid.rb +4 -4
- data/lib/ohai/plugins/linux/network.rb +16 -16
- data/lib/ohai/plugins/linux/platform.rb +4 -10
- data/lib/ohai/plugins/linux/sessions.rb +2 -1
- data/lib/ohai/plugins/linux/virtualization.rb +53 -31
- data/lib/ohai/plugins/lua.rb +1 -1
- data/lib/ohai/plugins/mono.rb +2 -2
- data/lib/ohai/plugins/network.rb +11 -11
- data/lib/ohai/plugins/nodejs.rb +1 -1
- data/lib/ohai/plugins/ohai.rb +0 -2
- data/lib/ohai/plugins/openstack.rb +7 -10
- data/lib/ohai/plugins/packages.rb +1 -1
- data/lib/ohai/plugins/passwd.rb +1 -0
- data/lib/ohai/plugins/perl.rb +1 -1
- data/lib/ohai/plugins/php.rb +1 -1
- data/lib/ohai/plugins/powershell.rb +1 -1
- data/lib/ohai/plugins/python.rb +1 -1
- data/lib/ohai/plugins/rackspace.rb +5 -5
- data/lib/ohai/plugins/root_group.rb +6 -9
- data/lib/ohai/plugins/ruby.rb +2 -2
- data/lib/ohai/plugins/rust.rb +1 -1
- data/lib/ohai/plugins/scala.rb +1 -1
- data/lib/ohai/plugins/scaleway.rb +56 -0
- data/lib/ohai/plugins/shard.rb +1 -0
- data/lib/ohai/plugins/softlayer.rb +2 -2
- data/lib/ohai/plugins/solaris2/cpu.rb +1 -1
- data/lib/ohai/plugins/solaris2/dmi.rb +13 -13
- data/lib/ohai/plugins/solaris2/network.rb +6 -6
- data/lib/ohai/plugins/solaris2/platform.rb +2 -2
- data/lib/ohai/plugins/ssh_host_key.rb +7 -7
- data/lib/ohai/plugins/uptime.rb +2 -7
- data/lib/ohai/plugins/virtualbox.rb +1 -1
- data/lib/ohai/plugins/vmware.rb +2 -2
- data/lib/ohai/plugins/windows/cpu.rb +2 -16
- data/lib/ohai/plugins/windows/network.rb +4 -2
- data/lib/ohai/plugins/zpools.rb +3 -3
- data/lib/ohai/provides_map.rb +1 -1
- data/lib/ohai/runner.rb +11 -14
- data/lib/ohai/system.rb +8 -71
- data/lib/ohai/util/file_helper.rb +2 -2
- data/lib/ohai/util/win32/group_helper.rb +0 -2
- data/lib/ohai/version.rb +1 -1
- data/ohai.gemspec +6 -5
- data/spec/functional/plugins/root_group_spec.rb +2 -2
- data/spec/functional/plugins/windows/uptime_spec.rb +0 -29
- data/spec/unit/dsl/plugin_spec.rb +14 -46
- data/spec/unit/loader_spec.rb +8 -70
- data/spec/unit/mixin/azure_metadata_spec.rb +9 -4
- data/spec/unit/mixin/command_spec.rb +11 -8
- data/spec/unit/mixin/ec2_metadata_spec.rb +5 -0
- data/spec/unit/mixin/softlayer_metadata_spec.rb +6 -1
- data/spec/unit/plugins/aix/filesystem_spec.rb +10 -10
- data/spec/unit/plugins/aix/network_spec.rb +1 -1
- data/spec/unit/plugins/aix/virtualization_spec.rb +3 -3
- data/spec/unit/plugins/cloud_spec.rb +0 -12
- data/spec/unit/plugins/darwin/cpu_spec.rb +2 -2
- data/spec/unit/plugins/darwin/filesystem_spec.rb +1 -6
- data/spec/unit/plugins/darwin/hardware_spec.rb +1 -1
- data/spec/unit/plugins/darwin/virtualization_spec.rb +8 -0
- data/spec/unit/plugins/dmi_spec.rb +17 -25
- data/spec/unit/plugins/docker_spec.rb +100 -0
- data/spec/unit/plugins/fail_spec.rb +3 -58
- data/spec/unit/plugins/haskell_spec.rb +1 -1
- data/spec/unit/plugins/init_package_spec.rb +1 -1
- data/spec/unit/plugins/kernel_spec.rb +0 -52
- data/spec/unit/plugins/linux/block_device_spec.rb +2 -2
- data/spec/unit/plugins/linux/filesystem_spec.rb +2 -7
- data/spec/unit/plugins/linux/lsb_spec.rb +5 -5
- data/spec/unit/plugins/linux/lspci_spec.rb +2 -2
- data/spec/unit/plugins/linux/machineid_spec.rb +5 -5
- data/spec/unit/plugins/linux/network_spec.rb +16 -16
- data/spec/unit/plugins/linux/platform_spec.rb +1 -17
- data/spec/unit/plugins/linux/virtualization_spec.rb +21 -1
- data/spec/unit/plugins/network_spec.rb +58 -58
- data/spec/unit/plugins/openstack_spec.rb +5 -24
- data/spec/unit/plugins/rackspace_spec.rb +6 -6
- data/spec/unit/plugins/root_group_spec.rb +1 -1
- data/spec/unit/plugins/ruby_spec.rb +1 -1
- data/spec/unit/plugins/rust_spec.rb +1 -1
- data/spec/unit/plugins/scala_spec.rb +1 -1
- data/spec/unit/plugins/scaleway_spec.rb +91 -0
- data/spec/unit/plugins/solaris2/cpu_spec.rb +3 -3
- data/spec/unit/plugins/solaris2/platform_spec.rb +2 -2
- data/spec/unit/plugins/ssh_host_keys_spec.rb +8 -8
- data/spec/unit/plugins/sysconf_spec.rb +1 -0
- data/spec/unit/plugins/windows/kernel_spec.rb +79 -0
- data/spec/unit/plugins/windows/uptime_spec.rb +8 -58
- data/spec/unit/provides_map_spec.rb +4 -4
- data/spec/unit/runner_spec.rb +15 -54
- data/spec/unit/system_spec.rb +35 -348
- data/spec/unit/util/file_helper_spec.rb +2 -0
- metadata +28 -28
- data/lib/ohai/dsl/plugin/versionvi.rb +0 -61
- data/lib/ohai/plugins/bsd/filesystem2.rb +0 -121
- data/lib/ohai/plugins/ip_scopes.rb +0 -67
- data/lib/ohai/plugins/virtualization.rb +0 -83
- data/spec/data/plugins/messages.rb +0 -8
- data/spec/data/plugins/v6message.rb +0 -2
- data/spec/unit/plugins/bsd/filesystem2_spec.rb +0 -126
- data/spec/unit/plugins/ip_scopes_spec.rb +0 -139
@@ -79,7 +79,7 @@ describe Ohai::System, "root_group" do
|
|
79
79
|
|
80
80
|
describe "windows platform" do
|
81
81
|
it "should return the group administrators" do
|
82
|
-
|
82
|
+
allow(@plugin).to receive(:collect_os).and_return(:windows)
|
83
83
|
expect(Ohai::Util::Win32::GroupHelper).to receive(:windows_root_group_name).and_return("administrators")
|
84
84
|
@plugin.run
|
85
85
|
expect(@plugin[:root_group]).to eq("administrators")
|
@@ -49,7 +49,7 @@ describe Ohai::System, "plugin ruby" do
|
|
49
49
|
:gems_dir => `#{ruby_bin} #{::RbConfig::CONFIG["bindir"]}/gem env gemdir`.chomp,
|
50
50
|
:gem_bin => [ ::Gem.default_exec_format % "gem", "gem" ].map do |bin|
|
51
51
|
"#{::RbConfig::CONFIG['bindir']}/#{bin}"
|
52
|
-
end.find { |bin| ::File.
|
52
|
+
end.find { |bin| ::File.exist? bin },
|
53
53
|
:ruby_bin => ruby_bin,
|
54
54
|
}.each do |attribute, value|
|
55
55
|
it "should have #{attribute} set to #{value.inspect}" do
|
@@ -18,7 +18,7 @@ require_relative "../../spec_helper.rb"
|
|
18
18
|
|
19
19
|
describe Ohai::System, "plugin rust" do
|
20
20
|
let(:stdout) { "rustc 1.0.0-nightly (29bd9a06e 2015-01-20 23:03:09 +0000)" }
|
21
|
-
let
|
21
|
+
let(:plugin) do
|
22
22
|
plugin = get_plugin("rust")
|
23
23
|
plugin[:languages] = Mash.new
|
24
24
|
allow(plugin).to receive(:shell_out).with("rustc --version").and_return(mock_shell_out(0, stdout, ""))
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jonathan Amiez (<jonathan.amiez@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 "spec_helper"
|
19
|
+
|
20
|
+
describe Ohai::System, "plugin scaleway" do
|
21
|
+
let(:plugin) { get_plugin("scaleway") }
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
allow(plugin).to receive(:hint?).with("scaleway").and_return(false)
|
25
|
+
allow(File).to receive(:read).with("/proc/cmdline").and_return(false)
|
26
|
+
end
|
27
|
+
|
28
|
+
shared_examples_for "!scaleway" do
|
29
|
+
it "should NOT attempt to fetch the scaleway metadata" do
|
30
|
+
expect(plugin).not_to receive(:http_client)
|
31
|
+
expect(plugin[:scaleway]).to be_nil
|
32
|
+
plugin.run
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
shared_examples_for "scaleway" do
|
37
|
+
before(:each) do
|
38
|
+
@http_client = double("Net::HTTP client")
|
39
|
+
allow(plugin).to receive(:http_client).and_return(@http_client)
|
40
|
+
allow(IO).to receive(:select).and_return([[], [1], []])
|
41
|
+
t = double("connection")
|
42
|
+
allow(t).to receive(:connect_nonblock).and_raise(Errno::EINPROGRESS)
|
43
|
+
allow(Socket).to receive(:new).and_return(t)
|
44
|
+
allow(Socket).to receive(:pack_sockaddr_in).and_return(nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:body) do
|
48
|
+
'{"tags": [], "state_detail": "booted", "public_ip": {"dynamic": false, "id": "7564c721-a128-444e-9c95-0754a7616482", "address": "5.1.9.3"}, "ssh_public_keys": [{"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEA5qK2s41yyrNpaXXiQtb/1ADaVHVZZp9rYEtG6Dz7trOPtxkxNsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/j2C+NAzo6TZCLTbJjBf89ieazqVqhY/dMNLDJINY2Ss2ytgyiJm9bp5bYcZz441czijBlmY/qmI0cFCVOJoDq6X9Lmn/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee+hmLFaTE3FeMr1hmeZT2ChH6ruHi8m6m18SfW0fl2fS8zG4yB+WE2IawdsoZmtgtY/Re3CpvhYP9S/JxpUedl+zzzzzzzzzzzzzzzzz5+YONBAt/PWMelXThfMukbwykto6IXmsX2qflBPsRVrWe0D7vt48loVScHDv5D05ZwqWY9rizFqCx3Y8xCLr6649ieonnnjHEsSOBREU507eXVJL6njHard+s+vuTC4bNH5LiP2INQS+9MaT37/l8WzIAL3U+hvcj95HS8KfATX+7XWa54bGJgeOnPle8ojwp1ssl7ddh2yFJozgk2CkUEyE4f1lmEX2YFJGoEoaW0QC2j0nNYiLs37yHG0h84AOgjoIAJo1rxpBAGGJOgFTkgnSdHjtDZsC9WjJYeu/QpxQ7Lf2Z+FCKoypfnZz/F10/z6nxnkZ3IKKM=", "fingerprint": "4096 4c:71:db:64:cd:24:da:4a:fa:5f:9e:70:af:ea:40:6e (no comment) (RSA)"}], "private_ip": "10.8.23.7", "timezone": "UTC", "id": "77fab916-e7ff-44c6-a025-ae08837b4c4f", "extra_networks": [], "name": "sample-hostname", "hostname": "sample-hostname", "bootscript": {"kernel": "http://169.254.42.24/kernel/x86_64-4.9.20-std-1/vmlinuz-4.9.20-std-1", "title": "x86_64 4.9.20 std #1 (longterm/latest)", "default": false, "dtb": "", "public": false, "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.12.7.gz", "bootcmdargs": "LINUX_COMMON scaleway boot=local", "architecture": "x86_64", "organization": "11111110-1112-4112-8112-111111111116", "id": "855f21ba-e7f9-421d-91b0-976a6ad59910"}, "location": {"platform_id": "21", "hypervisor_id": "518", "node_id": "4", "cluster_id": "82", "zone_id": "par1"}, "volumes": {"0": {"name": "x86_64-debian-stretch-2017-06-29_10:17", "modification_date": "2018-01-26T10:22:28.268074+00:00", "export_uri": "device://dev/vda", "volume_type": "l_ssd", "creation_date": "2018-01-26T10:22:28.268074+00:00", "organization": "90f39224-d0a2-4771-a2f0-1036a9402b97", "server": {"id": "77fab916-e7ff-44c6-a024-ae08837b4c4f", "name": "sample-hostname"}, "id": "3be53d4d-93d7-4430-a513-61cb4410624b", "size": 50000000000}}, "ipv6": null, "organization": "89f39224-d0a2-4771-a2f0-1036a9402b97", "commercial_type": "VC1S"}'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should fetch and properly parse json metadata" do
|
52
|
+
expect(@http_client).to receive(:get).
|
53
|
+
with("/conf?format=json").
|
54
|
+
and_return(double("Net::HTTP Response", :body => body, :code => "200"))
|
55
|
+
plugin.run
|
56
|
+
|
57
|
+
expect(plugin[:scaleway]).not_to be_nil
|
58
|
+
expect(plugin[:scaleway]["id"]).to eq("77fab916-e7ff-44c6-a025-ae08837b4c4f")
|
59
|
+
expect(plugin[:scaleway]["hostname"]).to eq("sample-hostname")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should complete the run despite unavailable metadata" do
|
63
|
+
expect(@http_client).to receive(:get).
|
64
|
+
with("/conf?format=json").
|
65
|
+
and_return(double("Net::HTTP Response", :body => "", :code => "404"))
|
66
|
+
plugin.run
|
67
|
+
|
68
|
+
expect(plugin[:scaleway]).not_to be_nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "without hint or cmdline" do
|
73
|
+
it_should_behave_like "!scaleway"
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "with scaleway hint file" do
|
77
|
+
it_should_behave_like "scaleway"
|
78
|
+
|
79
|
+
before(:each) do
|
80
|
+
allow(plugin).to receive(:hint?).with("scaleway").and_return(true)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "with scaleway cmdline" do
|
85
|
+
it_should_behave_like "scaleway"
|
86
|
+
|
87
|
+
before(:each) do
|
88
|
+
allow(File).to receive(:read).with("/proc/cmdline").and_return("initrd=initrd showopts console=ttyS0,115200 nousb vga=0 root=/dev/vda scaleway boot=local")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -455,15 +455,15 @@ END
|
|
455
455
|
end
|
456
456
|
|
457
457
|
it "should get the number of threads per core" do
|
458
|
-
expect(@plugin["cpu"]["corethreads"]).to eql
|
458
|
+
expect(@plugin["cpu"]["corethreads"]).to eql(2)
|
459
459
|
end
|
460
460
|
|
461
461
|
it "should get the total number of online cores" do
|
462
|
-
expect(@plugin["cpu"]["cpustates"]["on-line"]).to eql
|
462
|
+
expect(@plugin["cpu"]["cpustates"]["on-line"]).to eql(8)
|
463
463
|
end
|
464
464
|
|
465
465
|
it "should get the total number of offline cores" do
|
466
|
-
expect(@plugin["cpu"]["cpustates"]["off-line"]).to eql
|
466
|
+
expect(@plugin["cpu"]["cpustates"]["off-line"]).to eql(8)
|
467
467
|
end
|
468
468
|
|
469
469
|
describe "per-cpu information" do
|
@@ -41,7 +41,7 @@ Origin# = 1
|
|
41
41
|
NumCPU = 16
|
42
42
|
UNAME_X
|
43
43
|
|
44
|
-
allow(File).to receive(:
|
44
|
+
allow(File).to receive(:exist?).with("/sbin/uname").and_return(true)
|
45
45
|
allow(@plugin).to receive(:shell_out).with("/sbin/uname -X").and_return(mock_shell_out(0, @uname_x, ""))
|
46
46
|
|
47
47
|
@release = StringIO.new(" SmartOS 20120130T201844Z x86_64\n")
|
@@ -81,7 +81,7 @@ Origin# = 1
|
|
81
81
|
NumCPU = 1
|
82
82
|
UNAME_X
|
83
83
|
|
84
|
-
allow(File).to receive(:
|
84
|
+
allow(File).to receive(:exist?).with("/sbin/uname").and_return(true)
|
85
85
|
allow(@plugin).to receive(:shell_out).with("/sbin/uname -X").and_return(mock_shell_out(0, @uname_x, ""))
|
86
86
|
|
87
87
|
@release = StringIO.new(" Oracle Solaris 11.1 X86\n")
|
@@ -24,13 +24,13 @@ describe Ohai::System, "ssh_host_key plugin" do
|
|
24
24
|
@plugin = get_plugin("ssh_host_key")
|
25
25
|
@plugin[:keys] = Mash.new
|
26
26
|
|
27
|
-
allow(File).to receive(:
|
27
|
+
allow(File).to receive(:exist?).with("/etc/ssh/sshd_config").and_return(true)
|
28
28
|
allow(File).to receive(:open).with("/etc/ssh/sshd_config").and_yield(sshd_config_file)
|
29
|
-
allow(File).to receive(:
|
30
|
-
allow(File).to receive(:
|
31
|
-
allow(File).to receive(:
|
32
|
-
allow(File).to receive(:
|
33
|
-
allow(File).to receive(:
|
29
|
+
allow(File).to receive(:exist?).and_return(true)
|
30
|
+
allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(true)
|
31
|
+
allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(true)
|
32
|
+
allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(true)
|
33
|
+
allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(true)
|
34
34
|
|
35
35
|
# Ensure we can still use IO.read
|
36
36
|
io_read = IO.method(:read)
|
@@ -104,8 +104,8 @@ EOS
|
|
104
104
|
nil
|
105
105
|
end
|
106
106
|
before do
|
107
|
-
allow(File).to receive(:
|
108
|
-
allow(File).to receive(:
|
107
|
+
allow(File).to receive(:exist?).with("/etc/ssh/sshd_config").and_return(false)
|
108
|
+
allow(File).to receive(:exist?).with("/etc/sshd_config").and_return(false)
|
109
109
|
end
|
110
110
|
|
111
111
|
it_behaves_like "loads keys"
|
@@ -346,6 +346,7 @@ _POSIX_RAW_SOCKETS 200809
|
|
346
346
|
GETCONF_OUT
|
347
347
|
allow(plugin).to receive(:which).with("getconf").and_return("/usr/bin/getconf")
|
348
348
|
allow(plugin).to receive(:shell_out).with("/usr/bin/getconf -a").and_return(mock_shell_out(0, getconf_out, ""))
|
349
|
+
allow(plugin).to receive(:collect_os).and_return(:linux)
|
349
350
|
plugin.run
|
350
351
|
expect(plugin[:sysconf].to_hash).to eq({
|
351
352
|
"LINK_MAX" => 65000,
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2018 Chef Software, Inc.
|
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_relative "../../../spec_helper.rb"
|
19
|
+
|
20
|
+
describe Ohai::System, "Windows kernel plugin", :windows_only do
|
21
|
+
let(:plugin) { get_plugin("kernel") }
|
22
|
+
|
23
|
+
before do
|
24
|
+
require "wmi-lite/wmi"
|
25
|
+
|
26
|
+
# Mock a Win32_OperatingSystem OLE32 WMI object
|
27
|
+
caption = double("WIN32OLE", :name => "Caption")
|
28
|
+
version = double("WIN32OLE", :name => "Version")
|
29
|
+
build_number = double("WIN32OLE", :name => "BuildNumber")
|
30
|
+
csd_version = double("WIN32OLE", :name => "CsdVersion")
|
31
|
+
os_type = double("WIN32OLE", :name => "OsType")
|
32
|
+
product_type = double("WIN32OLE", :name => "ProductType")
|
33
|
+
operating_system_sku = double("WIN32OLE", :name => "OperatingSystemSKU")
|
34
|
+
os_properties = [ caption, version, build_number, csd_version, os_type, product_type, operating_system_sku ]
|
35
|
+
|
36
|
+
os = double( "WIN32OLE",
|
37
|
+
:properties_ => os_properties)
|
38
|
+
|
39
|
+
allow(os).to receive(:invoke).with(build_number.name).and_return("7601")
|
40
|
+
allow(os).to receive(:invoke).with(csd_version.name).and_return("Service Pack 1")
|
41
|
+
allow(os).to receive(:invoke).with(os_type.name).and_return(18)
|
42
|
+
allow(os).to receive(:invoke).with(caption.name).and_return("Microsoft Windows 7 Ultimate")
|
43
|
+
allow(os).to receive(:invoke).with(version.name).and_return("6.1.7601")
|
44
|
+
allow(os).to receive(:invoke).with(product_type.name).and_return(1)
|
45
|
+
allow(os).to receive(:invoke).with(operating_system_sku.name).and_return(48)
|
46
|
+
|
47
|
+
os_wmi = WmiLite::Wmi::Instance.new(os)
|
48
|
+
expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with("Win32_OperatingSystem").and_return(os_wmi)
|
49
|
+
|
50
|
+
system_type = double("WIN32OLE", :name => "SystemType")
|
51
|
+
pc_system_type = double("WIN32OLE", :name => "PCSystemType")
|
52
|
+
free_virtual_memory = double("WIN32OLE", :name => "FreeVirtualMemory")
|
53
|
+
cs_properties = [ system_type, pc_system_type, free_virtual_memory]
|
54
|
+
|
55
|
+
cs = double("WIN32OLE",
|
56
|
+
:properties_ => cs_properties)
|
57
|
+
|
58
|
+
allow(cs).to receive(:invoke).with(system_type.name).and_return("x64-based PC")
|
59
|
+
allow(cs).to receive(:invoke).with(pc_system_type.name).and_return(2)
|
60
|
+
allow(cs).to receive(:invoke).with(free_virtual_memory.name).and_return("Why would you want this data here?")
|
61
|
+
|
62
|
+
cs_wmi = WmiLite::Wmi::Instance.new(cs)
|
63
|
+
expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with("Win32_ComputerSystem").and_return(cs_wmi)
|
64
|
+
|
65
|
+
plugin.run
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set the correct system information" do
|
69
|
+
expect(plugin[:kernel][:name]).to eq("Microsoft Windows 7 Ultimate")
|
70
|
+
expect(plugin[:kernel][:release]).to eq("6.1.7601")
|
71
|
+
expect(plugin[:kernel][:version]).to eq("6.1.7601 Service Pack 1 Build 7601")
|
72
|
+
expect(plugin[:kernel][:os]).to eq("WINNT")
|
73
|
+
expect(plugin[:kernel][:machine]).to eq("x86_64")
|
74
|
+
expect(plugin[:kernel][:system_type]).to eq("Mobile")
|
75
|
+
expect(plugin[:kernel][:product_type]).to eq("Workstation")
|
76
|
+
expect(plugin[:kernel][:server_core]).to eq(false)
|
77
|
+
expect(plugin[:kernel]).not_to have_key(:free_virtual_memory)
|
78
|
+
end
|
79
|
+
end
|
@@ -20,69 +20,19 @@ require_relative "../../../spec_helper.rb"
|
|
20
20
|
|
21
21
|
describe Ohai::System, "Windows plugin uptime" do
|
22
22
|
|
23
|
+
let(:plugin) { get_plugin("uptime") }
|
23
24
|
let(:wmi) { double("wmi", { :first_of => "" }) }
|
24
25
|
|
25
26
|
before(:each) do
|
26
27
|
allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
|
28
|
+
allow(plugin).to receive(:collect_os).and_return(:windows)
|
27
29
|
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
it "uses Win32_OperatingSystem WMI class to fetch the system's uptime" do
|
36
|
-
expect(wmi).to receive(:first_of).with("Win32_OperatingSystem")
|
37
|
-
expect(Time).to receive(:new)
|
38
|
-
expect(Time).to receive(:parse)
|
39
|
-
expect(uptime_plugin).to receive(:seconds_to_human)
|
40
|
-
uptime_plugin.run
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
## Windows older versions category here includes server OS starting from Windows Server 2003 ##
|
45
|
-
shared_context "WMI class for older versions of Windows platform" do
|
46
|
-
before do
|
47
|
-
allow(uptime_plugin).to receive(:collect_os).and_return(:windows)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "uses Win32_PerfFormattedData_PerfOS_System WMI class to fetch the system's uptime" do
|
51
|
-
expect(wmi).to receive(:first_of).with("Win32_PerfFormattedData_PerfOS_System")
|
52
|
-
expect(Time).to_not receive(:new)
|
53
|
-
expect(Time).to_not receive(:parse)
|
54
|
-
expect(uptime_plugin).to receive(:seconds_to_human)
|
55
|
-
uptime_plugin.run
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "platform is Windows Server 2008 R2" do
|
60
|
-
let(:uptime_plugin) do
|
61
|
-
get_plugin("uptime").tap do |plugin|
|
62
|
-
plugin[:platform_version] = "6.1.7601"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
include_context "WMI class for newer versions of Windows platform"
|
67
|
-
end
|
68
|
-
|
69
|
-
context "platform is Windows Server 2003 R2" do
|
70
|
-
let(:uptime_plugin) do
|
71
|
-
get_plugin("uptime").tap do |plugin|
|
72
|
-
plugin[:platform_version] = "5.2.3790"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
include_context "WMI class for older versions of Windows platform"
|
77
|
-
end
|
78
|
-
|
79
|
-
context "platform is Windows Server 2012" do
|
80
|
-
let(:uptime_plugin) do
|
81
|
-
get_plugin("uptime").tap do |plugin|
|
82
|
-
plugin[:platform_version] = "6.2.9200"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
include_context "WMI class for newer versions of Windows platform"
|
31
|
+
it "uses Win32_OperatingSystem WMI class to fetch the system's uptime" do
|
32
|
+
expect(wmi).to receive(:first_of).with("Win32_OperatingSystem")
|
33
|
+
expect(Time).to receive(:new)
|
34
|
+
expect(Time).to receive(:parse)
|
35
|
+
expect(plugin).to receive(:seconds_to_human)
|
36
|
+
plugin.run
|
87
37
|
end
|
88
38
|
end
|
@@ -23,10 +23,10 @@ describe Ohai::ProvidesMap do
|
|
23
23
|
|
24
24
|
let(:ohai_system) { Ohai::System.new }
|
25
25
|
let(:provides_map) { Ohai::ProvidesMap.new }
|
26
|
-
let(:plugin_1) { Ohai::DSL::Plugin.new(ohai_system.data) }
|
27
|
-
let(:plugin_2) { Ohai::DSL::Plugin.new(ohai_system.data) }
|
28
|
-
let(:plugin_3) { Ohai::DSL::Plugin.new(ohai_system.data) }
|
29
|
-
let(:plugin_4) { Ohai::DSL::Plugin.new(ohai_system.data) }
|
26
|
+
let(:plugin_1) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) }
|
27
|
+
let(:plugin_2) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) }
|
28
|
+
let(:plugin_3) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) }
|
29
|
+
let(:plugin_4) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) }
|
30
30
|
|
31
31
|
describe "when looking up providing plugins for a single attribute" do
|
32
32
|
describe "when the attribute does not exist" do
|
data/spec/unit/runner_spec.rb
CHANGED
@@ -54,43 +54,6 @@ describe Ohai::Runner, "run_plugin" do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
describe "version 6" do
|
58
|
-
let(:version) { :version6 }
|
59
|
-
|
60
|
-
it "should call run_v6_plugin" do
|
61
|
-
expect(@runner).to receive(:run_v6_plugin)
|
62
|
-
@runner.run_plugin(plugin)
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "if the plugin has not run before" do
|
66
|
-
describe "if safe_run is not set" do
|
67
|
-
it "safe_run should be called" do
|
68
|
-
expect(plugin).to receive(:safe_run)
|
69
|
-
@runner.run_plugin(plugin)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "if safe_run is set" do
|
74
|
-
let(:safe_run) { false }
|
75
|
-
|
76
|
-
it "run should be called" do
|
77
|
-
expect(plugin).to receive(:run)
|
78
|
-
@runner.run_plugin(plugin)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "if the plugin has run before" do
|
84
|
-
let(:has_run) { true }
|
85
|
-
|
86
|
-
it "should not run" do
|
87
|
-
expect(plugin).not_to receive(:safe_run)
|
88
|
-
@runner.run_plugin(plugin)
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
57
|
describe "invalid version" do
|
95
58
|
let(:version) { :versionBla }
|
96
59
|
|
@@ -108,7 +71,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
108
71
|
thing(Mash.new)
|
109
72
|
end
|
110
73
|
end
|
111
|
-
klass.new(@ohai.data)
|
74
|
+
klass.new(@ohai.data, @ohai.logger)
|
112
75
|
end
|
113
76
|
|
114
77
|
it "should run the plugin" do
|
@@ -133,7 +96,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
133
96
|
thing(other_thing)
|
134
97
|
end
|
135
98
|
end
|
136
|
-
@plugin = klass.new(@ohai.data)
|
99
|
+
@plugin = klass.new(@ohai.data, @ohai.logger)
|
137
100
|
end
|
138
101
|
|
139
102
|
it "should raise Ohai::Excpetions::AttributeNotFound" do
|
@@ -164,7 +127,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
164
127
|
|
165
128
|
@plugins = []
|
166
129
|
[klass1, klass2].each do |klass|
|
167
|
-
@plugins << klass.new(@ohai.data)
|
130
|
+
@plugins << klass.new(@ohai.data, @ohai.logger)
|
168
131
|
end
|
169
132
|
@plugin1, @plugin2 = @plugins
|
170
133
|
|
@@ -197,7 +160,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
197
160
|
|
198
161
|
@plugins = []
|
199
162
|
[klass1, klass1, klass2].each do |klass|
|
200
|
-
@plugins << klass.new(@ohai.data)
|
163
|
+
@plugins << klass.new(@ohai.data, @ohai.logger)
|
201
164
|
end
|
202
165
|
@plugin1, @plugin2, @plugin3 = @plugins
|
203
166
|
|
@@ -241,7 +204,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
241
204
|
|
242
205
|
@plugins = []
|
243
206
|
[klass1, klass2, klass3].each do |klass|
|
244
|
-
@plugins << klass.new(@ohai.data)
|
207
|
+
@plugins << klass.new(@ohai.data, @ohai.logger)
|
245
208
|
end
|
246
209
|
@plugin1, @plugin2, @plugin3 = @plugins
|
247
210
|
@ohai.provides_map.set_providers_for(@plugin1, %w{one two})
|
@@ -261,7 +224,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
261
224
|
|
262
225
|
context "when there are no edges in the cycle (A->A)" do
|
263
226
|
let(:plugin_class) do
|
264
|
-
|
227
|
+
Ohai.plugin(:Thing) do
|
265
228
|
provides("thing")
|
266
229
|
depends("thing")
|
267
230
|
collect_data do
|
@@ -269,12 +232,10 @@ describe Ohai::Runner, "run_plugin" do
|
|
269
232
|
end
|
270
233
|
end
|
271
234
|
end
|
272
|
-
let(:plugin) { plugin_class.new(@ohai.data) }
|
235
|
+
let(:plugin) { plugin_class.new(@ohai.data, @ohai.logger) }
|
273
236
|
|
274
237
|
it "ignores the cycle" do
|
275
238
|
@ohai.provides_map.set_providers_for(plugin, ["thing"])
|
276
|
-
|
277
|
-
expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other"
|
278
239
|
runner.run_plugin(plugin) # should not raise
|
279
240
|
end
|
280
241
|
|
@@ -282,7 +243,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
282
243
|
|
283
244
|
context "when there is one edge in the cycle (A->B and B->A)" do
|
284
245
|
before(:each) do
|
285
|
-
klass1 = Ohai.plugin(:Thing) do
|
246
|
+
klass1 = Ohai.plugin(:Thing) do # rubocop disable Lint/UselessAssignment
|
286
247
|
provides("thing")
|
287
248
|
depends("other")
|
288
249
|
collect_data do
|
@@ -299,7 +260,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
299
260
|
|
300
261
|
@plugins = []
|
301
262
|
[klass1, klass2].each_with_index do |klass, idx|
|
302
|
-
@plugins << klass.new(@ohai.data)
|
263
|
+
@plugins << klass.new(@ohai.data, @ohai.logger)
|
303
264
|
end
|
304
265
|
|
305
266
|
@plugin1, @plugin2 = @plugins
|
@@ -336,7 +297,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
336
297
|
|
337
298
|
@plugins = []
|
338
299
|
[klass_a, klass_b, klass_c].each do |klass|
|
339
|
-
@plugins << klass.new(@ohai.data)
|
300
|
+
@plugins << klass.new(@ohai.data, @ohai.logger)
|
340
301
|
end
|
341
302
|
@plugin_a, @plugin_b, @plugin_c = @plugins
|
342
303
|
end
|
@@ -373,12 +334,12 @@ describe Ohai::Runner, "fetch_plugins" do
|
|
373
334
|
before(:each) do
|
374
335
|
@provides_map = Ohai::ProvidesMap.new
|
375
336
|
@data = Mash.new
|
376
|
-
@ohai = double("Ohai::System", :data => @data, :provides_map => @provides_map)
|
337
|
+
@ohai = double("Ohai::System", :data => @data, :provides_map => @provides_map, logger: Ohai::Log.with_child)
|
377
338
|
@runner = Ohai::Runner.new(@ohai, true)
|
378
339
|
end
|
379
340
|
|
380
341
|
it "should collect the provider" do
|
381
|
-
plugin = Ohai::DSL::Plugin.new(@ohai.data)
|
342
|
+
plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
|
382
343
|
@ohai.provides_map.set_providers_for(plugin, ["top/middle/bottom"])
|
383
344
|
|
384
345
|
dependency_providers = @runner.fetch_plugins(["top/middle/bottom"])
|
@@ -388,7 +349,7 @@ describe Ohai::Runner, "fetch_plugins" do
|
|
388
349
|
describe "when the attribute is not provided by any plugin" do
|
389
350
|
describe "and some parent attribute has providers" do
|
390
351
|
it "should return the providers for the parent" do
|
391
|
-
plugin = Ohai::DSL::Plugin.new(@ohai.data)
|
352
|
+
plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
|
392
353
|
@provides_map.set_providers_for(plugin, ["test/attribute"])
|
393
354
|
expect(@runner.fetch_plugins(["test/attribute/too_far"])).to eql([plugin])
|
394
355
|
end
|
@@ -403,7 +364,7 @@ describe Ohai::Runner, "fetch_plugins" do
|
|
403
364
|
end
|
404
365
|
|
405
366
|
it "should return unique providers" do
|
406
|
-
plugin = Ohai::DSL::Plugin.new(@ohai.data)
|
367
|
+
plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
|
407
368
|
@provides_map.set_providers_for(plugin, ["test", "test/too_far/way_too_far"])
|
408
369
|
expect(@runner.fetch_plugins(["test", "test/too_far/way_too_far"])).to eql([plugin])
|
409
370
|
end
|
@@ -438,7 +399,7 @@ describe Ohai::Runner, "#get_cycle" do
|
|
438
399
|
|
439
400
|
plugins = []
|
440
401
|
[klass1, klass2, klass3].each_with_index do |klass, idx|
|
441
|
-
plugins << klass.new(@ohai.data)
|
402
|
+
plugins << klass.new(@ohai.data, @ohai.logger)
|
442
403
|
end
|
443
404
|
@plugin1, @plugin2, @plugin3 = plugins
|
444
405
|
end
|