summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBryan McLellan <btm@getchef.com>2014-05-12 14:42:22 -0700
committerBryan McLellan <btm@getchef.com>2014-05-15 08:00:55 -0700
commit373d1893837eaae56c2c37e942004097f06a861b (patch)
treebfa5fb105d20c8f0a9325bbbf3a194b3e2437e9f /spec
parentdbc7089023c118f12bb0544bc492ccd67f8bf997 (diff)
downloadohai-373d1893837eaae56c2c37e942004097f06a861b.tar.gz
OHAI-573: Only claim to be an LXC Host if we're pretty sure that we are
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb41
-rw-r--r--spec/unit/util/file_helper_spec.rb45
2 files changed, 78 insertions, 8 deletions
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index 18a95768..890c425d 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -358,8 +358,9 @@ CGROUP
@plugin[:virtualization].should == {'systems' => {}}
end
- it "should set lxc host if /proc/self/cgroup only has / mounts" do
- self_cgroup=<<-CGROUP
+ context "/proc/self/cgroup only has / mounts" do
+ before(:each) do
+ self_cgroup=<<-CGROUP
8:blkio:/
7:net_cls:/
6:freezer:/
@@ -369,12 +370,36 @@ CGROUP
2:cpu:/
1:cpuset:/
CGROUP
- File.should_receive(:exists?).with("/proc/self/cgroup").and_return(true)
- File.stub(:read).with("/proc/self/cgroup").and_return(self_cgroup)
- @plugin.run
- @plugin[:virtualization][:system].should == "lxc"
- @plugin[:virtualization][:role].should == "host"
- @plugin[:virtualization][:systems][:lxc].should == "host"
+ 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
+ @plugin[:virtualization][:system].should == "lxc"
+ @plugin[:virtualization][:role].should == "host"
+ @plugin[:virtualization][:systems][:lxc].should == "host"
+ end
+
+ it "does not set the old virtualization attributes if they are already set" do
+ @plugin.stub(:lxc_version_exists?).and_return("/usr/bin/lxc-version")
+ @plugin[:virtualization] = Mash.new
+ @plugin[:virtualization][:system] = "the cloud"
+ @plugin[:virtualization][:role] = "cumulonimbus"
+ @plugin.run
+ @plugin[:virtualization][:system].should_not == "lxc"
+ @plugin[:virtualization][:role].should_not == "host"
+ end
+
+ it "does not set lxc host if lxc-version does not exist" do
+ @plugin.stub(:lxc_version_exists?).and_return(false)
+ @plugin.run
+ @plugin[:virtualization][:system].should be_nil
+ @plugin[:virtualization][:role].should be_nil
+ @plugin[:virtualization].should == {'systems' => {}}
+ end
+
end
it "should not set virtualization if /proc/self/cgroup isn't there" do
diff --git a/spec/unit/util/file_helper_spec.rb b/spec/unit/util/file_helper_spec.rb
new file mode 100644
index 00000000..5c6cf7f6
--- /dev/null
+++ b/spec/unit/util/file_helper_spec.rb
@@ -0,0 +1,45 @@
+# Author:: Bryan McLellan <btm@loftninjas.org>
+#
+# Copyright:: Copyright (c) 2014 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 'spec_helper'
+require 'ohai/util/file_helper'
+
+class FileHelperMock
+ include Ohai::Util::FileHelper
+end
+
+
+describe "Ohai::Util::FileHelper" do
+ let(:file_helper) { FileHelperMock.new }
+
+ before(:each) do
+ File.stub(:executable?).and_return(false)
+ end
+
+ describe "which" do
+ it "returns the path to an executable that is in the path" do
+ File.stub(:executable?).with('/usr/bin/skyhawk').and_return(true)
+
+ expect(file_helper.which('skyhawk')).to eql "/usr/bin/skyhawk"
+ end
+
+ it "returns false if the executable is not in the path" do
+ expect(file_helper.which('the_cake')).to be_false
+ end
+ end
+end