This makes the SELinux library marginally more robust by dealing
consistently with a missing proc/mounts, and also resoves the test
failures in a way that allows meaningful test runs on non-SELinux
systems.

Signed-off-by: Markus Roberts <[email protected]>
---
 lib/puppet/util/selinux.rb |    4 ++--
 spec/unit/util/selinux.rb  |   21 +++++++++++++++++++--
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb
index 331c8eb..628a6ec 100644
--- a/lib/puppet/util/selinux.rb
+++ b/lib/puppet/util/selinux.rb
@@ -166,8 +166,8 @@ module Puppet::Util::SELinux
             # that's expected
         rescue
             return nil
-        ensure        
-            mountfh.close
+        ensure
+            mountfh.close if mountfh
         end
 
         mntpoint = {}
diff --git a/spec/unit/util/selinux.rb b/spec/unit/util/selinux.rb
index 7e6cdaf..88f4ac8 100755
--- a/spec/unit/util/selinux.rb
+++ b/spec/unit/util/selinux.rb
@@ -27,7 +27,12 @@ describe Puppet::Util::SELinux do
              Selinux.expects(:is_selinux_enabled).returns 0
              selinux_support?.should be_false
         end
-    end
+ 
+        it "should return nil if /proc/mounts does not exist" do
+            File.stubs(:open).with("/proc/mounts").raises("No such file or 
directory - /proc/mounts")
+            read_mounts.should == nil
+        end
+   end
 
     describe "filesystem detection" do
         before :each do
@@ -189,7 +194,19 @@ describe Puppet::Util::SELinux do
     end
 
     describe "set_selinux_context" do
-        it "should return nil if there is no SELinux support" do
+         before :each do
+            fh = stub 'fh', :close => nil
+            File.stubs(:open).with("/proc/mounts").returns fh
+            fh.stubs(:read_nonblock).returns(
+                "rootfs / rootfs rw 0 0\n"+
+                "/dev/root / ext3 
rw,relatime,errors=continue,user_xattr,acl,data=ordered 0 0\n"+
+                "/dev /dev tmpfs rw,relatime,mode=755 0 0\n"+
+                "/proc /proc proc rw,relatime 0 0\n"+
+                "/sys /sys sysfs rw,relatime 0 0\n"
+                ).then.raises EOFError
+        end
+
+       it "should return nil if there is no SELinux support" do
             self.expects(:selinux_support?).returns false
             set_selinux_context("/foo", "user_u:role_r:type_t:s0").should 
be_nil
         end
-- 
1.6.4

--

You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.


Reply via email to