From bb11ff4df7ccc877044765d3965cda118fbc01fa Mon Sep 17 00:00:00 2001 From: Claire McQuin Date: Mon, 13 Oct 2014 15:34:10 -0700 Subject: detect any whitespace --- lib/ohai/plugins/linux/virtualization.rb | 4 ++-- spec/unit/plugins/linux/virtualization_spec.rb | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb index 6a9c9fa2..73ba253a 100644 --- a/lib/ohai/plugins/linux/virtualization.rb +++ b/lib/ohai/plugins/linux/virtualization.rb @@ -137,7 +137,7 @@ Ohai.plugin(:Virtualization) do # Detect Linux-VServer if File.exists?("/proc/self/status") proc_self_status = File.read("/proc/self/status") - vxid = proc_self_status.match(/^(s_context|VxID): *(\d+)$/) + vxid = proc_self_status.match(/^(s_context|VxID):\s*(\d+)$/) if vxid and vxid[2] virtualization[:system] = "linux-vserver" if vxid[2] == "0" @@ -158,7 +158,7 @@ Ohai.plugin(:Virtualization) do # /proc/self/cgroup could have a name including alpha/digit/dashes # ::/lxc/ # - # /proc/self/cgroup could have a non-lxc cgroup name indicating other uses + # /proc/self/cgroup could have a non-lxc cgroup name indicating other uses # of cgroups. This is probably not LXC/Docker. # ::/Charlie # diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index 77a810a0..9fb3744f 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -229,7 +229,7 @@ VBOX @plugin[:virtualization][:role].should == "host" @plugin[:virtualization][:systems]['linux-vserver'].should == "host" end - + it "should set Linux-VServer host if /proc/self/status contains multiple space VxID: 0" do File.should_receive(:exists?).with("/proc/self/status").and_return(true) File.stub(:read).with("/proc/self/status").and_return("VxID: 0") @@ -239,6 +239,15 @@ VBOX @plugin[:virtualization][:systems]['linux-vserver'].should == "host" end + it "should set Linux-VServer host if /proc/self/status contains tabbed VxID:\t0" do + File.should_receive(:exists?).with("/proc/self/status").and_return(true) + File.stub(:read).with("/proc/self/status").and_return("VxID:\t0") + @plugin.run + @plugin[:virtualization][:system].should == "linux-vserver" + @plugin[:virtualization][:role].should == "host" + @plugin[:virtualization][:systems]['linux-vserver'].should == "host" + end + it "should set Linux-VServer guest if /proc/self/status contains s_context > 0" do File.should_receive(:exists?).with("/proc/self/status").and_return(true) File.stub(:read).with("/proc/self/status").and_return("s_context: 2") @@ -382,7 +391,7 @@ CGROUP File.should_receive(:exists?).with("/proc/self/cgroup").and_return(true) File.stub(:read).with("/proc/self/cgroup").and_return(self_cgroup) end - + it "sets lxc host if lxc-version exists" do @plugin.stub(:lxc_version_exists?).and_return("/usr/bin/lxc-version") @plugin.run -- cgit v1.2.1