From 546f1d99680e4557b91bf8f5f619612c8fe8da24 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Thu, 9 May 2019 09:54:52 -0500 Subject: [PATCH] Test against small (fake) /tmp dir This is some test cases for: https://bugzilla.redhat.com/show_bug.cgi?id=1703278 which provides some failing tests for when `validate_free_space` checks the wrong directory, and helps validate that the fix here: https://github.com/ManageIQ/manageiq/pull/18745 Does what it is supposed to. Thanks a bunch to Dan Berger for the assist on this and pointing me in the direction to use loop back devices. Turned out to be a much better solution then what I was considering with vagrant directly. How it works ------------ This patch effectively does three things: First, it adds a provision step on VM boot to add a loop back device (or a file that acts like a file system) to represent a "fake tmp" directory that is under 2MB in size after file system overhead. The process for building this can be found in the "mount_fake_tmp" provision step, but the file is writable to just like a normal mountable file system, and since it is so small it won't fit even our ~2MB database dumps. Of note, something that was require was the `chmod +t`, which adds the sticky bit on to the dir. This is essential for the next part which... Secondly, adds a patch to `tmpdir` which forces `Dir.tmpdir` to return `/fake_tmp` instead of `/tmp`. This part we override both the `@@systmpdir` var and the `ENV['TMPDIR']` values since either one could be used in determining the `Dir.tmpdir` depending on the value of `$SAFE`. Since usually we aren't using `@@systmpdir`, the `chmod +t ...` becomes important here since it allows the `File::Stat#sticky?` check to pass, allowing `/fake_tmp` dir to be a vaild option, and not fall back to `/tmp` instead. Finally, we inject the patch into some tests to make sure that those tests still function when the "tmp" directory has a file that is smaller then the resulting dump/backup. These new tests fail without the patch from above, and pass with it. (transferred from https://gist.github.com/NickLaMuro/8438015363d90a2d2456be650a2b9bc6/bf256dd6a2f385a78cf945e4efea5084f63812e1) --- Vagrantfile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Vagrantfile b/Vagrantfile index c7382af..1935a4a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -39,6 +39,28 @@ Vagrant.configure("2") do |config| miq.vm.synced_folder "../manageiq-appliance_console", "/vagrant/manageiq-appliance_console", rsync_opts miq.vm.synced_folder "./", "/vagrant/tests", rsync_opts + # Create a small disk we can add to the VM that we can stub in for `/tmp` + # + # Only make it 3MB in size (smaller than DB dump size after FS overhead) + fake_tmp_fstab_entry = [ + "/dev/loop0".rjust(41), + "/fake_tmp".rjust(37), + "ext4".ljust(16), + "loop".ljust(15), + "0".ljust(8), + "0" + ].join " " + miq.vm.provision "mount_fake_tmp", :type => "shell", :inline => <<-MOUNT_DISK + dd if=/dev/zero of=/tmp/fake_tmp_fs bs=3M count=1 + losetup /dev/loop0 /tmp/fake_tmp_fs + mkfs.ext4 /dev/loop0 + mkdir /fake_tmp + echo "#{fake_tmp_fstab_entry}" >> /etc/fstab + mount /dev/loop0 + chmod -R 777 /fake_tmp + chmod +t /fake_tmp + MOUNT_DISK + ###### copy and update ssh key permissions miq.vm.provision "ssh_key", :type => "shell", :inline => <<-SSH_KEY cp /vagrant/tests/share.id_rsa /home/vagrant/.ssh/