ohai 15.3.1 → 15.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -6
- data/lib/ohai/mixin/{network_constants.rb → network_helper.rb} +8 -1
- data/lib/ohai/plugins/aix/network.rb +3 -8
- data/lib/ohai/plugins/darwin/network.rb +6 -4
- data/lib/ohai/plugins/filesystem.rb +166 -0
- data/lib/ohai/plugins/network.rb +5 -5
- data/lib/ohai/plugins/openstack.rb +2 -1
- data/lib/ohai/plugins/solaris2/network.rb +6 -4
- data/lib/ohai/version.rb +1 -1
- data/ohai.gemspec +1 -1
- metadata +3 -162
- data/Rakefile +0 -42
- data/lib/ohai/plugins/windows/filesystem.rb +0 -147
- data/spec/data/plugins/dpkg-query.output +0 -4
- data/spec/data/plugins/lslpp.output +0 -50
- data/spec/data/plugins/pacman.output +0 -51
- data/spec/data/plugins/pkg-query.output +0 -58
- data/spec/data/plugins/pkginfo.output +0 -50
- data/spec/data/plugins/pkglist.output +0 -24
- data/spec/data/plugins/rpmquery.output +0 -7
- data/spec/functional/application_spec.rb +0 -107
- data/spec/functional/loader_spec.rb +0 -53
- data/spec/functional/plugins/powershell_spec.rb +0 -88
- data/spec/functional/plugins/root_group_spec.rb +0 -41
- data/spec/functional/plugins/windows/uptime_spec.rb +0 -51
- data/spec/ohai_spec.rb +0 -27
- data/spec/rcov.opts +0 -2
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -124
- data/spec/support/integration_helper.rb +0 -61
- data/spec/support/platform_helpers.rb +0 -38
- data/spec/unit/application_spec.rb +0 -96
- data/spec/unit/config_spec.rb +0 -57
- data/spec/unit/dsl/plugin_spec.rb +0 -634
- data/spec/unit/hints_spec.rb +0 -65
- data/spec/unit/loader_spec.rb +0 -195
- data/spec/unit/mixin/azure_metadata_spec.rb +0 -72
- data/spec/unit/mixin/command_spec.rb +0 -151
- data/spec/unit/mixin/dmi_decode.rb +0 -75
- data/spec/unit/mixin/ec2_metadata_spec.rb +0 -88
- data/spec/unit/mixin/softlayer_metadata_spec.rb +0 -72
- data/spec/unit/plugin_config_spec.rb +0 -117
- data/spec/unit/plugins/abort_spec.rb +0 -69
- data/spec/unit/plugins/aix/cpu_spec.rb +0 -127
- data/spec/unit/plugins/aix/filesystem_spec.rb +0 -238
- data/spec/unit/plugins/aix/hostname_spec.rb +0 -33
- data/spec/unit/plugins/aix/kernel_spec.rb +0 -61
- data/spec/unit/plugins/aix/memory_spec.rb +0 -49
- data/spec/unit/plugins/aix/network_spec.rb +0 -313
- data/spec/unit/plugins/aix/platform_spec.rb +0 -44
- data/spec/unit/plugins/aix/uptime_spec.rb +0 -42
- data/spec/unit/plugins/aix/virtualization_spec.rb +0 -319
- data/spec/unit/plugins/azure_spec.rb +0 -243
- data/spec/unit/plugins/bsd/filesystem_spec.rb +0 -138
- data/spec/unit/plugins/bsd/virtualization_spec.rb +0 -145
- data/spec/unit/plugins/c_spec.rb +0 -341
- data/spec/unit/plugins/chef_spec.rb +0 -44
- data/spec/unit/plugins/cloud_spec.rb +0 -484
- data/spec/unit/plugins/darwin/cpu_spec.rb +0 -124
- data/spec/unit/plugins/darwin/filesystem_spec.rb +0 -140
- data/spec/unit/plugins/darwin/hardware_spec.rb +0 -105
- data/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +0 -1110
- data/spec/unit/plugins/darwin/hostname_spec.rb +0 -43
- data/spec/unit/plugins/darwin/kernel_spec.rb +0 -65
- data/spec/unit/plugins/darwin/memory_spec.rb +0 -64
- data/spec/unit/plugins/darwin/network_spec.rb +0 -849
- data/spec/unit/plugins/darwin/platform_spec.rb +0 -71
- data/spec/unit/plugins/darwin/virtualization_spec.rb +0 -156
- data/spec/unit/plugins/digital_ocean_spec.rb +0 -106
- data/spec/unit/plugins/dmi_spec.rb +0 -156
- data/spec/unit/plugins/docker_spec.rb +0 -100
- data/spec/unit/plugins/ec2_spec.rb +0 -452
- data/spec/unit/plugins/elixir_spec.rb +0 -55
- data/spec/unit/plugins/erlang_spec.rb +0 -71
- data/spec/unit/plugins/eucalyptus_spec.rb +0 -109
- data/spec/unit/plugins/fail_spec.rb +0 -260
- data/spec/unit/plugins/freebsd/cpu_spec.rb +0 -129
- data/spec/unit/plugins/freebsd/hostname_spec.rb +0 -35
- data/spec/unit/plugins/freebsd/kernel_spec.rb +0 -36
- data/spec/unit/plugins/freebsd/platform_spec.rb +0 -38
- data/spec/unit/plugins/gce_spec.rb +0 -81
- data/spec/unit/plugins/go_spec.rb +0 -48
- data/spec/unit/plugins/groovy_spec.rb +0 -66
- data/spec/unit/plugins/haskell_spec.rb +0 -231
- data/spec/unit/plugins/hostname_spec.rb +0 -162
- data/spec/unit/plugins/init_package_spec.rb +0 -60
- data/spec/unit/plugins/java_spec.rb +0 -230
- data/spec/unit/plugins/joyent_spec.rb +0 -100
- data/spec/unit/plugins/kernel_spec.rb +0 -38
- data/spec/unit/plugins/linode_spec.rb +0 -135
- data/spec/unit/plugins/linux/block_device_spec.rb +0 -75
- data/spec/unit/plugins/linux/cpu_spec.rb +0 -441
- data/spec/unit/plugins/linux/filesystem_spec.rb +0 -550
- data/spec/unit/plugins/linux/fips_spec.rb +0 -60
- data/spec/unit/plugins/linux/hostname_spec.rb +0 -52
- data/spec/unit/plugins/linux/hostnamectl_spec.rb +0 -59
- data/spec/unit/plugins/linux/kernel_spec.rb +0 -71
- data/spec/unit/plugins/linux/lsb_spec.rb +0 -147
- data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
- data/spec/unit/plugins/linux/machineid_spec.rb +0 -46
- data/spec/unit/plugins/linux/mdadm_spec.rb +0 -170
- data/spec/unit/plugins/linux/memory_spec.rb +0 -256
- data/spec/unit/plugins/linux/network_spec.rb +0 -1392
- data/spec/unit/plugins/linux/platform_spec.rb +0 -812
- data/spec/unit/plugins/linux/sessions_spec.rb +0 -98
- data/spec/unit/plugins/linux/sysctl_spec.rb +0 -53
- data/spec/unit/plugins/linux/systemd_paths_spec.rb +0 -122
- data/spec/unit/plugins/linux/uptime_spec.rb +0 -48
- data/spec/unit/plugins/linux/virtualization_spec.rb +0 -650
- data/spec/unit/plugins/lua_spec.rb +0 -60
- data/spec/unit/plugins/mono_spec.rb +0 -67
- data/spec/unit/plugins/netbsd/hostname_spec.rb +0 -43
- data/spec/unit/plugins/netbsd/kernel_spec.rb +0 -35
- data/spec/unit/plugins/netbsd/platform_spec.rb +0 -38
- data/spec/unit/plugins/network_spec.rb +0 -1078
- data/spec/unit/plugins/nodejs_spec.rb +0 -55
- data/spec/unit/plugins/ohai_spec.rb +0 -32
- data/spec/unit/plugins/ohai_time_spec.rb +0 -44
- data/spec/unit/plugins/openbsd/hostname_spec.rb +0 -43
- data/spec/unit/plugins/openbsd/kernel_spec.rb +0 -36
- data/spec/unit/plugins/openbsd/platform_spec.rb +0 -33
- data/spec/unit/plugins/openstack_spec.rb +0 -311
- data/spec/unit/plugins/os_spec.rb +0 -115
- data/spec/unit/plugins/packages_spec.rb +0 -353
- data/spec/unit/plugins/passwd_spec.rb +0 -65
- data/spec/unit/plugins/perl_spec.rb +0 -62
- data/spec/unit/plugins/php_spec.rb +0 -97
- data/spec/unit/plugins/platform_spec.rb +0 -65
- data/spec/unit/plugins/powershell_spec.rb +0 -71
- data/spec/unit/plugins/python_spec.rb +0 -51
- data/spec/unit/plugins/rackspace_spec.rb +0 -350
- data/spec/unit/plugins/root_group_spec.rb +0 -90
- data/spec/unit/plugins/ruby_spec.rb +0 -60
- data/spec/unit/plugins/rust_spec.rb +0 -43
- data/spec/unit/plugins/scala_spec.rb +0 -58
- data/spec/unit/plugins/scaleway_spec.rb +0 -93
- data/spec/unit/plugins/scsi_spec.rb +0 -69
- data/spec/unit/plugins/shard_spec.rb +0 -121
- data/spec/unit/plugins/shells_spec.rb +0 -56
- data/spec/unit/plugins/softlayer_spec.rb +0 -60
- data/spec/unit/plugins/solaris2/cpu_spec.rb +0 -2926
- data/spec/unit/plugins/solaris2/dmi_spec.rb +0 -153
- data/spec/unit/plugins/solaris2/filesystem.rb +0 -407
- data/spec/unit/plugins/solaris2/hostname_spec.rb +0 -37
- data/spec/unit/plugins/solaris2/kernel_spec.rb +0 -183
- data/spec/unit/plugins/solaris2/memory_spec.rb +0 -43
- data/spec/unit/plugins/solaris2/network_spec.rb +0 -201
- data/spec/unit/plugins/solaris2/platform_spec.rb +0 -108
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +0 -97
- data/spec/unit/plugins/ssh_host_keys_spec.rb +0 -116
- data/spec/unit/plugins/sysconf_spec.rb +0 -680
- data/spec/unit/plugins/timezone_spec.rb +0 -30
- data/spec/unit/plugins/vbox_host_spec.rb +0 -14
- data/spec/unit/plugins/virtualbox_spec.rb +0 -375
- data/spec/unit/plugins/vmware_spec.rb +0 -81
- data/spec/unit/plugins/windows/cpu_spec.rb +0 -118
- data/spec/unit/plugins/windows/filesystem_spec.rb +0 -226
- data/spec/unit/plugins/windows/fips_spec.rb +0 -60
- data/spec/unit/plugins/windows/kernel_spec.rb +0 -79
- data/spec/unit/plugins/windows/memory_spec.rb +0 -52
- data/spec/unit/plugins/windows/network_spec.rb +0 -137
- data/spec/unit/plugins/windows/system_enclosure_spec.rb +0 -45
- data/spec/unit/plugins/windows/uptime_spec.rb +0 -38
- data/spec/unit/plugins/windows/virtualization_spec.rb +0 -63
- data/spec/unit/plugins/zpools_spec.rb +0 -244
- data/spec/unit/provides_map_spec.rb +0 -208
- data/spec/unit/runner_spec.rb +0 -422
- data/spec/unit/system_spec.rb +0 -416
- data/spec/unit/util/file_helper_spec.rb +0 -47
- data/spec/unit/util/ip_helper_spec.rb +0 -128
@@ -1,100 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: 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
|
-
require "spec_helper"
|
18
|
-
|
19
|
-
docker_output = <<~EOF
|
20
|
-
{"ID":"KZET:VDFN:2V2G:JS5Z:HAKO:SOGI:AFSZ:HDMT:GVEM:V2NT:DUSW:J3Z6","Containers":11,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":11,"Images":30,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","extfs"],["Supports d_type","true"],["Native Overlay Diff","true"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":21,"OomKillDisable":true,"NGoroutines":39,"SystemTime":"2018-02-15T19:12:40.214106068Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":2,"KernelVersion":"4.9.60-linuxkit-aufs","OperatingSystem":"Docker for Mac","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":4,"MemTotal":2095816704,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"docker.for.mac.http.internal:3128","HttpsProxy":"docker.for.mac.http.internal:3129","NoProxy":"","Name":"linuxkit-025000000001","Labels":[],"ExperimentalBuild":true,"ServerVersion":"17.12.0-ce","ClusterStore":"","ClusterAdvertise":"","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"89623f28b87a6004d4b785663257362d1658a729","Expected":"89623f28b87a6004d4b785663257362d1658a729"},"RuncCommit":{"ID":"b2567b37d7b75eb4cf325b77297b140ea686ce8f","Expected":"b2567b37d7b75eb4cf325b77297b140ea686ce8f"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["name=seccomp,profile=default"]}
|
21
|
-
EOF
|
22
|
-
|
23
|
-
expected_output = {
|
24
|
-
"version_string" => "17.12.0-ce",
|
25
|
-
"version" => "17.12.0",
|
26
|
-
"runtimes" => {
|
27
|
-
"runc" => {
|
28
|
-
"path" => "docker-runc",
|
29
|
-
},
|
30
|
-
},
|
31
|
-
"root_dir" => "/var/lib/docker",
|
32
|
-
"containers" => {
|
33
|
-
"total" => 11,
|
34
|
-
"running" => 0,
|
35
|
-
"paused" => 0,
|
36
|
-
"stopped" => 11,
|
37
|
-
},
|
38
|
-
"plugins" => {
|
39
|
-
"Volume" => [
|
40
|
-
"local",
|
41
|
-
],
|
42
|
-
"Network" => %w{
|
43
|
-
bridge
|
44
|
-
host
|
45
|
-
ipvlan
|
46
|
-
macvlan
|
47
|
-
null
|
48
|
-
overlay},
|
49
|
-
"Authorization" => nil,
|
50
|
-
"Log" => %w{
|
51
|
-
awslogs
|
52
|
-
fluentd
|
53
|
-
gcplogs
|
54
|
-
gelf
|
55
|
-
journald
|
56
|
-
json-file
|
57
|
-
logentries
|
58
|
-
splunk
|
59
|
-
syslog
|
60
|
-
},
|
61
|
-
},
|
62
|
-
"networking" => {
|
63
|
-
"ipv4_forwarding" => true,
|
64
|
-
"bridge_nf_iptables" => true,
|
65
|
-
"bridge_nf_ipv6_iptables" => true,
|
66
|
-
},
|
67
|
-
"swarm" => {
|
68
|
-
"NodeID" => "",
|
69
|
-
"NodeAddr" => "",
|
70
|
-
"LocalNodeState" => "inactive",
|
71
|
-
"ControlAvailable" => false,
|
72
|
-
"Error" => "",
|
73
|
-
"RemoteManagers" => nil,
|
74
|
-
},
|
75
|
-
}
|
76
|
-
|
77
|
-
describe Ohai::System, "plugin docker" do
|
78
|
-
let(:plugin) { get_plugin("docker") }
|
79
|
-
|
80
|
-
context "if the machine does not have docker installed" do
|
81
|
-
it "does not create a docker attribute" do
|
82
|
-
plugin[:virtualization] = Mash.new
|
83
|
-
plugin[:virtualization][:systems] = Mash.new
|
84
|
-
plugin.run
|
85
|
-
expect(plugin).not_to have_key(:docker)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "if the machine has docker installed" do
|
90
|
-
it "creates a docker attribute with correct data" do
|
91
|
-
plugin[:virtualization] = Mash.new
|
92
|
-
plugin[:virtualization][:systems] = Mash.new
|
93
|
-
plugin[:virtualization][:systems][:docker] = "host"
|
94
|
-
allow(plugin).to receive(:shell_out).with("docker info --format '{{json .}}'").and_return(mock_shell_out(0, docker_output, ""))
|
95
|
-
plugin.run
|
96
|
-
expect(plugin).to have_key(:docker)
|
97
|
-
expect(plugin[:docker]).to eq(expected_output)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,452 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Tim Dysinger (<tim@dysinger.net>)
|
3
|
-
# Author:: Christopher Brown (cb@chef.io)
|
4
|
-
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "open-uri"
|
22
|
-
require "base64"
|
23
|
-
|
24
|
-
describe Ohai::System, "plugin ec2" do
|
25
|
-
|
26
|
-
let(:plugin) { get_plugin("ec2") }
|
27
|
-
|
28
|
-
before do
|
29
|
-
allow(plugin).to receive(:hint?).with("ec2").and_return(false)
|
30
|
-
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
|
-
end
|
34
|
-
|
35
|
-
shared_examples_for "!ec2" do
|
36
|
-
it "DOESN'T attempt to fetch the ec2 metadata or set ec2 attribute" do
|
37
|
-
expect(plugin).not_to receive(:http_client)
|
38
|
-
expect(plugin[:ec2]).to be_nil
|
39
|
-
plugin.run
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
shared_examples_for "ec2" do
|
44
|
-
before do
|
45
|
-
@http_client = double("Net::HTTP client")
|
46
|
-
allow(plugin).to receive(:http_client).and_return(@http_client)
|
47
|
-
allow(IO).to receive(:select).and_return([[], [1], []])
|
48
|
-
t = double("connection")
|
49
|
-
allow(t).to receive(:connect_nonblock).and_raise(Errno::EINPROGRESS)
|
50
|
-
allow(Socket).to receive(:new).and_return(t)
|
51
|
-
expect(@http_client).to receive(:get)
|
52
|
-
.with("/")
|
53
|
-
.and_return(double("Net::HTTP Response", body: "2012-01-12", code: "200"))
|
54
|
-
end
|
55
|
-
|
56
|
-
context "with common metadata paths" do
|
57
|
-
let(:paths) do
|
58
|
-
{ "meta-data/" => "instance_type\nami_id\nsecurity-groups",
|
59
|
-
"meta-data/instance_type" => "c1.medium",
|
60
|
-
"meta-data/ami_id" => "ami-5d2dc934",
|
61
|
-
"meta-data/security-groups" => "group1\ngroup2",
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
it "recursively fetches all the ec2 metadata" do
|
66
|
-
paths.each do |name, body|
|
67
|
-
expect(@http_client).to receive(:get)
|
68
|
-
.with("/2012-01-12/#{name}")
|
69
|
-
.and_return(double("Net::HTTP Response", body: body, code: "200"))
|
70
|
-
end
|
71
|
-
expect(@http_client).to receive(:get)
|
72
|
-
.with("/2012-01-12/user-data/")
|
73
|
-
.and_return(double("Net::HTTP Response", body: "By the pricking of my thumb...", code: "200"))
|
74
|
-
expect(@http_client).to receive(:get)
|
75
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
76
|
-
.and_return(double("Net::HTTP Response", body: "{\"accountId\":\"4815162342\"}", code: "200"))
|
77
|
-
|
78
|
-
plugin.run
|
79
|
-
|
80
|
-
expect(plugin[:ec2]).not_to be_nil
|
81
|
-
expect(plugin[:ec2]["instance_type"]).to eq("c1.medium")
|
82
|
-
expect(plugin[:ec2]["ami_id"]).to eq("ami-5d2dc934")
|
83
|
-
expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2}
|
84
|
-
end
|
85
|
-
|
86
|
-
it "fetches binary userdata opaquely" do
|
87
|
-
paths.each do |name, body|
|
88
|
-
expect(@http_client).to receive(:get)
|
89
|
-
.with("/2012-01-12/#{name}")
|
90
|
-
.and_return(double("Net::HTTP Response", body: body, code: "200"))
|
91
|
-
end
|
92
|
-
expect(@http_client).to receive(:get)
|
93
|
-
.with("/2012-01-12/user-data/")
|
94
|
-
.and_return(double("Net::HTTP Response", body: "^_<8B>^H^H<C7>U^@^Csomething^@KT<C8><C9>,)<C9>IU(I-.I<CB><CC>I<E5>^B^@^Qz<BF><B0>^R^@^@^@", code: "200"))
|
95
|
-
expect(@http_client).to receive(:get)
|
96
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
97
|
-
.and_return(double("Net::HTTP Response", body: "{\"accountId\":\"4815162342\"}", code: "200"))
|
98
|
-
|
99
|
-
plugin.run
|
100
|
-
|
101
|
-
expect(plugin[:ec2]).not_to be_nil
|
102
|
-
expect(plugin[:ec2]["instance_type"]).to eq("c1.medium")
|
103
|
-
expect(plugin[:ec2]["ami_id"]).to eq("ami-5d2dc934")
|
104
|
-
expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2}
|
105
|
-
expect(plugin[:ec2]["userdata"]).to eq(Base64.decode64("Xl88OEI+XkheSDxDNz5VXkBeQ3NvbWV0aGluZ15AS1Q8Qzg+PEM5PiwpPEM5\nPklVKEktLkk8Q0I+PENDPkk8RTU+XkJeQF5RejxCRj48QjA+XlJeQF5AXkA="))
|
106
|
-
end
|
107
|
-
|
108
|
-
it "fetches AWS account id" do
|
109
|
-
paths.each do |name, body|
|
110
|
-
expect(@http_client).to receive(:get)
|
111
|
-
.with("/2012-01-12/#{name}")
|
112
|
-
.and_return(double("Net::HTTP Response", body: body, code: "200"))
|
113
|
-
end
|
114
|
-
expect(@http_client).to receive(:get)
|
115
|
-
.with("/2012-01-12/user-data/")
|
116
|
-
.and_return(double("Net::HTTP Response", body: "^_<8B>^H^H<C7>U^@^Csomething^@KT<C8><C9>,)<C9>IU(I-.I<CB><CC>I<E5>^B^@^Qz<BF><B0>^R^@^@^@", code: "200"))
|
117
|
-
expect(@http_client).to receive(:get)
|
118
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
119
|
-
.and_return(double("Net::HTTP Response", body: "{\"accountId\":\"4815162342\"}", code: "200"))
|
120
|
-
|
121
|
-
plugin.run
|
122
|
-
|
123
|
-
expect(plugin[:ec2]).not_to be_nil
|
124
|
-
expect(plugin[:ec2]["instance_type"]).to eq("c1.medium")
|
125
|
-
expect(plugin[:ec2]["ami_id"]).to eq("ami-5d2dc934")
|
126
|
-
expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2}
|
127
|
-
expect(plugin[:ec2]["account_id"]).to eq("4815162342")
|
128
|
-
end
|
129
|
-
|
130
|
-
it "fetches AWS region" do
|
131
|
-
paths.each do |name, body|
|
132
|
-
expect(@http_client).to receive(:get)
|
133
|
-
.with("/2012-01-12/#{name}")
|
134
|
-
.and_return(double("Net::HTTP Response", body: body, code: "200"))
|
135
|
-
end
|
136
|
-
expect(@http_client).to receive(:get)
|
137
|
-
.with("/2012-01-12/user-data/")
|
138
|
-
.and_return(double("Net::HTTP Response", body: "^_<8B>^H^H<C7>U^@^Csomething^@KT<C8><C9>,)<C9>IU(I-.I<CB><CC>I<E5>^B^@^Qz<BF><B0>^R^@^@^@", code: "200"))
|
139
|
-
expect(@http_client).to receive(:get)
|
140
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
141
|
-
.and_return(double("Net::HTTP Response", body: "{\"region\":\"us-east-1\"}", code: "200"))
|
142
|
-
|
143
|
-
plugin.run
|
144
|
-
|
145
|
-
expect(plugin[:ec2]).not_to be_nil
|
146
|
-
expect(plugin[:ec2]["instance_type"]).to eq("c1.medium")
|
147
|
-
expect(plugin[:ec2]["ami_id"]).to eq("ami-5d2dc934")
|
148
|
-
expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2}
|
149
|
-
expect(plugin[:ec2]["region"]).to eq("us-east-1")
|
150
|
-
end
|
151
|
-
|
152
|
-
it "fetches AWS availability zone" do
|
153
|
-
paths.each do |name, body|
|
154
|
-
expect(@http_client).to receive(:get)
|
155
|
-
.with("/2012-01-12/#{name}")
|
156
|
-
.and_return(double("Net::HTTP Response", body: body, code: "200"))
|
157
|
-
end
|
158
|
-
expect(@http_client).to receive(:get)
|
159
|
-
.with("/2012-01-12/user-data/")
|
160
|
-
.and_return(double("Net::HTTP Response", body: "^_<8B>^H^H<C7>U^@^Csomething^@KT<C8><C9>,)<C9>IU(I-.I<CB><CC>I<E5>^B^@^Qz<BF><B0>^R^@^@^@", code: "200"))
|
161
|
-
expect(@http_client).to receive(:get)
|
162
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
163
|
-
.and_return(double("Net::HTTP Response", body: "{\"availabilityZone\":\"us-east-1d\"}", code: "200"))
|
164
|
-
|
165
|
-
plugin.run
|
166
|
-
|
167
|
-
expect(plugin[:ec2]).not_to be_nil
|
168
|
-
expect(plugin[:ec2]["instance_type"]).to eq("c1.medium")
|
169
|
-
expect(plugin[:ec2]["ami_id"]).to eq("ami-5d2dc934")
|
170
|
-
expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2}
|
171
|
-
expect(plugin[:ec2]["availability_zone"]).to eq("us-east-1d")
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
it "parses ec2 network/ directory as a multi-level hash" do
|
176
|
-
expect(@http_client).to receive(:get)
|
177
|
-
.with("/2012-01-12/meta-data/")
|
178
|
-
.and_return(double("Net::HTTP Response", body: "network/", code: "200"))
|
179
|
-
expect(@http_client).to receive(:get)
|
180
|
-
.with("/2012-01-12/meta-data/network/")
|
181
|
-
.and_return(double("Net::HTTP Response", body: "interfaces/", code: "200"))
|
182
|
-
expect(@http_client).to receive(:get)
|
183
|
-
.with("/2012-01-12/meta-data/network/interfaces/")
|
184
|
-
.and_return(double("Net::HTTP Response", body: "macs/", code: "200"))
|
185
|
-
expect(@http_client).to receive(:get)
|
186
|
-
.with("/2012-01-12/meta-data/network/interfaces/macs/")
|
187
|
-
.and_return(double("Net::HTTP Response", body: "12:34:56:78:9a:bc/", code: "200"))
|
188
|
-
expect(@http_client).to receive(:get)
|
189
|
-
.with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/")
|
190
|
-
.and_return(double("Net::HTTP Response", body: "public_hostname", code: "200"))
|
191
|
-
expect(@http_client).to receive(:get)
|
192
|
-
.with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/public_hostname")
|
193
|
-
.and_return(double("Net::HTTP Response", body: "server17.opscode.com", code: "200"))
|
194
|
-
expect(@http_client).to receive(:get)
|
195
|
-
.with("/2012-01-12/user-data/")
|
196
|
-
.and_return(double("Net::HTTP Response", body: "By the pricking of my thumb...", code: "200"))
|
197
|
-
expect(@http_client).to receive(:get)
|
198
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
199
|
-
.and_return(double("Net::HTTP Response", body: "{\"accountId\":\"4815162342\"}", code: "200"))
|
200
|
-
|
201
|
-
plugin.run
|
202
|
-
|
203
|
-
expect(plugin[:ec2]).not_to be_nil
|
204
|
-
expect(plugin[:ec2]["network_interfaces_macs"]["12:34:56:78:9a:bc"]["public_hostname"]).to eql("server17.opscode.com")
|
205
|
-
end # context with common metadata paths
|
206
|
-
|
207
|
-
context "with ec2_iam hint file" do
|
208
|
-
before do
|
209
|
-
allow(plugin).to receive(:hint?).with("iam").and_return(true)
|
210
|
-
end
|
211
|
-
|
212
|
-
it "parses ec2 iam/ directory and collect iam/security-credentials/" do
|
213
|
-
expect(@http_client).to receive(:get)
|
214
|
-
.with("/2012-01-12/meta-data/")
|
215
|
-
.and_return(double("Net::HTTP Response", body: "iam/", code: "200"))
|
216
|
-
expect(@http_client).to receive(:get)
|
217
|
-
.with("/2012-01-12/meta-data/iam/")
|
218
|
-
.and_return(double("Net::HTTP Response", body: "security-credentials/", code: "200"))
|
219
|
-
expect(@http_client).to receive(:get)
|
220
|
-
.with("/2012-01-12/meta-data/iam/security-credentials/")
|
221
|
-
.and_return(double("Net::HTTP Response", body: "MyRole", code: "200"))
|
222
|
-
expect(@http_client).to receive(:get)
|
223
|
-
.with("/2012-01-12/meta-data/iam/security-credentials/MyRole")
|
224
|
-
.and_return(double("Net::HTTP Response", body: "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", code: "200"))
|
225
|
-
expect(@http_client).to receive(:get)
|
226
|
-
.with("/2012-01-12/user-data/")
|
227
|
-
.and_return(double("Net::HTTP Response", body: "By the pricking of my thumb...", code: "200"))
|
228
|
-
expect(@http_client).to receive(:get)
|
229
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
230
|
-
.and_return(double("Net::HTTP Response", body: "{\"accountId\":\"4815162342\"}", code: "200"))
|
231
|
-
|
232
|
-
plugin.run
|
233
|
-
|
234
|
-
expect(plugin[:ec2]).not_to be_nil
|
235
|
-
expect(plugin[:ec2]["iam"]["security-credentials"]["MyRole"]["Code"]).to eql "Success"
|
236
|
-
expect(plugin[:ec2]["iam"]["security-credentials"]["MyRole"]["Token"]).to eql "12345678"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
context "without ec2_iam hint file" do
|
241
|
-
before do
|
242
|
-
allow(plugin).to receive(:hint?).with("iam").and_return(false)
|
243
|
-
end
|
244
|
-
|
245
|
-
it "parses ec2 iam/ directory and NOT collect iam/security-credentials/" do
|
246
|
-
expect(@http_client).to receive(:get)
|
247
|
-
.with("/2012-01-12/meta-data/")
|
248
|
-
.and_return(double("Net::HTTP Response", body: "iam/", code: "200"))
|
249
|
-
expect(@http_client).to receive(:get)
|
250
|
-
.with("/2012-01-12/meta-data/iam/")
|
251
|
-
.and_return(double("Net::HTTP Response", body: "security-credentials/", code: "200"))
|
252
|
-
expect(@http_client).to receive(:get)
|
253
|
-
.with("/2012-01-12/meta-data/iam/security-credentials/")
|
254
|
-
.and_return(double("Net::HTTP Response", body: "MyRole", code: "200"))
|
255
|
-
expect(@http_client).to receive(:get)
|
256
|
-
.with("/2012-01-12/meta-data/iam/security-credentials/MyRole")
|
257
|
-
.and_return(double("Net::HTTP Response", body: "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", code: "200"))
|
258
|
-
expect(@http_client).to receive(:get)
|
259
|
-
.with("/2012-01-12/user-data/")
|
260
|
-
.and_return(double("Net::HTTP Response", body: "By the pricking of my thumb...", code: "200"))
|
261
|
-
expect(@http_client).to receive(:get)
|
262
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
263
|
-
.and_return(double("Net::HTTP Response", body: "{\"accountId\":\"4815162342\"}", code: "200"))
|
264
|
-
|
265
|
-
plugin.run
|
266
|
-
|
267
|
-
expect(plugin[:ec2]).not_to be_nil
|
268
|
-
expect(plugin[:ec2]["iam"]).to be_nil
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
it "ignores \"./\" and \"../\" on ec2 metadata paths to avoid infinity loops" do
|
273
|
-
expect(@http_client).to receive(:get)
|
274
|
-
.with("/2012-01-12/meta-data/")
|
275
|
-
.and_return(double("Net::HTTP Response", body: ".\n./\n..\n../\npath1/.\npath2/./\npath3/..\npath4/../", code: "200"))
|
276
|
-
|
277
|
-
expect(@http_client).not_to receive(:get)
|
278
|
-
.with("/2012-01-12/meta-data/.")
|
279
|
-
expect(@http_client).not_to receive(:get)
|
280
|
-
.with("/2012-01-12/meta-data/./")
|
281
|
-
expect(@http_client).not_to receive(:get)
|
282
|
-
.with("/2012-01-12/meta-data/..")
|
283
|
-
expect(@http_client).not_to receive(:get)
|
284
|
-
.with("/2012-01-12/meta-data/../")
|
285
|
-
expect(@http_client).not_to receive(:get)
|
286
|
-
.with("/2012-01-12/meta-data/path1/..")
|
287
|
-
|
288
|
-
expect(@http_client).to receive(:get)
|
289
|
-
.with("/2012-01-12/meta-data/path1/")
|
290
|
-
.and_return(double("Net::HTTP Response", body: "", code: "200"))
|
291
|
-
expect(@http_client).to receive(:get)
|
292
|
-
.with("/2012-01-12/meta-data/path2/")
|
293
|
-
.and_return(double("Net::HTTP Response", body: "", code: "200"))
|
294
|
-
expect(@http_client).to receive(:get)
|
295
|
-
.with("/2012-01-12/meta-data/path3/")
|
296
|
-
.and_return(double("Net::HTTP Response", body: "", code: "200"))
|
297
|
-
expect(@http_client).to receive(:get)
|
298
|
-
.with("/2012-01-12/meta-data/path4/")
|
299
|
-
.and_return(double("Net::HTTP Response", body: "", code: "200"))
|
300
|
-
expect(@http_client).to receive(:get)
|
301
|
-
.with("/2012-01-12/user-data/")
|
302
|
-
.and_return(double("Net::HTTP Response", body: "By the pricking of my thumb...", code: "200"))
|
303
|
-
expect(@http_client).to receive(:get)
|
304
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
305
|
-
.and_return(double("Net::HTTP Response", body: "{\"accountId\":\"4815162342\"}", code: "200"))
|
306
|
-
|
307
|
-
plugin.run
|
308
|
-
|
309
|
-
expect(plugin[:ec2]).not_to be_nil
|
310
|
-
end
|
311
|
-
|
312
|
-
it "completes the run despite unavailable metadata" do
|
313
|
-
expect(@http_client).to receive(:get)
|
314
|
-
.with("/2012-01-12/meta-data/")
|
315
|
-
.and_return(double("Net::HTTP Response", body: "metrics/", code: "200"))
|
316
|
-
expect(@http_client).to receive(:get)
|
317
|
-
.with("/2012-01-12/meta-data/metrics/")
|
318
|
-
.and_return(double("Net::HTTP Response", body: "vhostmd", code: "200"))
|
319
|
-
expect(@http_client).to receive(:get)
|
320
|
-
.with("/2012-01-12/meta-data/metrics/vhostmd")
|
321
|
-
.and_return(double("Net::HTTP Response", body: "", code: "404"))
|
322
|
-
expect(@http_client).to receive(:get)
|
323
|
-
.with("/2012-01-12/user-data/")
|
324
|
-
.and_return(double("Net::HTTP Response", body: "By the pricking of my thumb...", code: "200"))
|
325
|
-
expect(@http_client).to receive(:get)
|
326
|
-
.with("/2012-01-12/dynamic/instance-identity/document/")
|
327
|
-
.and_return(double("Net::HTTP Response", body: "{\"accountId\":\"4815162342\"}", code: "200"))
|
328
|
-
|
329
|
-
plugin.run
|
330
|
-
|
331
|
-
expect(plugin[:ec2]).not_to be_nil
|
332
|
-
expect(plugin[:ec2]["metrics"]).to be_nil
|
333
|
-
expect(plugin[:ec2]["metrics_vhostmd"]).to be_nil
|
334
|
-
end
|
335
|
-
end # shared examples for ec2
|
336
|
-
|
337
|
-
describe "with amazon dmi bios version data" do
|
338
|
-
before do
|
339
|
-
allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
|
340
|
-
allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("4.2.amazon\n")
|
341
|
-
end
|
342
|
-
|
343
|
-
it_behaves_like "ec2"
|
344
|
-
|
345
|
-
end
|
346
|
-
|
347
|
-
describe "with non-amazon dmi bios version data" do
|
348
|
-
before do
|
349
|
-
allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
|
350
|
-
allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("1.0\n")
|
351
|
-
end
|
352
|
-
|
353
|
-
it_behaves_like "!ec2"
|
354
|
-
|
355
|
-
end
|
356
|
-
|
357
|
-
describe "with amazon dmi bios vendor data" do
|
358
|
-
before do
|
359
|
-
allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
|
360
|
-
allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Amazon EC2\n")
|
361
|
-
end
|
362
|
-
|
363
|
-
it_behaves_like "ec2"
|
364
|
-
|
365
|
-
end
|
366
|
-
|
367
|
-
describe "with non-amazon dmi bios vendor data" do
|
368
|
-
before do
|
369
|
-
allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
|
370
|
-
allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Xen\n")
|
371
|
-
end
|
372
|
-
|
373
|
-
it_behaves_like "!ec2"
|
374
|
-
|
375
|
-
end
|
376
|
-
|
377
|
-
describe "with EC2 Xen UUID" do
|
378
|
-
before do
|
379
|
-
allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
|
380
|
-
allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
|
381
|
-
end
|
382
|
-
|
383
|
-
it_behaves_like "ec2"
|
384
|
-
|
385
|
-
end
|
386
|
-
|
387
|
-
describe "with non-EC2 Xen UUID" do
|
388
|
-
before do
|
389
|
-
allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
|
390
|
-
allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
|
391
|
-
end
|
392
|
-
|
393
|
-
it_behaves_like "!ec2"
|
394
|
-
|
395
|
-
end
|
396
|
-
|
397
|
-
describe "with EC2 Identifying Number", :windows_only do
|
398
|
-
before do
|
399
|
-
allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return(
|
400
|
-
{ "caption" => "Computer System Product",
|
401
|
-
"description" => "Computer System Product",
|
402
|
-
"identifyingnumber" => "ec2a355a-91cd-5fe8-bbfc-cc891d0bf9d6",
|
403
|
-
"name" => "HVM domU",
|
404
|
-
"skunumber" => nil,
|
405
|
-
"uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6",
|
406
|
-
"vendor" => "Xen",
|
407
|
-
"version" => "4.2.amazon" }
|
408
|
-
)
|
409
|
-
end
|
410
|
-
|
411
|
-
it_behaves_like "ec2"
|
412
|
-
|
413
|
-
end
|
414
|
-
|
415
|
-
describe "without EC2 Identifying Number", :windows_only do
|
416
|
-
before do
|
417
|
-
allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return(
|
418
|
-
{ "caption" => "Computer System Product",
|
419
|
-
"description" => "Computer System Product",
|
420
|
-
"identifyingnumber" => "1234",
|
421
|
-
"name" => "HVM domU",
|
422
|
-
"skunumber" => nil,
|
423
|
-
"uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6",
|
424
|
-
"vendor" => "Xen",
|
425
|
-
"version" => "1.2.3" }
|
426
|
-
)
|
427
|
-
end
|
428
|
-
|
429
|
-
it_behaves_like "!ec2"
|
430
|
-
|
431
|
-
end
|
432
|
-
|
433
|
-
describe "with ec2 hint file" do
|
434
|
-
before do
|
435
|
-
allow(plugin).to receive(:hint?).with("ec2").and_return({})
|
436
|
-
end
|
437
|
-
|
438
|
-
it_behaves_like "ec2"
|
439
|
-
|
440
|
-
end
|
441
|
-
|
442
|
-
describe "without any hints that it is an ec2 system" do
|
443
|
-
before do
|
444
|
-
allow(plugin).to receive(:hint?).with("ec2").and_return(false)
|
445
|
-
plugin[:dmi] = nil
|
446
|
-
end
|
447
|
-
|
448
|
-
it_behaves_like "!ec2"
|
449
|
-
|
450
|
-
end
|
451
|
-
|
452
|
-
end
|