summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-11-23 20:22:05 -0800
committerTim Smith <tsmith84@gmail.com>2020-11-23 22:09:20 -0800
commita81624c0debe6ed3dbf4d4f150eacdfdb60198a3 (patch)
tree0f7315fae9844c9685d085ca9f1a76da9ce4ff5c
parent115f471fb35e058d009cf86cc59f8d49c602b64f (diff)
downloadohai-docker_crash.tar.gz
Prevent docker plugin crashes on AIXdocker_crash
AIX lacks node['virtualization']['systems'] like every other OS so we need to be a bit more defensive here. Just skip running this plugin entirely on platforms without Docker Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/docker.rb2
-rw-r--r--spec/unit/plugins/docker_spec.rb10
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/ohai/plugins/docker.rb b/lib/ohai/plugins/docker.rb
index 92e7a5c4..425d03c2 100644
--- a/lib/ohai/plugins/docker.rb
+++ b/lib/ohai/plugins/docker.rb
@@ -48,7 +48,7 @@ Ohai.plugin(:Docker) do
docker[:swarm] = shellout_data["Swarm"]
end
- collect_data do
+ collect_data(:linux, :windows, :darwin) do
require "json" unless defined?(JSON)
if virtualization[:systems][:docker]
diff --git a/spec/unit/plugins/docker_spec.rb b/spec/unit/plugins/docker_spec.rb
index 781b1f97..5816bc37 100644
--- a/spec/unit/plugins/docker_spec.rb
+++ b/spec/unit/plugins/docker_spec.rb
@@ -78,10 +78,14 @@ expected_output = {
describe Ohai::System, "plugin docker" do
let(:plugin) { get_plugin("docker") }
+ before do
+ plugin[:virtualization] = Mash.new
+ plugin[:virtualization][:systems] = Mash.new
+ allow(plugin).to receive(:collect_os).and_return(:linux)
+ end
+
context "without docker installed" do
it "does not create a docker attribute" do
- plugin[:virtualization] = Mash.new
- plugin[:virtualization][:systems] = Mash.new
plugin.run
expect(plugin).not_to have_key(:docker)
end
@@ -89,8 +93,6 @@ describe Ohai::System, "plugin docker" do
context "with docker installed" do
it "creates a docker attribute with correct data" do
- plugin[:virtualization] = Mash.new
- plugin[:virtualization][:systems] = Mash.new
plugin[:virtualization][:systems][:docker] = "host"
allow(plugin).to receive(:shell_out).with("docker info --format '{{json .}}'").and_return(mock_shell_out(0, docker_output, ""))
plugin.run