spec/unit/plugins/linux/filesystem_spec.rb in ohai-7.2.0 vs spec/unit/plugins/linux/filesystem_spec.rb in ohai-7.2.2
- old
+ new
@@ -24,14 +24,22 @@
@plugin.stub(:collect_os).and_return(:linux)
@plugin.stub(:shell_out).with("df -P").and_return(mock_shell_out(0, "", ""))
@plugin.stub(:shell_out).with("df -i").and_return(mock_shell_out(0, "", ""))
@plugin.stub(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
+ File.stub(:exists?).with("/bin/lsblk").and_return(false)
@plugin.stub(:shell_out).with("blkid -s TYPE").and_return(mock_shell_out(0, "", ""))
@plugin.stub(:shell_out).with("blkid -s UUID").and_return(mock_shell_out(0, "", ""))
@plugin.stub(:shell_out).with("blkid -s LABEL").and_return(mock_shell_out(0, "", ""))
+ @plugin.stub(:shell_out).with("lsblk -r -n -o NAME,FSTYPE").
+ and_return(mock_shell_out(0, "", ""))
+ @plugin.stub(:shell_out).with("lsblk -r -n -o NAME,UUID").
+ and_return(mock_shell_out(0, "", ""))
+ @plugin.stub(:shell_out).with("lsblk -r -n -o NAME,LABEL").
+ and_return(mock_shell_out(0, "", ""))
+
File.stub(:exists?).with("/proc/mounts").and_return(false)
end
describe "when gathering filesystem usage data from df" do
before(:each) do
@@ -152,11 +160,11 @@
end
describe "when gathering filesystem type data from blkid" do
before(:each) do
@stdout = <<-BLKID_TYPE
-dev/sdb1: TYPE=\"linux_raid_member\"
+/dev/sdb1: TYPE=\"linux_raid_member\"
/dev/sdb2: TYPE=\"linux_raid_member\"
/dev/sda1: TYPE=\"linux_raid_member\"
/dev/sda2: TYPE=\"linux_raid_member\"
/dev/md0: TYPE=\"ext3\"
/dev/md1: TYPE=\"LVM2_member\"
@@ -179,10 +187,43 @@
@plugin.run
@plugin[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member"
end
end
+ describe "when gathering filesystem type data from lsblk" do
+ before(:each) do
+ File.stub(:exists?).with("/bin/lsblk").and_return(true)
+ @stdout = <<-BLKID_TYPE
+/dev/sdb1 linux_raid_member
+/dev/sdb2 linux_raid_member
+/dev/sda1 linux_raid_member
+/dev/sda2 linux_raid_member
+/dev/md0 ext3
+/dev/md1 LVM2_member
+/dev/mapper/sys.vg-root.lv ext4
+/dev/mapper/sys.vg-swap.lv swap
+/dev/mapper/sys.vg-tmp.lv ext4
+/dev/mapper/sys.vg-usr.lv ext4
+/dev/mapper/sys.vg-var.lv ext4
+/dev/mapper/sys.vg-home.lv xfs
+BLKID_TYPE
+ @plugin.stub(:shell_out).with("lsblk -r -n -o NAME,FSTYPE").
+ and_return(mock_shell_out(0, @stdout, ""))
+ end
+
+ it "should run lsblk -r -n -o NAME,FSTYPE" do
+ @plugin.should_receive(:shell_out).with("lsblk -r -n -o NAME,FSTYPE").
+ and_return(mock_shell_out(0, @stdout, ""))
+ @plugin.run
+ end
+
+ it "should set kb_size to value from lsblk -r -n -o NAME,FSTYPE" do
+ @plugin.run
+ @plugin[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member"
+ end
+ end
+
describe "when gathering filesystem uuid data from blkid" do
before(:each) do
@stdout = <<-BLKID_UUID
/dev/sdb1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\"
/dev/sdb2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\"
@@ -209,10 +250,44 @@
@plugin.run
@plugin[:filesystem]["/dev/sda2"][:uuid].should be == "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
end
end
+ describe "when gathering filesystem uuid data from lsblk" do
+ before(:each) do
+ File.stub(:exists?).with("/bin/lsblk").and_return(true)
+ @stdout = <<-BLKID_UUID
+/dev/sdb1 bd1197e0-6997-1f3a-e27e-7801388308b5
+/dev/sdb2 e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa
+/dev/sda1 bd1197e0-6997-1f3a-e27e-7801388308b5
+/dev/sda2 e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa
+/dev/md0 37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32
+/dev/md1 YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK
+/dev/mapper/sys.vg-root.lv 7742d14b-80a3-4e97-9a32-478be9ea9aea
+/dev/mapper/sys.vg-swap.lv 9bc2e515-8ddc-41c3-9f63-4eaebde9ce96
+/dev/mapper/sys.vg-tmp.lv 74cf7eb9-428f-479e-9a4a-9943401e81e5
+/dev/mapper/sys.vg-usr.lv 26ec33c5-d00b-4f88-a550-492def013bbc
+/dev/mapper/sys.vg-var.lv 6b559c35-7847-4ae2-b512-c99012d3f5b3
+/dev/mapper/sys.vg-home.lv d6efda02-1b73-453c-8c74-7d8dee78fa5e
+BLKID_UUID
+ @plugin.stub(:shell_out).with("lsblk -r -n -o NAME,UUID").
+ and_return(mock_shell_out(0, @stdout, ""))
+ end
+
+ it "should run lsblk -r -n -o NAME,UUID" do
+ @plugin.should_receive(:shell_out).with("lsblk -r -n -o NAME,UUID").
+ and_return(mock_shell_out(0, @stdout, ""))
+ @plugin.run
+ end
+
+ it "should set kb_size to value from lsblk -r -n -o NAME,UUID" do
+ @plugin.run
+ @plugin[:filesystem]["/dev/sda2"][:uuid].should be ==
+ "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
+ end
+ end
+
describe "when gathering filesystem label data from blkid" do
before(:each) do
@stdout = <<-BLKID_LABEL
/dev/sda1: LABEL=\"fuego:0\"
/dev/sda2: LABEL=\"fuego:1\"
@@ -237,31 +312,70 @@
@plugin.run
@plugin[:filesystem]["/dev/md0"][:label].should be == "/boot"
end
end
+ describe "when gathering filesystem label data from lsblk" do
+ before(:each) do
+ File.stub(:exists?).with("/bin/lsblk").and_return(true)
+ @stdout = <<-BLKID_LABEL
+/dev/sda1 fuego:0
+/dev/sda2 fuego:1
+/dev/sdb1 fuego:0
+/dev/sdb2 fuego:1
+/dev/md0 /boot
+/dev/mapper/sys.vg-root.lv /
+/dev/mapper/sys.vg-tmp.lv /tmp
+/dev/mapper/sys.vg-usr.lv /usr
+/dev/mapper/sys.vg-var.lv /var
+/dev/mapper/sys.vg-home.lv /home
+BLKID_LABEL
+ @plugin.stub(:shell_out).with("lsblk -r -n -o NAME,LABEL").
+ and_return(mock_shell_out(0, @stdout, ""))
+ end
+
+ it "should run blkid -s LABEL" do
+ @plugin.should_receive(:shell_out).with("lsblk -r -n -o NAME,LABEL").
+ and_return(mock_shell_out(0, @stdout, ""))
+ @plugin.run
+ end
+
+ it "should set kb_size to value from blkid -s LABEL" do
+ @plugin.run
+ @plugin[:filesystem]["/dev/md0"][:label].should be == "/boot"
+ end
+ end
+
+
describe "when gathering data from /proc/mounts" do
before(:each) do
File.stub(:exists?).with("/proc/mounts").and_return(true)
@double_file = double("/proc/mounts")
- @double_file.stub(:read_nonblock).and_return(@double_file)
- @double_file.stub(:each_line).
- and_yield("rootfs / rootfs rw 0 0").
- and_yield("none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0").
- and_yield("none /proc proc rw,nosuid,nodev,noexec,relatime 0 0").
- and_yield("none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0").
- and_yield("none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0").
- and_yield("/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0").
- and_yield("tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0").
- and_yield("tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0").
- and_yield("/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0").
- and_yield("/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0").
- and_yield("/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0").
- and_yield("/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0").
- and_yield("/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0").
- and_yield("/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0").
- and_yield("fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0").
- and_yield("binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0")
+ @mounts = <<-MOUNTS
+rootfs / rootfs rw 0 0
+none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
+none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
+none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0
+none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
+/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0
+tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0
+tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
+/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0
+/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0
+/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0
+/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0
+/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0
+/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0
+fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
+binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
+MOUNTS
+ @counter = 0
+ @double_file.stub(:read_nonblock) do
+ @counter += 1
+ raise EOFError if @counter == 2
+ @mounts
+ end
+ @double_file.stub(:close)
File.stub(:open).with("/proc/mounts").and_return(@double_file)
end
it "should set mount to value from /proc/mounts" do
@plugin.run