spec/unit/plugins/linux/filesystem_spec.rb in ohai-15.2.5 vs spec/unit/plugins/linux/filesystem_spec.rb in ohai-15.3.1
- old
+ new
@@ -18,11 +18,12 @@
require "spec_helper"
describe Ohai::System, "Linux filesystem plugin" do
let(:plugin) { get_plugin("filesystem") }
- before(:each) do
+
+ before do
allow(plugin).to receive(:collect_os).and_return(:linux)
allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, "", ""))
allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, "", ""))
allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
@@ -54,11 +55,11 @@
allow(File).to receive(:exist?).with("/dev/mapper/#{name}").and_return(true)
end
end
describe "when gathering filesystem usage data from df" do
- before(:each) do
+ before do
@stdout = <<~DF
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /
tmpfs 2030944 0 2030944 0% /lib/init/rw
udev 2025576 228 2025348 1% /dev
@@ -81,59 +82,59 @@
none 126922 1 126921 1% /run/shm
DFI
allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, ""))
end
- it "should run df -P and df -iP" do
+ it "runs df -P and df -iP" do
expect(plugin).to receive(:shell_out).ordered.with("df -P").and_return(mock_shell_out(0, @stdout, ""))
expect(plugin).to receive(:shell_out).ordered.with("df -iP").and_return(mock_shell_out(0, @inode_stdout, ""))
plugin.run
end
- it "should set kb_size to value from df -P" do
+ it "sets kb_size to value from df -P" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_size]).to eq("97605057")
end
- it "should set kb_used to value from df -P" do
+ it "sets kb_used to value from df -P" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_used]).to eq("53563253")
end
- it "should set kb_available to value from df -P" do
+ it "sets kb_available to value from df -P" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_available]).to eq("44041805")
end
- it "should set percent_used to value from df -P" do
+ it "sets percent_used to value from df -P" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:percent_used]).to eq("56%")
end
- it "should set mount to value from df -P" do
+ it "sets mount to value from df -P" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special")
end
- it "should set total_inodes to value from df -iP" do
+ it "sets total_inodes to value from df -iP" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:total_inodes]).to eq("124865")
end
- it "should set inodes_used to value from df -iP" do
+ it "sets inodes_used to value from df -iP" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:inodes_used]).to eq("380")
end
- it "should set inodes_available to value from df -iP" do
+ it "sets inodes_available to value from df -iP" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:inodes_available]).to eq("124485")
end
end
describe "when gathering mounted filesystem data from mount" do
- before(:each) do
+ before do
@stdout = <<~MOUNT
/dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
@@ -150,33 +151,33 @@
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
MOUNT
allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, ""))
end
- it "should run mount" do
+ it "runs mount" do
expect(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, ""))
plugin.run
end
- it "should set mount to value from mount" do
+ it "sets mount to value from mount" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special")
end
- it "should set fs_type to value from mount" do
+ it "sets fs_type to value from mount" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:fs_type]).to eq("xfs")
end
- it "should set mount_options to an array of values from mount" do
+ it "sets mount_options to an array of values from mount" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount_options]).to eq(%w{ro noatime})
end
end
describe "when gathering filesystem type data from blkid" do
- before(:each) do
+ before do
# blkid and lsblk output are coorelated with df/mount output, so the
# most full test of them actually requires we have both
@dfstdout = <<~DF
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /
@@ -217,24 +218,24 @@
/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" TYPE=\"xfs\"
BLKID_TYPE
allow(plugin).to receive(:shell_out).with("/sbin/blkid", timeout: 60).and_return(mock_shell_out(0, @stdout, ""))
end
- it "should run blkid" do
+ it "runs blkid" do
plugin.run
end
- it "should set kb_size to value from blkid" do
+ it "sets kb_size to value from blkid" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/md1,"][:fs_type]).to eq("LVM2_member")
expect(plugin[:filesystem]["by_pair"]["/dev/sda2,"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa")
expect(plugin[:filesystem]["by_pair"]["/dev/md0,/boot"][:label]).to eq("/boot")
end
end
describe "when gathering filesystem type data from lsblk" do
- before(:each) do
+ before do
@dfstdout = <<~DF
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /
tmpfs 2030944 0 2030944 0% /lib/init/rw
udev 2025576 228 2025348 1% /dev
@@ -278,30 +279,30 @@
allow(plugin).to receive(:shell_out)
.with("/sbin/lsblk -n -P -o NAME,UUID,LABEL,FSTYPE", timeout: 60)
.and_return(mock_shell_out(0, @stdout, ""))
end
- it "should run lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do
+ it "runs lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do
plugin.run
end
- it "should set kb_size to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do
+ it "sets kb_size to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/md1,"][:fs_type]).to eq("LVM2_member")
expect(plugin[:filesystem]["by_pair"]["/dev/sda2,"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa")
expect(plugin[:filesystem]["by_pair"]["/dev/md0,/boot"][:label]).to eq("/boot")
end
- it "should ignore extra info in name and set label to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do
+ it "ignores extra info in name and set label to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/debian--7-root,"][:label]).to eq("root")
end
end
describe "when gathering filesystem type data from both lsblk and blkid" do
- before(:each) do
+ before do
@dfstdout = <<~DF
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /
tmpfs 2030944 0 2030944 0% /lib/init/rw
udev 2025576 228 2025348 1% /dev
@@ -360,34 +361,34 @@
/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" TYPE=\"xfs\"
BLKID_TYPE
allow(plugin).to receive(:shell_out).with("/sbin/blkid", timeout: 60).and_return(mock_shell_out(0, @stdout, ""))
end
- it "should fill in missing FS data from lsblk using blkid" do
+ it "fills in missing FS data from lsblk using blkid" do
plugin.run
pairs = plugin[:filesystem]["by_pair"]
expect(pairs["/dev/mapper/sys.vg-root.lv,/"]["fs_type"]).to eq("ext4")
expect(pairs["/dev/mapper/sys.vg-usr.lv,/usr"]["fs_type"]).to eq("ext4")
end
- it "should fill in missing FS data from blkid using lsblk" do
+ it "fills in missing FS data from blkid using lsblk" do
plugin.run
pairs = plugin[:filesystem]["by_pair"]
expect(pairs["/dev/sdb1,"]["uuid"]).to eq("bd1197e0-6997-1f3a-e27e-7801388308b5")
expect(pairs["/dev/sdb2,"]["uuid"]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa")
end
- it "should prefer lsblk data to blkid data when they conflict" do
+ it "prefers lsblk data to blkid data when they conflict" do
plugin.run
pairs = plugin[:filesystem]["by_pair"]
expect(pairs["/dev/mapper/sys.vg-home.lv,/home"]["label"]).to eq("/home")
end
end
describe "when gathering data from /proc/mounts" do
- before(:each) do
+ before do
allow(File).to receive(:exist?).with("/proc/mounts").and_return(true)
@double_file = double("/proc/mounts")
@mounts = <<~MOUNTS
rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
@@ -415,28 +416,28 @@
end
allow(@double_file).to receive(:close)
allow(File).to receive(:open).with("/proc/mounts").and_return(@double_file)
end
- it "should set mount to value from /proc/mounts" do
+ it "sets mount to value from /proc/mounts" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special")
end
- it "should set fs_type to value from /proc/mounts" do
+ it "sets fs_type to value from /proc/mounts" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:fs_type]).to eq("xfs")
end
- it "should set mount_options to an array of values from /proc/mounts" do
+ it "sets mount_options to an array of values from /proc/mounts" do
plugin.run
expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount_options]).to eq(%w{ro noatime attr2 noquota})
end
end
describe "when gathering filesystem data with devices mounted more than once" do
- before(:each) do
+ before do
# there's a few different examples one can run into in this output:
# 1. A device physically mounted in more than one place: /home and /home2
# 2. A bind-mounted directory, which shows up as the same device in a
# subdir: / and /var/chroot
# 3. tmpfs in multiple places.
@@ -473,20 +474,20 @@
allow(plugin).to receive(:shell_out)
.with("/sbin/lsblk -n -P -o NAME,UUID,LABEL,FSTYPE", timeout: 60)
.and_return(mock_shell_out(0, @stdout, ""))
end
- it "should provide a devices view with all mountpoints" do
+ it "provides a devices view with all mountpoints" do
plugin.run
expect(plugin[:filesystem]["by_device"]["/dev/mapper/sys.vg-root.lv"][:mounts]).to eq(["/", "/var/chroot"])
expect(plugin[:filesystem]["by_device"]["/dev/mapper/sys.vg-home.lv"][:mounts]).to eq(["/home", "/home2"])
expect(plugin[:filesystem]["by_device"]["tmpfs"][:mounts]).to eq(["/lib/init/rw", "/dev/shm"])
end
end
describe "when gathering filesystem data with double-mounts" do
- before(:each) do
+ before do
@dfstdout = <<~DF
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /
tmpfs 2030944 0 2030944 0% /lib/init/rw
udev 2025576 228 2025348 1% /dev
@@ -520,10 +521,10 @@
allow(plugin).to receive(:shell_out)
.with("/sbin/lsblk -n -P -o NAME,UUID,LABEL,FSTYPE", timeout: 60)
.and_return(mock_shell_out(0, @stdout, ""))
end
- it "should provide a mounts view with all devices" do
+ it "provides a mounts view with all devices" do
plugin.run
expect(plugin[:filesystem]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/sdb1", "/dev/sdc1"])
end
end