summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-07 16:00:22 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-07 16:00:22 -0700
commit803a230286b0637208edc96cb0eff86f40b34b24 (patch)
tree031f0f56b8883ada7466cd1aad056854f2876075
parentae3f94030dc67d3484f2052fbdb00addd3509a72 (diff)
downloadohai-rubocop_Performance_RegexpMatch.tar.gz
Make sure /proc/cmdline exists before reading itrubocop_Performance_RegexpMatch
Don't run match? against nil Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/scaleway.rb2
-rw-r--r--spec/unit/plugins/scaleway_spec.rb3
2 files changed, 3 insertions, 2 deletions
diff --git a/lib/ohai/plugins/scaleway.rb b/lib/ohai/plugins/scaleway.rb
index 9ac73cf8..006be6e6 100644
--- a/lib/ohai/plugins/scaleway.rb
+++ b/lib/ohai/plugins/scaleway.rb
@@ -26,7 +26,7 @@ Ohai.plugin(:Scaleway) do
# looks for `scaleway` keyword in kernel command line
# @return [Boolean] do we have the keyword or not?
def has_scaleway_cmdline?
- if /scaleway/.match?(::File.read("/proc/cmdline"))
+ if ::File.exist?("/proc/cmdline") && /scaleway/.match?(::File.read("/proc/cmdline"))
logger.trace("Plugin Scaleway: has_scaleway_cmdline? == true")
return true
end
diff --git a/spec/unit/plugins/scaleway_spec.rb b/spec/unit/plugins/scaleway_spec.rb
index 713a8312..f10f1ecb 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(:read).with("/proc/cmdline").and_return(false)
+ allow(File).to receive(:exist?).with("/proc/cmdline").and_return(false)
end
shared_examples_for "!scaleway" do
@@ -84,6 +84,7 @@ 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")
end