summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-10-01 21:04:19 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-10-01 21:05:33 -0700
commit782ea2a1e27d6f6caf336da18ca99ac377c95948 (patch)
tree1193747c900622efd8568877a2e85633378f0fa7 /spec
parent6d6e6f4cd6218d2e4285897cbda1cf9c11c094a9 (diff)
downloadohai-782ea2a1e27d6f6caf336da18ca99ac377c95948.tar.gz
Target Mode Ohai
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/plugins/linux/interrupts_spec.rb12
-rw-r--r--spec/spec_helper.rb4
-rw-r--r--spec/unit/dsl/plugin_spec.rb4
-rw-r--r--spec/unit/loader_spec.rb2
-rw-r--r--spec/unit/mixin/shell_out_spec.rb102
-rw-r--r--spec/unit/mixin/which_spec.rb7
-rw-r--r--spec/unit/plugins/azure_spec.rb30
-rw-r--r--spec/unit/plugins/ec2_spec.rb30
-rw-r--r--spec/unit/plugins/joyent_spec.rb4
-rw-r--r--spec/unit/plugins/linux/block_device_spec.rb2
-rw-r--r--spec/unit/plugins/linux/interrupts_spec.rb12
-rw-r--r--spec/unit/plugins/linux/kernel_spec.rb4
-rw-r--r--spec/unit/plugins/linux/machineid_spec.rb10
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb134
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb196
-rw-r--r--spec/unit/plugins/scaleway_spec.rb6
-rw-r--r--spec/unit/plugins/shells_spec.rb10
-rw-r--r--spec/unit/plugins/solaris2/virtualization_spec.rb8
-rw-r--r--spec/unit/plugins/ssh_host_keys_spec.rb30
-rw-r--r--spec/unit/system_spec.rb4
20 files changed, 278 insertions, 333 deletions
diff --git a/spec/functional/plugins/linux/interrupts_spec.rb b/spec/functional/plugins/linux/interrupts_spec.rb
index 22306cb7..64863586 100644
--- a/spec/functional/plugins/linux/interrupts_spec.rb
+++ b/spec/functional/plugins/linux/interrupts_spec.rb
@@ -26,7 +26,7 @@ describe Ohai::System, "Linux interrupts plugin" do
end
it "parses smp_affinity (partial mask, all)" do
- allow(::File).to receive(:read).with("/affinity").and_return("f")
+ allow(plugin).to receive(:file_read).with("/affinity").and_return("f")
expect(plugin.parse_smp_affinity("/affinity", 2)).to eq({
0 => true,
1 => true,
@@ -34,7 +34,7 @@ describe Ohai::System, "Linux interrupts plugin" do
end
it "parses smp_affinity (partial mask, one)" do
- allow(::File).to receive(:read).with("/affinity").and_return("e")
+ allow(plugin).to receive(:file_read).with("/affinity").and_return("e")
expect(plugin.parse_smp_affinity("/affinity", 2)).to eq({
0 => false,
1 => true,
@@ -42,7 +42,7 @@ describe Ohai::System, "Linux interrupts plugin" do
end
it "parses smp_affinity (full mask, all)" do
- allow(::File).to receive(:read).with("/affinity").and_return("ff")
+ allow(plugin).to receive(:file_read).with("/affinity").and_return("ff")
expect(plugin.parse_smp_affinity("/affinity", 2)).to eq({
0 => true,
1 => true,
@@ -50,7 +50,7 @@ describe Ohai::System, "Linux interrupts plugin" do
end
it "parses smp_affinity (full mask, one)" do
- allow(::File).to receive(:read).with("/affinity").and_return("fe")
+ allow(plugin).to receive(:file_read).with("/affinity").and_return("fe")
expect(plugin.parse_smp_affinity("/affinity", 2)).to eq({
0 => false,
1 => true,
@@ -62,7 +62,7 @@ describe Ohai::System, "Linux interrupts plugin" do
(0..47).each do |i|
cpus[i] = true
end
- allow(::File).to receive(:read).with("/affinity")
+ allow(plugin).to receive(:file_read).with("/affinity")
.and_return("ffff,ffffffff")
expect(plugin.parse_smp_affinity("/affinity", 48)).to eq(cpus)
end
@@ -74,7 +74,7 @@ describe Ohai::System, "Linux interrupts plugin" do
end
cpus[12] = false
cpus[32] = false
- allow(::File).to receive(:read).with("/affinity")
+ allow(plugin).to receive(:file_read).with("/affinity")
.and_return("fffe,ffffefff")
expect(plugin.parse_smp_affinity("/affinity", 48)).to eq(cpus)
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 5f7cadfb..70320232 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -22,10 +22,6 @@ end
include Ohai::Mixin::ConstantHelper
-if Ohai::Mixin::OS.collect_os == /mswin|mingw32|windows/
- ENV["PATH"] = ""
-end
-
def get_plugin(plugin, ohai = Ohai::System.new, path = PLUGIN_PATH)
loader = Ohai::Loader.new(ohai)
loader.load_plugin(File.join(path, "#{plugin}.rb"))
diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb
index 5c73a4a4..d6d4956c 100644
--- a/spec/unit/dsl/plugin_spec.rb
+++ b/spec/unit/dsl/plugin_spec.rb
@@ -521,7 +521,7 @@ describe Ohai::DSL::Plugin::VersionVII do
it "fails a platform has already been defined in the same plugin" do
Ohai.plugin(:Test) { collect_data {} }
- expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/).twice
+ expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on os/).twice
Ohai.plugin(:Test) do
collect_data {}
collect_data {}
@@ -530,7 +530,7 @@ describe Ohai::DSL::Plugin::VersionVII do
it "fails if a platform has already been defined in another plugin file" do
Ohai.plugin(:Test) { collect_data {} }
- expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/)
+ expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on os/)
Ohai.plugin(:Test) do
collect_data {}
end
diff --git a/spec/unit/loader_spec.rb b/spec/unit/loader_spec.rb
index 9275b5e6..d7915bd3 100644
--- a/spec/unit/loader_spec.rb
+++ b/spec/unit/loader_spec.rb
@@ -130,7 +130,7 @@ describe Ohai::Loader do
describe "when the plugin defines collect_data on the same platform more than once" do
it "shoud log an illegal plugin definition warning" do
- expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/)
+ expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on os/)
loader.load_plugin(path_to("illegal_def.rb"))
end
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index 35873e04..76e2e178 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -28,8 +28,11 @@ describe Ohai::Mixin::ShellOut, "shell_out" do
let(:timeout) { 30 }
let(:options) do
+ path_var = windows? ? "Path" : "PATH"
+
# this just replicates the behavior of default_paths in chef-utils
- default_paths = [ Gem.bindir, RbConfig::CONFIG["bindir"] ].compact.uniq
+ split_path = instance.send(:__env_path).split(File::PATH_SEPARATOR)
+ default_paths = [ RbConfig::CONFIG["bindir"], Gem.bindir, split_path ].flatten.compact.uniq
if windows?
default_paths = default_paths.join(";")
@@ -37,8 +40,6 @@ describe Ohai::Mixin::ShellOut, "shell_out" do
default_paths = ( default_paths + [ "/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin" ] ).compact.uniq.join(":")
end
- path_var = windows? ? "Path" : "PATH"
-
default_locale = ChefConfig::Config.guess_internal_locale
{
timeout: timeout,
@@ -55,6 +56,9 @@ describe Ohai::Mixin::ShellOut, "shell_out" do
class DummyPlugin
include Ohai::Mixin::ShellOut
+ def transport_connection
+ nil
+ end
end
let(:instance) { DummyPlugin.new }
@@ -73,64 +77,33 @@ describe Ohai::Mixin::ShellOut, "shell_out" do
describe "when the command runs" do
it "logs the command and exitstatus" do
- expect(Mixlib::ShellOut)
- .to receive(:new)
- .with(cmd, options)
- .and_return(shell_out)
-
- expect(shell_out)
- .to receive(:run_command)
-
- expect(shell_out)
- .to receive(:exitstatus)
- .and_return(256)
-
+ expect(Mixlib::ShellOut).to receive(:new).with(cmd, options).and_return(shell_out)
+ expect(shell_out).to receive(:run_command)
+ expect(shell_out).to receive(:exitstatus).and_return(256)
expect(logger).to receive(:trace)
.with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and returned 256")
-
instance.shell_out(cmd)
end
end
describe "when the command does not exist" do
it "logs the command and error message" do
- expect(Mixlib::ShellOut)
- .to receive(:new)
- .with(cmd, options)
- .and_return(shell_out)
-
- expect(shell_out)
- .to receive(:run_command)
- .and_raise(Errno::ENOENT, "sparkle-dream")
-
- expect(logger)
- .to receive(:trace)
+ expect(Mixlib::ShellOut).to receive(:new).with(cmd, options).and_return(shell_out)
+ expect(shell_out).to receive(:run_command).and_raise(Errno::ENOENT, "sparkle-dream")
+ expect(logger).to receive(:trace)
.with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and failed " \
"#<Errno::ENOENT: No such file or directory - sparkle-dream>")
-
- expect { instance.shell_out(cmd) }
- .to raise_error(Ohai::Exceptions::Exec)
+ expect { instance.shell_out(cmd) }.to raise_error(Ohai::Exceptions::Exec)
end
end
describe "when the command times out" do
it "logs the command an timeout error message" do
- expect(Mixlib::ShellOut)
- .to receive(:new)
- .with(cmd, options)
- .and_return(shell_out)
-
- expect(shell_out)
- .to receive(:run_command)
- .and_raise(Mixlib::ShellOut::CommandTimeout)
-
- expect(logger)
- .to receive(:trace)
- .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed " \
- "out after 30 seconds")
-
- expect { instance.shell_out(cmd) }
- .to raise_error(Ohai::Exceptions::Exec)
+ expect(Mixlib::ShellOut).to receive(:new).with(cmd, options).and_return(shell_out)
+ expect(shell_out).to receive(:run_command).and_raise(Mixlib::ShellOut::CommandTimeout)
+ expect(logger).to receive(:trace)
+ .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed out after 30 seconds")
+ expect { instance.shell_out(cmd) }.to raise_error(Ohai::Exceptions::Exec)
end
end
@@ -138,42 +111,21 @@ describe Ohai::Mixin::ShellOut, "shell_out" do
let(:timeout) { 10 }
it "runs the command with the provided timeout" do
- expect(Mixlib::ShellOut)
- .to receive(:new)
- .with(cmd, options)
- .and_return(shell_out)
-
- expect(shell_out)
- .to receive(:run_command)
-
- expect(shell_out)
- .to receive(:exitstatus)
- .and_return(256)
-
+ expect(Mixlib::ShellOut).to receive(:new).with(cmd, options).and_return(shell_out)
+ expect(shell_out).to receive(:run_command)
+ expect(shell_out).to receive(:exitstatus).and_return(256)
expect(logger).to receive(:trace)
.with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and returned 256")
-
instance.shell_out(cmd, timeout: 10)
end
describe "when the command times out" do
it "logs the command an timeout error message" do
- expect(Mixlib::ShellOut)
- .to receive(:new)
- .with(cmd, options)
- .and_return(shell_out)
-
- expect(shell_out)
- .to receive(:run_command)
- .and_raise(Mixlib::ShellOut::CommandTimeout)
-
- expect(logger)
- .to receive(:trace)
- .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed " \
- "out after 10 seconds")
-
- expect { instance.shell_out(cmd, timeout: 10) }
- .to raise_error(Ohai::Exceptions::Exec)
+ expect(Mixlib::ShellOut).to receive(:new).with(cmd, options).and_return(shell_out)
+ expect(shell_out).to receive(:run_command).and_raise(Mixlib::ShellOut::CommandTimeout)
+ expect(logger).to receive(:trace)
+ .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed out after 10 seconds")
+ expect { instance.shell_out(cmd, timeout: 10) }.to raise_error(Ohai::Exceptions::Exec)
end
end
end
diff --git a/spec/unit/mixin/which_spec.rb b/spec/unit/mixin/which_spec.rb
index d6236757..c1d4c661 100644
--- a/spec/unit/mixin/which_spec.rb
+++ b/spec/unit/mixin/which_spec.rb
@@ -20,19 +20,20 @@ require "spec_helper"
class FileHelperMock
include Ohai::Mixin::Which
+ def transport_connection
+ nil
+ end
end
describe "Ohai::Mixin::Which" do
let(:file_helper) { FileHelperMock.new }
before do
- old_env = ENV
- ENV["Path"] = ENV["PATH"] = "/usr/bin"
+ Ohai::Mixin::ChefUtilsWiring::PathCache.instance.path_cache = "/usr/bin"
allow(file_helper).to receive(:name).and_return("Fakeclass")
logger = instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil)
allow(file_helper).to receive(:logger).and_return(logger)
allow(File).to receive(:executable?).and_return(false)
- ENV = old_env
end
describe "which" do
diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb
index 86e8ec86..1ddfe3d1 100644
--- a/spec/unit/plugins/azure_spec.rb
+++ b/spec/unit/plugins/azure_spec.rb
@@ -134,9 +134,9 @@ describe Ohai::System, "plugin azure" do
describe "without azure hint file or agent or dhcp options" do
before do
allow(plugin).to receive(:hint?).with("azure").and_return(false)
- allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(false)
- allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(false)
- allow(File).to receive(:exist?).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/usr/sbin/waagent").and_return(false)
+ allow(plugin).to receive(:dir_exist?).with('C:\WindowsAzure').and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(true)
@double_file = double("/var/lib/dhcp/dhclient.eth0.leases")
allow(@double_file).to receive(:each)
.and_yield("lease {")
@@ -158,7 +158,7 @@ describe Ohai::System, "plugin azure" do
.and_yield(" rebind 2 2016/03/01 13:22:07;")
.and_yield(" expire 2 2016/03/01 16:40:56;")
.and_yield("}")
- allow(File).to receive(:open).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(@double_file)
+ allow(plugin).to receive(:file_open).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(@double_file)
end
it_behaves_like "!azure"
@@ -168,9 +168,9 @@ describe Ohai::System, "plugin azure" do
before do
allow(plugin).to receive(:hint?).with("rackspace").and_return(true)
allow(plugin).to receive(:hint?).with("azure").and_return(false)
- allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(false)
- allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(false)
- allow(File).to receive(:exist?).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/usr/sbin/waagent").and_return(false)
+ allow(plugin).to receive(:dir_exist?).with('C:\WindowsAzure').and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(false)
end
it_behaves_like "!azure"
@@ -179,8 +179,8 @@ describe Ohai::System, "plugin azure" do
describe "without azure hint file but with agent on linux" do
before do
allow(plugin).to receive(:hint?).with("azure").and_return(false)
- allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(true)
- allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/usr/sbin/waagent").and_return(true)
+ allow(plugin).to receive(:dir_exist?).with('C:\WindowsAzure').and_return(false)
end
it_behaves_like "azure"
@@ -189,8 +189,8 @@ describe Ohai::System, "plugin azure" do
describe "without azure hint file but with agent on windows" do
before do
allow(plugin).to receive(:hint?).with("azure").and_return(false)
- allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(false)
- allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/usr/sbin/waagent").and_return(false)
+ allow(plugin).to receive(:dir_exist?).with('C:\WindowsAzure').and_return(true)
end
it_behaves_like "azure"
@@ -199,9 +199,9 @@ describe Ohai::System, "plugin azure" do
describe "without azure hint or agent but with dhcp option" do
before do
allow(plugin).to receive(:hint?).with("azure").and_return(false)
- allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(false)
- allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(false)
- allow(File).to receive(:exist?).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/usr/sbin/waagent").and_return(false)
+ allow(plugin).to receive(:dir_exist?).with('C:\WindowsAzure').and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(true)
@double_file = double("/var/lib/dhcp/dhclient.eth0.leases")
allow(@double_file).to receive(:each)
.and_yield("lease {")
@@ -223,7 +223,7 @@ describe Ohai::System, "plugin azure" do
.and_yield(" rebind 5 2152/03/10 09:03:39;")
.and_yield(" expire 5 2152/03/10 09:03:39;")
.and_yield("}")
- allow(File).to receive(:open).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(@double_file)
+ allow(plugin).to receive(:file_open).with("/var/lib/dhcp/dhclient.eth0.leases").and_return(@double_file)
end
it_behaves_like "azure"
diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb
index d3e6e3d6..e1641b89 100644
--- a/spec/unit/plugins/ec2_spec.rb
+++ b/spec/unit/plugins/ec2_spec.rb
@@ -25,9 +25,9 @@ describe Ohai::System, "plugin ec2" do
before do
allow(plugin).to receive(:hint?).with("ec2").and_return(false)
- allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(false)
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(false)
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/sys/hypervisor/uuid").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/sys/class/dmi/id/bios_vendor").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/sys/class/dmi/id/bios_version").and_return(false)
end
shared_examples_for "!ec2" do
@@ -334,8 +334,8 @@ describe Ohai::System, "plugin ec2" do
describe "with amazon dmi bios version data" do
before do
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
- allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("4.2.amazon\n")
+ allow(plugin).to receive(:file_exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
+ allow(plugin).to receive(:file_read).with("/sys/class/dmi/id/bios_version").and_return("4.2.amazon\n")
end
it_behaves_like "ec2"
@@ -344,8 +344,8 @@ describe Ohai::System, "plugin ec2" do
describe "with non-amazon dmi bios version data" do
before do
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
- allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("1.0\n")
+ allow(plugin).to receive(:file_exist?).with("/sys/class/dmi/id/bios_version").and_return(true)
+ allow(plugin).to receive(:file_read).with("/sys/class/dmi/id/bios_version").and_return("1.0\n")
end
it_behaves_like "!ec2"
@@ -354,8 +354,8 @@ describe Ohai::System, "plugin ec2" do
describe "with amazon dmi bios vendor data" do
before do
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
- allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Amazon EC2\n")
+ allow(plugin).to receive(:file_exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
+ allow(plugin).to receive(:file_read).with("/sys/class/dmi/id/bios_vendor").and_return("Amazon EC2\n")
end
it_behaves_like "ec2"
@@ -364,8 +364,8 @@ describe Ohai::System, "plugin ec2" do
describe "with non-amazon dmi bios vendor data" do
before do
- allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
- allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Xen\n")
+ allow(plugin).to receive(:file_exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true)
+ allow(plugin).to receive(:file_read).with("/sys/class/dmi/id/bios_vendor").and_return("Xen\n")
end
it_behaves_like "!ec2"
@@ -374,8 +374,8 @@ describe Ohai::System, "plugin ec2" do
describe "with EC2 Xen UUID" do
before do
- allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
- allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
+ allow(plugin).to receive(:file_exist?).with("/sys/hypervisor/uuid").and_return(true)
+ allow(plugin).to receive(:file_read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
end
it_behaves_like "ec2"
@@ -384,8 +384,8 @@ describe Ohai::System, "plugin ec2" do
describe "with non-EC2 Xen UUID" do
before do
- allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true)
- allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
+ allow(plugin).to receive(:file_exist?).with("/sys/hypervisor/uuid").and_return(true)
+ allow(plugin).to receive(:file_read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8\n")
end
it_behaves_like "!ec2"
diff --git a/spec/unit/plugins/joyent_spec.rb b/spec/unit/plugins/joyent_spec.rb
index 516cd90e..b62aae5f 100644
--- a/spec/unit/plugins/joyent_spec.rb
+++ b/spec/unit/plugins/joyent_spec.rb
@@ -74,8 +74,8 @@ describe Ohai::System, "plugin joyent" do
VERIFIED_INSTALLATION=trusted
EOS
- allow(::File).to receive(:read).with("/etc/product").and_return(etc_product)
- allow(::File).to receive(:read).with("/opt/local/etc/pkg_install.conf").and_return(pkg_install_conf)
+ allow(plugin).to receive(:file_read).with("/etc/product").and_return(etc_product)
+ allow(plugin).to receive(:file_read).with("/opt/local/etc/pkg_install.conf").and_return(pkg_install_conf)
plugin.run
end
diff --git a/spec/unit/plugins/linux/block_device_spec.rb b/spec/unit/plugins/linux/block_device_spec.rb
index 9a75c12f..ce273b92 100644
--- a/spec/unit/plugins/linux/block_device_spec.rb
+++ b/spec/unit/plugins/linux/block_device_spec.rb
@@ -46,7 +46,7 @@ describe Ohai::System, "Linux Block Device Plugin" do
allow(@plugin).to receive(:collect_os).and_return(:linux)
allow(File).to receive(:exist?).with("/sys/block").and_return(true)
- allow(Dir).to receive(:[]).with("/sys/block/*") do
+ allow(@plugin).to receive(:dir_glob).with("/sys/block/*") do
DISKS.collect { |disk, _files| "/sys/block/#{disk}" }
end
diff --git a/spec/unit/plugins/linux/interrupts_spec.rb b/spec/unit/plugins/linux/interrupts_spec.rb
index abed19e0..4ff1dec3 100644
--- a/spec/unit/plugins/linux/interrupts_spec.rb
+++ b/spec/unit/plugins/linux/interrupts_spec.rb
@@ -549,12 +549,12 @@ describe Ohai::System, "Linux interrupts plugin" do
plugin[:cpu] = {
"total" => 4,
}
- allow(File).to receive(:exist?).and_return(false)
- allow(File).to receive(:open).with("/proc/interrupts").and_return(@proc_interrupts)
- allow(File).to receive(:exist?).with("/proc/irq/default_smp_affinity").and_return(true)
- allow(File).to receive(:read).with("/proc/irq/default_smp_affinity").and_return("ff")
- allow(File).to receive(:exist?).with("/proc/irq/1/smp_affinity").and_return(true)
- allow(File).to receive(:read).with("/proc/irq/1/smp_affinity").and_return("ff")
+ allow(plugin).to receive(:file_exist?).and_return(false)
+ allow(plugin).to receive(:file_open).with("/proc/interrupts").and_return(@proc_interrupts)
+ allow(plugin).to receive(:file_exist?).with("/proc/irq/default_smp_affinity").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/irq/default_smp_affinity").and_return("ff")
+ allow(plugin).to receive(:file_exist?).with("/proc/irq/1/smp_affinity").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/irq/1/smp_affinity").and_return("ff")
plugin.run
expect(plugin[:interrupts]).to eq(interrupts)
end
diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb
index 2a1446b2..74ba6f43 100644
--- a/spec/unit/plugins/linux/kernel_spec.rb
+++ b/spec/unit/plugins/linux/kernel_spec.rb
@@ -56,8 +56,8 @@ describe Ohai::System, "Linux kernel plugin" do
allow(@plugin).to receive(:shell_out).with("uname -o").and_return(mock_shell_out(0, "Linux", ""))
allow(@plugin).to receive(:shell_out).with("env lsmod").and_return(mock_shell_out(0, @env_lsmod, ""))
@version_module.each do |mod, vers|
- allow(File).to receive(:exist?).with("/sys/module/#{mod}/version").and_return(true)
- allow(File).to receive(:read).with("/sys/module/#{mod}/version").and_return(vers)
+ allow(@plugin).to receive(:file_exist?).with("/sys/module/#{mod}/version").and_return(true)
+ allow(@plugin).to receive(:file_read).with("/sys/module/#{mod}/version").and_return(vers)
end
expect(@plugin).to receive(:shell_out).with("env lsmod").at_least(:once)
@plugin.run
diff --git a/spec/unit/plugins/linux/machineid_spec.rb b/spec/unit/plugins/linux/machineid_spec.rb
index e751def0..cb668ebf 100644
--- a/spec/unit/plugins/linux/machineid_spec.rb
+++ b/spec/unit/plugins/linux/machineid_spec.rb
@@ -28,8 +28,8 @@ describe Ohai::System, "Machine id plugin" do
it "reads /etc/machine-id if available" do
machine_id = "6f702523e2fc7499eb1dc68e5314dacf"
- allow(::File).to receive(:exist?).with("/etc/machine-id").and_return(true)
- allow(::File).to receive(:read).with("/etc/machine-id").and_return(machine_id)
+ allow(plugin).to receive(:file_exist?).with("/etc/machine-id").and_return(true)
+ allow(plugin).to receive(:file_read).with("/etc/machine-id").and_return(machine_id)
plugin.run
expect(plugin[:machine_id]).to eq(machine_id)
end
@@ -37,9 +37,9 @@ describe Ohai::System, "Machine id plugin" do
it "reads /var/lib/dbus/machine-id if available" do
machine_id = "6f702523e2fc7499eb1dc68e5314dacf"
- allow(::File).to receive(:exist?).with("/etc/machine-id").and_return(false)
- allow(::File).to receive(:exist?).with("/var/lib/dbus/machine-id").and_return(true)
- allow(::File).to receive(:read).with("/var/lib/dbus/machine-id").and_return(machine_id)
+ allow(plugin).to receive(:file_exist?).with("/etc/machine-id").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/var/lib/dbus/machine-id").and_return(true)
+ allow(plugin).to receive(:file_read).with("/var/lib/dbus/machine-id").and_return(machine_id)
plugin.run
expect(plugin[:machine_id]).to eq(machine_id)
end
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index b482574a..520a5a26 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -25,13 +25,13 @@ describe Ohai::System, "Linux plugin platform" do
let(:file_contents) { "COW=MOO\nDOG=\"BARK\"" }
it "returns nil if the file does not exist" do
- allow(File).to receive(:exist?).with("/etc/test-release").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/etc/test-release").and_return(false)
expect(plugin.read_os_release_info("/etc/test-release")).to be nil
end
it "returns a hash of expected contents" do
- allow(File).to receive(:exist?).with("/etc/test-release").and_return(true)
- allow(File).to receive(:read).with("/etc/test-release").and_return(file_contents)
+ allow(plugin).to receive(:file_exist?).with("/etc/test-release").and_return(true)
+ allow(plugin).to receive(:file_read).with("/etc/test-release").and_return(file_contents)
release_info = plugin.read_os_release_info("/etc/test-release")
expect(release_info["COW"]).to eq("MOO")
@@ -44,7 +44,7 @@ describe Ohai::System, "Linux plugin platform" do
let(:release_info) { { "ID" => "os_id" } }
before do
- allow(File).to receive(:exist?).with("/etc/os-release").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/etc/os-release").and_return(true)
allow(plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
end
@@ -63,8 +63,8 @@ describe Ohai::System, "Linux plugin platform" do
let(:cisco_release_info) { { "ID" => "cisco_id" } }
before do
- allow(File).to receive(:exist?).with("/etc/os-release").and_return(true)
- allow(File).to receive(:exist?).with("/etc/cisco-release").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/etc/os-release").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/etc/cisco-release").and_return(true)
allow(plugin).to receive(:read_os_release_info).with("/etc/os-release").and_return(release_info)
allow(plugin).to receive(:read_os_release_info).with("/etc/cisco-release").and_return(cisco_release_info)
end
@@ -160,10 +160,10 @@ describe Ohai::System, "Linux plugin platform" do
end
it "returns nexus_centos for centos os-release id" do
- expect(File).to receive(:exist?).at_least(:once).with("/etc/shared/os-release").and_return(true)
- expect(File).to receive(:exist?).at_least(:once).with("/etc/os-release").and_return(true)
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_release_content)
- expect(File).to receive(:read).with("/etc/shared/os-release").and_return(cisco_release_content)
+ expect(plugin).to receive(:file_exist?).at_least(:once).with("/etc/shared/os-release").and_return(true)
+ expect(plugin).to receive(:file_exist?).at_least(:once).with("/etc/os-release").and_return(true)
+ expect(plugin).to receive(:file_read).with("/etc/os-release").and_return(os_release_content)
+ expect(plugin).to receive(:file_read).with("/etc/shared/os-release").and_return(cisco_release_content)
expect(plugin.platform_id_remap("centos")).to eq("nexus_centos")
end
end
@@ -214,7 +214,7 @@ describe Ohai::System, "Linux plugin platform" do
describe "on system with /etc/os-release" do
before do
allow(plugin).to receive(:collect_os).and_return(:linux)
- allow(::File).to receive(:exist?).with("/etc/os-release").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/etc/os-release").and_return(true)
end
context "when os-release data is correct" do
@@ -230,7 +230,7 @@ describe Ohai::System, "Linux plugin platform" do
end
before do
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_data)
+ expect(plugin).to receive(:file_read).with("/etc/os-release").and_return(os_data)
end
it "sets platform, platform_family, and platform_version from os-release" do
@@ -252,7 +252,7 @@ describe Ohai::System, "Linux plugin platform" do
end
before do
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_data)
+ expect(plugin).to receive(:file_read).with("/etc/os-release").and_return(os_data)
end
it "sets platform_version using kernel version from uname" do
@@ -277,7 +277,7 @@ describe Ohai::System, "Linux plugin platform" do
end
before do
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_data)
+ expect(plugin).to receive(:file_read).with("/etc/os-release").and_return(os_data)
end
it "sets platform, platform_family, and platform_version from os-release" do
@@ -301,8 +301,8 @@ describe Ohai::System, "Linux plugin platform" do
end
before do
- expect(File).to receive(:read).with("/etc/os-release").and_return(os_data)
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)")
+ expect(plugin).to receive(:file_read).with("/etc/os-release").and_return(os_data)
+ expect(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)")
end
it "sets platform, platform_family, and platform_version from os-release" do
@@ -334,22 +334,22 @@ describe Ohai::System, "Linux plugin platform" do
before do
allow(plugin).to receive(:collect_os).and_return(:linux)
plugin[:lsb] = Mash.new
- allow(File).to receive(:exist?).with("/etc/debian_version").and_return(have_debian_version)
- allow(File).to receive(:exist?).with("/etc/redhat-release").and_return(have_redhat_release)
- allow(File).to receive(:exist?).with("/etc/exherbo-release").and_return(have_exherbo_release)
- allow(File).to receive(:exist?).with("/etc/Eos-release").and_return(have_eos_release)
- allow(File).to receive(:exist?).with("/etc/SuSE-release").and_return(have_suse_release)
- allow(File).to receive(:exist?).with("/etc/system-release").and_return(have_system_release)
- allow(File).to receive(:exist?).with("/etc/slackware-version").and_return(have_slackware_version)
- allow(File).to receive(:exist?).with("/etc/enterprise-release").and_return(have_enterprise_release)
- allow(File).to receive(:exist?).with("/etc/oracle-release").and_return(have_oracle_release)
- allow(File).to receive(:exist?).with("/etc/parallels-release").and_return(have_parallels_release)
- allow(File).to receive(:exist?).with("/etc/os-release").and_return(have_os_release)
- allow(File).to receive(:exist?).with("/etc/f5-release").and_return(have_f5_release)
- allow(File).to receive(:exist?).with("/usr/lib/os-release").and_return(have_usr_lib_os_release)
- allow(File).to receive(:exist?).with("/etc/shared/os-release").and_return(have_cisco_release)
-
- allow(File).to receive(:read).with("PLEASE STUB ALL File.read CALLS")
+ allow(plugin).to receive(:file_exist?).with("/etc/debian_version").and_return(have_debian_version)
+ allow(plugin).to receive(:file_exist?).with("/etc/redhat-release").and_return(have_redhat_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/exherbo-release").and_return(have_exherbo_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/Eos-release").and_return(have_eos_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/SuSE-release").and_return(have_suse_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/system-release").and_return(have_system_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/slackware-version").and_return(have_slackware_version)
+ allow(plugin).to receive(:file_exist?).with("/etc/enterprise-release").and_return(have_enterprise_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/oracle-release").and_return(have_oracle_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/parallels-release").and_return(have_parallels_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/os-release").and_return(have_os_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/f5-release").and_return(have_f5_release)
+ allow(plugin).to receive(:file_exist?).with("/usr/lib/os-release").and_return(have_usr_lib_os_release)
+ allow(plugin).to receive(:file_exist?).with("/etc/shared/os-release").and_return(have_cisco_release)
+
+ allow(plugin).to receive(:file_read).with("PLEASE STUB ALL plugin.read CALLS")
end
describe "on lsb compliant distributions" do
@@ -423,13 +423,13 @@ describe Ohai::System, "Linux plugin platform" do
end
it "reads the version from /etc/debian_version" do
- expect(File).to receive(:read).with("/etc/debian_version").and_return("9.5")
+ expect(plugin).to receive(:file_read).with("/etc/debian_version").and_return("9.5")
plugin.run
expect(plugin[:platform_version]).to eq("9.5")
end
it "correctlies strip any newlines" do
- expect(File).to receive(:read).with("/etc/debian_version").and_return("9.5\n")
+ expect(plugin).to receive(:file_read).with("/etc/debian_version").and_return("9.5\n")
plugin.run
expect(plugin[:platform_version]).to eq("9.5")
end
@@ -452,14 +452,14 @@ describe Ohai::System, "Linux plugin platform" do
end
it "sets platform and platform_family to slackware" do
- expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
+ expect(plugin).to receive(:file_read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
plugin.run
expect(plugin[:platform]).to eq("slackware")
expect(plugin[:platform_family]).to eq("slackware")
end
it "sets platform_version on slackware" do
- expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
+ expect(plugin).to receive(:file_read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
plugin.run
expect(plugin[:platform_version]).to eq("12.0.0")
end
@@ -476,7 +476,7 @@ describe Ohai::System, "Linux plugin platform" do
end
it "sets platform to arista_eos" do
- expect(File).to receive(:read).with("/etc/Eos-release").and_return("Arista Networks EOS 4.21.1.1F")
+ expect(plugin).to receive(:file_read).with("/etc/Eos-release").and_return("Arista Networks EOS 4.21.1.1F")
plugin.run
expect(plugin[:platform]).to eq("arista_eos")
expect(plugin[:platform_family]).to eq("fedora")
@@ -493,7 +493,7 @@ describe Ohai::System, "Linux plugin platform" do
end
it "sets platform to bigip" do
- expect(File).to receive(:read).with("/etc/f5-release").and_return("BIG-IP release 13.0.0 (Final)")
+ expect(plugin).to receive(:file_read).with("/etc/f5-release").and_return("BIG-IP release 13.0.0 (Final)")
plugin.run
expect(plugin[:platform]).to eq("bigip")
expect(plugin[:platform_family]).to eq("rhel")
@@ -553,20 +553,20 @@ describe Ohai::System, "Linux plugin platform" do
end
it "reads the platform as centos and version as 7.5" do
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)")
+ expect(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)")
plugin.run
expect(plugin[:platform]).to eq("centos")
expect(plugin[:platform_version]).to eq("7.5.1804")
end
it "reads platform of Red Hat with a space" do
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.5 (Santiago)")
+ expect(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.5 (Santiago)")
plugin.run
expect(plugin[:platform]).to eq("redhat")
end
it "reads the platform as redhat without a space" do
- expect(File).to receive(:read).with("/etc/redhat-release").and_return("RedHat release 5.3")
+ expect(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("RedHat release 5.3")
plugin.run
expect(plugin[:platform]).to eq("redhat")
expect(plugin[:platform_version]).to eq("5.3")
@@ -585,8 +585,8 @@ describe Ohai::System, "Linux plugin platform" do
it "reads the platform as parallels and version as 6.0.5" do
plugin[:lsb][:id] = "CloudLinuxServer"
plugin[:lsb][:release] = "6.5"
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
- expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
+ expect(plugin).to receive(:file_read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
plugin.run
expect(plugin[:platform]).to eq("parallels")
expect(plugin[:platform_version]).to eq("6.0.5")
@@ -601,8 +601,8 @@ describe Ohai::System, "Linux plugin platform" do
end
it "reads the platform as parallels and version as 6.0.5" do
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
- expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)")
+ expect(plugin).to receive(:file_read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)")
plugin.run
expect(plugin[:platform]).to eq("parallels")
expect(plugin[:platform_version]).to eq("6.0.5")
@@ -624,8 +624,8 @@ describe Ohai::System, "Linux plugin platform" do
it "reads the platform as oracle and version as 5.7" do
plugin[:lsb][:id] = "EnterpriseEnterpriseServer"
plugin[:lsb][:release] = "5.7"
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
+ expect(plugin).to receive(:file_read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
plugin.run
expect(plugin[:platform]).to eq("oracle")
expect(plugin[:platform_version]).to eq("5.7")
@@ -639,8 +639,8 @@ describe Ohai::System, "Linux plugin platform" do
it "reads the platform as oracle and version as 6.1" do
plugin[:lsb][:id] = "OracleServer"
plugin[:lsb][:release] = "6.1"
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
+ expect(plugin).to receive(:file_read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
plugin.run
expect(plugin[:platform]).to eq("oracle")
expect(plugin[:platform_version]).to eq("6.1")
@@ -659,24 +659,24 @@ describe Ohai::System, "Linux plugin platform" do
let(:have_enterprise_release) { true }
it "reads the platform as oracle and version as 5" do
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
+ expect(plugin).to receive(:file_read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
plugin.run
expect(plugin[:platform]).to eq("oracle")
expect(plugin[:platform_version]).to eq("5")
end
it "reads the platform as oracle and version as 5.1" do
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
+ expect(plugin).to receive(:file_read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
plugin.run
expect(plugin[:platform]).to eq("oracle")
expect(plugin[:platform_version]).to eq("5.1")
end
it "reads the platform as oracle and version as 5.7" do
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
- expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
+ expect(plugin).to receive(:file_read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
plugin.run
expect(plugin[:platform]).to eq("oracle")
expect(plugin[:platform_version]).to eq("5.7")
@@ -689,16 +689,16 @@ describe Ohai::System, "Linux plugin platform" do
let(:have_oracle_release) { true }
it "reads the platform as oracle and version as 6.0" do
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
+ expect(plugin).to receive(:file_read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0")
plugin.run
expect(plugin[:platform]).to eq("oracle")
expect(plugin[:platform_version]).to eq("6.0")
end
it "reads the platform as oracle and version as 6.1" do
- allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
- expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
+ allow(plugin).to receive(:file_read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
+ expect(plugin).to receive(:file_read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
plugin.run
expect(plugin[:platform]).to eq("oracle")
expect(plugin[:platform_version]).to eq("6.1")
@@ -719,7 +719,7 @@ describe Ohai::System, "Linux plugin platform" do
it "reads the platform as opensuse on openSUSE" do
plugin[:lsb][:release] = "12.1"
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
+ expect(plugin).to receive(:file_read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
plugin.run
expect(plugin[:platform]).to eq("opensuse")
expect(plugin[:platform_family]).to eq("suse")
@@ -736,14 +736,14 @@ describe Ohai::System, "Linux plugin platform" do
end
it "sets platform and platform_family to suse and bogus verion to 10.0" do
- expect(File).to receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
+ expect(plugin).to receive(:file_read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
plugin.run
expect(plugin[:platform]).to eq("suse")
expect(plugin[:platform_family]).to eq("suse")
end
it "reads the version as 11.2" do
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
+ expect(plugin).to receive(:file_read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
plugin.run
expect(plugin[:platform]).to eq("suse")
expect(plugin[:platform_version]).to eq("11.2")
@@ -751,7 +751,7 @@ describe Ohai::System, "Linux plugin platform" do
end
it "[OHAI-272] should read the version as 11.3" do
- expect(File).to receive(:read).with("/etc/SuSE-release").once.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
+ expect(plugin).to receive(:file_read).with("/etc/SuSE-release").once.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
plugin.run
expect(plugin[:platform]).to eq("opensuse")
expect(plugin[:platform_version]).to eq("11.3")
@@ -759,7 +759,7 @@ describe Ohai::System, "Linux plugin platform" do
end
it "[OHAI-272] should read the version as 11.4" do
- expect(File).to receive(:read).with("/etc/SuSE-release").once.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
+ expect(plugin).to receive(:file_read).with("/etc/SuSE-release").once.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
plugin.run
expect(plugin[:platform]).to eq("opensuse")
expect(plugin[:platform_version]).to eq("11.4")
@@ -767,14 +767,14 @@ describe Ohai::System, "Linux plugin platform" do
end
it "reads the platform as opensuse on openSUSE" do
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n")
+ expect(plugin).to receive(:file_read).with("/etc/SuSE-release").and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n")
plugin.run
expect(plugin[:platform]).to eq("opensuse")
expect(plugin[:platform_family]).to eq("suse")
end
it "reads the platform as opensuseleap on openSUSE Leap" do
- expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 42.1 (x86_64)\nVERSION = 42.1\nCODENAME = Malachite\n")
+ expect(plugin).to receive(:file_read).with("/etc/SuSE-release").and_return("openSUSE 42.1 (x86_64)\nVERSION = 42.1\nCODENAME = Malachite\n")
plugin.run
expect(plugin[:platform]).to eq("opensuseleap")
expect(plugin[:platform_family]).to eq("suse")
@@ -797,7 +797,7 @@ describe Ohai::System, "Linux plugin platform" do
end
before do
- expect(File).to receive(:read).with("/usr/lib/os-release").and_return(usr_lib_os_release_content)
+ expect(plugin).to receive(:file_read).with("/usr/lib/os-release").and_return(usr_lib_os_release_content)
end
it "sets platform to clearlinux and platform_family to clearlinux" do
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index 3234a09b..eeb12176 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -24,23 +24,23 @@ describe Ohai::System, "Linux virtualization platform" do
before do
allow(plugin).to receive(:collect_os).and_return(:linux)
- # default to all requested Files not existing
- allow(File).to receive(:exist?).with("/proc/xen").and_return(false)
- allow(File).to receive(:exist?).with("/proc/xen/capabilities").and_return(false)
- allow(File).to receive(:exist?).with("/proc/modules").and_return(false)
- allow(File).to receive(:exist?).with("/proc/cpuinfo").and_return(false)
- allow(File).to receive(:exist?).with("/var/lib/hyperv/.kvp_pool_3").and_return(false)
- allow(File).to receive(:exist?).with("/proc/self/status").and_return(false)
- allow(File).to receive(:exist?).with("/proc/bc/0").and_return(false)
- allow(File).to receive(:exist?).with("/proc/vz").and_return(false)
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(false)
- allow(File).to receive(:exist?).with("/.dockerenv").and_return(false)
- allow(File).to receive(:exist?).with("/.dockerinit").and_return(false)
- allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(false)
- allow(File).to receive(:exist?).with("/dev/lxd/sock").and_return(false)
- allow(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(false)
- allow(File).to receive(:exist?).with("/var/snap/lxd/common/lxd/devlxd").and_return(false)
- allow(File).to receive(:exist?).with("/proc/1/environ").and_return(false)
+ # default to all requested plugins not existing
+ allow(plugin).to receive(:file_exist?).with("/proc/xen").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/xen/capabilities").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/modules").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/cpuinfo").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/var/lib/hyperv/.kvp_pool_3").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/status").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/bc/0").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/vz").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/.dockerenv").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/.dockerinit").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/sys/devices/virtual/misc/kvm").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/dev/lxd/sock").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/var/lib/lxd/devlxd").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/var/snap/lxd/common/lxd/devlxd").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/1/environ").and_return(false)
# default the which wrappers to nil
allow(plugin).to receive(:which).with("lxc-version").and_return(nil)
@@ -51,8 +51,8 @@ describe Ohai::System, "Linux virtualization platform" do
describe "when we are checking for xen" do
it "sets xen guest if /proc/xen exists but /proc/xen/capabilities does not" do
- expect(File).to receive(:exist?).with("/proc/xen").and_return(true)
- expect(File).to receive(:exist?).with("/proc/xen/capabilities").and_return(false)
+ expect(plugin).to receive(:file_exist?).with("/proc/xen").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/proc/xen/capabilities").and_return(false)
plugin.run
expect(plugin[:virtualization][:system]).to eq("xen")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -60,9 +60,9 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets xen host if /proc/xen/capabilities contains control_d " do
- expect(File).to receive(:exist?).with("/proc/xen").and_return(true)
- expect(File).to receive(:exist?).with("/proc/xen/capabilities").and_return(true)
- allow(File).to receive(:read).with("/proc/xen/capabilities").and_return("control_d")
+ expect(plugin).to receive(:file_exist?).with("/proc/xen").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/proc/xen/capabilities").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/xen/capabilities").and_return("control_d")
plugin.run
expect(plugin[:virtualization][:system]).to eq("xen")
expect(plugin[:virtualization][:role]).to eq("host")
@@ -70,9 +70,9 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets xen guest if /proc/xen/capabilities exists but is empty" do
- expect(File).to receive(:exist?).with("/proc/xen").and_return(true)
- expect(File).to receive(:exist?).with("/proc/xen/capabilities").and_return(true)
- allow(File).to receive(:read).with("/proc/xen/capabilities").and_return("")
+ expect(plugin).to receive(:file_exist?).with("/proc/xen").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/proc/xen/capabilities").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/xen/capabilities").and_return("")
plugin.run
expect(plugin[:virtualization][:system]).to eq("xen")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -80,7 +80,7 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "does not set virtualization if xen isn't there" do
- expect(File).to receive(:exist?).at_least(:once).and_return(false)
+ expect(plugin).to receive(:file_exist?).at_least(:once).and_return(false)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -108,8 +108,8 @@ describe Ohai::System, "Linux virtualization platform" do
describe "when we are checking for kvm" do
it "sets kvm guest if /sys/devices/virtual/misc/kvm exists & hypervisor cpu feature is present" do
- allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(true)
- 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")
+ allow(plugin).to receive(:file_exist?).with("/sys/devices/virtual/misc/kvm").and_return(true)
+ allow(plugin).to receive(:file_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")
plugin.run
expect(plugin[:virtualization][:system]).to eq("kvm")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -117,8 +117,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets kvm host if /sys/devices/virtual/misc/kvm exists & hypervisor cpu feature is not present" do
- allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(true)
- 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")
+ allow(plugin).to receive(:file_exist?).with("/sys/devices/virtual/misc/kvm").and_return(true)
+ allow(plugin).to receive(:file_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")
plugin.run
expect(plugin[:virtualization][:system]).to eq("kvm")
expect(plugin[:virtualization][:role]).to eq("host")
@@ -126,8 +126,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets kvm guest if /proc/cpuinfo contains QEMU Virtual CPU" do
- expect(File).to receive(:exist?).with("/proc/cpuinfo").and_return(true)
- allow(File).to receive(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
+ expect(plugin).to receive(:file_exist?).with("/proc/cpuinfo").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
plugin.run
expect(plugin[:virtualization][:system]).to eq("kvm")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -135,8 +135,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets kvm guest if /proc/cpuinfo contains Common KVM processor" do
- expect(File).to receive(:exist?).with("/proc/cpuinfo").and_return(true)
- allow(File).to receive(:read).with("/proc/cpuinfo").and_return("Common KVM processor")
+ expect(plugin).to receive(:file_exist?).with("/proc/cpuinfo").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/cpuinfo").and_return("Common KVM processor")
plugin.run
expect(plugin[:virtualization][:system]).to eq("kvm")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -144,8 +144,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets kvm guest if /proc/cpuinfo contains Common 32-bit KVM processor" do
- expect(File).to receive(:exist?).with("/proc/cpuinfo").and_return(true)
- allow(File).to receive(:read).with("/proc/cpuinfo").and_return("Common 32-bit KVM processor")
+ expect(plugin).to receive(:file_exist?).with("/proc/cpuinfo").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/cpuinfo").and_return("Common 32-bit KVM processor")
plugin.run
expect(plugin[:virtualization][:system]).to eq("kvm")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -153,7 +153,7 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "does not set virtualization if kvm isn't there" do
- expect(File).to receive(:exist?).at_least(:once).and_return(false)
+ expect(plugin).to receive(:file_exist?).at_least(:once).and_return(false)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -161,8 +161,8 @@ describe Ohai::System, "Linux virtualization platform" do
describe "when we are checking for VirtualBox" do
it "sets vbox host if /proc/modules contains vboxdrv" do
- expect(File).to receive(:exist?).with("/proc/modules").and_return(true)
- allow(File).to receive(:read).with("/proc/modules").and_return("vboxdrv 268268 3 vboxnetadp,vboxnetflt")
+ expect(plugin).to receive(:file_exist?).with("/proc/modules").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/modules").and_return("vboxdrv 268268 3 vboxnetadp,vboxnetflt")
plugin.run
expect(plugin[:virtualization][:system]).to eq("vbox")
expect(plugin[:virtualization][:role]).to eq("host")
@@ -170,8 +170,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets vbox gues if /proc/modules contains vboxguest" do
- expect(File).to receive(:exist?).with("/proc/modules").and_return(true)
- allow(File).to receive(:read).with("/proc/modules").and_return("vboxguest 214901 2 vboxsf, Live 0xffffffffa00db000 (OF)")
+ expect(plugin).to receive(:file_exist?).with("/proc/modules").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/modules").and_return("vboxguest 214901 2 vboxsf, Live 0xffffffffa00db000 (OF)")
plugin.run
expect(plugin[:virtualization][:system]).to eq("vbox")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -179,7 +179,7 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "does not set virtualization if vbox isn't there" do
- expect(File).to receive(:exist?).at_least(:once).and_return(false)
+ expect(plugin).to receive(:file_exist?).at_least(:once).and_return(false)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -214,8 +214,8 @@ describe Ohai::System, "Linux virtualization platform" do
describe "when we are checking for Hyper-V guest and the hostname of the host" do
it "sets Hyper-V guest if /var/lib/hyperv/.kvp_pool_3 contains hyper_v.example.com" do
- expect(File).to receive(:exist?).with("/var/lib/hyperv/.kvp_pool_3").and_return(true)
- allow(File).to receive(:read).with("/var/lib/hyperv/.kvp_pool_3").and_return("HostNamehyper_v.example.comHostingSystemEditionId")
+ expect(plugin).to receive(:file_exist?).with("/var/lib/hyperv/.kvp_pool_3").and_return(true)
+ allow(plugin).to receive(:file_read).with("/var/lib/hyperv/.kvp_pool_3").and_return("HostNamehyper_v.example.comHostingSystemEditionId")
plugin.run
expect(plugin[:virtualization][:system]).to eq("hyperv")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -226,8 +226,8 @@ describe Ohai::System, "Linux virtualization platform" do
describe "when we are checking for Linux-VServer" do
it "sets Linux-VServer host if /proc/self/status contains s_context: 0" do
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
- allow(File).to receive(:read).with("/proc/self/status").and_return("s_context: 0")
+ expect(plugin).to receive(:file_exist?).with("/proc/self/status").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/status").and_return("s_context: 0")
plugin.run
expect(plugin[:virtualization][:system]).to eq("linux-vserver")
expect(plugin[:virtualization][:role]).to eq("host")
@@ -235,8 +235,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets Linux-VServer host if /proc/self/status contains VxID: 0" do
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
- allow(File).to receive(:read).with("/proc/self/status").and_return("VxID: 0")
+ expect(plugin).to receive(:file_exist?).with("/proc/self/status").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/status").and_return("VxID: 0")
plugin.run
expect(plugin[:virtualization][:system]).to eq("linux-vserver")
expect(plugin[:virtualization][:role]).to eq("host")
@@ -244,8 +244,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets Linux-VServer host if /proc/self/status contains multiple space VxID: 0" do
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
- allow(File).to receive(:read).with("/proc/self/status").and_return("VxID: 0")
+ expect(plugin).to receive(:file_exist?).with("/proc/self/status").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/status").and_return("VxID: 0")
plugin.run
expect(plugin[:virtualization][:system]).to eq("linux-vserver")
expect(plugin[:virtualization][:role]).to eq("host")
@@ -253,8 +253,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets Linux-VServer host if /proc/self/status contains tabbed VxID:\t0" do
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
- allow(File).to receive(:read).with("/proc/self/status").and_return("VxID:\t0")
+ expect(plugin).to receive(:file_exist?).with("/proc/self/status").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/status").and_return("VxID:\t0")
plugin.run
expect(plugin[:virtualization][:system]).to eq("linux-vserver")
expect(plugin[:virtualization][:role]).to eq("host")
@@ -262,8 +262,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets Linux-VServer guest if /proc/self/status contains s_context > 0" do
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
- allow(File).to receive(:read).with("/proc/self/status").and_return("s_context: 2")
+ expect(plugin).to receive(:file_exist?).with("/proc/self/status").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/status").and_return("s_context: 2")
plugin.run
expect(plugin[:virtualization][:system]).to eq("linux-vserver")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -271,8 +271,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets Linux-VServer guest if /proc/self/status contains VxID > 0" do
- expect(File).to receive(:exist?).with("/proc/self/status").and_return(true)
- allow(File).to receive(:read).with("/proc/self/status").and_return("VxID: 2")
+ expect(plugin).to receive(:file_exist?).with("/proc/self/status").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/status").and_return("VxID: 2")
plugin.run
expect(plugin[:virtualization][:system]).to eq("linux-vserver")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -280,7 +280,7 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "does not set virtualization if Linux-VServer isn't there" do
- expect(File).to receive(:exist?).at_least(:once).and_return(false)
+ expect(plugin).to receive(:file_exist?).at_least(:once).and_return(false)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -288,7 +288,7 @@ describe Ohai::System, "Linux virtualization platform" do
describe "when we are checking for openvz" do
it "sets openvz host if /proc/bc/0 exists" do
- expect(File).to receive(:exist?).with("/proc/bc/0").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/proc/bc/0").and_return(true)
plugin.run
expect(plugin[:virtualization][:system]).to eq("openvz")
expect(plugin[:virtualization][:role]).to eq("host")
@@ -296,8 +296,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets openvz guest if /proc/bc/0 does not exist and /proc/vz exists" do
- expect(File).to receive(:exist?).with("/proc/bc/0").and_return(false)
- expect(File).to receive(:exist?).with("/proc/vz").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/proc/bc/0").and_return(false)
+ expect(plugin).to receive(:file_exist?).with("/proc/vz").and_return(true)
plugin.run
expect(plugin[:virtualization][:system]).to eq("openvz")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -305,8 +305,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "does not set virtualization if openvz isn't there" do
- expect(File).to receive(:exist?).with("/proc/bc/0").and_return(false)
- expect(File).to receive(:exist?).with("/proc/vz").and_return(false)
+ expect(plugin).to receive(:file_exist?).with("/proc/bc/0").and_return(false)
+ expect(plugin).to receive(:file_exist?).with("/proc/vz").and_return(false)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -314,7 +314,7 @@ describe Ohai::System, "Linux virtualization platform" do
describe "when we are checking for lxd" do
it "sets lxc guest if /dev/lxd/sock exists" do
- expect(File).to receive(:exist?).with("/dev/lxd/sock").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/dev/lxd/sock").and_return(true)
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxd")
@@ -322,7 +322,7 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets lxd host if /var/lib/lxd/devlxd exists" do
- expect(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/var/lib/lxd/devlxd").and_return(true)
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxd")
@@ -330,7 +330,7 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets lxd host if /var/snap/lxd/common/lxd/devlxd exists" do
- expect(File).to receive(:exist?).with("/var/snap/lxd/common/lxd/devlxd").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/var/snap/lxd/common/lxd/devlxd").and_return(true)
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxd")
@@ -350,8 +350,8 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/lxc/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
1:cpuset:/
CGROUP
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ expect(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxc")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -369,8 +369,8 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/lxc/vanilla
1:cpuset:/lxc/vanilla
CGROUP
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ expect(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxc")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -388,9 +388,9 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/Charlie
1:cpuset:/Charlie
CGROUP
- allow(File).to receive(:read).with("/proc/1/environ").and_return("")
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(plugin).to receive(:file_read).with("/proc/1/environ").and_return("")
+ expect(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -407,9 +407,9 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/
1:cpuset:/
CGROUP
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
- allow(File).to receive(:read).with("/proc/1/environ").and_return("")
+ expect(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(plugin).to receive(:file_read).with("/proc/1/environ").and_return("")
end
it "sets lxc host if lxc-version exists" do
@@ -447,7 +447,7 @@ describe Ohai::System, "Linux virtualization platform" do
it "sets lxc guest if /proc/1/environ has lxccontainer string in it" do
one_environ = "container=lxccontainer_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3".chomp
- allow(File).to receive(:read).with("/proc/1/environ").and_return(one_environ)
+ allow(plugin).to receive(:file_read).with("/proc/1/environ").and_return(one_environ)
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxc")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -456,7 +456,7 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "does not set virtualization if /proc/self/cgroup isn't there" do
- expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(false)
+ expect(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(false)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -464,10 +464,10 @@ describe Ohai::System, "Linux virtualization platform" do
describe "when we are checking for systemd-nspawn" do
it "sets nspawn guest if /proc/1/environ has nspawn string in it" do
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
one_environ = "container=systemd-nspawn_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3".chomp
- allow(File).to receive(:read).with("/proc/1/environ").and_return(one_environ)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return("")
+ allow(plugin).to receive(:file_read).with("/proc/1/environ").and_return(one_environ)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return("")
plugin.run
expect(plugin[:virtualization][:system]).to eq("nspawn")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -486,8 +486,8 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/docker/baa660ed81bc81d262ac6e19486142aeec5fce2043e2a173eb2505c6fbed89bc
1:cpuset:/
CGROUP
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
expect(plugin[:virtualization][:system]).to eq("docker")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -505,8 +505,8 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/docker/vanilla
1:cpuset:/docker/vanilla
CGROUP
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
expect(plugin[:virtualization][:system]).to eq("docker")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -529,8 +529,8 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
1:cpuset:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468
CGROUP
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
expect(plugin[:virtualization][:system]).to eq("docker")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -550,8 +550,8 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu,cpuacct:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
1:name=systemd:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
CGROUP
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
expect(plugin[:virtualization][:system]).to eq("docker")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -569,9 +569,9 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/Charlie
1:cpuset:/Charlie
CGROUP
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
- allow(File).to receive(:read).with("/proc/1/environ").and_return("")
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(plugin).to receive(:file_read).with("/proc/1/environ").and_return("")
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -588,8 +588,8 @@ describe Ohai::System, "Linux virtualization platform" do
2:cpu:/
1:cpuset:/
CGROUP
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
- allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
@@ -613,13 +613,13 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "does not set virtualization if /proc/self/cgroup isn't there" do
- allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(false)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
it "sets virtualization if /.dockerenv exists" do
- allow(File).to receive(:exist?).with("/.dockerenv").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/.dockerenv").and_return(true)
plugin.run
expect(plugin[:virtualization][:system]).to eq("docker")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -627,7 +627,7 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "sets virtualization if /.dockerinit exists" do
- allow(File).to receive(:exist?).with("/.dockerinit").and_return(true)
+ allow(plugin).to receive(:file_exist?).with("/.dockerinit").and_return(true)
plugin.run
expect(plugin[:virtualization][:system]).to eq("docker")
expect(plugin[:virtualization][:role]).to eq("guest")
@@ -635,8 +635,8 @@ describe Ohai::System, "Linux virtualization platform" do
end
it "does not set virtualization if /.dockerenv or /.dockerinit does not exists" do
- allow(File).to receive(:exist?).with("/.dockerenv").and_return(false)
- allow(File).to receive(:exist?).with("/.dockerinit").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/.dockerenv").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/.dockerinit").and_return(false)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
diff --git a/spec/unit/plugins/scaleway_spec.rb b/spec/unit/plugins/scaleway_spec.rb
index f10f1ecb..1869322a 100644
--- a/spec/unit/plugins/scaleway_spec.rb
+++ b/spec/unit/plugins/scaleway_spec.rb
@@ -22,7 +22,7 @@ describe Ohai::System, "plugin scaleway" do
before do
allow(plugin).to receive(:hint?).with("scaleway").and_return(false)
- allow(File).to receive(:exist?).with("/proc/cmdline").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/proc/cmdline").and_return(false)
end
shared_examples_for "!scaleway" do
@@ -84,8 +84,8 @@ describe Ohai::System, "plugin scaleway" do
describe "with scaleway cmdline" do
before do
- allow(File).to receive(:exist?).with("/proc/cmdline").and_return(true)
- allow(File).to receive(:read).with("/proc/cmdline").and_return("initrd=initrd showopts console=ttyS0,115200 nousb vga=0 root=/dev/vda scaleway boot=local")
+ allow(plugin).to receive(:file_exist?).with("/proc/cmdline").and_return(true)
+ allow(plugin).to receive(:file_read).with("/proc/cmdline").and_return("initrd=initrd showopts console=ttyS0,115200 nousb vga=0 root=/dev/vda scaleway boot=local")
end
it_behaves_like "scaleway"
diff --git a/spec/unit/plugins/shells_spec.rb b/spec/unit/plugins/shells_spec.rb
index 7002c6bc..4116f325 100644
--- a/spec/unit/plugins/shells_spec.rb
+++ b/spec/unit/plugins/shells_spec.rb
@@ -32,18 +32,18 @@ describe Ohai::System, "plugin shells" do
"/bin/tcsh\n",
"/bin/zsh\n"]
- let(:shell_file_content) { shell_file }
+ let(:shell_file_content) { shell_file.join }
it "does not set shells attribute if /etc/shells does not exist" do
- allow(::File).to receive(:exist?).with("/etc/shells").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/etc/shells").and_return(false)
plugin.run
expect(plugin).not_to have_key(:shells)
end
it "sets shells to an array of shells if /etc/shells exists" do
- allow(::File).to receive(:readlines).with("/etc/shells").and_return(shell_file_content)
- allow(::File).to receive(:exist?).and_call_original
- allow(::File).to receive(:exist?).with("/etc/shells").and_return(true)
+ allow(plugin).to receive(:file_open).with("/etc/shells").and_return(StringIO.new(shell_file_content))
+ allow(plugin).to receive(:file_exist?).and_call_original
+ allow(plugin).to receive(:file_exist?).with("/etc/shells").and_return(true)
plugin.run
expect(plugin.shells).to match_array([
"/bin/bash",
diff --git a/spec/unit/plugins/solaris2/virtualization_spec.rb b/spec/unit/plugins/solaris2/virtualization_spec.rb
index e06211f8..ac1bd178 100644
--- a/spec/unit/plugins/solaris2/virtualization_spec.rb
+++ b/spec/unit/plugins/solaris2/virtualization_spec.rb
@@ -31,16 +31,16 @@ describe Ohai::System, "Solaris virtualization platform" do
allow(plugin).to receive(:collect_os).and_return(:solaris2)
# default to all requested Files not existing
- allow(File).to receive(:exist?).with("/usr/sbin/psrinfo").and_return(false)
- allow(File).to receive(:exist?).with("/usr/sbin/smbios").and_return(false)
- allow(File).to receive(:exist?).with("/usr/sbin/zoneadm").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/usr/sbin/psrinfo").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/usr/sbin/smbios").and_return(false)
+ allow(plugin).to receive(:file_exist?).with("/usr/sbin/zoneadm").and_return(false)
allow(plugin).to receive(:shell_out).with("/usr/sbin/smbios").and_return(mock_shell_out(0, "", ""))
allow(plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, "", ""))
end
describe "when we are checking for kvm" do
before do
- expect(File).to receive(:exist?).with("/usr/sbin/psrinfo").and_return(true)
+ expect(plugin).to receive(:file_exist?).with("/usr/sbin/psrinfo").and_return(true)
end
it "runs psrinfo -pv" do
diff --git a/spec/unit/plugins/ssh_host_keys_spec.rb b/spec/unit/plugins/ssh_host_keys_spec.rb
index 80bd9727..28ddae48 100644
--- a/spec/unit/plugins/ssh_host_keys_spec.rb
+++ b/spec/unit/plugins/ssh_host_keys_spec.rb
@@ -24,27 +24,23 @@ describe Ohai::System, "ssh_host_key plugin" do
@plugin = get_plugin("ssh_host_key")
@plugin[:keys] = Mash.new
- allow(File).to receive(:exist?).with("/etc/ssh/sshd_config").and_return(true)
- allow(File).to receive(:open).with("/etc/ssh/sshd_config").and_yield(sshd_config_file)
- allow(File).to receive(:exist?).and_return(true)
- allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(true)
- allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(true)
- allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(true)
- allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(true)
-
- # Ensure we can still use IO.read
- io_read = IO.method(:read)
- allow(IO).to receive(:read) { |file| io_read.call(file) }
+ allow(@plugin).to receive(:file_exist?).with("/etc/ssh/sshd_config").and_return(true)
+ allow(@plugin).to receive(:file_open).with("/etc/ssh/sshd_config").and_yield(sshd_config_file)
+ allow(@plugin).to receive(:file_exist?).and_return(true)
+ allow(@plugin).to receive(:file_exist?).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(true)
+ allow(@plugin).to receive(:file_exist?).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(true)
+ allow(@plugin).to receive(:file_exist?).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(true)
+ allow(@plugin).to receive(:file_exist?).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(true)
# Return fake public key files so we don't have to go digging for them in unit tests
@dsa_key = "ssh-dss AAAAB3NzaC1kc3MAAACBAMHlT02xN8kietxPfhcb98xHueTzKCOTz6dZlP/dmKILHrQOAExuSEeNiA2uvmhHNVQvs/cBsRiDxgSKux3ie2q8+MB6vHCiSpSkoPjrL75iT57YDilCB4/sytt6IJpj+H42wRDWTX0/QRybMHUvmnmEL0cwZXykSvrIum0BKB6hAAAAFQDsi6WUCClhtZIiTY9uh8eAre+SbQAAAIEAgNnuw0uEuqtcVif+AYd/bCZvL9FPqg7DrmTkamNEcVinhUGwsPGJTLJf+o5ens1X4RzQoi1R6Y6zCTL2FN/hZgINJNO0z9BN402wWrZmQd+Vb1U5DyDtveuvipqyQS+fm9neRwdLuv36Fc9f9nkZ7YHpkGPJp+yJpG4OoeREhwgAAACBAIf9kKLf2XiXnlByzlJ2Naa55d/hp2E059VKCRsBS++xFKYKvSqjnDQBFiMtAUhb8EdTyBGyalqOgqogDQVtwHfTZWZwqHAhry9aM06y92Eu/xSey4tWjKeknOsnRe640KC4zmKDBRTrjjkuAdrKPN9k3jl+OCc669JHlIfo6kqf oppa"
@rsa_key = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuhcVXV+nNapkyUC5p4TH1ymRxUjtMBKqYWmwyI29gVFnUNeHkKFHWon0KFeGJP2Rm8BfTiZa9ER9e8pRr4Nd+z1C1o0kVoxEEfB9tpSdTlpk1GG83D94l57fij8THRVIwuCEosViUlg1gDgC4SpxbqfdBkUN2qyf6JDOh7t2QpYh7berpDEWeBpb7BKdLEDT57uw7ijKzSNyaXqq8KkB9I+UFrRwpuos4W7ilX+PQ+mWLi2ZZJfTYZMxxVS+qJwiDtNxGCRwTOQZG03kI7eLBZG+igupr0uD4o6qeftPOr0kxgjoPU4nEKvYiGq8Rqd2vYrhiaJHLk9QB6xStQvS3Q== oppa"
@ecdsa_key = "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBx8VgvxmHxs/sIn/ATh0iUcuz1I2Xc0e1ejXCGHBMZ98IE3FBt1ezlqCpNMcHVV2skQQ8vyLbKxzweyZuNSDU8= oppa"
@ed25519_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFYGnIM5K5JaRxbMCqz8cPMmLp57ZoJQvA5Tlj18EO6H djb"
- allow(IO).to receive(:read).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(@dsa_key)
- allow(IO).to receive(:read).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(@rsa_key)
- allow(IO).to receive(:read).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(@ecdsa_key)
- allow(IO).to receive(:read).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(@ed25519_key)
+ allow(@plugin).to receive(:file_read).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(@dsa_key)
+ allow(@plugin).to receive(:file_read).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(@rsa_key)
+ allow(@plugin).to receive(:file_read).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(@ecdsa_key)
+ allow(@plugin).to receive(:file_read).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(@ed25519_key)
end
shared_examples "loads keys" do
@@ -107,8 +103,8 @@ describe Ohai::System, "ssh_host_key plugin" do
end
before do
- allow(File).to receive(:exist?).with("/etc/ssh/sshd_config").and_return(false)
- allow(File).to receive(:exist?).with("/etc/sshd_config").and_return(false)
+ allow(@plugin).to receive(:file_exist?).with("/etc/ssh/sshd_config").and_return(false)
+ allow(@plugin).to receive(:file_exist?).with("/etc/sshd_config").and_return(false)
end
it_behaves_like "loads keys"
diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb
index 62e558d4..9d02f1e7 100644
--- a/spec/unit/system_spec.rb
+++ b/spec/unit/system_spec.rb
@@ -146,7 +146,7 @@ describe "Ohai::System" do
message("default")
end
- collect_data(:#{Ohai::Mixin::OS.collect_os}) do
+ collect_data(:#{Ohai::Mixin::OS.collect_os_local}) do
message("platform_specific_message")
end
end
@@ -212,7 +212,7 @@ describe "Ohai::System" do
Ohai.config[:plugin_path] = [ path_to(".") ]
# Make sure the stubbing of runner is not overriden with reset_system during test
allow(ohai).to receive(:reset_system)
- allow(ohai.instance_variable_get("@runner")).to receive(:run_plugin).and_raise(Ohai::Exceptions::AttributeNotFound)
+ allow(ohai.runner).to receive(:run_plugin).and_raise(Ohai::Exceptions::AttributeNotFound)
expect(ohai.logger).to receive(:error).with(/Encountered error while running plugins/)
expect { ohai.all_plugins }.to raise_error(Ohai::Exceptions::AttributeNotFound)
end