summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalim Alam <salam@chef.io>2015-09-24 14:37:19 -0700
committerSalim Alam <salam@chef.io>2015-09-24 14:37:19 -0700
commit0e6456ca3e56ae4e84feabff87f3c538bf38964a (patch)
tree9941273593aaa6a4db99d3163f94aaf6a2c46da5
parent7b80ddbb760997c6a2ac08aefa2c62206cbc706b (diff)
parent49384afcf2d992a80e46a097296fdad09648b4aa (diff)
downloadohai-0e6456ca3e56ae4e84feabff87f3c538bf38964a.tar.gz
Merge pull request #625 from chef/salam/plugin-fix
Fix behavior of Ohai plug-in abort
-rw-r--r--CHANGELOG.md3
-rw-r--r--lib/ohai/runner.rb2
-rw-r--r--spec/unit/plugins/abort_spec.rb69
3 files changed, 74 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b26bfa24..7442801a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
# Ohai Changelog
+## Unreleased
+* Fix behavior when abort called from plug-in (Ohai should exit with error code)
+
## Release 8.6.0
* [**Phil Dibowitz**](https://github.com/jaymzh):
- Provide a new and improved filesystem plugin for Linux & Mac (filesystem2), to
diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb
index bfa8ae4c..1e788e5c 100644
--- a/lib/ohai/runner.rb
+++ b/lib/ohai/runner.rb
@@ -48,6 +48,8 @@ module Ohai
end
rescue Ohai::Exceptions::Error
raise
+ rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code
+ raise
rescue Exception,Errno::ENOENT => e
Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
end
diff --git a/spec/unit/plugins/abort_spec.rb b/spec/unit/plugins/abort_spec.rb
new file mode 100644
index 00000000..b99647f1
--- /dev/null
+++ b/spec/unit/plugins/abort_spec.rb
@@ -0,0 +1,69 @@
+#
+# Author:: Salim Alam (salam@chef.io)
+# Copyright:: Copyright (c) 2015 Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb'))
+
+tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'
+
+abortstr = <<EOF
+Ohai.plugin(:Abort) do
+ provides "abort_test"
+ collect_data do
+ abort
+ end
+end
+EOF
+
+describe "a plug-in that aborts execution" do
+ before(:all) do
+ begin
+ Dir.mkdir("#{tmp}/plugins")
+ rescue Errno::EEXIST
+ # ignore
+ end
+ end
+
+ before(:each) do
+ fail_file = File.open("#{tmp}/plugins/abort.rb", "w+")
+ fail_file.write(abortstr)
+ fail_file.close
+ end
+
+ after(:each) do
+ File.delete("#{tmp}/plugins/abort.rb")
+ end
+
+ after(:all) do
+ begin
+ Dir.delete("#{tmp}/plugins")
+ rescue
+ # ignore
+ end
+ end
+
+ before(:each) do
+ @ohai = Ohai::System.new
+ @loader = Ohai::Loader.new(@ohai)
+ @runner = Ohai::Runner.new(@ohai)
+ end
+
+ it "should raise SystemExit" do
+ @plugin = @loader.load_plugin("#{tmp}/plugins/abort.rb")
+ expect { @runner.run_plugin(@plugin) }.to raise_error(SystemExit)
+ end
+end \ No newline at end of file