Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LXC detection on lxc 1+ by also checking for lxc-start binary #1070

Merged
merged 1 commit into from Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ohai/plugins/linux/virtualization.rb
Expand Up @@ -22,7 +22,7 @@
provides "virtualization"

def lxc_version_exists?
which("lxc-version")
which("lxc-version") || which("lxc-start")
end

def nova_exists?
Expand Down
18 changes: 13 additions & 5 deletions spec/unit/plugins/linux/virtualization_spec.rb
Expand Up @@ -42,7 +42,8 @@
allow(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(false)

# default the which wrappers to nil
allow(plugin).to receive(:lxc_version_exists?).and_return(false)
allow(plugin).to receive(:which).with("lxc-version").and_return(nil)
allow(plugin).to receive(:which).with("lxc-start").and_return(nil)
allow(plugin).to receive(:nova_exists?).and_return(false)
end

Expand Down Expand Up @@ -577,15 +578,23 @@
end

it "sets lxc host if lxc-version exists" do
allow(plugin).to receive(:lxc_version_exists?).and_return("/usr/bin/lxc-version")
allow(plugin).to receive(:which).with("lxc-start").and_return("/usr/bin/lxc-version")
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxc")
expect(plugin[:virtualization][:role]).to eq("host")
expect(plugin[:virtualization][:systems][:lxc]).to eq("host")
end

it "sets lxc host if lxc-start exists" do
allow(plugin).to receive(:which).with("lxc-start").and_return("/usr/bin/lxc-start")
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxc")
expect(plugin[:virtualization][:role]).to eq("host")
expect(plugin[:virtualization][:systems][:lxc]).to eq("host")
end

it "does not set the old virtualization attributes if they are already set" do
allow(plugin).to receive(:lxc_version_exists?).and_return("/usr/bin/lxc-version")
allow(plugin).to receive(:which).with("lxc-version").and_return("/usr/bin/lxc-version")
plugin[:virtualization] = Mash.new
plugin[:virtualization][:system] = "the cloud"
plugin[:virtualization][:role] = "cumulonimbus"
Expand All @@ -594,8 +603,7 @@
expect(plugin[:virtualization][:role]).not_to eq("host")
end

it "does not set lxc host if lxc-version does not exist" do
allow(plugin).to receive(:lxc_version_exists?).and_return(false)
it "does not set lxc host if neither lxc-version nor lxc-start exists" do
plugin.run
expect(plugin[:virtualization][:system]).to be_nil
expect(plugin[:virtualization][:role]).to be_nil
Expand Down