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,98 +0,0 @@
1
- #
2
- # Author:: Davide Cavalca <dcavalca@fb.com>
3
- # Copyright:: Copyright (c) 2016 Facebook
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, "Linux sessions plugin" do
22
- let(:plugin) { get_plugin("linux/sessions") }
23
-
24
- before do
25
- allow(plugin).to receive(:collect_os).and_return(:linux)
26
- end
27
-
28
- it "populates sessions if loginctl is found" do
29
- loginctl_out = <<-LOGINCTL_OUT
30
- c1 118 Debian-gdm seat0
31
- 318 0 root
32
- 46 0 root
33
- 306 1000 joe
34
- LOGINCTL_OUT
35
- allow(plugin).to receive(:which).with("loginctl").and_return("/bin/loginctl")
36
- allow(plugin).to receive(:shell_out).with("/bin/loginctl --no-pager --no-legend --no-ask-password list-sessions").and_return(mock_shell_out(0, loginctl_out, ""))
37
- plugin.run
38
- expect(plugin[:sessions].to_hash).to eq({
39
- "by_session" => {
40
- "c1" => {
41
- "session" => "c1",
42
- "uid" => "118",
43
- "user" => "Debian-gdm",
44
- "seat" => "seat0",
45
- },
46
- "318" => {
47
- "session" => "318",
48
- "uid" => "0",
49
- "user" => "root",
50
- "seat" => nil,
51
- },
52
- "46" => {
53
- "session" => "46",
54
- "uid" => "0",
55
- "user" => "root",
56
- "seat" => nil,
57
- },
58
- "306" => {
59
- "session" => "306",
60
- "uid" => "1000",
61
- "user" => "joe",
62
- "seat" => nil,
63
- },
64
- },
65
- "by_user" => {
66
- "Debian-gdm" => [{
67
- "session" => "c1",
68
- "uid" => "118",
69
- "user" => "Debian-gdm",
70
- "seat" => "seat0",
71
- }],
72
- "root" => [{
73
- "session" => "318",
74
- "uid" => "0",
75
- "user" => "root",
76
- "seat" => nil,
77
- }, {
78
- "session" => "46",
79
- "uid" => "0",
80
- "user" => "root",
81
- "seat" => nil,
82
- }],
83
- "joe" => [{
84
- "session" => "306",
85
- "uid" => "1000",
86
- "user" => "joe",
87
- "seat" => nil,
88
- }],
89
- },
90
- })
91
- end
92
-
93
- it "does not populate sessions if loginctl is not found" do
94
- allow(plugin).to receive(:which).with("loginctl").and_return(false)
95
- plugin.run
96
- expect(plugin[:sessions]).to be(nil)
97
- end
98
- end
@@ -1,53 +0,0 @@
1
- #
2
- # Author:: Joshua Miller <joshmiller@fb.com>
3
- # Copyright:: Copyright (c) 2019 Facebook
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_relative "../../../spec_helper.rb"
20
-
21
- describe Ohai::System, "sysctl plugin", :unix_only do
22
- let(:plugin) { get_plugin("linux/sysctl") }
23
-
24
- it "should populate sysctl if sysctl is found" do
25
- sysctl_out = <<-SYSCTL_OUT
26
- vm.nr_overcommit_hugepages = 0
27
- vm.numa_stat = 1
28
- vm.numa_zonelist_order = Node
29
- vm.oom_dump_tasks = 1
30
- vm.oom_kill_allocating_task = 0
31
- vm.overcommit_kbytes = 0
32
- SYSCTL_OUT
33
- allow(plugin).to receive(:collect_os).and_return(:linux)
34
- allow(plugin).to receive(:which).with("sysctl").and_return("/usr/sbin/sysctl")
35
- allow(plugin).to receive(:shell_out).with("/usr/sbin/sysctl -a").and_return(mock_shell_out(0, sysctl_out, ""))
36
- plugin.run
37
- expect(plugin[:sysctl].to_hash).to eq({
38
- "vm.nr_overcommit_hugepages" => "0",
39
- "vm.numa_stat" => "1",
40
- "vm.numa_zonelist_order" => "Node",
41
- "vm.oom_dump_tasks" => "1",
42
- "vm.oom_kill_allocating_task" => "0",
43
- "vm.overcommit_kbytes" => "0",
44
- })
45
- end
46
-
47
- it "should not populate sysctl if sysctl is not found" do
48
- allow(plugin).to receive(:collect_os).and_return(:linux)
49
- allow(plugin).to receive(:which).with("sysctl").and_return(false)
50
- plugin.run
51
- expect(plugin[:sysctl]).to be(nil)
52
- end
53
- end
@@ -1,122 +0,0 @@
1
- #
2
- # Author:: Davide Cavalca <dcavalca@fb.com>
3
- # Copyright:: Copyright (c) 2017 Facebook
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 File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
20
-
21
- describe Ohai::System, "Linux systemd paths plugin" do
22
- let(:plugin) { get_plugin("linux/systemd_paths") }
23
-
24
- before do
25
- allow(plugin).to receive(:collect_os).and_return(:linux)
26
- end
27
-
28
- it "populates systemd_paths if systemd-path is found" do
29
- systemd_path_out = <<~SYSTEMD_PATH_OUT
30
- temporary: /tmp
31
- temporary-large: /var/tmp
32
- system-binaries: /usr/bin
33
- system-include: /usr/include
34
- system-library-private: /usr/lib
35
- system-library-arch: /usr/lib/x86_64-linux-gnu
36
- system-shared: /usr/share
37
- system-configuration-factory: /usr/share/factory/etc
38
- system-state-factory: /usr/share/factory/var
39
- system-configuration: /etc
40
- system-runtime: /run
41
- system-runtime-logs: /run/log
42
- system-state-private: /var/lib
43
- system-state-logs: /var/log
44
- system-state-cache: /var/cache
45
- system-state-spool: /var/spool
46
- user-binaries: /home/foo/.local/bin
47
- user-library-private: /home/foo/.local/lib
48
- user-library-arch: /home/foo/.local/lib/x86_64-linux-gnu
49
- user-shared: /home/foo/.local/share
50
- user-configuration: /home/foo/.config
51
- user-runtime: /run/user/1000
52
- user-state-cache: /home/foo/.cache
53
- user: /home/foo
54
- user-documents: /home/foo/Documents
55
- user-music: /home/foo/Music
56
- user-pictures: /home/foo/Pictures
57
- user-videos: /home/foo/Videos
58
- user-download: /home/foo/Downloads
59
- user-public: /home/foo/Public
60
- user-templates: /home/foo/Templates
61
- user-desktop: /home/foo/Desktop
62
- search-binaries: /home/foo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/facebook/bin:/home/foo/.rvm/bin:/home/foo/.rvm/bin
63
- search-library-private: /home/foo/.local/lib:/usr/local/lib:/usr/lib:/lib
64
- search-library-arch: /home/foo/.local/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu
65
- search-shared: /home/foo/.local/share:/usr/share/gnome:/home/foo/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
66
- search-configuration-factory: /usr/local/share/factory/etc:/usr/share/factory/etc
67
- search-state-factory: /usr/local/share/factory/var:/usr/share/factory/var
68
- search-configuration: /home/foo/.config:/etc
69
- SYSTEMD_PATH_OUT
70
-
71
- allow(plugin).to receive(:which).with("systemd-path").and_return("/bin/systemd-path")
72
- allow(plugin).to receive(:shell_out).with("/bin/systemd-path").and_return(mock_shell_out(0, systemd_path_out, ""))
73
- plugin.run
74
- expect(plugin[:systemd_paths].to_hash).to eq({
75
- "search-binaries" => "/home/foo/bin",
76
- "search-configuration" => "/home/foo/.config",
77
- "search-configuration-factory" => "/usr/local/share/factory/etc",
78
- "search-library-arch" => "/home/foo/.local/lib/x86_64-linux-gnu",
79
- "search-library-private" => "/home/foo/.local/lib",
80
- "search-shared" => "/home/foo/.local/share",
81
- "search-state-factory" => "/usr/local/share/factory/var",
82
- "system-binaries" => "/usr/bin",
83
- "system-configuration" => "/etc",
84
- "system-configuration-factory" => "/usr/share/factory/etc",
85
- "system-include" => "/usr/include",
86
- "system-library-arch" => "/usr/lib/x86_64-linux-gnu",
87
- "system-library-private" => "/usr/lib",
88
- "system-runtime" => "/run",
89
- "system-runtime-logs" => "/run/log",
90
- "system-shared" => "/usr/share",
91
- "system-state-cache" => "/var/cache",
92
- "system-state-factory" => "/usr/share/factory/var",
93
- "system-state-logs" => "/var/log",
94
- "system-state-private" => "/var/lib",
95
- "system-state-spool" => "/var/spool",
96
- "temporary" => "/tmp",
97
- "temporary-large" => "/var/tmp",
98
- "user" => "/home/foo",
99
- "user-binaries" => "/home/foo/.local/bin",
100
- "user-configuration" => "/home/foo/.config",
101
- "user-desktop" => "/home/foo/Desktop",
102
- "user-documents" => "/home/foo/Documents",
103
- "user-download" => "/home/foo/Downloads",
104
- "user-library-arch" => "/home/foo/.local/lib/x86_64-linux-gnu",
105
- "user-library-private" => "/home/foo/.local/lib",
106
- "user-music" => "/home/foo/Music",
107
- "user-pictures" => "/home/foo/Pictures",
108
- "user-public" => "/home/foo/Public",
109
- "user-runtime" => "/run/user/1000",
110
- "user-shared" => "/home/foo/.local/share",
111
- "user-state-cache" => "/home/foo/.cache",
112
- "user-templates" => "/home/foo/Templates",
113
- "user-videos" => "/home/foo/Videos",
114
- })
115
- end
116
-
117
- it "does not populate systemd paths if systemd-path is not found" do
118
- allow(plugin).to receive(:which).with("systemd-path").and_return(false)
119
- plugin.run
120
- expect(plugin[:systemd_paths]).to be(nil)
121
- end
122
- end
@@ -1,48 +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, "Linux plugin uptime" do
22
- before do
23
- @plugin = get_plugin("uptime")
24
- allow(@plugin).to receive(:collect_os).and_return(:linux)
25
- @double_file = double("/proc/uptime", { gets: "18423 989" })
26
- allow(File).to receive(:open).with("/proc/uptime").and_return(@double_file)
27
- end
28
-
29
- it "sets uptime_seconds to uptime" do
30
- @plugin.run
31
- expect(@plugin[:uptime_seconds]).to eq(18423)
32
- end
33
-
34
- it "sets uptime to a human readable date" do
35
- @plugin.run
36
- expect(@plugin[:uptime]).to eq("5 hours 07 minutes 03 seconds")
37
- end
38
-
39
- it "sets idletime_seconds to uptime" do
40
- @plugin.run
41
- expect(@plugin[:idletime_seconds]).to eq(989)
42
- end
43
-
44
- it "sets idletime to a human readable date" do
45
- @plugin.run
46
- expect(@plugin[:idletime]).to eq("16 minutes 29 seconds")
47
- end
48
- end
@@ -1,650 +0,0 @@
1
- #
2
- # Author:: Thom May (<thom@clearairturbulence.org>)
3
- # Copyright:: Copyright (c) 2009-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, "Linux virtualization platform" do
22
- let(:plugin) { get_plugin("linux/virtualization") }
23
-
24
- before do
25
- allow(plugin).to receive(:collect_os).and_return(:linux)
26
-
27
- # default to all requested Files not existing
28
- allow(File).to receive(:exist?).with("/proc/xen").and_return(false)
29
- allow(File).to receive(:exist?).with("/proc/xen/capabilities").and_return(false)
30
- allow(File).to receive(:exist?).with("/proc/modules").and_return(false)
31
- allow(File).to receive(:exist?).with("/proc/cpuinfo").and_return(false)
32
- allow(File).to receive(:exist?).with("/var/lib/hyperv/.kvp_pool_3").and_return(false)
33
- allow(File).to receive(:exist?).with("/proc/self/status").and_return(false)
34
- allow(File).to receive(:exist?).with("/proc/bc/0").and_return(false)
35
- allow(File).to receive(:exist?).with("/proc/vz").and_return(false)
36
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(false)
37
- allow(File).to receive(:exist?).with("/.dockerenv").and_return(false)
38
- allow(File).to receive(:exist?).with("/.dockerinit").and_return(false)
39
- allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(false)
40
- allow(File).to receive(:exist?).with("/dev/lxd/sock").and_return(false)
41
- allow(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(false)
42
- allow(File).to receive(:exist?).with("/var/snap/lxd/common/lxd/devlxd").and_return(false)
43
- allow(File).to receive(:exist?).with("/proc/1/environ").and_return(false)
44
-
45
- # default the which wrappers to nil
46
- allow(plugin).to receive(:which).with("lxc-version").and_return(nil)
47
- allow(plugin).to receive(:which).with("lxc-start").and_return(nil)
48
- allow(plugin).to receive(:which).with("docker").and_return(nil)
49
- allow(plugin).to receive(:nova_exists?).and_return(false)
50
- end
51
-
52
- describe "when we are checking for xen" do
53
- it "sets xen guest if /proc/xen exists but /proc/xen/capabilities does not" do
54
- expect(File).to receive(:exist?).with("/proc/xen").and_return(true)
55
- expect(File).to receive(:exist?).with("/proc/xen/capabilities").and_return(false)
56
- plugin.run
57
- expect(plugin[:virtualization][:system]).to eq("xen")
58
- expect(plugin[:virtualization][:role]).to eq("guest")
59
- expect(plugin[:virtualization][:systems][:xen]).to eq("guest")
60
- end
61
-
62
- it "sets xen host if /proc/xen/capabilities contains control_d " do
63
- expect(File).to receive(:exist?).with("/proc/xen").and_return(true)
64
- expect(File).to receive(:exist?).with("/proc/xen/capabilities").and_return(true)
65
- allow(File).to receive(:read).with("/proc/xen/capabilities").and_return("control_d")
66
- plugin.run
67
- expect(plugin[:virtualization][:system]).to eq("xen")
68
- expect(plugin[:virtualization][:role]).to eq("host")
69
- expect(plugin[:virtualization][:systems][:xen]).to eq("host")
70
- end
71
-
72
- it "sets xen guest if /proc/xen/capabilities exists but is empty" do
73
- expect(File).to receive(:exist?).with("/proc/xen").and_return(true)
74
- expect(File).to receive(:exist?).with("/proc/xen/capabilities").and_return(true)
75
- allow(File).to receive(:read).with("/proc/xen/capabilities").and_return("")
76
- plugin.run
77
- expect(plugin[:virtualization][:system]).to eq("xen")
78
- expect(plugin[:virtualization][:role]).to eq("guest")
79
- expect(plugin[:virtualization][:systems][:xen]).to eq("guest")
80
- end
81
-
82
- it "does not set virtualization if xen isn't there" do
83
- expect(File).to receive(:exist?).at_least(:once).and_return(false)
84
- plugin.run
85
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
86
- end
87
- end
88
-
89
- describe "when we are checking for docker" do
90
- it "sets docker host if docker binary exists" do
91
- allow(plugin).to receive(:which).with("docker").and_return(true)
92
- plugin.run
93
- expect(plugin[:virtualization][:system]).to eq("docker")
94
- expect(plugin[:virtualization][:role]).to eq("host")
95
- expect(plugin[:virtualization][:systems][:docker]).to eq("host")
96
- end
97
- end
98
-
99
- describe "when we are checking for openstack" do
100
- it "sets openstack host if nova binary exists" do
101
- allow(plugin).to receive(:nova_exists?).and_return("/usr/bin/nova")
102
- plugin.run
103
- expect(plugin[:virtualization][:system]).to eq("openstack")
104
- expect(plugin[:virtualization][:role]).to eq("host")
105
- expect(plugin[:virtualization][:systems][:openstack]).to eq("host")
106
- end
107
- end
108
-
109
- describe "when we are checking for kvm" do
110
- it "sets kvm guest if /sys/devices/virtual/misc/kvm exists & hypervisor cpu feature is present" do
111
- allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(true)
112
- allow(File).to receive(:read).with("/proc/cpuinfo").and_return("fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon rep_good nopl pni vmx ssse3 cx16 sse4_1 sse4_2 x2apic popcnt hypervisor lahf_lm vnmi ept tsc_adjust")
113
- plugin.run
114
- expect(plugin[:virtualization][:system]).to eq("kvm")
115
- expect(plugin[:virtualization][:role]).to eq("guest")
116
- expect(plugin[:virtualization][:systems][:kvm]).to eq("guest")
117
- end
118
-
119
- it "sets kvm host if /sys/devices/virtual/misc/kvm exists & hypervisor cpu feature is not present" do
120
- allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(true)
121
- allow(File).to receive(:read).with("/proc/cpuinfo").and_return("fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt lahf_lm ida dtherm tpr_shadow vnmi flexpriority ept vpid")
122
- plugin.run
123
- expect(plugin[:virtualization][:system]).to eq("kvm")
124
- expect(plugin[:virtualization][:role]).to eq("host")
125
- expect(plugin[:virtualization][:systems][:kvm]).to eq("host")
126
- end
127
-
128
- it "sets kvm guest if /proc/cpuinfo contains QEMU Virtual CPU" do
129
- expect(File).to receive(:exist?).with("/proc/cpuinfo").and_return(true)
130
- allow(File).to receive(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
131
- plugin.run
132
- expect(plugin[:virtualization][:system]).to eq("kvm")
133
- expect(plugin[:virtualization][:role]).to eq("guest")
134
- expect(plugin[:virtualization][:systems][:kvm]).to eq("guest")
135
- end
136
-
137
- it "sets kvm guest if /proc/cpuinfo contains Common KVM processor" do
138
- expect(File).to receive(:exist?).with("/proc/cpuinfo").and_return(true)
139
- allow(File).to receive(:read).with("/proc/cpuinfo").and_return("Common KVM processor")
140
- plugin.run
141
- expect(plugin[:virtualization][:system]).to eq("kvm")
142
- expect(plugin[:virtualization][:role]).to eq("guest")
143
- expect(plugin[:virtualization][:systems][:kvm]).to eq("guest")
144
- end
145
-
146
- it "sets kvm guest if /proc/cpuinfo contains Common 32-bit KVM processor" do
147
- expect(File).to receive(:exist?).with("/proc/cpuinfo").and_return(true)
148
- allow(File).to receive(:read).with("/proc/cpuinfo").and_return("Common 32-bit KVM processor")
149
- plugin.run
150
- expect(plugin[:virtualization][:system]).to eq("kvm")
151
- expect(plugin[:virtualization][:role]).to eq("guest")
152
- expect(plugin[:virtualization][:systems][:kvm]).to eq("guest")
153
- end
154
-
155
- it "does not set virtualization if kvm isn't there" do
156
- expect(File).to receive(:exist?).at_least(:once).and_return(false)
157
- plugin.run
158
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
159
- end
160
- end
161
-
162
- describe "when we are checking for VirtualBox" do
163
- it "sets vbox host if /proc/modules contains vboxdrv" do
164
- expect(File).to receive(:exist?).with("/proc/modules").and_return(true)
165
- allow(File).to receive(:read).with("/proc/modules").and_return("vboxdrv 268268 3 vboxnetadp,vboxnetflt")
166
- plugin.run
167
- expect(plugin[:virtualization][:system]).to eq("vbox")
168
- expect(plugin[:virtualization][:role]).to eq("host")
169
- expect(plugin[:virtualization][:systems][:vbox]).to eq("host")
170
- end
171
-
172
- it "sets vbox gues if /proc/modules contains vboxguest" do
173
- expect(File).to receive(:exist?).with("/proc/modules").and_return(true)
174
- allow(File).to receive(:read).with("/proc/modules").and_return("vboxguest 214901 2 vboxsf, Live 0xffffffffa00db000 (OF)")
175
- plugin.run
176
- expect(plugin[:virtualization][:system]).to eq("vbox")
177
- expect(plugin[:virtualization][:role]).to eq("guest")
178
- expect(plugin[:virtualization][:systems][:vbox]).to eq("guest")
179
- end
180
-
181
- it "does not set virtualization if vbox isn't there" do
182
- expect(File).to receive(:exist?).at_least(:once).and_return(false)
183
- plugin.run
184
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
185
- end
186
- end
187
-
188
- describe "when we are parsing DMI data" do
189
-
190
- it "sets virtualization attributes if the appropriate DMI data is present" do
191
- plugin[:dmi] = { system: {
192
- manufacturer: "Amazon EC2",
193
- product: "c5n.large",
194
- version: nil,
195
- },
196
- }
197
- plugin.run
198
- expect(plugin[:virtualization][:system]).to eq("amazonec2")
199
- expect(plugin[:virtualization][:role]).to eq("guest")
200
- expect(plugin[:virtualization][:systems][:amazonec2]).to eq("guest")
201
- end
202
-
203
- it "sets empty virtualization attributes if nothing is detected" do
204
- plugin[:dmi] = { system: {
205
- manufacturer: "Supermicro",
206
- product: "X10SLH-N6-ST031",
207
- version: "0123456789",
208
- },
209
- }
210
- plugin.run
211
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
212
- end
213
- end
214
-
215
- describe "when we are checking for Hyper-V guest and the hostname of the host" do
216
- it "sets Hyper-V guest if /var/lib/hyperv/.kvp_pool_3 contains hyper_v.example.com" do
217
- expect(File).to receive(:exist?).with("/var/lib/hyperv/.kvp_pool_3").and_return(true)
218
- allow(File).to receive(:read).with("/var/lib/hyperv/.kvp_pool_3").and_return("HostNamehyper_v.example.comHostingSystemEditionId")
219
- plugin.run
220
- expect(plugin[:virtualization][:system]).to eq("hyperv")
221
- expect(plugin[:virtualization][:role]).to eq("guest")
222
- expect(plugin[:virtualization][:systems]["hyperv"]).to eq("guest")
223
- expect(plugin[:virtualization]["hypervisor_host"]).to eq("hyper_v.example.com")
224
- end
225
- end
226
-
227
- describe "when we are checking for Linux-VServer" do
228
- it "sets Linux-VServer host if /proc/self/status contains s_context: 0" do
229
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
230
- allow(File).to receive(:read).with("/proc/self/status").and_return("s_context: 0")
231
- plugin.run
232
- expect(plugin[:virtualization][:system]).to eq("linux-vserver")
233
- expect(plugin[:virtualization][:role]).to eq("host")
234
- expect(plugin[:virtualization][:systems]["linux-vserver"]).to eq("host")
235
- end
236
-
237
- it "sets Linux-VServer host if /proc/self/status contains VxID: 0" do
238
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
239
- allow(File).to receive(:read).with("/proc/self/status").and_return("VxID: 0")
240
- plugin.run
241
- expect(plugin[:virtualization][:system]).to eq("linux-vserver")
242
- expect(plugin[:virtualization][:role]).to eq("host")
243
- expect(plugin[:virtualization][:systems]["linux-vserver"]).to eq("host")
244
- end
245
-
246
- it "sets Linux-VServer host if /proc/self/status contains multiple space VxID: 0" do
247
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
248
- allow(File).to receive(:read).with("/proc/self/status").and_return("VxID: 0")
249
- plugin.run
250
- expect(plugin[:virtualization][:system]).to eq("linux-vserver")
251
- expect(plugin[:virtualization][:role]).to eq("host")
252
- expect(plugin[:virtualization][:systems]["linux-vserver"]).to eq("host")
253
- end
254
-
255
- it "sets Linux-VServer host if /proc/self/status contains tabbed VxID:\t0" do
256
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
257
- allow(File).to receive(:read).with("/proc/self/status").and_return("VxID:\t0")
258
- plugin.run
259
- expect(plugin[:virtualization][:system]).to eq("linux-vserver")
260
- expect(plugin[:virtualization][:role]).to eq("host")
261
- expect(plugin[:virtualization][:systems]["linux-vserver"]).to eq("host")
262
- end
263
-
264
- it "sets Linux-VServer guest if /proc/self/status contains s_context > 0" do
265
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
266
- allow(File).to receive(:read).with("/proc/self/status").and_return("s_context: 2")
267
- plugin.run
268
- expect(plugin[:virtualization][:system]).to eq("linux-vserver")
269
- expect(plugin[:virtualization][:role]).to eq("guest")
270
- expect(plugin[:virtualization][:systems]["linux-vserver"]).to eq("guest")
271
- end
272
-
273
- it "sets Linux-VServer guest if /proc/self/status contains VxID > 0" do
274
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
275
- allow(File).to receive(:read).with("/proc/self/status").and_return("VxID: 2")
276
- plugin.run
277
- expect(plugin[:virtualization][:system]).to eq("linux-vserver")
278
- expect(plugin[:virtualization][:role]).to eq("guest")
279
- expect(plugin[:virtualization][:systems]["linux-vserver"]).to eq("guest")
280
- end
281
-
282
- it "does not set virtualization if Linux-VServer isn't there" do
283
- expect(File).to receive(:exist?).at_least(:once).and_return(false)
284
- plugin.run
285
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
286
- end
287
- end
288
-
289
- describe "when we are checking for openvz" do
290
- it "sets openvz host if /proc/bc/0 exists" do
291
- expect(File).to receive(:exist?).with("/proc/bc/0").and_return(true)
292
- plugin.run
293
- expect(plugin[:virtualization][:system]).to eq("openvz")
294
- expect(plugin[:virtualization][:role]).to eq("host")
295
- expect(plugin[:virtualization][:systems][:openvz]).to eq("host")
296
- end
297
-
298
- it "sets openvz guest if /proc/bc/0 does not exist and /proc/vz exists" do
299
- expect(File).to receive(:exist?).with("/proc/bc/0").and_return(false)
300
- expect(File).to receive(:exist?).with("/proc/vz").and_return(true)
301
- plugin.run
302
- expect(plugin[:virtualization][:system]).to eq("openvz")
303
- expect(plugin[:virtualization][:role]).to eq("guest")
304
- expect(plugin[:virtualization][:systems][:openvz]).to eq("guest")
305
- end
306
-
307
- it "does not set virtualization if openvz isn't there" do
308
- expect(File).to receive(:exist?).with("/proc/bc/0").and_return(false)
309
- expect(File).to receive(:exist?).with("/proc/vz").and_return(false)
310
- plugin.run
311
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
312
- end
313
- end
314
-
315
- describe "when we are checking for lxd" do
316
- it "sets lxc guest if /dev/lxd/sock exists" do
317
- expect(File).to receive(:exist?).with("/dev/lxd/sock").and_return(true)
318
-
319
- plugin.run
320
- expect(plugin[:virtualization][:system]).to eq("lxd")
321
- expect(plugin[:virtualization][:role]).to eq("guest")
322
- end
323
-
324
- it "sets lxd host if /var/lib/lxd/devlxd exists" do
325
- expect(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(true)
326
-
327
- plugin.run
328
- expect(plugin[:virtualization][:system]).to eq("lxd")
329
- expect(plugin[:virtualization][:role]).to eq("host")
330
- end
331
-
332
- it "sets lxd host if /var/snap/lxd/common/lxd/devlxd exists" do
333
- expect(File).to receive(:exist?).with("/var/snap/lxd/common/lxd/devlxd").and_return(true)
334
-
335
- plugin.run
336
- expect(plugin[:virtualization][:system]).to eq("lxd")
337
- expect(plugin[:virtualization][:role]).to eq("host")
338
- end
339
- end
340
-
341
- describe "when we are checking for lxc" do
342
- it "sets lxc guest if /proc/self/cgroup exist and there are /lxc/<hexadecimal> mounts" do
343
- self_cgroup = <<~CGROUP
344
- 8:blkio:/lxc/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
345
- 7:net_cls:/lxc/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
346
- 6:freezer:/lxc/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
347
- 5:devices:/lxc/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
348
- 4:memory:/lxc/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
349
- 3:cpuacct:/lxc/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
350
- 2:cpu:/lxc/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
351
- 1:cpuset:/
352
- CGROUP
353
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
354
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
355
- plugin.run
356
- expect(plugin[:virtualization][:system]).to eq("lxc")
357
- expect(plugin[:virtualization][:role]).to eq("guest")
358
- expect(plugin[:virtualization][:systems][:lxc]).to eq("guest")
359
- end
360
-
361
- it "sets lxc guest if /proc/self/cgroup exist and there are /lxc/<name> mounts" do
362
- self_cgroup = <<~CGROUP
363
- 8:blkio:/lxc/vanilla
364
- 7:net_cls:/lxc/vanilla
365
- 6:freezer:/lxc/vanilla
366
- 5:devices:/lxc/vanilla
367
- 4:memory:/lxc/vanilla
368
- 3:cpuacct:/lxc/vanilla
369
- 2:cpu:/lxc/vanilla
370
- 1:cpuset:/lxc/vanilla
371
- CGROUP
372
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
373
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
374
- plugin.run
375
- expect(plugin[:virtualization][:system]).to eq("lxc")
376
- expect(plugin[:virtualization][:role]).to eq("guest")
377
- expect(plugin[:virtualization][:systems][:lxc]).to eq("guest")
378
- end
379
-
380
- it "sets not set anything if /proc/self/cgroup exist and the cgroup is named arbitrarily, it isn't necessarily lxc." do
381
- self_cgroup = <<~CGROUP
382
- 8:blkio:/Charlie
383
- 7:net_cls:/Charlie
384
- 6:freezer:/Charlie
385
- 5:devices:/Charlie
386
- 4:memory:/Charlie
387
- 3:cpuacct:/Charlie
388
- 2:cpu:/Charlie
389
- 1:cpuset:/Charlie
390
- CGROUP
391
- allow(File).to receive(:read).with("/proc/1/environ").and_return("")
392
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
393
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
394
- plugin.run
395
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
396
- end
397
-
398
- context "/proc/self/cgroup only has / mounts" do
399
- before do
400
- self_cgroup = <<~CGROUP
401
- 8:blkio:/
402
- 7:net_cls:/
403
- 6:freezer:/
404
- 5:devices:/
405
- 4:memory:/
406
- 3:cpuacct:/
407
- 2:cpu:/
408
- 1:cpuset:/
409
- CGROUP
410
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
411
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
412
- allow(File).to receive(:read).with("/proc/1/environ").and_return("")
413
- end
414
-
415
- it "sets lxc host if lxc-version exists" do
416
- allow(plugin).to receive(:which).with("lxc-start").and_return("/usr/bin/lxc-version")
417
- plugin.run
418
- expect(plugin[:virtualization][:system]).to eq("lxc")
419
- expect(plugin[:virtualization][:role]).to eq("host")
420
- expect(plugin[:virtualization][:systems][:lxc]).to eq("host")
421
- end
422
-
423
- it "sets lxc host if lxc-start exists" do
424
- allow(plugin).to receive(:which).with("lxc-start").and_return("/usr/bin/lxc-start")
425
- plugin.run
426
- expect(plugin[:virtualization][:system]).to eq("lxc")
427
- expect(plugin[:virtualization][:role]).to eq("host")
428
- expect(plugin[:virtualization][:systems][:lxc]).to eq("host")
429
- end
430
-
431
- it "does not set the old virtualization attributes if they are already set" do
432
- allow(plugin).to receive(:which).with("lxc-version").and_return("/usr/bin/lxc-version")
433
- plugin[:virtualization] = Mash.new
434
- plugin[:virtualization][:system] = "the cloud"
435
- plugin[:virtualization][:role] = "cumulonimbus"
436
- plugin.run
437
- expect(plugin[:virtualization][:system]).not_to eq("lxc")
438
- expect(plugin[:virtualization][:role]).not_to eq("host")
439
- end
440
-
441
- it "does not set lxc host if neither lxc-version nor lxc-start exists" do
442
- plugin.run
443
- expect(plugin[:virtualization][:system]).to be_nil
444
- expect(plugin[:virtualization][:role]).to be_nil
445
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
446
- end
447
-
448
- it "sets lxc guest if /proc/1/environ has lxccontainer string in it" do
449
- one_environ = "container=lxccontainer_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3".chomp
450
- allow(File).to receive(:read).with("/proc/1/environ").and_return(one_environ)
451
- plugin.run
452
- expect(plugin[:virtualization][:system]).to eq("lxc")
453
- expect(plugin[:virtualization][:role]).to eq("guest")
454
- end
455
-
456
- end
457
-
458
- it "does not set virtualization if /proc/self/cgroup isn't there" do
459
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(false)
460
- plugin.run
461
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
462
- end
463
- end
464
-
465
- describe "when we are checking for systemd-nspawn" do
466
- it "sets nspawn guest if /proc/1/environ has nspawn string in it" do
467
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
468
- one_environ = "container=systemd-nspawn_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3".chomp
469
- allow(File).to receive(:read).with("/proc/1/environ").and_return(one_environ)
470
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return("")
471
- plugin.run
472
- expect(plugin[:virtualization][:system]).to eq("nspawn")
473
- expect(plugin[:virtualization][:role]).to eq("guest")
474
- end
475
- end
476
-
477
- describe "when we are checking for docker" do
478
- it "sets docker guest if /proc/self/cgroup exist and there are /docker/<hexadecimal> mounts" do
479
- self_cgroup = <<~CGROUP
480
- 8:blkio:/docker/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
481
- 7:net_cls:/docker/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
482
- 6:freezer:/docker/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
483
- 5:devices:/docker/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
484
- 4:memory:/docker/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
485
- 3:cpuacct:/docker/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
486
- 2:cpu:/docker/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
487
- 1:cpuset:/
488
- CGROUP
489
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
490
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
491
- plugin.run
492
- expect(plugin[:virtualization][:system]).to eq("docker")
493
- expect(plugin[:virtualization][:role]).to eq("guest")
494
- expect(plugin[:virtualization][:systems][:docker]).to eq("guest")
495
- end
496
-
497
- it "sets docker guest if /proc/self/cgroup exist and there are /docker/<name> mounts" do
498
- self_cgroup = <<~CGROUP
499
- 8:blkio:/docker/vanilla
500
- 7:net_cls:/docker/vanilla
501
- 6:freezer:/docker/vanilla
502
- 5:devices:/docker/vanilla
503
- 4:memory:/docker/vanilla
504
- 3:cpuacct:/docker/vanilla
505
- 2:cpu:/docker/vanilla
506
- 1:cpuset:/docker/vanilla
507
- CGROUP
508
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
509
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
510
- plugin.run
511
- expect(plugin[:virtualization][:system]).to eq("docker")
512
- expect(plugin[:virtualization][:role]).to eq("guest")
513
- expect(plugin[:virtualization][:systems][:docker]).to eq("guest")
514
- end
515
-
516
- it "sets docker guest if /proc/self/cgroup exist and there are /docker/docker-ce/<hexadecimal> mounts" do
517
- self_cgroup = <<~CGROUP
518
- 13:name=systemd:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
519
- 12:pids:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
520
- 11:hugetlb:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
521
- 10:net_prio:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
522
- 9:perf_event:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
523
- 8:net_cls:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
524
- 7:freezer:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
525
- 6:devices:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
526
- 5:memory:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
527
- 4:blkio:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
528
- 3:cpuacct:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
529
- 2:cpu:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
530
- 1:cpuset:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
531
- CGROUP
532
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
533
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
534
- plugin.run
535
- expect(plugin[:virtualization][:system]).to eq("docker")
536
- expect(plugin[:virtualization][:role]).to eq("guest")
537
- expect(plugin[:virtualization][:systems][:docker]).to eq("guest")
538
- end
539
-
540
- # Relevant at least starting docker 1.6.2, kernel 4.0.5 & systemd 224-1.
541
- # Doi not exactly know which software/version really matters here.
542
- it "sets docker guest if /proc/self/cgroup exists and there are /system.slice/docker-<hexadecimal> mounts (systemd managed cgroup)" do
543
- self_cgroup = <<~CGROUP
544
- 8:devices:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
545
- 7:cpuset:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
546
- 6:blkio:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
547
- 5:freezer:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
548
- 4:net_cls:/
549
- 3:memory:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
550
- 2:cpu,cpuacct:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
551
- 1:name=systemd:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
552
- CGROUP
553
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
554
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
555
- plugin.run
556
- expect(plugin[:virtualization][:system]).to eq("docker")
557
- expect(plugin[:virtualization][:role]).to eq("guest")
558
- expect(plugin[:virtualization][:systems][:docker]).to eq("guest")
559
- end
560
-
561
- it "sets not set anything if /proc/self/cgroup exist and the cgroup is named arbitrarily, it isn't necessarily lxc." do
562
- self_cgroup = <<~CGROUP
563
- 8:blkio:/Charlie
564
- 7:net_cls:/Charlie
565
- 6:freezer:/Charlie
566
- 5:devices:/Charlie
567
- 4:memory:/Charlie
568
- 3:cpuacct:/Charlie
569
- 2:cpu:/Charlie
570
- 1:cpuset:/Charlie
571
- CGROUP
572
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
573
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
574
- allow(File).to receive(:read).with("/proc/1/environ").and_return("")
575
- plugin.run
576
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
577
- end
578
-
579
- context "/proc/self/cgroup only has / mounts" do
580
- before do
581
- self_cgroup = <<~CGROUP
582
- 8:blkio:/
583
- 7:net_cls:/
584
- 6:freezer:/
585
- 5:devices:/
586
- 4:memory:/
587
- 3:cpuacct:/
588
- 2:cpu:/
589
- 1:cpuset:/
590
- CGROUP
591
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
592
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
593
- plugin.run
594
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
595
- end
596
-
597
- end
598
-
599
- it "does not set the old virtualization attributes if they are already set" do
600
- plugin[:virtualization] = Mash.new
601
- plugin[:virtualization][:system] = "the cloud"
602
- plugin[:virtualization][:role] = "cumulonimbus"
603
- plugin.run
604
- expect(plugin[:virtualization][:system]).not_to eq("docker")
605
- expect(plugin[:virtualization][:role]).not_to eq("host")
606
- end
607
-
608
- it "does not set docker host if docker does not exist" do
609
- plugin.run
610
- expect(plugin[:virtualization][:system]).to be_nil
611
- expect(plugin[:virtualization][:role]).to be_nil
612
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
613
- end
614
-
615
- it "does not set virtualization if /proc/self/cgroup isn't there" do
616
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(false)
617
- plugin.run
618
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
619
- end
620
-
621
- it "sets virtualization if /.dockerenv exists" do
622
- allow(File).to receive(:exist?).with("/.dockerenv").and_return(true)
623
- plugin.run
624
- expect(plugin[:virtualization][:system]).to eq("docker")
625
- expect(plugin[:virtualization][:role]).to eq("guest")
626
- expect(plugin[:virtualization][:systems][:docker]).to eq("guest")
627
- end
628
-
629
- it "sets virtualization if /.dockerinit exists" do
630
- allow(File).to receive(:exist?).with("/.dockerinit").and_return(true)
631
- plugin.run
632
- expect(plugin[:virtualization][:system]).to eq("docker")
633
- expect(plugin[:virtualization][:role]).to eq("guest")
634
- expect(plugin[:virtualization][:systems][:docker]).to eq("guest")
635
- end
636
-
637
- it "does not set virtualization if /.dockerenv or /.dockerinit does not exists" do
638
- allow(File).to receive(:exist?).with("/.dockerenv").and_return(false)
639
- allow(File).to receive(:exist?).with("/.dockerinit").and_return(false)
640
- plugin.run
641
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
642
- end
643
-
644
- end
645
-
646
- it "does not set virtualization if no tests match" do
647
- plugin.run
648
- expect(plugin[:virtualization]).to eq({ "systems" => {} })
649
- end
650
- end