Skip to content
Browse files

Manually attach file to loopback device

If this is done automatically, /etc/mtab contains the file instead of
the loopback device, breaking src/repquota/repquota.
  • Loading branch information...
1 parent b5f69e0 commit e576c8107344ad69d16e3f70ff3a29a9f25d93ac Dmitriy Kalinin and Pieter Noordhuis committed Mar 14, 2013
Showing with 22 additions and 13 deletions.
  1. +22 −13 warden/spec/container/linux_spec.rb
View
35 warden/spec/container/linux_spec.rb
@@ -27,6 +27,12 @@ def next_class_c
let(:have_uid_support) { true }
let(:netmask) { Warden::Network::Netmask.new(255, 255, 255, 252) }
+ def x(command)
+ `#{command}`.tap do
+ $?.should be_success
+ end
+ end
+
before do
FileUtils.mkdir_p(work_path)
@@ -38,25 +44,31 @@ def next_class_c
end
before do
- `dd if=/dev/null of=#{container_depot_file} bs=1M seek=100 1> /dev/null 2> /dev/null`
- $?.should be_success
+ x("dd if=/dev/null of=#{container_depot_file} bs=1M seek=100 1> /dev/null 2> /dev/null")
features = []
features << "^has_journal" # don't include a journal
features << "uninit_bg" # skip initialization of block groups
- `mkfs.ext4 -b 4096 -q -F -O #{features.join(",")} #{container_depot_file}`
- $?.should be_success
+ x("mkfs.ext4 -b 4096 -q -F -O #{features.join(",")} #{container_depot_file}")
+ x("losetup -a | grep #{container_depot_file} | cut -d: -f1 | xargs -r -n1 losetup -d")
+ x("losetup -f #{container_depot_file}")
+ @loop_device = x("losetup -a | grep #{container_depot_file} | cut -d: -f1").strip
+ end
- `mount -o loop #{container_depot_file} #{container_depot_path}`
- $?.should be_success
+ after do
+ x("losetup -a | grep #{container_depot_file} | cut -d: -f1 | xargs -r -n1 losetup -d")
+ end
+
+ before do
+ x("mount #{@loop_device} #{container_depot_path}")
end
after do
tries = 0
begin
- out = `umount #{container_depot_path} 2>&1`
+ out = x("umount #{container_depot_path} 2>&1")
raise "Failed unmounting #{container_depot_path}: #{out}" unless $?.success?
rescue
tries += 1
@@ -68,11 +80,8 @@ def next_class_c
end
end
- `rmdir #{container_depot_path}`
- $?.should be_success
-
- `rm #{container_depot_file}`
- $?.should be_success
+ x("rmdir #{container_depot_path}")
+ x("rm #{container_depot_file}")
end
before do
@@ -84,7 +93,7 @@ def next_class_c
# Destroy all artifacts
Dir[File.join(Warden::Util.path("root"), "*", "clear.sh")].each do |clear|
- `#{clear} #{container_depot_path} > /dev/null`
+ x("#{clear} #{container_depot_path} > /dev/null")
end
end

0 comments on commit e576c81

Please sign in to comment.
Something went wrong with that request. Please try again.