ohai 14.15.0 → 15.0.35

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/ohai/application.rb +0 -4
  4. data/lib/ohai/common/dmi.rb +43 -43
  5. data/lib/ohai/config.rb +1 -1
  6. data/lib/ohai/loader.rb +32 -47
  7. data/lib/ohai/mixin/dmi_decode.rb +29 -32
  8. data/lib/ohai/mixin/os.rb +0 -2
  9. data/lib/ohai/mixin/softlayer_metadata.rb +5 -5
  10. data/lib/ohai/plugins/aix/virtualization.rb +4 -4
  11. data/lib/ohai/plugins/bsd/virtualization.rb +10 -12
  12. data/lib/ohai/plugins/c.rb +0 -20
  13. data/lib/ohai/plugins/elixir.rb +13 -13
  14. data/lib/ohai/plugins/filesystem.rb +10 -10
  15. data/lib/ohai/plugins/gce.rb +42 -8
  16. data/lib/ohai/plugins/go.rb +11 -11
  17. data/lib/ohai/plugins/groovy.rb +12 -12
  18. data/lib/ohai/plugins/hostname.rb +9 -2
  19. data/lib/ohai/plugins/linux/fips.rb +2 -9
  20. data/lib/ohai/plugins/linux/memory.rb +5 -0
  21. data/lib/ohai/plugins/linux/network.rb +1 -1
  22. data/lib/ohai/plugins/linux/platform.rb +84 -83
  23. data/lib/ohai/plugins/linux/systemd_paths.rb +0 -3
  24. data/lib/ohai/plugins/linux/virtualization.rb +10 -20
  25. data/lib/ohai/plugins/lua.rb +13 -13
  26. data/lib/ohai/plugins/mono.rb +23 -23
  27. data/lib/ohai/plugins/nodejs.rb +13 -13
  28. data/lib/ohai/plugins/openstack.rb +1 -1
  29. data/lib/ohai/plugins/packages.rb +1 -28
  30. data/lib/ohai/plugins/perl.rb +17 -17
  31. data/lib/ohai/plugins/php.rb +22 -22
  32. data/lib/ohai/plugins/powershell.rb +30 -30
  33. data/lib/ohai/plugins/ps.rb +1 -1
  34. data/lib/ohai/plugins/python.rb +15 -15
  35. data/lib/ohai/plugins/rust.rb +11 -11
  36. data/lib/ohai/plugins/solaris2/dmi.rb +48 -48
  37. data/lib/ohai/plugins/solaris2/virtualization.rb +8 -10
  38. data/lib/ohai/plugins/virtualbox.rb +21 -21
  39. data/lib/ohai/plugins/windows/filesystem.rb +2 -2
  40. data/lib/ohai/plugins/windows/fips.rb +2 -21
  41. data/lib/ohai/plugins/windows/virtualization.rb +9 -35
  42. data/lib/ohai/runner.rb +2 -2
  43. data/lib/ohai/system.rb +0 -17
  44. data/lib/ohai/version.rb +1 -1
  45. data/ohai.gemspec +2 -2
  46. data/spec/data/plugins/rpmquery.output +0 -2
  47. data/spec/functional/application_spec.rb +1 -1
  48. data/spec/functional/loader_spec.rb +2 -2
  49. data/spec/functional/plugins/powershell_spec.rb +2 -2
  50. data/spec/functional/plugins/root_group_spec.rb +1 -1
  51. data/spec/functional/plugins/windows/uptime_spec.rb +2 -2
  52. data/spec/ohai_spec.rb +1 -1
  53. data/spec/unit/application_spec.rb +1 -1
  54. data/spec/unit/config_spec.rb +1 -1
  55. data/spec/unit/dsl/plugin_spec.rb +1 -1
  56. data/spec/unit/hints_spec.rb +2 -2
  57. data/spec/unit/loader_spec.rb +12 -12
  58. data/spec/unit/mixin/azure_metadata_spec.rb +1 -1
  59. data/spec/unit/mixin/command_spec.rb +1 -1
  60. data/spec/unit/mixin/dmi_decode.rb +68 -0
  61. data/spec/unit/mixin/ec2_metadata_spec.rb +1 -1
  62. data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
  63. data/spec/unit/plugin_config_spec.rb +1 -1
  64. data/spec/unit/plugins/abort_spec.rb +9 -9
  65. data/spec/unit/plugins/aix/cpu_spec.rb +4 -4
  66. data/spec/unit/plugins/aix/filesystem_spec.rb +5 -5
  67. data/spec/unit/plugins/aix/hostname_spec.rb +1 -1
  68. data/spec/unit/plugins/aix/kernel_spec.rb +1 -1
  69. data/spec/unit/plugins/aix/memory_spec.rb +1 -1
  70. data/spec/unit/plugins/aix/network_spec.rb +6 -6
  71. data/spec/unit/plugins/aix/platform_spec.rb +1 -1
  72. data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
  73. data/spec/unit/plugins/aix/virtualization_spec.rb +2 -2
  74. data/spec/unit/plugins/azure_spec.rb +1 -1
  75. data/spec/unit/plugins/bsd/filesystem_spec.rb +4 -4
  76. data/spec/unit/plugins/bsd/virtualization_spec.rb +3 -3
  77. data/spec/unit/plugins/c_spec.rb +1 -53
  78. data/spec/unit/plugins/chef_spec.rb +1 -1
  79. data/spec/unit/plugins/cloud_spec.rb +1 -1
  80. data/spec/unit/plugins/darwin/cpu_spec.rb +2 -2
  81. data/spec/unit/plugins/darwin/filesystem_spec.rb +5 -5
  82. data/spec/unit/plugins/darwin/hardware_spec.rb +2 -2
  83. data/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +3 -3
  84. data/spec/unit/plugins/darwin/hostname_spec.rb +1 -1
  85. data/spec/unit/plugins/darwin/kernel_spec.rb +1 -1
  86. data/spec/unit/plugins/darwin/memory_spec.rb +1 -1
  87. data/spec/unit/plugins/darwin/network_spec.rb +1 -1
  88. data/spec/unit/plugins/darwin/platform_spec.rb +1 -1
  89. data/spec/unit/plugins/darwin/virtualization_spec.rb +1 -1
  90. data/spec/unit/plugins/dmi_spec.rb +1 -1
  91. data/spec/unit/plugins/docker_spec.rb +1 -1
  92. data/spec/unit/plugins/ec2_spec.rb +1 -1
  93. data/spec/unit/plugins/elixir_spec.rb +1 -1
  94. data/spec/unit/plugins/erlang_spec.rb +1 -1
  95. data/spec/unit/plugins/eucalyptus_spec.rb +1 -1
  96. data/spec/unit/plugins/fail_spec.rb +28 -28
  97. data/spec/unit/plugins/freebsd/cpu_spec.rb +1 -1
  98. data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -1
  99. data/spec/unit/plugins/freebsd/kernel_spec.rb +1 -1
  100. data/spec/unit/plugins/freebsd/platform_spec.rb +1 -1
  101. data/spec/unit/plugins/gce_spec.rb +1 -1
  102. data/spec/unit/plugins/go_spec.rb +1 -1
  103. data/spec/unit/plugins/groovy_spec.rb +1 -1
  104. data/spec/unit/plugins/haskell_spec.rb +1 -1
  105. data/spec/unit/plugins/hostname_spec.rb +68 -1
  106. data/spec/unit/plugins/init_package_spec.rb +1 -1
  107. data/spec/unit/plugins/java_spec.rb +1 -1
  108. data/spec/unit/plugins/joyent_spec.rb +3 -3
  109. data/spec/unit/plugins/kernel_spec.rb +1 -1
  110. data/spec/unit/plugins/linode_spec.rb +1 -1
  111. data/spec/unit/plugins/linux/block_device_spec.rb +1 -1
  112. data/spec/unit/plugins/linux/cpu_spec.rb +6 -6
  113. data/spec/unit/plugins/linux/filesystem_spec.rb +21 -21
  114. data/spec/unit/plugins/linux/fips_spec.rb +13 -45
  115. data/spec/unit/plugins/linux/hostname_spec.rb +1 -1
  116. data/spec/unit/plugins/linux/hostnamectl_spec.rb +2 -2
  117. data/spec/unit/plugins/linux/kernel_spec.rb +8 -8
  118. data/spec/unit/plugins/linux/lsb_spec.rb +3 -3
  119. data/spec/unit/plugins/linux/lspci_spec.rb +2 -2
  120. data/spec/unit/plugins/linux/machineid_spec.rb +1 -1
  121. data/spec/unit/plugins/linux/mdadm_spec.rb +2 -2
  122. data/spec/unit/plugins/linux/memory_spec.rb +26 -1
  123. data/spec/unit/plugins/linux/network_spec.rb +37 -37
  124. data/spec/unit/plugins/linux/platform_spec.rb +580 -837
  125. data/spec/unit/plugins/linux/sessions_spec.rb +2 -2
  126. data/spec/unit/plugins/linux/systemd_paths_spec.rb +1 -1
  127. data/spec/unit/plugins/linux/uptime_spec.rb +1 -1
  128. data/spec/unit/plugins/linux/virtualization_spec.rb +28 -227
  129. data/spec/unit/plugins/lua_spec.rb +1 -1
  130. data/spec/unit/plugins/mono_spec.rb +2 -2
  131. data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -1
  132. data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -1
  133. data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
  134. data/spec/unit/plugins/network_spec.rb +11 -11
  135. data/spec/unit/plugins/nodejs_spec.rb +1 -1
  136. data/spec/unit/plugins/ohai_spec.rb +1 -1
  137. data/spec/unit/plugins/ohai_time_spec.rb +1 -1
  138. data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -1
  139. data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -1
  140. data/spec/unit/plugins/openbsd/platform_spec.rb +1 -1
  141. data/spec/unit/plugins/openstack_spec.rb +8 -4
  142. data/spec/unit/plugins/os_spec.rb +1 -1
  143. data/spec/unit/plugins/packages_spec.rb +1 -21
  144. data/spec/unit/plugins/passwd_spec.rb +1 -1
  145. data/spec/unit/plugins/perl_spec.rb +1 -1
  146. data/spec/unit/plugins/php_spec.rb +6 -6
  147. data/spec/unit/plugins/platform_spec.rb +1 -1
  148. data/spec/unit/plugins/powershell_spec.rb +3 -3
  149. data/spec/unit/plugins/python_spec.rb +1 -1
  150. data/spec/unit/plugins/rackspace_spec.rb +2 -2
  151. data/spec/unit/plugins/root_group_spec.rb +1 -11
  152. data/spec/unit/plugins/ruby_spec.rb +1 -1
  153. data/spec/unit/plugins/rust_spec.rb +1 -1
  154. data/spec/unit/plugins/scala_spec.rb +1 -1
  155. data/spec/unit/plugins/scsi_spec.rb +2 -2
  156. data/spec/unit/plugins/shard_spec.rb +1 -1
  157. data/spec/unit/plugins/shells_spec.rb +1 -1
  158. data/spec/unit/plugins/softlayer_spec.rb +1 -1
  159. data/spec/unit/plugins/solaris2/cpu_spec.rb +3 -3
  160. data/spec/unit/plugins/solaris2/dmi_spec.rb +1 -1
  161. data/spec/unit/plugins/solaris2/filesystem.rb +4 -4
  162. data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
  163. data/spec/unit/plugins/solaris2/kernel_spec.rb +1 -1
  164. data/spec/unit/plugins/solaris2/memory_spec.rb +1 -1
  165. data/spec/unit/plugins/solaris2/network_spec.rb +6 -6
  166. data/spec/unit/plugins/solaris2/platform_spec.rb +3 -3
  167. data/spec/unit/plugins/solaris2/virtualization_spec.rb +41 -69
  168. data/spec/unit/plugins/ssh_host_keys_spec.rb +3 -3
  169. data/spec/unit/plugins/sysconf_spec.rb +2 -2
  170. data/spec/unit/plugins/timezone_spec.rb +1 -1
  171. data/spec/unit/plugins/virtualbox_spec.rb +1 -1
  172. data/spec/unit/plugins/vmware_spec.rb +1 -1
  173. data/spec/unit/plugins/windows/cpu_spec.rb +1 -2
  174. data/spec/unit/plugins/windows/filesystem_spec.rb +2 -2
  175. data/spec/unit/plugins/windows/fips_spec.rb +17 -77
  176. data/spec/unit/plugins/windows/kernel_spec.rb +1 -1
  177. data/spec/unit/plugins/windows/memory_spec.rb +2 -2
  178. data/spec/unit/plugins/windows/network_spec.rb +1 -1
  179. data/spec/unit/plugins/windows/system_enclosure_spec.rb +1 -1
  180. data/spec/unit/plugins/windows/uptime_spec.rb +1 -1
  181. data/spec/unit/plugins/windows/virtualization_spec.rb +20 -238
  182. data/spec/unit/plugins/zpools_spec.rb +7 -7
  183. data/spec/unit/provides_map_spec.rb +1 -1
  184. data/spec/unit/runner_spec.rb +1 -1
  185. data/spec/unit/system_spec.rb +10 -77
  186. data/spec/unit/util/file_helper_spec.rb +1 -1
  187. data/spec/unit/util/ip_helper_spec.rb +1 -1
  188. metadata +6 -9
  189. data/lib/ohai/plugins/darwin/system_profiler.rb +0 -72
  190. data/lib/ohai/util/win32/group_helper.rb +0 -76
  191. data/spec/unit/plugins/darwin/system_profiler_output.rb +0 -79524
  192. data/spec/unit/plugins/darwin/system_profiler_spec.rb +0 -40
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2017, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 2008-2018, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,1045 +16,788 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_relative "../../../spec_helper.rb"
19
+ require "spec_helper"
20
20
 
21
21
  describe Ohai::System, "Linux plugin platform" do
22
+ let(:plugin) { get_plugin("linux/platform") }
22
23
 
23
- let(:have_debian_version) { false }
24
- let(:have_redhat_release) { false }
25
- let(:have_gentoo_release) { false }
26
- let(:have_exherbo_release) { false }
27
- let(:have_alpine_release) { false }
28
- let(:have_eos_release) { false }
29
- let(:have_suse_release) { false }
30
- let(:have_arch_release) { false }
31
- let(:have_system_release) { false }
32
- let(:have_slackware_version) { false }
33
- let(:have_enterprise_release) { false }
34
- let(:have_oracle_release) { false }
35
- let(:have_parallels_release) { false }
36
- let(:have_raspi_config) { false }
37
- let(:have_os_release) { false }
38
- let(:have_usr_lib_os_release) { false }
39
- let(:have_cisco_release) { false }
40
- let(:have_f5_release) { false }
41
- let(:have_cumulus_dir) { false }
42
-
43
- before(:each) do
44
- @plugin = get_plugin("linux/platform")
45
- allow(@plugin).to receive(:collect_os).and_return(:linux)
46
- @plugin[:lsb] = Mash.new
47
- allow(File).to receive(:exist?).with("/etc/debian_version").and_return(have_debian_version)
48
- allow(File).to receive(:exist?).with("/etc/redhat-release").and_return(have_redhat_release)
49
- allow(File).to receive(:exist?).with("/etc/gentoo-release").and_return(have_gentoo_release)
50
- allow(File).to receive(:exist?).with("/etc/exherbo-release").and_return(have_exherbo_release)
51
- allow(File).to receive(:exist?).with("/etc/alpine-release").and_return(have_alpine_release)
52
- allow(File).to receive(:exist?).with("/etc/Eos-release").and_return(have_eos_release)
53
- allow(File).to receive(:exist?).with("/etc/SuSE-release").and_return(have_suse_release)
54
- allow(File).to receive(:exist?).with("/etc/arch-release").and_return(have_arch_release)
55
- allow(File).to receive(:exist?).with("/etc/system-release").and_return(have_system_release)
56
- allow(File).to receive(:exist?).with("/etc/slackware-version").and_return(have_slackware_version)
57
- allow(File).to receive(:exist?).with("/etc/enterprise-release").and_return(have_enterprise_release)
58
- allow(File).to receive(:exist?).with("/etc/oracle-release").and_return(have_oracle_release)
59
- allow(File).to receive(:exist?).with("/etc/parallels-release").and_return(have_parallels_release)
60
- allow(File).to receive(:exist?).with("/usr/bin/raspi-config").and_return(have_raspi_config)
61
- allow(File).to receive(:exist?).with("/etc/os-release").and_return(have_os_release)
62
- allow(File).to receive(:exist?).with("/etc/f5-release").and_return(have_f5_release)
63
- allow(File).to receive(:exist?).with("/usr/lib/os-release").and_return(have_usr_lib_os_release)
64
- allow(File).to receive(:exist?).with("/etc/shared/os-release").and_return(have_cisco_release)
65
- allow(Dir).to receive(:exist?).with("/etc/cumulus").and_return(have_cumulus_dir)
66
-
67
- allow(File).to receive(:read).with("PLEASE STUB ALL File.read CALLS")
68
- end
69
-
70
- describe "on lsb compliant distributions" do
71
- before(:each) do
72
- @plugin[:lsb][:id] = "Ubuntu"
73
- @plugin[:lsb][:release] = "8.04"
74
- end
75
-
76
- it "should set platform to lowercased lsb[:id]" do
77
- @plugin.run
78
- expect(@plugin[:platform]).to eq("ubuntu")
79
- end
80
-
81
- it "should set platform_version to lsb[:release]" do
82
- @plugin.run
83
- expect(@plugin[:platform_version]).to eq("8.04")
84
- end
85
-
86
- it "should set platform to ubuntu and platform_family to debian [:lsb][:id] contains Ubuntu" do
87
- @plugin[:lsb][:id] = "Ubuntu"
88
- @plugin.run
89
- expect(@plugin[:platform]).to eq("ubuntu")
90
- expect(@plugin[:platform_family]).to eq("debian")
91
- end
92
-
93
- it "should set platform to linuxmint and platform_family to debian [:lsb][:id] contains LinuxMint" do
94
- @plugin[:lsb][:id] = "LinuxMint"
95
- @plugin.run
96
- expect(@plugin[:platform]).to eq("linuxmint")
97
- expect(@plugin[:platform_family]).to eq("debian")
98
- end
99
-
100
- it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do
101
- @plugin[:lsb][:id] = "Debian"
102
- @plugin.run
103
- expect(@plugin[:platform]).to eq("debian")
104
- expect(@plugin[:platform_family]).to eq("debian")
105
- end
106
-
107
- it "should set platform to redhat and platform_family to rhel when [:lsb][:id] contains Redhat" do
108
- @plugin[:lsb][:id] = "RedHatEnterpriseServer"
109
- @plugin[:lsb][:release] = "5.7"
110
- @plugin.run
111
- expect(@plugin[:platform]).to eq("redhat")
112
- expect(@plugin[:platform_family]).to eq("rhel")
113
- end
114
-
115
- it "should set platform to amazon and platform_family to rhel when [:lsb][:id] contains Amazon" do
116
- @plugin[:lsb][:id] = "AmazonAMI"
117
- @plugin[:lsb][:release] = "2011.09"
118
- @plugin.run
119
- expect(@plugin[:platform]).to eq("amazon")
120
- expect(@plugin[:platform_family]).to eq("amazon")
24
+ describe "#read_os_release_info" do
25
+ let(:file_contents) { "COW=MOO\nDOG=\"BARK\"" }
26
+ it "returns nil if the file does not exist" do
27
+ allow(File).to receive(:exist?).with("/etc/test-release").and_return(false)
28
+ expect(plugin.read_os_release_info("/etc/test-release")).to be nil
121
29
  end
122
30
 
123
- it "should set platform to scientific when [:lsb][:id] contains ScientificSL" do
124
- @plugin[:lsb][:id] = "ScientificSL"
125
- @plugin[:lsb][:release] = "5.7"
126
- @plugin.run
127
- expect(@plugin[:platform]).to eq("scientific")
128
- end
31
+ it "returns a hash of expected contents" do
32
+ allow(File).to receive(:exist?).with("/etc/test-release").and_return(true)
33
+ allow(File).to receive(:read).with("/etc/test-release").and_return(file_contents)
34
+ release_info = plugin.read_os_release_info("/etc/test-release")
129
35
 
130
- it "should set platform to ibm_powerkvm and platform_family to rhel when [:lsb][:id] contains IBM_PowerKVM" do
131
- @plugin[:lsb][:id] = "IBM_PowerKVM"
132
- @plugin[:lsb][:release] = "2.1"
133
- @plugin.run
134
- expect(@plugin[:platform]).to eq("ibm_powerkvm")
135
- expect(@plugin[:platform_family]).to eq("rhel")
36
+ expect(release_info["COW"]).to eq("MOO")
37
+ expect(release_info["DOG"]).to eq("BARK")
136
38
  end
137
39
  end
138
40
 
139
- describe "on debian" do
140
-
141
- let(:have_debian_version) { true }
142
-
143
- before(:each) do
144
- @plugin.lsb = nil
145
- end
146
-
147
- it "should read the version from /etc/debian_version" do
148
- expect(File).to receive(:read).with("/etc/debian_version").and_return("5.0")
149
- @plugin.run
150
- expect(@plugin[:platform_version]).to eq("5.0")
151
- end
152
-
153
- it "should correctly strip any newlines" do
154
- expect(File).to receive(:read).with("/etc/debian_version").and_return("5.0\n")
155
- @plugin.run
156
- expect(@plugin[:platform_version]).to eq("5.0")
157
- end
158
-
159
- # Ubuntu has /etc/debian_version as well
160
- it "should detect Ubuntu as itself rather than debian" do
161
- @plugin[:lsb][:id] = "Ubuntu"
162
- @plugin[:lsb][:release] = "8.04"
163
- @plugin.run
164
- expect(@plugin[:platform]).to eq("ubuntu")
165
- end
41
+ describe "#os_release_info" do
42
+ context "when CISCO_RELEASE_INFO is not populated" do
43
+ let(:release_info) { { "ID" => "os_id" } }
166
44
 
167
- context "on raspbian" do
45
+ before do
46
+ allow(File).to receive(:exist?).with("/etc/os-release").and_return(true)
47
+ allow(plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
48
+ end
168
49
 
169
- let(:have_raspi_config) { true }
50
+ it "reads the os-release file" do
51
+ expect(plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
52
+ plugin.os_release_info
53
+ end
170
54
 
171
- # Raspbian is a debian clone
172
- it "should detect Raspbian as itself with debian as the family" do
173
- expect(File).to receive(:read).with("/etc/debian_version").and_return("wheezy/sid")
174
- @plugin.run
175
- expect(@plugin[:platform]).to eq("raspbian")
176
- expect(@plugin[:platform_family]).to eq("debian")
55
+ it "returns a hash of expected contents" do
56
+ expect(plugin.os_release_info["ID"]).to eq("os_id")
177
57
  end
178
58
  end
179
59
 
180
- context "on cumulus" do
181
-
182
- let(:have_cumulus_dir) { true }
183
- let(:cumulus_release_content) do
184
- <<~OS_RELEASE
185
- NAME="Cumulus Linux"
186
- VERSION_ID=3.1.2
187
- VERSION="Cumulus Linux 3.1.2"
188
- PRETTY_NAME="Cumulus Linux"
189
- ID=cumulus-linux
190
- ID_LIKE=debian
191
- CPE_NAME=cpe:/o:cumulusnetworks:cumulus_linux:3.1.2
192
- HOME_URL="http://www.cumulusnetworks.com/"
193
- SUPPORT_URL="http://support.cumulusnetworks.com/"
194
-
195
- OS_RELEASE
196
- end
60
+ context "when CISCO_RELEASE_INFO is populated" do
61
+ let(:release_info) { { "ID" => "os_id", "CISCO_RELEASE_INFO" => "/etc/cisco-release" } }
62
+ let(:cisco_release_info) { { "ID" => "cisco_id" } }
197
63
 
198
- before(:each) do
199
- expect(File).to receive(:read).with("/etc/cumulus/etc.replace/os-release").and_return(cumulus_release_content)
64
+ before do
65
+ allow(File).to receive(:exist?).with("/etc/os-release").and_return(true)
66
+ allow(File).to receive(:exist?).with("/etc/cisco-release").and_return(true)
67
+ allow(plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
68
+ allow(plugin).to receive(:read_os_release_info).with("/etc/cisco-release").and_return(cisco_release_info)
200
69
  end
201
70
 
202
- # Cumulus is a debian derivative
203
- it "should detect Cumulus as itself with debian as the family" do
204
- @plugin.run
205
- expect(@plugin[:platform]).to eq("cumulus")
206
- expect(@plugin[:platform_family]).to eq("debian")
71
+ it "reads the os-release AND the cisco-release file" do
72
+ expect(plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
73
+ expect(plugin).to receive(:read_os_release_info).with("/etc/cisco-release").and_return(release_info)
74
+ plugin.os_release_info
207
75
  end
208
76
 
209
- it "should detect Cumulus platform_version" do
210
- @plugin.run
211
- expect(@plugin[:platform_version]).to eq("3.1.2")
77
+ it "returns the ID from the cisco-release file instead of the os-release file" do
78
+ expect(plugin.os_release_info["ID"]).to eq("cisco_id")
212
79
  end
213
80
  end
214
81
  end
215
82
 
216
- describe "on slackware" do
217
-
218
- let(:have_slackware_version) { true }
219
-
220
- before(:each) do
221
- @plugin.lsb = nil
83
+ describe "#platform_id_remap" do
84
+ # https://github.com/chef/os_release/blob/master/redhat_7
85
+ it "returns redhat for rhel os-release id" do
86
+ expect(plugin.platform_id_remap("rhel")).to eq("redhat")
222
87
  end
223
88
 
224
- it "should set platform and platform_family to slackware" do
225
- expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
226
- @plugin.run
227
- expect(@plugin[:platform]).to eq("slackware")
228
- expect(@plugin[:platform_family]).to eq("slackware")
89
+ # https://github.com/chef/os_release/blob/master/amazon_2018
90
+ it "returns amazon for amzn os-release id" do
91
+ expect(plugin.platform_id_remap("amzn")).to eq("amazon")
229
92
  end
230
93
 
231
- it "should set platform_version on slackware" do
232
- expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
233
- @plugin.run
234
- expect(@plugin[:platform_version]).to eq("12.0.0")
94
+ # https://github.com/chef/os_release/blob/master/oracle_7
95
+ it "returns oracle for ol os-release id" do
96
+ expect(plugin.platform_id_remap("ol")).to eq("oracle")
235
97
  end
236
- end
237
-
238
- describe "on arch" do
239
-
240
- let(:have_arch_release) { true }
241
98
 
242
- before(:each) do
243
- @plugin.lsb = nil
99
+ # https://github.com/chef/os_release/blob/master/sles_sap_12_3
100
+ it "returns suse for sles_sap os-release id" do
101
+ expect(plugin.platform_id_remap("sles_sap")).to eq("suse")
244
102
  end
245
103
 
246
- it "should set platform to arch and platform_family to arch" do
247
- @plugin.run
248
- expect(@plugin[:platform]).to eq("arch")
249
- expect(@plugin[:platform_family]).to eq("arch")
104
+ # https://github.com/chef/os_release/blob/master/sles_15_0
105
+ it "returns suse for sles os-release id" do
106
+ expect(plugin.platform_id_remap("sles")).to eq("suse")
250
107
  end
251
108
 
252
- it "should set platform_version to kernel release" do
253
- expect(@plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.2-2-ARCH\n", ""))
254
- @plugin.run
255
- expect(@plugin[:platform_version]).to eq("3.18.2-2-ARCH")
109
+ # https://github.com/chef/os_release/blob/master/opensuseleap_15_0
110
+ it "returns opensuseleap for opensuse-leap os-release id" do
111
+ expect(plugin.platform_id_remap("opensuse-leap")).to eq("opensuseleap")
256
112
  end
257
- end
258
113
 
259
- describe "on gentoo" do
260
-
261
- let(:have_gentoo_release) { true }
114
+ # https://github.com/chef/os_release/blob/master/xenserver_7_6
115
+ it "returns xenserver for xenenterprise os-release id" do
116
+ expect(plugin.platform_id_remap("xenenterprise")).to eq("xenserver")
117
+ end
262
118
 
263
- before(:each) do
264
- @plugin.lsb = nil
119
+ # https://github.com/chef/os_release/blob/master/cumulus_3_7
120
+ it "returns cumulus for cumulus-linux os-release id" do
121
+ expect(plugin.platform_id_remap("cumulus-linux")).to eq("cumulus")
265
122
  end
266
123
 
267
- it "should set platform and platform_family to gentoo" do
268
- @plugin.run
269
- expect(@plugin[:platform]).to eq("gentoo")
270
- expect(@plugin[:platform_family]).to eq("gentoo")
124
+ it "does not transformation for any other platform" do
125
+ expect(plugin.platform_id_remap("ubuntu")).to eq("ubuntu")
271
126
  end
272
127
 
273
- it "should set platform_version to kernel release" do
274
- expect(@plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.7-gentoo\n", ""))
275
- @plugin.run
276
- expect(@plugin[:platform_version]).to eq("3.18.7-gentoo")
128
+ context "on a centos subshell on a nexus switch" do
129
+ let(:os_release_content) do
130
+ <<~OS_RELEASE
131
+ NAME="CentOS Linux"
132
+ VERSION="7 (Core)"
133
+ ID="centos"
134
+ ID_LIKE="rhel fedora"
135
+ VERSION_ID="7"
136
+ PRETTY_NAME="CentOS Linux 7 (Core)"
137
+
138
+ CISCO_RELEASE_INFO=/etc/shared/os-release
139
+ OS_RELEASE
140
+ end
141
+
142
+ let(:cisco_release_content) do
143
+ <<~CISCO_RELEASE
144
+ ID=nexus
145
+ ID_LIKE=wrlinux
146
+ NAME=Nexus
147
+ VERSION="7.0(3)I2(0.475E.6)"
148
+ VERSION_ID="7.0(3)I2"
149
+ PRETTY_NAME="Nexus 7.0(3)I2"
150
+ HOME_URL=http://www.cisco.com
151
+ BUILD_ID=6
152
+ CISCO_RELEASE_INFO=/etc/shared/os-release
153
+ CISCO_RELEASE
154
+ end
155
+
156
+ it "returns nexus_centos for centos os-release id" do
157
+ expect(File).to receive(:exist?).at_least(:once).with("/etc/shared/os-release").and_return(true)
158
+ expect(File).to receive(:exist?).at_least(:once).with("/etc/os-release").and_return(true)
159
+ expect(File).to receive(:read).with("/etc/os-release").and_return(os_release_content)
160
+ expect(File).to receive(:read).with("/etc/shared/os-release").and_return(cisco_release_content)
161
+ expect(plugin.platform_id_remap("centos")).to eq("nexus_centos")
162
+ end
277
163
  end
278
164
  end
279
165
 
280
- describe "on alpine" do
281
-
282
- let(:have_alpine_release) { true }
283
-
284
- before(:each) do
285
- @plugin.lsb = nil
166
+ describe "#platform_family_from_platform" do
167
+ %w{oracle centos redhat scientific enterpriseenterprise xenserver cloudlinux ibm_powerkvm parallels nexus_centos clearos bigip}.each do |p|
168
+ it "returns rhel for #{p} platform" do
169
+ expect(plugin.platform_family_from_platform(p)).to eq("rhel")
170
+ end
286
171
  end
287
172
 
288
- it "should set platform and platform_family to alpine" do
289
- expect(File).to receive(:read).with("/etc/alpine-release").and_return("3.2.3")
290
- @plugin.run
291
- expect(@plugin[:platform]).to eq("alpine")
292
- expect(@plugin[:platform_family]).to eq("alpine")
293
- expect(@plugin[:platform_version]).to eq("3.2.3")
173
+ %w{suse sles opensuse opensuseleap sled}.each do |p|
174
+ it "returns suse for #{p} platform_family" do
175
+ expect(plugin.platform_family_from_platform(p)).to eq("suse")
176
+ end
294
177
  end
295
- end
296
-
297
- describe "on arista eos" do
298
178
 
299
- let(:have_system_release) { true }
300
- let(:have_redhat_release) { true }
301
- let(:have_eos_release) { true }
302
-
303
- before(:each) do
304
- @plugin.lsb = nil
179
+ %w{fedora pidora arista_eos}.each do |p|
180
+ it "returns fedora for #{p} platform_family" do
181
+ expect(plugin.platform_family_from_platform(p)).to eq("fedora")
182
+ end
305
183
  end
306
184
 
307
- it "should set platform to arista_eos" do
308
- expect(File).to receive(:read).with("/etc/Eos-release").and_return("Arista Networks EOS 4.21.1.1F")
309
- @plugin.run
310
- expect(@plugin[:platform]).to eq("arista_eos")
311
- expect(@plugin[:platform_family]).to eq("fedora")
312
- expect(@plugin[:platform_version]).to eq("4.21.1.1F")
185
+ %w{nexus ios_xr}.each do |p|
186
+ it "returns wrlinux for #{p} platform_family" do
187
+ expect(plugin.platform_family_from_platform(p)).to eq("wrlinux")
188
+ end
313
189
  end
314
- end
315
-
316
- describe "on f5 big-ip" do
317
190
 
318
- let(:have_f5_release) { true }
191
+ %w{arch manjaro antergos}.each do |p|
192
+ it "returns arch for #{p} platform_family" do
193
+ expect(plugin.platform_family_from_platform(p)).to eq("arch")
194
+ end
195
+ end
319
196
 
320
- before(:each) do
321
- @plugin.lsb = nil
197
+ %w{amazon slackware gentoo exherbo alpine clearlinux}.each do |same_name|
198
+ it "returns #{same_name} for #{same_name} platform_family" do
199
+ expect(plugin.platform_family_from_platform(same_name)).to eq(same_name)
200
+ end
322
201
  end
323
202
 
324
- it "should set platform to bigip" do
325
- expect(File).to receive(:read).with("/etc/f5-release").and_return("BIG-IP release 13.0.0 (Final)")
326
- @plugin.run
327
- expect(@plugin[:platform]).to eq("bigip")
328
- expect(@plugin[:platform_family]).to eq("rhel")
329
- expect(@plugin[:platform_version]).to eq("13.0.0")
203
+ it "returns mandriva for mangeia platform" do
204
+ expect(plugin.platform_family_from_platform("mangeia")).to eq("mandriva")
330
205
  end
331
206
  end
332
207
 
333
- describe "on exherbo" do
334
-
335
- let(:have_exherbo_release) { true }
336
-
208
+ describe "on system with /etc/os-release" do
337
209
  before(:each) do
338
- @plugin.lsb = nil
339
- end
340
-
341
- it "should set platform and platform_family to exherbo" do
342
- @plugin.run
343
- expect(@plugin[:platform]).to eq("exherbo")
344
- expect(@plugin[:platform_family]).to eq("exherbo")
210
+ allow(plugin).to receive(:collect_os).and_return(:linux)
211
+ allow(::File).to receive(:exist?).with("/etc/os-release").and_return(true)
345
212
  end
346
213
 
347
- it "should set platform_version to kernel release" do
348
- expect(@plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.2-2-ARCH", ""))
349
- @plugin.run
350
- expect(@plugin[:platform_version]).to eq("3.18.2-2-ARCH")
351
- end
214
+ context "when os-release data is correct" do
215
+ let(:os_data) do
216
+ <<~OS_DATA
217
+ NAME="Ubuntu"
218
+ VERSION="14.04.5 LTS, Trusty Tahr"
219
+ ID=ubuntu
220
+ ID_LIKE=debian
221
+ PRETTY_NAME="Ubuntu 14.04.5 LTS"
222
+ VERSION_ID="14.04"
223
+ OS_DATA
224
+ end
352
225
 
353
- end
226
+ before(:each) do
227
+ expect(File).to receive(:read).with("/etc/os-release").and_return(os_data)
228
+ end
354
229
 
355
- describe "on redhat breeds" do
356
- describe "with lsb_release results" do
357
- it "should set the platform to redhat and platform_family to rhel even if the LSB name is something absurd but redhat like" do
358
- @plugin[:lsb][:id] = "RedHatEnterpriseServer"
359
- @plugin[:lsb][:release] = "6.1"
360
- @plugin.run
361
- expect(@plugin[:platform]).to eq("redhat")
362
- expect(@plugin[:platform_version]).to eq("6.1")
363
- expect(@plugin[:platform_family]).to eq("rhel")
230
+ it "should set platform, platform_family, and platform_version from os-release" do
231
+ plugin.run
232
+ expect(plugin[:platform]).to eq("ubuntu")
233
+ expect(plugin[:platform_family]).to eq("debian")
234
+ expect(plugin[:platform_version]).to eq("14.04")
364
235
  end
236
+ end
365
237
 
366
- it "should set the platform to centos and platform_family to rhel" do
367
- @plugin[:lsb][:id] = "CentOS"
368
- @plugin[:lsb][:release] = "5.4"
369
- @plugin.run
370
- expect(@plugin[:platform]).to eq("centos")
371
- expect(@plugin[:platform_version]).to eq("5.4")
372
- expect(@plugin[:platform_family]).to eq("rhel")
238
+ context "when os-release data is missing a version_id" do
239
+ let(:os_data) do
240
+ <<~OS_DATA
241
+ NAME="Arch Linux"
242
+ PRETTY_NAME="Arch Linux"
243
+ ID=arch
244
+ ID_LIKE=archlinux
245
+ OS_DATA
373
246
  end
374
247
 
375
- it "should set the platform_family to rhel if the LSB name is oracle-ish" do
376
- @plugin[:lsb][:id] = "EnterpriseEnterpriseServer"
377
- @plugin.run
378
- expect(@plugin[:platform_family]).to eq("rhel")
248
+ before(:each) do
249
+ expect(File).to receive(:read).with("/etc/os-release").and_return(os_data)
379
250
  end
380
251
 
381
- it "should set the platform_family to rhel if the LSB name is amazon-ish" do
382
- @plugin[:lsb][:id] = "Amazon"
383
- @plugin.run
384
- expect(@plugin[:platform_family]).to eq("amazon")
252
+ it "should set platform_version using kernel version from uname" do
253
+ allow(plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.2-2-ARCH\n", ""))
254
+ plugin.run
255
+ expect(plugin[:platform]).to eq("arch")
256
+ expect(plugin[:platform_family]).to eq("arch")
257
+ expect(plugin[:platform_version]).to eq("3.18.2-2-ARCH")
385
258
  end
259
+ end
386
260
 
387
- it "should set the platform_family to fedora if the LSB name is fedora-ish" do
388
- @plugin[:lsb][:id] = "Fedora"
389
- @plugin.run
390
- expect(@plugin[:platform_family]).to eq("fedora")
261
+ context "when platform requires remapping" do
262
+ let(:os_data) do
263
+ <<~OS_DATA
264
+ NAME="openSUSE Leap"
265
+ VERSION="15.0"
266
+ ID="opensuse-leap"
267
+ ID_LIKE="suse opensuse"
268
+ VERSION_ID="15.0"
269
+ PRETTY_NAME="openSUSE Leap 15.0"
270
+ OS_DATA
391
271
  end
392
272
 
393
- it "should set the platform_family to redhat if the LSB name is scientific-ish" do
394
- @plugin[:lsb][:id] = "Scientific"
395
- @plugin.run
396
- expect(@plugin[:platform_family]).to eq("rhel")
273
+ before(:each) do
274
+ expect(File).to receive(:read).with("/etc/os-release").and_return(os_data)
397
275
  end
398
276
 
399
- it "should set the platform_family to redhat if the LSB name is ibm-ish" do
400
- @plugin[:lsb][:id] = "IBM_PowerKVM"
401
- @plugin.run
402
- expect(@plugin[:platform_family]).to eq("rhel")
277
+ it "should set platform, platform_family, and platform_version from os-release" do
278
+ plugin.run
279
+ expect(plugin[:platform]).to eq("opensuseleap")
280
+ expect(plugin[:platform_family]).to eq("suse")
281
+ expect(plugin[:platform_version]).to eq("15.0")
403
282
  end
404
283
  end
405
284
 
406
- describe "without lsb_release results" do
407
-
408
- let(:have_redhat_release) { true }
285
+ context "when on centos where version data in os-release is wrong" do
286
+ let(:os_data) do
287
+ <<~OS_DATA
288
+ NAME="CentOS Linux"
289
+ VERSION="7 (Core)"
290
+ ID="centos"
291
+ ID_LIKE="rhel fedora"
292
+ VERSION_ID="7"
293
+ PRETTY_NAME="CentOS Linux 7 (Core)"
294
+ OS_DATA
295
+ end
409
296
 
410
297
  before(:each) do
411
- @plugin.lsb = nil
298
+ expect(File).to receive(:read).with("/etc/os-release").and_return(os_data)
299
+ expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)")
412
300
  end
413
301
 
414
- it "should read the platform as centos and version as 5.3" do
415
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS release 5.3")
416
- @plugin.run
417
- expect(@plugin[:platform]).to eq("centos")
302
+ it "should set platform, platform_family, and platform_version from os-release" do
303
+ plugin.run
304
+ expect(plugin[:platform]).to eq("centos")
305
+ expect(plugin[:platform_family]).to eq("rhel")
306
+ expect(plugin[:platform_version]).to eq("7.5.1804")
418
307
  end
308
+ end
309
+ end
419
310
 
420
- it "may be that someone munged Red Hat to be RedHat" do
421
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("RedHat release 5.3")
422
- @plugin.run
423
- expect(@plugin[:platform]).to eq("redhat")
424
- expect(@plugin[:platform_version]).to eq("5.3")
425
- end
311
+ context "on system without /etc/os-release (legacy)" do
312
+ let(:have_debian_version) { false }
313
+ let(:have_redhat_release) { false }
314
+ let(:have_exherbo_release) { false }
315
+ let(:have_eos_release) { false }
316
+ let(:have_suse_release) { false }
317
+ let(:have_system_release) { false }
318
+ let(:have_slackware_version) { false }
319
+ let(:have_enterprise_release) { false }
320
+ let(:have_oracle_release) { false }
321
+ let(:have_parallels_release) { false }
322
+ let(:have_os_release) { false }
323
+ let(:have_os_release) { false }
324
+ let(:have_usr_lib_os_release) { false }
325
+ let(:have_cisco_release) { false }
326
+ let(:have_f5_release) { false }
426
327
 
427
- it "should read the platform as redhat and version as 5.3" do
428
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat release 5.3")
429
- @plugin.run
430
- expect(@plugin[:platform]).to eq("redhat")
431
- expect(@plugin[:platform_version]).to eq("5.3")
328
+ before(:each) do
329
+ allow(plugin).to receive(:collect_os).and_return(:linux)
330
+ plugin[:lsb] = Mash.new
331
+ allow(File).to receive(:exist?).with("/etc/debian_version").and_return(have_debian_version)
332
+ allow(File).to receive(:exist?).with("/etc/redhat-release").and_return(have_redhat_release)
333
+ allow(File).to receive(:exist?).with("/etc/exherbo-release").and_return(have_exherbo_release)
334
+ allow(File).to receive(:exist?).with("/etc/Eos-release").and_return(have_eos_release)
335
+ allow(File).to receive(:exist?).with("/etc/SuSE-release").and_return(have_suse_release)
336
+ allow(File).to receive(:exist?).with("/etc/system-release").and_return(have_system_release)
337
+ allow(File).to receive(:exist?).with("/etc/slackware-version").and_return(have_slackware_version)
338
+ allow(File).to receive(:exist?).with("/etc/enterprise-release").and_return(have_enterprise_release)
339
+ allow(File).to receive(:exist?).with("/etc/oracle-release").and_return(have_oracle_release)
340
+ allow(File).to receive(:exist?).with("/etc/parallels-release").and_return(have_parallels_release)
341
+ allow(File).to receive(:exist?).with("/etc/os-release").and_return(have_os_release)
342
+ allow(File).to receive(:exist?).with("/etc/f5-release").and_return(have_f5_release)
343
+ allow(File).to receive(:exist?).with("/usr/lib/os-release").and_return(have_usr_lib_os_release)
344
+ allow(File).to receive(:exist?).with("/etc/shared/os-release").and_return(have_cisco_release)
345
+
346
+ allow(File).to receive(:read).with("PLEASE STUB ALL File.read CALLS")
347
+ end
348
+
349
+ describe "on lsb compliant distributions" do
350
+ before(:each) do
351
+ plugin[:lsb][:id] = "Ubuntu"
352
+ plugin[:lsb][:release] = "18.04"
432
353
  end
433
354
 
434
- it "should read the platform as fedora and version as 13 (rawhide)" do
435
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)")
436
- @plugin.run
437
- expect(@plugin[:platform]).to eq("fedora")
438
- expect(@plugin[:platform_version]).to eq("13 (rawhide)")
355
+ it "should set platform to lowercased lsb[:id]" do
356
+ plugin.run
357
+ expect(plugin[:platform]).to eq("ubuntu")
439
358
  end
440
359
 
441
- it "should read the platform as fedora and version as 10" do
442
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("Fedora release 10")
443
- @plugin.run
444
- expect(@plugin[:platform]).to eq("fedora")
445
- expect(@plugin[:platform_version]).to eq("10")
360
+ it "should set platform_version to lsb[:release]" do
361
+ plugin.run
362
+ expect(plugin[:platform_version]).to eq("18.04")
446
363
  end
447
364
 
448
- it "should read the platform as fedora and version as 13 using to_i" do
449
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)")
450
- @plugin.run
451
- expect(@plugin[:platform]).to eq("fedora")
452
- expect(@plugin[:platform_version].to_i).to eq(13)
365
+ it "should set platform to ubuntu and platform_family to debian [:lsb][:id] contains Ubuntu" do
366
+ plugin[:lsb][:id] = "Ubuntu"
367
+ plugin.run
368
+ expect(plugin[:platform]).to eq("ubuntu")
369
+ expect(plugin[:platform_family]).to eq("debian")
453
370
  end
454
371
 
455
- it "should read the platform as clearos and version as 7.3" do
456
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("ClearOS release 7.3.0 (Final)")
457
- @plugin.run
458
- expect(@plugin[:platform]).to eq("clearos")
459
- expect(@plugin[:platform_family]).to eq("rhel")
460
- expect(@plugin[:platform_version].to_f).to eq(7.3)
372
+ it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do
373
+ plugin[:lsb][:id] = "Debian"
374
+ plugin.run
375
+ expect(plugin[:platform]).to eq("debian")
376
+ expect(plugin[:platform_family]).to eq("debian")
461
377
  end
462
378
 
463
- it "should read the platform as amazon and version as 2 on the RC release" do
464
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("Amazon Linux release 2 (2017.12) LTS Release Candidate")
465
- @plugin.run
466
- expect(@plugin[:platform]).to eq("amazon")
467
- expect(@plugin[:platform_family]).to eq("amazon")
468
- expect(@plugin[:platform_version].to_f).to eq(2)
379
+ it "should set platform to redhat and platform_family to rhel when [:lsb][:id] contains Redhat" do
380
+ plugin[:lsb][:id] = "RedHatEnterpriseServer"
381
+ plugin[:lsb][:release] = "7.5"
382
+ plugin.run
383
+ expect(plugin[:platform]).to eq("redhat")
384
+ expect(plugin[:platform_family]).to eq("rhel")
469
385
  end
470
386
 
471
- it "should read the platform as amazon and version as 2 on the final release" do
472
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("Amazon Linux 2")
473
- @plugin.run
474
- expect(@plugin[:platform]).to eq("amazon")
475
- expect(@plugin[:platform_family]).to eq("amazon")
476
- expect(@plugin[:platform_version].to_f).to eq(2)
387
+ it "should set platform to amazon and platform_family to rhel when [:lsb][:id] contains Amazon" do
388
+ plugin[:lsb][:id] = "AmazonAMI"
389
+ plugin[:lsb][:release] = "2018.03"
390
+ plugin.run
391
+ expect(plugin[:platform]).to eq("amazon")
392
+ expect(plugin[:platform_family]).to eq("amazon")
477
393
  end
478
394
 
479
- # https://github.com/chef/ohai/issues/560
480
- # Issue is seen on EL7, so that's what we're testing.
481
- context "on versions that have /etc/os-release" do
482
-
483
- let(:have_os_release) { true }
484
-
485
- let(:os_release_content) do
486
- <<~OS_RELEASE
487
- NAME="CentOS Linux"
488
- VERSION="7 (Core)"
489
- ID="centos"
490
- ID_LIKE="rhel fedora"
491
- VERSION_ID="7"
492
- PRETTY_NAME="CentOS Linux 7 (Core)"
493
- ANSI_COLOR="0;31"
494
- CPE_NAME="cpe:/o:centos:centos:7"
495
- HOME_URL="https://www.centos.org/"
496
- BUG_REPORT_URL="https://bugs.centos.org/"
497
-
498
- OS_RELEASE
499
- end
500
-
501
- before do
502
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS release 7.1")
503
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_release_content)
504
- end
505
-
506
- it "correctly detects EL7" do
507
- @plugin.run
508
- expect(@plugin[:platform]).to eq("centos")
509
- expect(@plugin[:platform_version]).to eq("7.1")
510
- end
511
-
395
+ it "should set platform to scientific when [:lsb][:id] contains ScientificSL" do
396
+ plugin[:lsb][:id] = "ScientificSL"
397
+ plugin[:lsb][:release] = "7.5"
398
+ plugin.run
399
+ expect(plugin[:platform]).to eq("scientific")
512
400
  end
513
401
 
514
- context "on 'guestshell' with /etc/os-release and overrides for Cisco Nexus" do
515
-
516
- let(:have_os_release) { true }
517
-
518
- let(:os_release_content) do
519
- <<~OS_RELEASE
520
- NAME="CentOS Linux"
521
- VERSION="7 (Core)"
522
- ID="centos"
523
- ID_LIKE="rhel fedora"
524
- VERSION_ID="7"
525
- PRETTY_NAME="CentOS Linux 7 (Core)"
526
- ANSI_COLOR="0;31"
527
- CPE_NAME="cpe:/o:centos:centos:7"
528
- HOME_URL="https://www.centos.org/"
529
- BUG_REPORT_URL="https://bugs.centos.org/"
530
-
531
- CENTOS_MANTISBT_PROJECT="CentOS-7"
532
- CENTOS_MANTISBT_PROJECT_VERSION="7"
533
- REDHAT_SUPPORT_PRODUCT="centos"
534
- REDHAT_SUPPORT_PRODUCT_VERSION="7"
535
-
536
- CISCO_RELEASE_INFO=/etc/shared/os-release
537
- OS_RELEASE
538
- end
539
-
540
- let(:have_cisco_release) { true }
541
-
542
- let(:cisco_release_content) do
543
- <<~CISCO_RELEASE
544
- ID=nexus
545
- ID_LIKE=wrlinux
546
- NAME=Nexus
547
- VERSION="7.0(3)I2(0.475E.6)"
548
- VERSION_ID="7.0(3)I2"
549
- PRETTY_NAME="Nexus 7.0(3)I2"
550
- HOME_URL=http://www.cisco.com
551
- BUILD_ID=6
552
- CISCO_RELEASE_INFO=/etc/os-release
553
- CISCO_RELEASE
554
- end
555
-
556
- before do
557
- expect(File).to receive(:read).at_least(:once).with("/etc/os-release").and_return(os_release_content)
558
- expect(File).to receive(:read).with("/etc/shared/os-release").and_return(cisco_release_content)
559
- end
560
-
561
- it "should set platform to nexus_guestshell and platform_family to rhel" do
562
- @plugin.run
563
- expect(@plugin[:platform]).to start_with("nexus")
564
- expect(@plugin[:platform]).to eq("nexus_centos")
565
- expect(@plugin[:platform_family]).to eq("rhel")
566
- expect(@plugin[:platform_version]).to eq("7.0(3)I2(0.475E.6)")
567
- end
402
+ it "should set platform to ibm_powerkvm and platform_family to rhel when [:lsb][:id] contains IBM_PowerKVM" do
403
+ plugin[:lsb][:id] = "IBM_PowerKVM"
404
+ plugin[:lsb][:release] = "2.1"
405
+ plugin.run
406
+ expect(plugin[:platform]).to eq("ibm_powerkvm")
407
+ expect(plugin[:platform_family]).to eq("rhel")
568
408
  end
569
409
  end
570
410
 
571
- end
572
-
573
- describe "on pcs linux" do
574
-
575
- let(:have_redhat_release) { true }
576
- let(:have_parallels_release) { true }
411
+ describe "on debian" do
577
412
 
578
- describe "with lsb_result" do
413
+ let(:have_debian_version) { true }
579
414
 
580
- it "should read the platform as parallels and version as 6.0.5" do
581
- @plugin[:lsb][:id] = "CloudLinuxServer"
582
- @plugin[:lsb][:release] = "6.5"
583
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
584
- expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
585
- @plugin.run
586
- expect(@plugin[:platform]).to eq("parallels")
587
- expect(@plugin[:platform_version]).to eq("6.0.5")
588
- expect(@plugin[:platform_family]).to eq("rhel")
415
+ before(:each) do
416
+ plugin.lsb = nil
589
417
  end
590
- end
591
418
 
592
- describe "without lsb_results" do
419
+ it "should read the version from /etc/debian_version" do
420
+ expect(File).to receive(:read).with("/etc/debian_version").and_return("9.5")
421
+ plugin.run
422
+ expect(plugin[:platform_version]).to eq("9.5")
423
+ end
593
424
 
594
- before(:each) do
595
- @plugin.lsb = nil
425
+ it "should correctly strip any newlines" do
426
+ expect(File).to receive(:read).with("/etc/debian_version").and_return("9.5\n")
427
+ plugin.run
428
+ expect(plugin[:platform_version]).to eq("9.5")
596
429
  end
597
430
 
598
- it "should read the platform as parallels and version as 6.0.5" do
599
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
600
- expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
601
- @plugin.run
602
- expect(@plugin[:platform]).to eq("parallels")
603
- expect(@plugin[:platform_version]).to eq("6.0.5")
604
- expect(@plugin[:platform_family]).to eq("rhel")
431
+ # Ubuntu has /etc/debian_version as well
432
+ it "should detect Ubuntu as itself rather than debian" do
433
+ plugin[:lsb][:id] = "Ubuntu"
434
+ plugin[:lsb][:release] = "18.04"
435
+ plugin.run
436
+ expect(plugin[:platform]).to eq("ubuntu")
605
437
  end
606
438
  end
607
- end
608
-
609
- describe "on oracle enterprise linux" do
610
-
611
- let(:have_redhat_release) { true }
612
439
 
613
- context "with lsb_results" do
440
+ describe "on slackware" do
614
441
 
615
- context "on version 5.x" do
442
+ let(:have_slackware_version) { true }
616
443
 
617
- let(:have_enterprise_release) { true }
618
-
619
- it "should read the platform as oracle and version as 5.7" do
620
- @plugin[:lsb][:id] = "EnterpriseEnterpriseServer"
621
- @plugin[:lsb][:release] = "5.7"
622
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
623
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
624
- @plugin.run
625
- expect(@plugin[:platform]).to eq("oracle")
626
- expect(@plugin[:platform_version]).to eq("5.7")
627
- end
444
+ before(:each) do
445
+ plugin.lsb = nil
628
446
  end
629
447
 
630
- context "on version 6.x" do
631
-
632
- let(:have_oracle_release) { true }
633
-
634
- it "should read the platform as oracle and version as 6.1" do
635
- @plugin[:lsb][:id] = "OracleServer"
636
- @plugin[:lsb][:release] = "6.1"
637
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
638
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
639
- @plugin.run
640
- expect(@plugin[:platform]).to eq("oracle")
641
- expect(@plugin[:platform_version]).to eq("6.1")
642
- end
643
-
448
+ it "should set platform and platform_family to slackware" do
449
+ expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
450
+ plugin.run
451
+ expect(plugin[:platform]).to eq("slackware")
452
+ expect(plugin[:platform_family]).to eq("slackware")
644
453
  end
645
- end
646
454
 
647
- context "without lsb_results" do
648
- before(:each) do
649
- @plugin.lsb = nil
455
+ it "should set platform_version on slackware" do
456
+ expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
457
+ plugin.run
458
+ expect(plugin[:platform_version]).to eq("12.0.0")
650
459
  end
460
+ end
651
461
 
652
- context "on version 5.x" do
653
-
654
- let(:have_enterprise_release) { true }
655
-
656
- it "should read the platform as oracle and version as 5" do
657
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
658
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
659
- @plugin.run
660
- expect(@plugin[:platform]).to eq("oracle")
661
- expect(@plugin[:platform_version]).to eq("5")
662
- end
663
-
664
- it "should read the platform as oracle and version as 5.1" do
665
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
666
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
667
- @plugin.run
668
- expect(@plugin[:platform]).to eq("oracle")
669
- expect(@plugin[:platform_version]).to eq("5.1")
670
- end
462
+ describe "on arista eos" do
671
463
 
672
- it "should read the platform as oracle and version as 5.7" do
673
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
674
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
675
- @plugin.run
676
- expect(@plugin[:platform]).to eq("oracle")
677
- expect(@plugin[:platform_version]).to eq("5.7")
678
- end
464
+ let(:have_system_release) { true }
465
+ let(:have_redhat_release) { true }
466
+ let(:have_eos_release) { true }
679
467
 
468
+ before(:each) do
469
+ plugin.lsb = nil
680
470
  end
681
471
 
682
- context "on version 6.x" do
683
-
684
- let(:have_oracle_release) { true }
685
-
686
- it "should read the platform as oracle and version as 6.0" do
687
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
688
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0")
689
- @plugin.run
690
- expect(@plugin[:platform]).to eq("oracle")
691
- expect(@plugin[:platform_version]).to eq("6.0")
692
- end
693
-
694
- it "should read the platform as oracle and version as 6.1" do
695
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
696
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
697
- @plugin.run
698
- expect(@plugin[:platform]).to eq("oracle")
699
- expect(@plugin[:platform_version]).to eq("6.1")
700
- end
472
+ it "should set platform to arista_eos" do
473
+ expect(File).to receive(:read).with("/etc/Eos-release").and_return("Arista Networks EOS 4.21.1.1F")
474
+ plugin.run
475
+ expect(plugin[:platform]).to eq("arista_eos")
476
+ expect(plugin[:platform_family]).to eq("fedora")
477
+ expect(plugin[:platform_version]).to eq("4.21.1.1F")
701
478
  end
702
479
  end
703
- end
704
480
 
705
- describe "on suse" do
706
- context "on openSUSE 15+" do
481
+ describe "on f5 big-ip" do
707
482
 
708
- let(:have_usr_lib_os_release) { true }
709
- let(:have_suse_release) { false }
710
- let(:have_os_release) { true }
711
-
712
- let(:os_release_content) do
713
- <<~OS_RELEASE
714
- NAME="openSUSE Leap"
715
- VERSION="15.0"
716
- ID="opensuse-leap"
717
- ID_LIKE="suse opensuse"
718
- VERSION_ID="15.0"
719
- PRETTY_NAME="openSUSE Leap 15.0"
720
- ANSI_COLOR="0;32"
721
- CPE_NAME="cpe:/o:opensuse:leap:15.0"
722
- OS_RELEASE
723
- end
483
+ let(:have_f5_release) { true }
724
484
 
725
- before do
726
- expect(File).to_not receive(:read).with("/etc/SuSE-release")
727
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_release_content)
485
+ before(:each) do
486
+ plugin.lsb = nil
728
487
  end
729
488
 
730
- it "correctly detects opensuseleap 15" do
731
- @plugin.run
732
- expect(@plugin[:platform]).to eq("opensuseleap")
733
- expect(@plugin[:platform_version]).to eq("15.0")
734
- expect(@plugin[:platform_family]).to eq("suse")
489
+ it "should set platform to bigip" do
490
+ expect(File).to receive(:read).with("/etc/f5-release").and_return("BIG-IP release 13.0.0 (Final)")
491
+ plugin.run
492
+ expect(plugin[:platform]).to eq("bigip")
493
+ expect(plugin[:platform_family]).to eq("rhel")
494
+ expect(plugin[:platform_version]).to eq("13.0.0")
735
495
  end
736
-
737
496
  end
738
497
 
739
- context "on SLES 15+" do
498
+ describe "on exherbo" do
740
499
 
741
- let(:have_suse_release) { false }
742
- let(:have_os_release) { true }
500
+ let(:have_exherbo_release) { true }
743
501
 
744
- let(:os_release_content) do
745
- <<~OS_RELEASE
746
- NAME="SLES"
747
- VERSION="15"
748
- VERSION_ID="15"
749
- PRETTY_NAME="SUSE Linux Enterprise Server 15"
750
- ID="sles"
751
- ID_LIKE="suse"
752
- ANSI_COLOR="0;32"
753
- CPE_NAME="cpe:/o:suse:sles:15"
754
-
755
- OS_RELEASE
502
+ before(:each) do
503
+ allow(plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.2-2-ARCH\n", ""))
504
+ plugin.lsb = nil
756
505
  end
757
506
 
758
- before do
759
- expect(File).to_not receive(:read).with("/etc/SuSE-release")
760
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_release_content)
507
+ it "should set platform and platform_family to exherbo" do
508
+ plugin.run
509
+ expect(plugin[:platform]).to eq("exherbo")
510
+ expect(plugin[:platform_family]).to eq("exherbo")
761
511
  end
762
512
 
763
- it "correctly detects SLES15" do
764
- @plugin.run
765
- expect(@plugin[:platform]).to eq("suse")
766
- expect(@plugin[:platform_version]).to eq("15")
767
- expect(@plugin[:platform_family]).to eq("suse")
513
+ it "should set platform_version to kernel release" do
514
+ plugin.run
515
+ expect(plugin[:platform_version]).to eq("3.18.2-2-ARCH")
768
516
  end
769
- end
770
-
771
- context "on versions that have both /etc/os-release and /etc/SuSE-release (e.g. SLES12)" do
772
- let(:have_suse_release) { true }
773
- let(:have_os_release) { true }
774
-
775
- describe "with lsb_release results" do
776
- before(:each) do
777
- @plugin[:lsb][:id] = "SUSE LINUX"
778
- end
779
517
 
780
- it "should read the platform as opensuse on openSUSE" do
781
- @plugin[:lsb][:release] = "12.1"
782
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
783
- @plugin.run
784
- expect(@plugin[:platform]).to eq("opensuse")
785
- expect(@plugin[:platform_family]).to eq("suse")
786
- end
787
- end
788
518
  end
789
519
 
790
- context "on versions that have no /etc/os-release but /etc/SuSE-release (e.g. SLES11)" do
791
- let(:have_suse_release) { true }
792
- let(:have_os_release) { false }
793
-
520
+ describe "on redhat breeds" do
794
521
  describe "with lsb_release results" do
795
- before(:each) do
796
- @plugin[:lsb][:id] = "SUSE LINUX"
522
+ it "should set the platform to redhat and platform_family to rhel even if the LSB name is something absurd but redhat like" do
523
+ plugin[:lsb][:id] = "RedHatEnterpriseServer"
524
+ plugin[:lsb][:release] = "7.5"
525
+ plugin.run
526
+ expect(plugin[:platform]).to eq("redhat")
527
+ expect(plugin[:platform_version]).to eq("7.5")
528
+ expect(plugin[:platform_family]).to eq("rhel")
797
529
  end
798
530
 
799
- it "should read the platform as opensuse on openSUSE" do
800
- @plugin[:lsb][:release] = "12.1"
801
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
802
- @plugin.run
803
- expect(@plugin[:platform]).to eq("opensuse")
804
- expect(@plugin[:platform_family]).to eq("suse")
531
+ it "should set the platform to centos and platform_family to rhel" do
532
+ plugin[:lsb][:id] = "CentOS"
533
+ plugin[:lsb][:release] = "7.5"
534
+ plugin.run
535
+ expect(plugin[:platform]).to eq("centos")
536
+ expect(plugin[:platform_version]).to eq("7.5")
537
+ expect(plugin[:platform_family]).to eq("rhel")
805
538
  end
806
539
  end
807
- end
808
-
809
- context "on openSUSE and older SLES versions" do
810
- let(:have_suse_release) { true }
811
- let(:have_os_release) { true }
812
540
 
813
541
  describe "without lsb_release results" do
542
+
543
+ let(:have_redhat_release) { true }
544
+
814
545
  before(:each) do
815
- @plugin.lsb = nil
546
+ plugin.lsb = nil
816
547
  end
817
548
 
818
- it "should set platform and platform_family to suse and bogus verion to 10.0" do
819
- expect(File).to receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
820
- @plugin.run
821
- expect(@plugin[:platform]).to eq("suse")
822
- expect(@plugin[:platform_family]).to eq("suse")
549
+ it "should read the platform as centos and version as 7.5" do
550
+ expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)")
551
+ plugin.run
552
+ expect(plugin[:platform]).to eq("centos")
553
+ expect(plugin[:platform_version]).to eq("7.5.1804")
823
554
  end
824
555
 
825
- it "should read the version as 10.1 for bogus SLES 10" do
826
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 10 (i586)\nVERSION = 10\nPATCHLEVEL = 1\n")
827
- @plugin.run
828
- expect(@plugin[:platform]).to eq("suse")
829
- expect(@plugin[:platform_version]).to eq("10.1")
830
- expect(@plugin[:platform_family]).to eq("suse")
556
+ it "reads platform of Red Hat with a space" do
557
+ expect(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.5 (Santiago)")
558
+ plugin.run
559
+ expect(plugin[:platform]).to eq("redhat")
831
560
  end
832
561
 
833
- it "should read the version as 11.2" do
834
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
835
- @plugin.run
836
- expect(@plugin[:platform]).to eq("suse")
837
- expect(@plugin[:platform_version]).to eq("11.2")
838
- expect(@plugin[:platform_family]).to eq("suse")
562
+ it "should read the platform as redhat without a space" do
563
+ expect(File).to receive(:read).with("/etc/redhat-release").and_return("RedHat release 5.3")
564
+ plugin.run
565
+ expect(plugin[:platform]).to eq("redhat")
566
+ expect(plugin[:platform_version]).to eq("5.3")
839
567
  end
568
+ end
840
569
 
841
- it "[OHAI-272] should read the version as 11.3" do
842
- expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
843
- @plugin.run
844
- expect(@plugin[:platform]).to eq("opensuse")
845
- expect(@plugin[:platform_version]).to eq("11.3")
846
- expect(@plugin[:platform_family]).to eq("suse")
847
- end
570
+ end
848
571
 
849
- it "[OHAI-272] should read the version as 9.1" do
850
- expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
851
- @plugin.run
852
- expect(@plugin[:platform]).to eq("suse")
853
- expect(@plugin[:platform_version]).to eq("9.1")
854
- expect(@plugin[:platform_family]).to eq("suse")
855
- end
572
+ describe "on pcs linux" do
856
573
 
857
- it "[OHAI-272] should read the version as 11.4" do
858
- expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
859
- @plugin.run
860
- expect(@plugin[:platform]).to eq("opensuse")
861
- expect(@plugin[:platform_version]).to eq("11.4")
862
- expect(@plugin[:platform_family]).to eq("suse")
574
+ let(:have_redhat_release) { true }
575
+ let(:have_parallels_release) { true }
576
+
577
+ describe "with lsb_result" do
578
+
579
+ it "should read the platform as parallels and version as 6.0.5" do
580
+ plugin[:lsb][:id] = "CloudLinuxServer"
581
+ plugin[:lsb][:release] = "6.5"
582
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
583
+ expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
584
+ plugin.run
585
+ expect(plugin[:platform]).to eq("parallels")
586
+ expect(plugin[:platform_version]).to eq("6.0.5")
587
+ expect(plugin[:platform_family]).to eq("rhel")
863
588
  end
589
+ end
590
+
591
+ describe "without lsb_results" do
864
592
 
865
- it "should read the platform as opensuse on openSUSE" do
866
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n")
867
- @plugin.run
868
- expect(@plugin[:platform]).to eq("opensuse")
869
- expect(@plugin[:platform_family]).to eq("suse")
593
+ before(:each) do
594
+ plugin.lsb = nil
870
595
  end
871
596
 
872
- it "should read the platform as opensuseleap on openSUSE Leap" do
873
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 42.1 (x86_64)\nVERSION = 42.1\nCODENAME = Malachite\n")
874
- @plugin.run
875
- expect(@plugin[:platform]).to eq("opensuseleap")
876
- expect(@plugin[:platform_family]).to eq("suse")
597
+ it "should read the platform as parallels and version as 6.0.5" do
598
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
599
+ expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
600
+ plugin.run
601
+ expect(plugin[:platform]).to eq("parallels")
602
+ expect(plugin[:platform_version]).to eq("6.0.5")
603
+ expect(plugin[:platform_family]).to eq("rhel")
877
604
  end
878
605
  end
879
606
  end
880
- end
881
607
 
882
- describe "#read_os_release_info" do
883
- let(:file_contents) { "COW=MOO\nDOG=\"BARK\"" }
884
- it "returns nil if the file does not exist" do
885
- allow(File).to receive(:exist?).with("/etc/test-release").and_return(false)
886
- expect(@plugin.read_os_release_info("/etc/test-release")).to be nil
887
- end
608
+ describe "on oracle enterprise linux" do
888
609
 
889
- it "returns a hash of expected contents" do
890
- allow(File).to receive(:exist?).with("/etc/test-release").and_return(true)
891
- allow(File).to receive(:read).with("/etc/test-release").and_return(file_contents)
892
- release_info = @plugin.read_os_release_info("/etc/test-release")
610
+ let(:have_redhat_release) { true }
893
611
 
894
- expect(release_info["COW"]).to eq("MOO")
895
- expect(release_info["DOG"]).to eq("BARK")
896
- end
897
- end
612
+ context "with lsb_results" do
898
613
 
899
- describe "#os_release_info" do
900
- context "when CISCO_RELEASE_INFO is not populated" do
901
- let(:release_info) { { "ID" => "os_id" } }
614
+ context "on version 5.x" do
902
615
 
903
- before do
904
- allow(File).to receive(:exist?).with("/etc/os-release").and_return(true)
905
- allow(@plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
906
- end
616
+ let(:have_enterprise_release) { true }
907
617
 
908
- it "reads the os-release file" do
909
- expect(@plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
910
- @plugin.os_release_info
911
- end
618
+ it "should read the platform as oracle and version as 5.7" do
619
+ plugin[:lsb][:id] = "EnterpriseEnterpriseServer"
620
+ plugin[:lsb][:release] = "5.7"
621
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
622
+ expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
623
+ plugin.run
624
+ expect(plugin[:platform]).to eq("oracle")
625
+ expect(plugin[:platform_version]).to eq("5.7")
626
+ end
627
+ end
912
628
 
913
- it "returns a hash of expected contents" do
914
- expect(@plugin.os_release_info["ID"]).to eq("os_id")
915
- end
916
- end
629
+ context "on version 6.x" do
917
630
 
918
- context "when CISCO_RELEASE_INFO is populated" do
919
- let(:release_info) { { "ID" => "os_id", "CISCO_RELEASE_INFO" => "/etc/cisco-release" } }
920
- let(:cisco_release_info) { { "ID" => "cisco_id" } }
921
-
922
- before do
923
- allow(File).to receive(:exist?).with("/etc/os-release").and_return(true)
924
- allow(File).to receive(:exist?).with("/etc/cisco-release").and_return(true)
925
- allow(@plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
926
- allow(@plugin).to receive(:read_os_release_info).with("/etc/cisco-release").and_return(cisco_release_info)
927
- end
631
+ let(:have_oracle_release) { true }
928
632
 
929
- it "reads the os-release AND the cisco-release file" do
930
- expect(@plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
931
- expect(@plugin).to receive(:read_os_release_info).with("/etc/cisco-release").and_return(release_info)
932
- @plugin.os_release_info
933
- end
633
+ it "should read the platform as oracle and version as 6.1" do
634
+ plugin[:lsb][:id] = "OracleServer"
635
+ plugin[:lsb][:release] = "6.1"
636
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
637
+ expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
638
+ plugin.run
639
+ expect(plugin[:platform]).to eq("oracle")
640
+ expect(plugin[:platform_version]).to eq("6.1")
641
+ end
934
642
 
935
- it "returns the ID from the cisco-release file instead of the os-release file" do
936
- expect(@plugin.os_release_info["ID"]).to eq("cisco_id")
643
+ end
937
644
  end
938
- end
939
- end
940
645
 
941
- describe "on Wind River Linux 5 for Cisco Nexus" do
942
- let(:have_os_release) { true }
943
- let(:os_release_info) do
944
- {
945
- "ID" => "nexus",
946
- "ID_LIKE" => "wrlinux",
947
- "NAME" => "Nexus",
948
- "VERSION" => "7.0(3)I2(0.475E.6)",
949
- "VERSION_ID" => "7.0(3)I2",
950
- "PRETTY_NAME" => "Nexus 7.0(3)I2",
951
- "HOME_URL" => "http://www.cisco.com",
952
- "BUILD_ID" => "6",
953
- "CISCO_RELEASE_INFO" => "/etc/os-release",
954
- }
955
- end
646
+ context "without lsb_results" do
647
+ before(:each) do
648
+ plugin.lsb = nil
649
+ end
956
650
 
957
- it "should set platform to nexus and platform_family to wrlinux" do
958
- allow(@plugin).to receive(:os_release_info).and_return(os_release_info)
959
- @plugin.lsb = nil
960
- @plugin.run
651
+ context "on version 5.x" do
652
+
653
+ let(:have_enterprise_release) { true }
654
+
655
+ it "should read the platform as oracle and version as 5" do
656
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
657
+ expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
658
+ plugin.run
659
+ expect(plugin[:platform]).to eq("oracle")
660
+ expect(plugin[:platform_version]).to eq("5")
661
+ end
662
+
663
+ it "should read the platform as oracle and version as 5.1" do
664
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
665
+ expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
666
+ plugin.run
667
+ expect(plugin[:platform]).to eq("oracle")
668
+ expect(plugin[:platform_version]).to eq("5.1")
669
+ end
670
+
671
+ it "should read the platform as oracle and version as 5.7" do
672
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
673
+ expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
674
+ plugin.run
675
+ expect(plugin[:platform]).to eq("oracle")
676
+ expect(plugin[:platform_version]).to eq("5.7")
677
+ end
961
678
 
962
- expect(@plugin[:platform]).to eq("nexus")
963
- expect(@plugin[:platform_family]).to eq("wrlinux")
964
- expect(@plugin[:platform_version]).to eq("7.0(3)I2(0.475E.6)")
965
- end
966
- end
679
+ end
967
680
 
968
- describe "on Wind River Linux 7 for Cisco IOS-XR" do
969
- let(:have_os_release) { true }
970
- let(:os_release_info) do
971
- {
972
- "ID" => "ios_xr",
973
- "ID_LIKE" => "cisco-wrlinux wrlinux",
974
- "NAME" => "IOS XR",
975
- "VERSION" => "6.0.0.14I",
976
- "VERSION_ID" => "6.0.0.14I",
977
- "PRETTY_NAME" => "Cisco IOS XR Software, Version 6.0.0.14I",
978
- "BUILD_ID" => "2015-09-10-15-50-17",
979
- "HOME_URL" => "http://www.cisco.com",
980
- "CISCO_RELEASE_INFO" => "/etc/os-release",
981
- }
681
+ context "on version 6.x" do
682
+
683
+ let(:have_oracle_release) { true }
684
+
685
+ it "should read the platform as oracle and version as 6.0" do
686
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
687
+ expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0")
688
+ plugin.run
689
+ expect(plugin[:platform]).to eq("oracle")
690
+ expect(plugin[:platform_version]).to eq("6.0")
691
+ end
692
+
693
+ it "should read the platform as oracle and version as 6.1" do
694
+ allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
695
+ expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
696
+ plugin.run
697
+ expect(plugin[:platform]).to eq("oracle")
698
+ expect(plugin[:platform_version]).to eq("6.1")
699
+ end
700
+ end
701
+ end
982
702
  end
983
703
 
984
- it "should set platform to ios_xr and platform_family to wrlinux" do
985
- allow(@plugin).to receive(:os_release_info).and_return(os_release_info)
986
- @plugin.lsb = nil
987
- @plugin.run
988
-
989
- expect(@plugin[:platform]).to eq("ios_xr")
990
- expect(@plugin[:platform_family]).to eq("wrlinux")
991
- expect(@plugin[:platform_version]).to eq("6.0.0.14I")
992
- end
993
- end
704
+ describe "on suse" do
705
+ context "on versions that have no /etc/os-release but /etc/SuSE-release (e.g. SLES12.1)" do
706
+ let(:have_suse_release) { true }
707
+ let(:have_os_release) { false }
994
708
 
995
- describe "on clearlinux" do
996
- context "without /etc/os-release file" do
997
- let(:have_os_release) { false }
998
- let(:have_usr_lib_os_release) { true }
999
- let(:usr_lib_os_release_content) do
1000
- <<~CLEARLINUX_RELEASE
1001
- NAME="Clear Linux Software for Intel Architecture"
1002
- VERSION=1
1003
- ID=clear-linux-os
1004
- VERSION_ID=16140
1005
- PRETTY_NAME="Clear Linux OS for Intel Architecture"
1006
- ANSI_COLOR="1;35"
1007
- HOME_URL="https://clearlinux.org"
1008
- SUPPORT_URL="https://clearlinux.org"
1009
- BUG_REPORT_URL="mailto:dev@lists.clearlinux.org"
1010
- PRIVACY_POLICY_URL="http://www.intel.com/privacy"
1011
- CLEARLINUX_RELEASE
1012
- end
709
+ describe "with lsb_release results" do
710
+ before(:each) do
711
+ plugin[:lsb][:id] = "SUSE LINUX"
712
+ end
1013
713
 
1014
- before do
1015
- expect(File).to receive(:read).with("/usr/lib/os-release").and_return(usr_lib_os_release_content)
714
+ it "should read the platform as opensuse on openSUSE" do
715
+ plugin[:lsb][:release] = "12.1"
716
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
717
+ plugin.run
718
+ expect(plugin[:platform]).to eq("opensuse")
719
+ expect(plugin[:platform_family]).to eq("suse")
720
+ end
721
+ end
1016
722
  end
1017
723
 
1018
- it "should set platform to clearlinux and platform_family to clearlinux" do
1019
- @plugin.lsb = nil
1020
- @plugin.run
1021
-
1022
- expect(@plugin[:platform]).to eq("clearlinux")
1023
- expect(@plugin[:platform_family]).to eq("clearlinux")
1024
- expect(@plugin[:platform_version]).to eq("16140")
724
+ context "on openSUSE and older SLES versions" do
725
+ let(:have_suse_release) { true }
726
+
727
+ describe "without lsb_release results" do
728
+ before(:each) do
729
+ plugin.lsb = nil
730
+ end
731
+
732
+ it "should set platform and platform_family to suse and bogus verion to 10.0" do
733
+ expect(File).to receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
734
+ plugin.run
735
+ expect(plugin[:platform]).to eq("suse")
736
+ expect(plugin[:platform_family]).to eq("suse")
737
+ end
738
+
739
+ it "should read the version as 11.2" do
740
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
741
+ plugin.run
742
+ expect(plugin[:platform]).to eq("suse")
743
+ expect(plugin[:platform_version]).to eq("11.2")
744
+ expect(plugin[:platform_family]).to eq("suse")
745
+ end
746
+
747
+ it "[OHAI-272] should read the version as 11.3" do
748
+ expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
749
+ plugin.run
750
+ expect(plugin[:platform]).to eq("opensuse")
751
+ expect(plugin[:platform_version]).to eq("11.3")
752
+ expect(plugin[:platform_family]).to eq("suse")
753
+ end
754
+
755
+ it "[OHAI-272] should read the version as 11.4" do
756
+ expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
757
+ plugin.run
758
+ expect(plugin[:platform]).to eq("opensuse")
759
+ expect(plugin[:platform_version]).to eq("11.4")
760
+ expect(plugin[:platform_family]).to eq("suse")
761
+ end
762
+
763
+ it "should read the platform as opensuse on openSUSE" do
764
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n")
765
+ plugin.run
766
+ expect(plugin[:platform]).to eq("opensuse")
767
+ expect(plugin[:platform_family]).to eq("suse")
768
+ end
769
+
770
+ it "should read the platform as opensuseleap on openSUSE Leap" do
771
+ expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 42.1 (x86_64)\nVERSION = 42.1\nCODENAME = Malachite\n")
772
+ plugin.run
773
+ expect(plugin[:platform]).to eq("opensuseleap")
774
+ expect(plugin[:platform_family]).to eq("suse")
775
+ end
776
+ end
1025
777
  end
1026
778
  end
1027
779
 
1028
- context "with /etc/os-release file" do
1029
- let(:have_os_release) { true }
780
+ describe "on clearlinux" do
1030
781
  let(:have_usr_lib_os_release) { true }
1031
- let(:os_release_content) do
782
+ let(:usr_lib_os_release_content) do
1032
783
  <<~CLEARLINUX_RELEASE
1033
- NAME="Clear Linux Software for Intel Architecture"
784
+ NAME="Clear Linux OS"
1034
785
  VERSION=1
1035
786
  ID=clear-linux-os
1036
- VERSION_ID=16140
1037
- PRETTY_NAME="Clear Linux OS for Intel Architecture"
1038
- ANSI_COLOR="1;35"
1039
- HOME_URL="https://clearlinux.org"
1040
- SUPPORT_URL="https://clearlinux.org"
1041
- BUG_REPORT_URL="mailto:dev@lists.clearlinux.org"
1042
- PRIVACY_POLICY_URL="http://www.intel.com/privacy"
1043
- CLEARLINUX_RELEASE
787
+ ID_LIKE=clear-linux-os
788
+ VERSION_ID=26290
789
+ PRETTY_NAME="Clear Linux OS"
790
+ CLEARLINUX_RELEASE
1044
791
  end
1045
-
1046
792
  before do
1047
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_release_content)
1048
- expect(File).not_to receive(:read).with("/usr/lib/os-release")
793
+ expect(File).to receive(:read).with("/usr/lib/os-release").and_return(usr_lib_os_release_content)
1049
794
  end
1050
-
1051
795
  it "should set platform to clearlinux and platform_family to clearlinux" do
1052
- @plugin.lsb = nil
1053
- @plugin.run
1054
-
1055
- expect(@plugin[:platform]).to eq("clearlinux")
1056
- expect(@plugin[:platform_family]).to eq("clearlinux")
1057
- expect(@plugin[:platform_version]).to eq("16140")
796
+ plugin.lsb = nil
797
+ plugin.run
798
+ expect(plugin[:platform]).to eq("clearlinux")
799
+ expect(plugin[:platform_family]).to eq("clearlinux")
800
+ expect(plugin[:platform_version]).to eq("26290")
1058
801
  end
1059
802
  end
1060
803
  end