spec/unit/plugins/linux/filesystem_spec.rb in ohai-6.22.0.rc.0 vs spec/unit/plugins/linux/filesystem_spec.rb in ohai-6.22.0

- old
+ new

@@ -23,12 +23,27 @@ @ohai = Ohai::System.new @ohai[:os] = "linux" @ohai.stub!(:require_plugin).and_return(true) @ohai.extend(SimpleFromFile) - @ohai.stub!(:popen4).with("df -P").and_return(false) - @ohai.stub!(:popen4).with("mount").and_return(false) + stdout = mock("STDOUT_SKEL") + stderr = mock("STDERR_SKEL") + stdout.stub!(:each_line).and_yield('') + stderr.stub!(:each_line).and_yield('') + + @df_cmd = { + :command => "df -P", + :timeout => 120, + :no_status_check => true + } + @mount_cmd = { + :command => "mount", + :timeout => 120, + } + + @ohai.stub!(:run_command).with(@df_cmd).and_return([0,stdout,stderr]) + @ohai.stub!(:run_command).with(@mount_cmd).and_return([0,stdout,stderr]) @ohai.stub!(:popen4).with("blkid -s TYPE").and_return(false) @ohai.stub!(:popen4).with("blkid -s UUID").and_return(false) @ohai.stub!(:popen4).with("blkid -s LABEL").and_return(false) File.stub!(:exists?).with("/proc/mounts").and_return(false) @@ -40,11 +55,11 @@ @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 - @stdout.stub!(:each). + @stdout.stub!(:each_line). and_yield("Filesystem 1024-blocks Used Available Capacity Mounted on"). and_yield("/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /"). and_yield("tmpfs 2030944 0 2030944 0% /lib/init/rw"). and_yield("udev 2025576 228 2025348 1% /dev"). and_yield("tmpfs 2030944 2960 2027984 1% /dev/shm"). @@ -55,40 +70,40 @@ and_yield("/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var"). and_yield("/dev/md0 960492 36388 875312 4% /boot") end it "should run df -P" do - @ohai.should_receive(:popen4).with("df -P").and_return(true) + @ohai.should_receive(:run_command).with(@df_cmd).and_return(true) @ohai._require_plugin("linux::filesystem") end it "should set kb_size to value from df -P" do - @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_size].should be == "97605057" end it "should set kb_used to value from df -P" do - @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_used].should be == "53563253" end it "should set kb_available to value from df -P" do - @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_available].should be == "44041805" end it "should set percent_used to value from df -P" do - @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:percent_used].should be == "56%" end it "should set mount to value from df -P" do - @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special" end end @@ -98,11 +113,11 @@ @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 - @stdout.stub!(:each). + @stdout.stub!(:each_line). and_yield("/dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro)"). and_yield("tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)"). and_yield("proc on /proc type proc (rw,noexec,nosuid,nodev)"). and_yield("sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)"). and_yield("udev on /dev type tmpfs (rw,mode=0755)"). @@ -117,27 +132,27 @@ and_yield("fusectl on /sys/fs/fuse/connections type fusectl (rw)"). and_yield("binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)") end it "should run mount" do - @ohai.should_receive(:popen4).with("mount").and_return(true) + @ohai.stub!(:run_command).with(@mount_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") end it "should set mount to value from mount" do - @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @ohai.stub!(:run_command).with(@mount_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special" end it "should set fs_type to value from mount" do - @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @ohai.stub!(:run_command).with(@mount_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs" end it "should set mount_options to an array of values from mount" do - @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @ohai.stub!(:run_command).with(@mount_cmd).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime" ] end end