ohai 15.3.1 → 15.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -6
  3. data/lib/ohai/mixin/{network_constants.rb → network_helper.rb} +8 -1
  4. data/lib/ohai/plugins/aix/network.rb +3 -8
  5. data/lib/ohai/plugins/darwin/network.rb +6 -4
  6. data/lib/ohai/plugins/filesystem.rb +166 -0
  7. data/lib/ohai/plugins/network.rb +5 -5
  8. data/lib/ohai/plugins/openstack.rb +2 -1
  9. data/lib/ohai/plugins/solaris2/network.rb +6 -4
  10. data/lib/ohai/version.rb +1 -1
  11. data/ohai.gemspec +1 -1
  12. metadata +3 -162
  13. data/Rakefile +0 -42
  14. data/lib/ohai/plugins/windows/filesystem.rb +0 -147
  15. data/spec/data/plugins/dpkg-query.output +0 -4
  16. data/spec/data/plugins/lslpp.output +0 -50
  17. data/spec/data/plugins/pacman.output +0 -51
  18. data/spec/data/plugins/pkg-query.output +0 -58
  19. data/spec/data/plugins/pkginfo.output +0 -50
  20. data/spec/data/plugins/pkglist.output +0 -24
  21. data/spec/data/plugins/rpmquery.output +0 -7
  22. data/spec/functional/application_spec.rb +0 -107
  23. data/spec/functional/loader_spec.rb +0 -53
  24. data/spec/functional/plugins/powershell_spec.rb +0 -88
  25. data/spec/functional/plugins/root_group_spec.rb +0 -41
  26. data/spec/functional/plugins/windows/uptime_spec.rb +0 -51
  27. data/spec/ohai_spec.rb +0 -27
  28. data/spec/rcov.opts +0 -2
  29. data/spec/spec.opts +0 -2
  30. data/spec/spec_helper.rb +0 -124
  31. data/spec/support/integration_helper.rb +0 -61
  32. data/spec/support/platform_helpers.rb +0 -38
  33. data/spec/unit/application_spec.rb +0 -96
  34. data/spec/unit/config_spec.rb +0 -57
  35. data/spec/unit/dsl/plugin_spec.rb +0 -634
  36. data/spec/unit/hints_spec.rb +0 -65
  37. data/spec/unit/loader_spec.rb +0 -195
  38. data/spec/unit/mixin/azure_metadata_spec.rb +0 -72
  39. data/spec/unit/mixin/command_spec.rb +0 -151
  40. data/spec/unit/mixin/dmi_decode.rb +0 -75
  41. data/spec/unit/mixin/ec2_metadata_spec.rb +0 -88
  42. data/spec/unit/mixin/softlayer_metadata_spec.rb +0 -72
  43. data/spec/unit/plugin_config_spec.rb +0 -117
  44. data/spec/unit/plugins/abort_spec.rb +0 -69
  45. data/spec/unit/plugins/aix/cpu_spec.rb +0 -127
  46. data/spec/unit/plugins/aix/filesystem_spec.rb +0 -238
  47. data/spec/unit/plugins/aix/hostname_spec.rb +0 -33
  48. data/spec/unit/plugins/aix/kernel_spec.rb +0 -61
  49. data/spec/unit/plugins/aix/memory_spec.rb +0 -49
  50. data/spec/unit/plugins/aix/network_spec.rb +0 -313
  51. data/spec/unit/plugins/aix/platform_spec.rb +0 -44
  52. data/spec/unit/plugins/aix/uptime_spec.rb +0 -42
  53. data/spec/unit/plugins/aix/virtualization_spec.rb +0 -319
  54. data/spec/unit/plugins/azure_spec.rb +0 -243
  55. data/spec/unit/plugins/bsd/filesystem_spec.rb +0 -138
  56. data/spec/unit/plugins/bsd/virtualization_spec.rb +0 -145
  57. data/spec/unit/plugins/c_spec.rb +0 -341
  58. data/spec/unit/plugins/chef_spec.rb +0 -44
  59. data/spec/unit/plugins/cloud_spec.rb +0 -484
  60. data/spec/unit/plugins/darwin/cpu_spec.rb +0 -124
  61. data/spec/unit/plugins/darwin/filesystem_spec.rb +0 -140
  62. data/spec/unit/plugins/darwin/hardware_spec.rb +0 -105
  63. data/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +0 -1110
  64. data/spec/unit/plugins/darwin/hostname_spec.rb +0 -43
  65. data/spec/unit/plugins/darwin/kernel_spec.rb +0 -65
  66. data/spec/unit/plugins/darwin/memory_spec.rb +0 -64
  67. data/spec/unit/plugins/darwin/network_spec.rb +0 -849
  68. data/spec/unit/plugins/darwin/platform_spec.rb +0 -71
  69. data/spec/unit/plugins/darwin/virtualization_spec.rb +0 -156
  70. data/spec/unit/plugins/digital_ocean_spec.rb +0 -106
  71. data/spec/unit/plugins/dmi_spec.rb +0 -156
  72. data/spec/unit/plugins/docker_spec.rb +0 -100
  73. data/spec/unit/plugins/ec2_spec.rb +0 -452
  74. data/spec/unit/plugins/elixir_spec.rb +0 -55
  75. data/spec/unit/plugins/erlang_spec.rb +0 -71
  76. data/spec/unit/plugins/eucalyptus_spec.rb +0 -109
  77. data/spec/unit/plugins/fail_spec.rb +0 -260
  78. data/spec/unit/plugins/freebsd/cpu_spec.rb +0 -129
  79. data/spec/unit/plugins/freebsd/hostname_spec.rb +0 -35
  80. data/spec/unit/plugins/freebsd/kernel_spec.rb +0 -36
  81. data/spec/unit/plugins/freebsd/platform_spec.rb +0 -38
  82. data/spec/unit/plugins/gce_spec.rb +0 -81
  83. data/spec/unit/plugins/go_spec.rb +0 -48
  84. data/spec/unit/plugins/groovy_spec.rb +0 -66
  85. data/spec/unit/plugins/haskell_spec.rb +0 -231
  86. data/spec/unit/plugins/hostname_spec.rb +0 -162
  87. data/spec/unit/plugins/init_package_spec.rb +0 -60
  88. data/spec/unit/plugins/java_spec.rb +0 -230
  89. data/spec/unit/plugins/joyent_spec.rb +0 -100
  90. data/spec/unit/plugins/kernel_spec.rb +0 -38
  91. data/spec/unit/plugins/linode_spec.rb +0 -135
  92. data/spec/unit/plugins/linux/block_device_spec.rb +0 -75
  93. data/spec/unit/plugins/linux/cpu_spec.rb +0 -441
  94. data/spec/unit/plugins/linux/filesystem_spec.rb +0 -550
  95. data/spec/unit/plugins/linux/fips_spec.rb +0 -60
  96. data/spec/unit/plugins/linux/hostname_spec.rb +0 -52
  97. data/spec/unit/plugins/linux/hostnamectl_spec.rb +0 -59
  98. data/spec/unit/plugins/linux/kernel_spec.rb +0 -71
  99. data/spec/unit/plugins/linux/lsb_spec.rb +0 -147
  100. data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
  101. data/spec/unit/plugins/linux/machineid_spec.rb +0 -46
  102. data/spec/unit/plugins/linux/mdadm_spec.rb +0 -170
  103. data/spec/unit/plugins/linux/memory_spec.rb +0 -256
  104. data/spec/unit/plugins/linux/network_spec.rb +0 -1392
  105. data/spec/unit/plugins/linux/platform_spec.rb +0 -812
  106. data/spec/unit/plugins/linux/sessions_spec.rb +0 -98
  107. data/spec/unit/plugins/linux/sysctl_spec.rb +0 -53
  108. data/spec/unit/plugins/linux/systemd_paths_spec.rb +0 -122
  109. data/spec/unit/plugins/linux/uptime_spec.rb +0 -48
  110. data/spec/unit/plugins/linux/virtualization_spec.rb +0 -650
  111. data/spec/unit/plugins/lua_spec.rb +0 -60
  112. data/spec/unit/plugins/mono_spec.rb +0 -67
  113. data/spec/unit/plugins/netbsd/hostname_spec.rb +0 -43
  114. data/spec/unit/plugins/netbsd/kernel_spec.rb +0 -35
  115. data/spec/unit/plugins/netbsd/platform_spec.rb +0 -38
  116. data/spec/unit/plugins/network_spec.rb +0 -1078
  117. data/spec/unit/plugins/nodejs_spec.rb +0 -55
  118. data/spec/unit/plugins/ohai_spec.rb +0 -32
  119. data/spec/unit/plugins/ohai_time_spec.rb +0 -44
  120. data/spec/unit/plugins/openbsd/hostname_spec.rb +0 -43
  121. data/spec/unit/plugins/openbsd/kernel_spec.rb +0 -36
  122. data/spec/unit/plugins/openbsd/platform_spec.rb +0 -33
  123. data/spec/unit/plugins/openstack_spec.rb +0 -311
  124. data/spec/unit/plugins/os_spec.rb +0 -115
  125. data/spec/unit/plugins/packages_spec.rb +0 -353
  126. data/spec/unit/plugins/passwd_spec.rb +0 -65
  127. data/spec/unit/plugins/perl_spec.rb +0 -62
  128. data/spec/unit/plugins/php_spec.rb +0 -97
  129. data/spec/unit/plugins/platform_spec.rb +0 -65
  130. data/spec/unit/plugins/powershell_spec.rb +0 -71
  131. data/spec/unit/plugins/python_spec.rb +0 -51
  132. data/spec/unit/plugins/rackspace_spec.rb +0 -350
  133. data/spec/unit/plugins/root_group_spec.rb +0 -90
  134. data/spec/unit/plugins/ruby_spec.rb +0 -60
  135. data/spec/unit/plugins/rust_spec.rb +0 -43
  136. data/spec/unit/plugins/scala_spec.rb +0 -58
  137. data/spec/unit/plugins/scaleway_spec.rb +0 -93
  138. data/spec/unit/plugins/scsi_spec.rb +0 -69
  139. data/spec/unit/plugins/shard_spec.rb +0 -121
  140. data/spec/unit/plugins/shells_spec.rb +0 -56
  141. data/spec/unit/plugins/softlayer_spec.rb +0 -60
  142. data/spec/unit/plugins/solaris2/cpu_spec.rb +0 -2926
  143. data/spec/unit/plugins/solaris2/dmi_spec.rb +0 -153
  144. data/spec/unit/plugins/solaris2/filesystem.rb +0 -407
  145. data/spec/unit/plugins/solaris2/hostname_spec.rb +0 -37
  146. data/spec/unit/plugins/solaris2/kernel_spec.rb +0 -183
  147. data/spec/unit/plugins/solaris2/memory_spec.rb +0 -43
  148. data/spec/unit/plugins/solaris2/network_spec.rb +0 -201
  149. data/spec/unit/plugins/solaris2/platform_spec.rb +0 -108
  150. data/spec/unit/plugins/solaris2/virtualization_spec.rb +0 -97
  151. data/spec/unit/plugins/ssh_host_keys_spec.rb +0 -116
  152. data/spec/unit/plugins/sysconf_spec.rb +0 -680
  153. data/spec/unit/plugins/timezone_spec.rb +0 -30
  154. data/spec/unit/plugins/vbox_host_spec.rb +0 -14
  155. data/spec/unit/plugins/virtualbox_spec.rb +0 -375
  156. data/spec/unit/plugins/vmware_spec.rb +0 -81
  157. data/spec/unit/plugins/windows/cpu_spec.rb +0 -118
  158. data/spec/unit/plugins/windows/filesystem_spec.rb +0 -226
  159. data/spec/unit/plugins/windows/fips_spec.rb +0 -60
  160. data/spec/unit/plugins/windows/kernel_spec.rb +0 -79
  161. data/spec/unit/plugins/windows/memory_spec.rb +0 -52
  162. data/spec/unit/plugins/windows/network_spec.rb +0 -137
  163. data/spec/unit/plugins/windows/system_enclosure_spec.rb +0 -45
  164. data/spec/unit/plugins/windows/uptime_spec.rb +0 -38
  165. data/spec/unit/plugins/windows/virtualization_spec.rb +0 -63
  166. data/spec/unit/plugins/zpools_spec.rb +0 -244
  167. data/spec/unit/provides_map_spec.rb +0 -208
  168. data/spec/unit/runner_spec.rb +0 -422
  169. data/spec/unit/system_spec.rb +0 -416
  170. data/spec/unit/util/file_helper_spec.rb +0 -47
  171. data/spec/unit/util/ip_helper_spec.rb +0 -128
@@ -1,55 +0,0 @@
1
- #
2
- # Author:: Jacques Marneweck (<jacques@powertrip.co.za>)
3
- # Author:: Theodore Nordsieck (<theo@chef.io>)
4
- # Copyright:: Copyright (c) Jacques Marneweck
5
- # Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- require "spec_helper"
22
-
23
- describe Ohai::System, "plugin nodejs" do
24
-
25
- let(:plugin) { get_plugin("nodejs") }
26
-
27
- before do
28
- plugin[:languages] = Mash.new
29
- @stdout = "v0.8.11\n"
30
- allow(plugin).to receive(:shell_out).with("node -v").and_return(mock_shell_out(0, @stdout, ""))
31
- end
32
-
33
- it "gets the nodejs version from running node -v" do
34
- expect(plugin).to receive(:shell_out).with("node -v")
35
- plugin.run
36
- end
37
-
38
- it "sets languages[:nodejs][:version]" do
39
- plugin.run
40
- expect(plugin.languages[:nodejs][:version]).to eql("0.8.11")
41
- end
42
-
43
- it "does not set the languages[:nodejs] tree up if node command fails" do
44
- allow(plugin).to receive(:shell_out).with("node -v").and_return(mock_shell_out(1, "", ""))
45
- plugin.run
46
- expect(plugin.languages).not_to have_key(:nodejs)
47
- end
48
-
49
- it "does not set languages[:nodejs] if node command doesn't exist" do
50
- allow(plugin).to receive(:shell_out).and_raise(Ohai::Exceptions::Exec)
51
- plugin.run
52
- expect(plugin.languages).not_to have_key(:nodejs)
53
- end
54
-
55
- end
@@ -1,32 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Author:: Tollef Fog Heen <tfheen@err.no>
4
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
- # Copyright:: Copyright (c) 2010 Tollef Fog Heen <tfheen@err.no>
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- require "spec_helper"
22
-
23
- describe Ohai::System, "plugin ohai" do
24
- before do
25
- @plugin = get_plugin("ohai")
26
- end
27
-
28
- it "sets [:chef_packages][:ohai][:version] to the current version" do
29
- @plugin.run
30
- expect(@plugin[:chef_packages][:ohai][:version]).to eq(Ohai::VERSION)
31
- end
32
- end
@@ -1,44 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "spec_helper"
20
-
21
- describe Ohai::System, "plugin ohai_time" do
22
- before do
23
- @plugin = get_plugin("ohai_time")
24
- end
25
-
26
- it "gets the current time" do
27
- expect(Time).to receive(:now)
28
- @plugin.run
29
- end
30
-
31
- it "turns the time into a floating point number" do
32
- time = Time.now
33
- expect(time).to receive(:to_f)
34
- allow(Time).to receive(:now).and_return(time)
35
- @plugin.run
36
- end
37
-
38
- it "sets ohai_time to the current time" do
39
- time = Time.now
40
- allow(Time).to receive(:now).and_return(time)
41
- @plugin.run
42
- expect(@plugin[:ohai_time]).to eq(time.to_f)
43
- end
44
- end
@@ -1,43 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "spec_helper"
20
-
21
- describe Ohai::System, "OpenBSD hostname plugin" do
22
- before do
23
- @plugin = get_plugin("hostname")
24
- allow(@plugin).to receive(:collect_os).and_return(:openbsd)
25
- allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie\n", ""))
26
- allow(@plugin).to receive(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.local", ""))
27
- allow(@plugin).to receive(:resolve_fqdn).and_return("katie.bethell")
28
- end
29
-
30
- it_should_check_from("linux::hostname", "hostname", "hostname -s", "katie")
31
-
32
- it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local")
33
-
34
- it "uses #resolve_fqdn to find the fqdn" do
35
- @plugin.run
36
- expect(@plugin[:fqdn]).to eq("katie.bethell")
37
- end
38
-
39
- it "sets the domain to everything after the first dot of the fqdn" do
40
- @plugin.run
41
- expect(@plugin[:domain]).to eq("bethell")
42
- end
43
- end
@@ -1,36 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "spec_helper"
20
-
21
- describe Ohai::System, "OpenBSD kernel plugin" do
22
- before do
23
- @plugin = get_plugin("kernel")
24
- allow(@plugin).to receive(:collect_os).and_return(:openbsd)
25
- allow(@plugin).to receive(:init_kernel).and_return({})
26
- allow(@plugin).to receive(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo", ""))
27
- allow(@plugin).to receive(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1\n", ""))
28
- allow(@plugin).to receive(:shell_out).with( Ohai.abs_path( "/usr/bin/modstat" )).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", ""))
29
- end
30
-
31
- it "sets the kernel_os to the kernel_name value" do
32
- @plugin.run
33
- expect(@plugin[:kernel][:os]).to eq(@plugin[:kernel][:name])
34
- end
35
-
36
- end
@@ -1,33 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "spec_helper"
20
-
21
- describe Ohai::System, "OpenBSD plugin platform" do
22
- before do
23
- @plugin = get_plugin("openbsd/platform")
24
- allow(@plugin).to receive(:shell_out).with("uname -s").and_return(mock_shell_out(0, "OpenBSD\n", ""))
25
- allow(@plugin).to receive(:shell_out).with("uname -r").and_return(mock_shell_out(0, "4.5\n", ""))
26
- allow(@plugin).to receive(:collect_os).and_return(:openbsd)
27
- end
28
-
29
- it "sets platform_version to lsb[:release]" do
30
- @plugin.run
31
- expect(@plugin[:platform_version]).to eq("4.5")
32
- end
33
- end
@@ -1,311 +0,0 @@
1
- #
2
- # Author:: Daniel DeLeo (dan@chef.io)
3
- # Copyright:: Copyright (c) 2014-2016 Chef Software, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDIT"Net::HTTP Response"NS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "spec_helper"
20
-
21
- describe Ohai::System, "plugin openstack" do
22
-
23
- let(:plugin) { get_plugin("openstack") }
24
- let(:default_timeout) { 2 }
25
-
26
- before do
27
- PasswdEntry = Struct.new(:name, :uid, :gid, :dir, :shell, :gecos)
28
- allow(plugin).to receive(:hint?).with("openstack").and_return(false)
29
- plugin[:virtualization] = { systems: {} }
30
- end
31
-
32
- context "when there is no relevant hint or virtualization data" do
33
- it "does not set any openstack data" do
34
- plugin.run
35
- expect(plugin[:openstack]).to be_nil
36
- end
37
- end
38
-
39
- context "when virtualization data is Openstack", :unix_only do
40
- context "and the metadata service is not available" do
41
- before do
42
- allow(plugin).to receive(:can_socket_connect?)
43
- .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
44
- .and_return(false)
45
- plugin[:virtualization] = { systems: { openstack: "guest" } }
46
- expect(Etc).to receive(:getpwnam).and_raise(ArgumentError)
47
- plugin.run
48
- end
49
-
50
- it "sets provider attribute to openstack" do
51
- expect(plugin[:openstack][:provider]).to eq("openstack")
52
- end
53
-
54
- it "doesn't set metadata attributes" do
55
- expect(plugin[:openstack][:instance_id]).to be_nil
56
- end
57
- end
58
- end
59
-
60
- context "when running on dreamhost", :unix_only do
61
- it "sets openstack provider attribute to dreamhost" do
62
- plugin["etc"] = { "passwd" => { "dhc-user" => {} } }
63
- allow(plugin).to receive(:can_socket_connect?)
64
- .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
65
- .and_return(false)
66
- plugin[:virtualization] = { systems: { openstack: "guest" } }
67
- expect(Etc).to receive(:getpwnam).and_return(PasswdEntry.new("dhc-user", 800, 800, "/var/www", "/bin/false", "The dreamhost user"))
68
- plugin.run
69
- expect(plugin[:openstack][:provider]).to eq("dreamhost")
70
- end
71
- end
72
-
73
- context "when the hint is present" do
74
- context "and the metadata service is not available" do
75
- before do
76
- allow(plugin).to receive(:can_socket_connect?)
77
- .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
78
- .and_return(false)
79
- allow(plugin).to receive(:hint?).with("openstack").and_return(true)
80
- plugin.run
81
- end
82
-
83
- it "sets openstack provider attribute if the hint is provided" do
84
- expect(plugin[:openstack][:provider]).to eq("openstack")
85
- end
86
-
87
- it "doesn't set metadata attributes" do
88
- expect(plugin[:openstack][:instance_id]).to be_nil
89
- end
90
- context "when timout was set" do
91
- let(:override_timout) { 10 }
92
-
93
- before do
94
- Ohai::Config.ohai[:openstack_metadata_timeout] = override_timout
95
- end
96
-
97
- after do
98
- Ohai::Config.ohai[:openstack_metadata_timeout] = nil
99
- end
100
-
101
- it "overwrite timout by setting" do
102
- allow(plugin).to receive(:can_socket_connect?)
103
- .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, override_timout)
104
- .and_return(false)
105
- allow(plugin).to receive(:hint?).with("openstack").and_return(true)
106
- plugin.run
107
- end
108
- end
109
- end
110
-
111
- context "and the metadata service is available" do
112
-
113
- let(:metadata_version) { "2009-04-04" }
114
-
115
- let(:metadata_root) do
116
- <<~EOM
117
- reservation-id
118
- public-keys/
119
- security-groups
120
- public-ipv4
121
- ami-manifest-path
122
- instance-type
123
- instance-id
124
- local-ipv4
125
- ari-id
126
- local-hostname
127
- placement/
128
- ami-launch-index
129
- public-hostname
130
- hostname
131
- ami-id
132
- instance-action
133
- aki-id
134
- block-device-mapping/
135
- EOM
136
- end
137
-
138
- let(:metadata_values) do
139
- {
140
- "reservation-id" => "r-4tjvl99h",
141
- "public-keys/" => "0=dan-default",
142
- "public-keys/0/" => "openssh-key",
143
- "public-keys/0/openssh-key" => "SSH KEY DATA",
144
- "security-groups" => "default",
145
- "public-ipv4" => "172.31.7.2",
146
- "public-ipv6" => "",
147
- "ami-manifest-path" => "FIXME",
148
- "instance-type" => "opc-tester",
149
- "instance-id" => "i-0000162a",
150
- "local-ipv4" => "172.31.7.23",
151
- "ari-id" => "ari-00000037",
152
- "local-hostname" => "ohai-7-system-test.opscode.us",
153
- "placement/" => "availability-zone",
154
- "placement/availability-zone" => "nova",
155
- "ami-launch-index" => "0",
156
- "public-hostname" => "ohai-7-system-test.opscode.us",
157
- "hostname" => "ohai-7-system-test.opscode.us",
158
- "ami-id" => "ami-00000035",
159
- "instance-action" => "none",
160
- "aki-id" => "aki-00000036",
161
- "block-device-mapping/" => "ami\nroot",
162
- "block-device-mapping/ami" => "vda",
163
- "block-device-mapping/root" => "/dev/vda",
164
- }
165
- end
166
-
167
- let(:openstack_metadata_version) { "2009-04-04" }
168
- let(:openstack_metadata_endpoint) { "http://169.254.169.254/" }
169
-
170
- let(:openstack_metadata_values) do
171
- '{
172
- "availability_zone" : "nova",
173
- "hostname" : "ohai.novalocal",
174
- "launch_index" : 0,
175
- "meta" : {
176
- "priority" : "low",
177
- "role" : "ohaiserver"
178
- },
179
- "name" : "ohai_spec",
180
- "public_keys" : {
181
- "mykey" : "SSH KEY DATA"
182
- },
183
- "uuid" : "00000000-0000-0000-0000-100000000000"
184
- }'
185
- end
186
-
187
- let(:http_client) { double("Net::HTTP", { :read_timeout= => nil, :keep_alive_timeout= => nil } ) }
188
-
189
- def allow_get(url, response_body)
190
- allow(http_client).to receive(:get)
191
- .with(url)
192
- .and_return(double("HTTP Response", code: "200", body: response_body))
193
- end
194
-
195
- def allow_get_response(url, response_body)
196
- allow(http_client).to receive(:get_response)
197
- .with(url, nil, nil)
198
- .and_return(double("HTTP Response", code: "200", body: response_body))
199
- end
200
-
201
- before do
202
- allow(plugin).to receive(:hint?).with("openstack").and_return(true)
203
- allow(plugin).to receive(:can_socket_connect?)
204
- .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
205
- .and_return(true)
206
-
207
- allow(Net::HTTP).to receive(:start)
208
- .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR)
209
- .and_return(http_client)
210
-
211
- allow(plugin).to receive(:best_api_version).and_return(metadata_version)
212
-
213
- allow_get("/#{metadata_version}/meta-data/", metadata_root)
214
-
215
- metadata_values.each do |md_id, md_value|
216
- allow_get("/#{metadata_version}/meta-data/#{md_id}", md_value)
217
- end
218
-
219
- allow_get_response(
220
- URI.parse("#{openstack_metadata_endpoint}#{openstack_metadata_version}/meta_data.json"),
221
- openstack_metadata_values
222
- )
223
- plugin.run
224
- end
225
-
226
- it "reads the reservation_id from the metadata service" do
227
- expect(plugin["openstack"]["reservation_id"]).to eq("r-4tjvl99h")
228
- end
229
- it "reads the public_keys_0_openssh_key from the metadata service" do
230
- expect(plugin["openstack"]["public_keys_0_openssh_key"]).to eq("SSH KEY DATA")
231
- end
232
- it "reads the security_groups from the metadata service" do
233
- expect(plugin["openstack"]["security_groups"]).to eq(["default"])
234
- end
235
- it "reads the public_ipv4 from the metadata service" do
236
- expect(plugin["openstack"]["public_ipv4"]).to eq("172.31.7.2")
237
- end
238
- it "ignore the public_ipv6 from the metadata service when empty" do
239
- expect(plugin["openstack"]).not_to have_key("public_ipv6")
240
- end
241
- it "reads the ami_manifest_path from the metadata service" do
242
- expect(plugin["openstack"]["ami_manifest_path"]).to eq("FIXME")
243
- end
244
- it "reads the instance_type from the metadata service" do
245
- expect(plugin["openstack"]["instance_type"]).to eq("opc-tester")
246
- end
247
- it "reads the instance_id from the metadata service" do
248
- expect(plugin["openstack"]["instance_id"]).to eq("i-0000162a")
249
- end
250
- it "reads the local_ipv4 from the metadata service" do
251
- expect(plugin["openstack"]["local_ipv4"]).to eq("172.31.7.23")
252
- end
253
- it "reads the ari_id from the metadata service" do
254
- expect(plugin["openstack"]["ari_id"]).to eq("ari-00000037")
255
- end
256
- it "reads the local_hostname from the metadata service" do
257
- expect(plugin["openstack"]["local_hostname"]).to eq("ohai-7-system-test.opscode.us")
258
- end
259
- it "reads the placement_availability_zone from the metadata service" do
260
- expect(plugin["openstack"]["placement_availability_zone"]).to eq("nova")
261
- end
262
- it "reads the ami_launch_index from the metadata service" do
263
- expect(plugin["openstack"]["ami_launch_index"]).to eq("0")
264
- end
265
- it "reads the public_hostname from the metadata service" do
266
- expect(plugin["openstack"]["public_hostname"]).to eq("ohai-7-system-test.opscode.us")
267
- end
268
- it "reads the hostname from the metadata service" do
269
- expect(plugin["openstack"]["hostname"]).to eq("ohai-7-system-test.opscode.us")
270
- end
271
- it "reads the ami_id from the metadata service" do
272
- expect(plugin["openstack"]["ami_id"]).to eq("ami-00000035")
273
- end
274
- it "reads the instance_action from the metadata service" do
275
- expect(plugin["openstack"]["instance_action"]).to eq("none")
276
- end
277
- it "reads the aki_id from the metadata service" do
278
- expect(plugin["openstack"]["aki_id"]).to eq("aki-00000036")
279
- end
280
- it "reads the block_device_mapping_ami from the metadata service" do
281
- expect(plugin["openstack"]["block_device_mapping_ami"]).to eq("vda")
282
- end
283
- it "reads the block_device_mapping_root from the metadata service" do
284
- expect(plugin["openstack"]["block_device_mapping_root"]).to eq("/dev/vda")
285
- end
286
- it "sets the provider to openstack" do
287
- expect(plugin["openstack"]["provider"]).to eq("openstack")
288
- end
289
- end
290
- end
291
-
292
- context "when openstack virtualization is present" do
293
- context "and the metadata service is not available" do
294
- before do
295
- allow(plugin).to receive(:can_socket_connect?)
296
- .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
297
- .and_return(false)
298
- plugin[:virtualization] = { systems: { openstack: "guest" } }
299
- plugin.run
300
- end
301
-
302
- it "sets openstack provider attribute since virtualization is present" do
303
- expect(plugin[:openstack][:provider]).to eq("openstack")
304
- end
305
-
306
- it "doesn't set metadata attributes" do
307
- expect(plugin[:openstack][:instance_id]).to be_nil
308
- end
309
- end
310
- end
311
- end