ohai 8.26.1 → 13.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +3 -4
- data/Rakefile +14 -0
- data/lib/ohai/application.rb +1 -0
- data/lib/ohai/config.rb +2 -88
- data/lib/ohai/dsl/plugin.rb +0 -4
- data/lib/ohai/exception.rb +0 -1
- data/lib/ohai/loader.rb +11 -2
- data/lib/ohai/log.rb +3 -1
- data/lib/ohai/mixin/command.rb +1 -318
- data/lib/ohai/mixin/do_metadata.rb +47 -0
- data/lib/ohai/mixin/ec2_metadata.rb +2 -29
- data/lib/ohai/mixin/gce_metadata.rb +0 -37
- data/lib/ohai/mixin/http_helper.rb +56 -0
- data/lib/ohai/mixin/network_constants.rb +0 -5
- data/lib/ohai/plugins/cloud.rb +144 -157
- data/lib/ohai/plugins/darwin/filesystem.rb +68 -22
- data/lib/ohai/plugins/digital_ocean.rb +24 -42
- data/lib/ohai/plugins/dmi.rb +81 -77
- data/lib/ohai/plugins/ec2.rb +33 -60
- data/lib/ohai/plugins/gce.rb +3 -1
- data/lib/ohai/plugins/hostname.rb +1 -16
- data/lib/ohai/plugins/linux/filesystem.rb +130 -81
- data/lib/ohai/plugins/linux/mdadm.rb +3 -45
- data/lib/ohai/plugins/linux/network.rb +1 -26
- data/lib/ohai/plugins/linux/platform.rb +4 -2
- data/lib/ohai/plugins/linux/virtualization.rb +1 -5
- data/lib/ohai/plugins/scala.rb +1 -13
- data/lib/ohai/plugins/solaris2/network.rb +1 -2
- data/lib/ohai/plugins/uptime.rb +0 -9
- data/lib/ohai/plugins/windows/cpu.rb +2 -1
- data/lib/ohai/plugins/windows/network.rb +1 -1
- data/lib/ohai/runner.rb +0 -5
- data/lib/ohai/system.rb +38 -8
- data/lib/ohai/version.rb +2 -2
- data/ohai.gemspec +1 -1
- data/spec/functional/application_spec.rb +0 -40
- data/spec/functional/plugins/powershell_spec.rb +1 -1
- data/spec/functional/plugins/root_group_spec.rb +1 -1
- data/spec/functional/plugins/windows/uptime_spec.rb +1 -1
- data/spec/ohai_spec.rb +1 -1
- data/spec/support/integration_helper.rb +17 -0
- data/spec/support/platform_helpers.rb +17 -0
- data/spec/unit/application_spec.rb +0 -1
- data/spec/unit/config_spec.rb +0 -111
- data/spec/unit/dsl/plugin_spec.rb +1 -1
- data/spec/unit/hints_spec.rb +1 -1
- data/spec/unit/loader_spec.rb +26 -1
- data/spec/unit/mixin/command_spec.rb +1 -69
- data/spec/unit/mixin/ec2_metadata_spec.rb +1 -1
- data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
- data/spec/unit/plugin_config_spec.rb +0 -1
- data/spec/unit/plugins/abort_spec.rb +1 -1
- data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
- data/spec/unit/plugins/aix/filesystem_spec.rb +2 -1
- data/spec/unit/plugins/aix/hostname_spec.rb +1 -1
- data/spec/unit/plugins/aix/kernel_spec.rb +1 -1
- data/spec/unit/plugins/aix/memory_spec.rb +1 -1
- data/spec/unit/plugins/aix/network_spec.rb +1 -1
- data/spec/unit/plugins/aix/os_spec.rb +1 -1
- data/spec/unit/plugins/aix/platform_spec.rb +1 -1
- data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
- data/spec/unit/plugins/aix/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/azure_spec.rb +1 -1
- data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
- data/spec/unit/plugins/bsd/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/c_spec.rb +1 -1
- data/spec/unit/plugins/chef_spec.rb +1 -2
- data/spec/unit/plugins/cloud_spec.rb +210 -50
- data/spec/unit/plugins/darwin/cpu_spec.rb +1 -1
- data/spec/unit/plugins/darwin/filesystem_spec.rb +62 -13
- data/spec/unit/plugins/darwin/hardware_spec.rb +2 -2
- data/spec/unit/plugins/darwin/hostname_spec.rb +1 -1
- data/spec/unit/plugins/darwin/kernel_spec.rb +1 -1
- data/spec/unit/plugins/darwin/memory_spec.rb +1 -1
- data/spec/unit/plugins/darwin/network_spec.rb +1 -1
- data/spec/unit/plugins/darwin/platform_spec.rb +1 -1
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +2 -9
- data/spec/unit/plugins/darwin/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/digital_ocean_spec.rb +39 -110
- data/spec/unit/plugins/dmi_spec.rb +1 -1
- data/spec/unit/plugins/ec2_spec.rb +10 -62
- data/spec/unit/plugins/elixir_spec.rb +1 -1
- data/spec/unit/plugins/erlang_spec.rb +1 -1
- data/spec/unit/plugins/eucalyptus_spec.rb +1 -1
- data/spec/unit/plugins/fail_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/cpu_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/os_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/gce_spec.rb +1 -1
- data/spec/unit/plugins/go_spec.rb +1 -1
- data/spec/unit/plugins/groovy_spec.rb +1 -1
- data/spec/unit/plugins/haskell_spec.rb +1 -1
- data/spec/unit/plugins/hostname_spec.rb +16 -41
- data/spec/unit/plugins/init_package_spec.rb +1 -1
- data/spec/unit/plugins/ip_scopes_spec.rb +18 -6
- data/spec/unit/plugins/java_spec.rb +1 -1
- data/spec/unit/plugins/joyent_spec.rb +17 -1
- data/spec/unit/plugins/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linode_spec.rb +1 -1
- data/spec/unit/plugins/linux/block_device_spec.rb +1 -1
- data/spec/unit/plugins/linux/cpu_spec.rb +1 -2
- data/spec/unit/plugins/linux/filesystem_spec.rb +207 -201
- data/spec/unit/plugins/linux/fips_spec.rb +1 -1
- data/spec/unit/plugins/linux/hostname_spec.rb +1 -1
- data/spec/unit/plugins/linux/hostnamectl_spec.rb +1 -1
- data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linux/lsb_spec.rb +1 -1
- data/spec/unit/plugins/linux/machineid_spec.rb +1 -1
- data/spec/unit/plugins/linux/mdadm_spec.rb +2 -68
- data/spec/unit/plugins/linux/memory_spec.rb +1 -1
- data/spec/unit/plugins/linux/network_spec.rb +3 -44
- data/spec/unit/plugins/linux/platform_spec.rb +4 -4
- data/spec/unit/plugins/linux/sessions_spec.rb +1 -1
- data/spec/unit/plugins/linux/uptime_spec.rb +1 -1
- data/spec/unit/plugins/linux/virtualization_spec.rb +1 -28
- data/spec/unit/plugins/lua_spec.rb +1 -1
- data/spec/unit/plugins/mono_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/network_spec.rb +1 -1
- data/spec/unit/plugins/nodejs_spec.rb +1 -1
- data/spec/unit/plugins/ohai_spec.rb +1 -1
- data/spec/unit/plugins/ohai_time_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/openstack_spec.rb +2 -3
- data/spec/unit/plugins/os_spec.rb +1 -1
- data/spec/unit/plugins/packages_spec.rb +1 -1
- data/spec/unit/plugins/passwd_spec.rb +17 -1
- data/spec/unit/plugins/perl_spec.rb +1 -1
- data/spec/unit/plugins/php_spec.rb +1 -1
- data/spec/unit/plugins/platform_spec.rb +1 -1
- data/spec/unit/plugins/powershell_spec.rb +1 -1
- data/spec/unit/plugins/python_spec.rb +1 -1
- data/spec/unit/plugins/rackspace_spec.rb +1 -2
- data/spec/unit/plugins/root_group_spec.rb +2 -2
- 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 +3 -37
- data/spec/unit/plugins/shard_spec.rb +1 -1
- data/spec/unit/plugins/shells_spec.rb +1 -1
- data/spec/unit/plugins/softlayer_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/cpu_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/dmi_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/kernel_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/memory_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/network_spec.rb +7 -4
- data/spec/unit/plugins/solaris2/platform_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/zpools_spec.rb +1 -1
- data/spec/unit/plugins/ssh_host_keys_spec.rb +1 -1
- data/spec/unit/plugins/sysconf_spec.rb +1 -1
- data/spec/unit/plugins/timezone_spec.rb +1 -1
- data/spec/unit/plugins/virtualbox_spec.rb +1 -1
- data/spec/unit/plugins/vmware_spec.rb +2 -1
- data/spec/unit/plugins/windows/cpu_spec.rb +9 -2
- data/spec/unit/plugins/windows/fips_spec.rb +1 -1
- data/spec/unit/plugins/windows/memory_spec.rb +1 -1
- data/spec/unit/plugins/windows/uptime_spec.rb +1 -1
- data/spec/unit/plugins/windows/virtualization_spec.rb +1 -1
- data/spec/unit/provides_map_spec.rb +1 -1
- data/spec/unit/runner_spec.rb +1 -1
- data/spec/unit/system_spec.rb +68 -76
- data/spec/unit/util/file_helper_spec.rb +1 -1
- data/spec/unit/util/ip_helper_spec.rb +1 -1
- metadata +6 -20
- data/lib/ohai/plugins/cloud_v2.rb +0 -315
- data/lib/ohai/plugins/darwin/filesystem2.rb +0 -107
- data/lib/ohai/plugins/linux/filesystem2.rb +0 -223
- data/lib/ohai/plugins/linux/lspci.rb +0 -76
- data/lib/ohai/plugins/network_listeners.rb +0 -60
- data/lib/ohai/plugins/sigar/cpu.rb +0 -44
- data/lib/ohai/plugins/sigar/filesystem.rb +0 -50
- data/lib/ohai/plugins/sigar/memory.rb +0 -39
- data/lib/ohai/plugins/sigar/network.rb +0 -168
- data/lib/ohai/plugins/sigar/network_route.rb +0 -64
- data/lib/ohai/plugins/sigar/platform.rb +0 -30
- data/spec/unit/plugins/cloud_v2_spec.rb +0 -389
- data/spec/unit/plugins/darwin/filesystem2_spec.rb +0 -139
- data/spec/unit/plugins/linux/filesystem2_spec.rb +0 -437
- data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
- data/spec/unit/plugins/sigar/network_route_spec.rb +0 -148
@@ -16,7 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
19
|
+
require_relative "../../../spec_helper.rb"
|
20
20
|
|
21
21
|
describe Ohai::System, "darwin filesystem plugin" do
|
22
22
|
let (:plugin) { get_plugin("darwin/filesystem") }
|
@@ -27,6 +27,11 @@ describe Ohai::System, "darwin filesystem plugin" do
|
|
27
27
|
allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
|
28
28
|
end
|
29
29
|
|
30
|
+
it "sets both filesystem and filesystem2 attributes" do
|
31
|
+
plugin.run
|
32
|
+
expect(plugin[:filesystem]).to eq(plugin[:filesystem2])
|
33
|
+
end
|
34
|
+
|
30
35
|
describe "when gathering filesystem usage data from df" do
|
31
36
|
before(:each) do
|
32
37
|
@stdout = <<-DF
|
@@ -48,22 +53,23 @@ DF
|
|
48
53
|
|
49
54
|
it "should set size to value from df -i" do
|
50
55
|
plugin.run
|
51
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:kb_size]).to eq(244277768)
|
52
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:kb_used]).to eq(156848224)
|
53
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:kb_available]).to eq(87173544)
|
54
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:percent_used]).to eq("65%")
|
56
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_size]).to eq("244277768")
|
57
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_used]).to eq("156848224")
|
58
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_available]).to eq("87173544")
|
59
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:percent_used]).to eq("65%")
|
55
60
|
end
|
56
61
|
|
57
|
-
it "should set mount to value from df -i" do
|
62
|
+
it "should set device and mount to value from df -i" do
|
58
63
|
plugin.run
|
59
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:mount]).to eq("/")
|
64
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/")
|
65
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:device]).to eq("/dev/disk0s2")
|
60
66
|
end
|
61
67
|
|
62
68
|
it "should set inode info to value from df -i" do
|
63
69
|
plugin.run
|
64
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:total_inodes]).to eq("61069440")
|
65
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:inodes_used]).to eq("39276054")
|
66
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:inodes_available]).to eq("21793386")
|
70
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:total_inodes]).to eq("61069440")
|
71
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_used]).to eq("39276054")
|
72
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_available]).to eq("21793386")
|
67
73
|
end
|
68
74
|
end
|
69
75
|
|
@@ -87,9 +93,52 @@ MOUNT
|
|
87
93
|
|
88
94
|
it "should set values from mount" do
|
89
95
|
plugin.run
|
90
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:mount]).to eq("/")
|
91
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:fs_type]).to eq("hfs")
|
92
|
-
expect(plugin[:filesystem]["/dev/disk0s2"][:mount_options]).to eq(%w{local journaled})
|
96
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/")
|
97
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:fs_type]).to eq("hfs")
|
98
|
+
expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount_options]).to eq(%w{local journaled})
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "when gathering filesystem data with devices mounted more than once" do
|
103
|
+
before(:each) do
|
104
|
+
@dfstdout = <<-DF
|
105
|
+
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
|
106
|
+
/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /
|
107
|
+
devfs 385 385 0 100% 666 0 100% /dev
|
108
|
+
map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol
|
109
|
+
map -hosts 0 0 0 100% 0 0 100% /net
|
110
|
+
map -static 0 0 0 100% 0 0 100% /mobile_symbol
|
111
|
+
deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey
|
112
|
+
/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /another/mountpoint
|
113
|
+
DF
|
114
|
+
allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, ""))
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should provide a devices view with all mountpoints" do
|
118
|
+
plugin.run
|
119
|
+
expect(plugin[:filesystem]["by_device"]["/dev/disk0s2"][:mounts]).to eq(["/", "/another/mountpoint"])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "when gathering filesystem data with double-mounts" do
|
124
|
+
before(:each) do
|
125
|
+
@dfstdout = <<-DF
|
126
|
+
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
|
127
|
+
/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /
|
128
|
+
devfs 385 385 0 100% 666 0 100% /dev
|
129
|
+
map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol
|
130
|
+
map -hosts 0 0 0 100% 0 0 100% /net
|
131
|
+
map -static 0 0 0 100% 0 0 100% /mobile_symbol
|
132
|
+
deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey
|
133
|
+
/dev/disk0s3 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt
|
134
|
+
/dev/disk0s4 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt
|
135
|
+
DF
|
136
|
+
allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, ""))
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should provide a mounts view with all devices" do
|
140
|
+
plugin.run
|
141
|
+
expect(plugin[:filesystem]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/disk0s3", "/dev/disk0s4"])
|
93
142
|
end
|
94
143
|
end
|
95
144
|
end
|
@@ -16,8 +16,8 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
require_relative "../../../spec_helper.rb"
|
20
|
+
require_relative "hardware_system_profiler_output.rb"
|
21
21
|
|
22
22
|
describe Ohai::System, "Darwin hardware plugin", :unix_only do
|
23
23
|
let (:plugin) { get_plugin("darwin/hardware") }
|
@@ -16,15 +16,8 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
begin
|
23
|
-
require "plist"
|
24
|
-
rescue LoadError => e
|
25
|
-
puts "The darwin systemprofile plugin spec tests will fail without the 'plist' library/gem.\n\n"
|
26
|
-
raise e
|
27
|
-
end
|
19
|
+
require_relative "../../../spec_helper.rb"
|
20
|
+
require_relative "system_profiler_output.rb"
|
28
21
|
|
29
22
|
describe Ohai::System, "Darwin system_profiler plugin", :unix_only do
|
30
23
|
before(:each) do
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
20
|
|
21
|
-
|
21
|
+
require_relative "../../../spec_helper.rb"
|
22
22
|
|
23
23
|
describe Ohai::System, "Darwin virtualization platform" do
|
24
24
|
let(:plugin) { get_plugin("darwin/virtualization") }
|
@@ -1,4 +1,5 @@
|
|
1
1
|
#
|
2
|
+
# Author:: Dylan Page (<dpage@digitalocean.com>)
|
2
3
|
# Author:: Stafford Brunk (<stafford.brunk@gmail.com>)
|
3
4
|
# License:: Apache License, Version 2.0
|
4
5
|
#
|
@@ -15,12 +16,10 @@
|
|
15
16
|
# limitations under the License.
|
16
17
|
#
|
17
18
|
|
18
|
-
require "ipaddress"
|
19
19
|
require "spec_helper"
|
20
20
|
|
21
21
|
describe Ohai::System, "plugin digital_ocean" do
|
22
22
|
let(:plugin) { get_plugin("digital_ocean") }
|
23
|
-
let(:digitalocean_path) { "/etc/digitalocean" }
|
24
23
|
let(:hint) do
|
25
24
|
{
|
26
25
|
"droplet_id" => 12345678,
|
@@ -35,141 +34,71 @@ describe Ohai::System, "plugin digital_ocean" do
|
|
35
34
|
}
|
36
35
|
end
|
37
36
|
|
38
|
-
before do
|
39
|
-
plugin
|
40
|
-
"interfaces" => {
|
41
|
-
"eth0" => {
|
42
|
-
"addresses" => {
|
43
|
-
"00:D3:AD:B3:3F:00" => {
|
44
|
-
"family" => "lladdr",
|
45
|
-
},
|
46
|
-
"1.2.3.4" => {
|
47
|
-
"netmask" => "255.255.255.0",
|
48
|
-
},
|
49
|
-
"2400:6180:0000:00d0:0000:0000:0009:7001" => {},
|
50
|
-
},
|
51
|
-
},
|
52
|
-
},
|
53
|
-
}
|
54
|
-
|
55
|
-
allow(plugin).to receive(:hint?).with("digital_ocean").and_return(hint)
|
37
|
+
before(:each) do
|
38
|
+
allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false)
|
56
39
|
end
|
57
40
|
|
58
41
|
shared_examples_for "!digital_ocean" do
|
59
|
-
|
60
|
-
plugin.
|
61
|
-
end
|
62
|
-
|
63
|
-
it "does not create the digital_ocean mash" do
|
42
|
+
it "should NOT attempt to fetch the digital_ocean metadata" do
|
43
|
+
expect(plugin).not_to receive(:http_client)
|
64
44
|
expect(plugin[:digital_ocean]).to be_nil
|
45
|
+
plugin.run
|
65
46
|
end
|
66
47
|
end
|
67
48
|
|
68
|
-
shared_examples_for "
|
69
|
-
|
70
|
-
|
49
|
+
shared_examples_for "digital_ocean" do
|
50
|
+
before(:each) do
|
51
|
+
@http_client = double("Net::HTTP client")
|
52
|
+
allow(plugin).to receive(:http_client).and_return(@http_client)
|
53
|
+
allow(IO).to receive(:select).and_return([[], [1], []])
|
54
|
+
t = double("connection")
|
55
|
+
allow(t).to receive(:connect_nonblock).and_raise(Errno::EINPROGRESS)
|
56
|
+
allow(Socket).to receive(:new).and_return(t)
|
57
|
+
allow(Socket).to receive(:pack_sockaddr_in).and_return(nil)
|
71
58
|
end
|
72
59
|
|
73
|
-
|
74
|
-
|
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 }])
|
60
|
+
let(:body) do
|
61
|
+
'{"droplet_id":2756924,"hostname":"sample-droplet","vendor_data":"#cloud-config\ndisable_root: false\nmanage_etc_hosts: true\n\n# The modules that run in the \'init\' stage\ncloud_init_modules:\n - migrator\n - ubuntu-init-switch\n - seed_random\n - bootcmd\n - write-files\n - growpart\n - resizefs\n - set_hostname\n - update_hostname\n - [ update_etc_hosts, once-per-instance ]\n - ca-certs\n - rsyslog\n - users-groups\n - ssh\n\n# The modules that run in the \'config\' stage\ncloud_config_modules:\n - disk_setup\n - mounts\n - ssh-import-id\n - locale\n - set-passwords\n - grub-dpkg\n - apt-pipelining\n - apt-configure\n - package-update-upgrade-install\n - landscape\n - timezone\n - puppet\n - chef\n - salt-minion\n - mcollective\n - disable-ec2-metadata\n - runcmd\n - byobu\n\n# The modules that run in the \'final\' stage\ncloud_final_modules:\n - rightscale_userdata\n - scripts-vendor\n - scripts-per-once\n - scripts-per-boot\n - scripts-per-instance\n - scripts-user\n - ssh-authkey-fingerprints\n - keys-to-console\n - phone-home\n - final-message\n - power-state-change\n","public_keys":["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDAkMD3PYKHaH0KbDiXrRE6KCBo/OKcFqhM+fmnnb0+LUh4RalJWX4edeJmnT5bxLeqmLV/Yggjlpfq73R+Dy7JB4pbBLuM959mSM9ohBCSnByAGoT2iUPev4aZFZZ/ahUzTCylNxXrhZV/bopD399CvYREt7Q+FlauBv0O8MMuMGR8aC69Z3jNL+r+fGWNq98JVHGFO/UgoNL15wGCaidMhzfRqkt1u+m1nY77SFM5qWJz2R0CEC4fMlOiCg8mWBklnryV4yDEPgiXp2I8Rli1Eu2GHwuY1YX9elMeQS7n3Pzq7l6aIQmSgvcEWx6TgMD2V7nQUWpfcud/8dpp/t7z9UyfzLmNwnULHNmUeEp52sejcH5lYzISnkkWa1LzlKSeIrhF3y45m9AyxIfjEqyh/mlKQtUaW3NVXXLPwrNitxHtMIZPU5b16BODn0wb8bqPxpDNpUYrQd/BS7mWDxNpICP2ObLPhd9LW9KIYRNTzryE+uKwxm9NkMlhRku2fu415fH0G0+7aURsHviNN9SO4zct3Pj6QE5rnbVHqxt3biplUTOScdWxSk2Nv3V2dGdt/lBfu6iRPAV9IAS31s7Po3qK1t2jpEPCJwstaCBOM80kmoi3zAgotiAW50X8CelaWsHNrq5jBBgeHUZWgn/c8BkcI61pUE9l34Q6gsiEMQ== tsmith84@gmail.com"],"region":"nyc3","interfaces":{"public":[{"ipv4":{"ip_address":"159.203.92.161","netmask":"255.255.240.0","gateway":"159.203.80.1"},"ipv6":{"ip_address":"2604:A880:0800:00A1:0000:0000:0201:0001","cidr":64,"gateway":"2604:A880:0800:00A1:0000:0000:0000:0001"},"anchor_ipv4":{"ip_address":"10.17.0.5","netmask":"255.255.0.0","gateway":"10.17.0.1"},"mac":"04:01:e5:14:03:01","type":"public"}]},"floating_ip":{"ipv4":{"active":false}},"dns":{"nameservers":["2001:4860:4860::8844","2001:4860:4860::8888","8.8.8.8"]}}'
|
80
62
|
end
|
81
|
-
end
|
82
63
|
|
83
|
-
|
84
|
-
|
64
|
+
it "should fetch and properly parse json metadata" do
|
65
|
+
expect(@http_client).to receive(:get).
|
66
|
+
with("/metadata/v1.json").
|
67
|
+
and_return(double("Net::HTTP Response", :body => body, :code => "200"))
|
85
68
|
plugin.run
|
86
|
-
end
|
87
69
|
|
88
|
-
it "creates a digital_ocean mash" do
|
89
70
|
expect(plugin[:digital_ocean]).not_to be_nil
|
71
|
+
expect(plugin[:digital_ocean]["droplet_id"]).to eq(2756924)
|
72
|
+
expect(plugin[:digital_ocean]["hostname"]).to eq("sample-droplet")
|
90
73
|
end
|
91
74
|
|
92
|
-
it "
|
93
|
-
expect(
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
expect(plugin[:digital_ocean][:region_id]).not_to be_nil
|
98
|
-
end
|
99
|
-
|
100
|
-
it "skips the ip_addresses hint attribute" do
|
101
|
-
expect(plugin[:digital_ocean][:ip_addresses]).to be_nil
|
102
|
-
end
|
75
|
+
it "should complete the run despite unavailable metadata" do
|
76
|
+
expect(@http_client).to receive(:get).
|
77
|
+
with("/metadata/v1.json").
|
78
|
+
and_return(double("Net::HTTP Response", :body => "", :code => "404"))
|
79
|
+
plugin.run
|
103
80
|
|
104
|
-
|
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)
|
81
|
+
expect(plugin[:digitalocean]).to be_nil
|
110
82
|
end
|
83
|
+
end
|
111
84
|
|
112
|
-
|
85
|
+
describe "without hint or dmi data" do
|
86
|
+
it_should_behave_like "!digital_ocean"
|
113
87
|
end
|
114
88
|
|
115
89
|
describe "with digital_ocean hint file" do
|
116
|
-
|
117
|
-
allow(plugin).to receive(:hint?).with("digital_ocean").and_return(hint)
|
118
|
-
end
|
119
|
-
|
120
|
-
context "without private networking enabled" do
|
121
|
-
it_behaves_like "digital_ocean"
|
122
|
-
end
|
90
|
+
it_should_behave_like "digital_ocean"
|
123
91
|
|
124
|
-
|
125
|
-
|
126
|
-
plugin[:network][:interfaces][:eth1] = {
|
127
|
-
"addresses" => {
|
128
|
-
"10.128.142.89" => {
|
129
|
-
"netmask" => "255.255.255.0",
|
130
|
-
},
|
131
|
-
"fdf8:f53b:82e4:0000:0000:0000:0000:0053" => {},
|
132
|
-
},
|
133
|
-
}
|
134
|
-
|
135
|
-
plugin.run
|
136
|
-
end
|
137
|
-
|
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" },
|
142
|
-
{ "ip_address" => "10.128.142.89",
|
143
|
-
"type" => "private",
|
144
|
-
"netmask" => "255.255.255.0" }])
|
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 },
|
148
|
-
{ "ip_address" => "fdf8:f53b:82e4:0000:0000:0000:0000:0053",
|
149
|
-
"type" => "private",
|
150
|
-
"cidr" => 128 }])
|
151
|
-
end
|
92
|
+
before(:each) do
|
93
|
+
allow(plugin).to receive(:hint?).with("digital_ocean").and_return(true)
|
152
94
|
end
|
153
95
|
end
|
154
96
|
|
155
|
-
describe "
|
156
|
-
|
157
|
-
allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false)
|
158
|
-
end
|
97
|
+
describe "with digital_ocean DMI data" do
|
98
|
+
it_should_behave_like "digital_ocean"
|
159
99
|
|
160
|
-
|
161
|
-
|
162
|
-
allow(File).to receive(:exist?).with(digitalocean_path).and_return(true)
|
163
|
-
plugin.run
|
164
|
-
end
|
165
|
-
it_behaves_like "digital_ocean_networking"
|
166
|
-
end
|
167
|
-
|
168
|
-
describe "without the /etc/digitalocean file" do
|
169
|
-
before do
|
170
|
-
allow(File).to receive(:exist?).with(digitalocean_path).and_return(false)
|
171
|
-
end
|
172
|
-
it_behaves_like "!digital_ocean"
|
100
|
+
before(:each) do
|
101
|
+
plugin[:dmi] = { :bios => { :all_records => [ { :Vendor => "DigitalOcean" } ] } }
|
173
102
|
end
|
174
103
|
end
|
175
104
|
end
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
19
|
+
require_relative "../../spec_helper.rb"
|
20
20
|
|
21
21
|
# NOTE: These data lines must be prefixed with one or two tabs, not spaces.
|
22
22
|
DMI_OUT = <<-EOS
|
@@ -23,16 +23,14 @@ require "base64"
|
|
23
23
|
|
24
24
|
describe Ohai::System, "plugin ec2" do
|
25
25
|
|
26
|
-
let(:plugin) { get_plugin("ec2") }
|
27
|
-
|
28
26
|
before(:each) do
|
29
27
|
allow(plugin).to receive(:hint?).with("ec2").and_return(false)
|
30
28
|
allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(false)
|
31
|
-
allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(false)
|
32
|
-
allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(false)
|
33
29
|
end
|
34
30
|
|
35
31
|
shared_examples_for "!ec2" do
|
32
|
+
let(:plugin) { get_plugin("ec2") }
|
33
|
+
|
36
34
|
it "DOESN'T attempt to fetch the ec2 metadata or set ec2 attribute" do
|
37
35
|
expect(plugin).not_to receive(:http_client)
|
38
36
|
expect(plugin[:ec2]).to be_nil
|
@@ -41,6 +39,8 @@ describe Ohai::System, "plugin ec2" do
|
|
41
39
|
end
|
42
40
|
|
43
41
|
shared_examples_for "ec2" do
|
42
|
+
let(:plugin) { get_plugin("ec2") }
|
43
|
+
|
44
44
|
before(:each) do
|
45
45
|
@http_client = double("Net::HTTP client")
|
46
46
|
allow(plugin).to receive(:http_client).and_return(@http_client)
|
@@ -334,39 +334,19 @@ describe Ohai::System, "plugin ec2" do
|
|
334
334
|
end
|
335
335
|
end # shared examples for ec2
|
336
336
|
|
337
|
-
describe "with
|
337
|
+
describe "with ec2 dmi data" do
|
338
338
|
it_behaves_like "ec2"
|
339
339
|
|
340
340
|
before(:each) do
|
341
|
-
|
342
|
-
allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("4.2.amazon\n")
|
341
|
+
plugin[:dmi] = { :bios => { :all_records => [ { :Version => "4.2.amazon" } ] } }
|
343
342
|
end
|
344
343
|
end
|
345
344
|
|
346
|
-
describe "with
|
347
|
-
it_behaves_like "!ec2"
|
348
|
-
|
349
|
-
before(:each) do
|
350
|
-
allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
|
351
|
-
allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("1.0\n")
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
describe "with amazon dmi bios vendor data" do
|
345
|
+
describe "with amazon kernel data" do
|
356
346
|
it_behaves_like "ec2"
|
357
347
|
|
358
348
|
before(:each) do
|
359
|
-
|
360
|
-
allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Amazon EC2\n")
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
describe "with non-amazon dmi bios vendor data" do
|
365
|
-
it_behaves_like "!ec2"
|
366
|
-
|
367
|
-
before(:each) do
|
368
|
-
allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
|
369
|
-
allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Xen\n")
|
349
|
+
plugin[:kernel] = { :os_info => { :organization => "Amazon.com" } }
|
370
350
|
end
|
371
351
|
end
|
372
352
|
|
@@ -375,7 +355,7 @@ describe Ohai::System, "plugin ec2" do
|
|
375
355
|
|
376
356
|
before(:each) do
|
377
357
|
allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
|
378
|
-
allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8
|
358
|
+
allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8")
|
379
359
|
end
|
380
360
|
end
|
381
361
|
|
@@ -384,39 +364,7 @@ describe Ohai::System, "plugin ec2" do
|
|
384
364
|
|
385
365
|
before(:each) do
|
386
366
|
allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
|
387
|
-
allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
describe "with EC2 Identifying Number", :windows_only do
|
392
|
-
it_behaves_like "ec2"
|
393
|
-
|
394
|
-
before do
|
395
|
-
allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return(
|
396
|
-
{ "caption" => "Computer System Product",
|
397
|
-
"description" => "Computer System Product",
|
398
|
-
"identifyingnumber" => "ec2a355a-91cd-5fe8-bbfc-cc891d0bf9d6",
|
399
|
-
"name" => "HVM domU",
|
400
|
-
"skunumber" => nil,
|
401
|
-
"uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6",
|
402
|
-
"vendor" => "Xen",
|
403
|
-
"version" => "4.2.amazon" })
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
describe "without EC2 Identifying Number", :windows_only do
|
408
|
-
it_behaves_like "!ec2"
|
409
|
-
|
410
|
-
before do
|
411
|
-
allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return(
|
412
|
-
{ "caption" => "Computer System Product",
|
413
|
-
"description" => "Computer System Product",
|
414
|
-
"identifyingnumber" => "1234",
|
415
|
-
"name" => "HVM domU",
|
416
|
-
"skunumber" => nil,
|
417
|
-
"uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6",
|
418
|
-
"vendor" => "Xen",
|
419
|
-
"version" => "1.2.3" })
|
367
|
+
allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8")
|
420
368
|
end
|
421
369
|
end
|
422
370
|
|