criu/test/mounts/mounts.py
Andrey Vagin fe1c16a502 test: generate a random tree of mounts
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:02:28 +04:00

31 lines
740 B
Python
Executable file

import os
import tempfile, random
def mount(src, dst, shared, private, slave):
cmd = "mount"
if shared:
cmd += " --make-shared"
if private:
cmd += " --make-private"
if slave:
cmd += " --make-slave"
if src:
cmd += " --bind '%s' '%s'" % (src, dst)
else:
cmd += " -t tmpfs none '%s'" % (dst)
print cmd
ret = os.system(cmd)
if ret:
print "failed"
root = tempfile.mkdtemp(prefix = "root.mount", dir = "/tmp")
mount(None, root, 1, 0, 0)
mounts = [root]
for i in xrange(10):
dstdir = random.choice(mounts)
dst = tempfile.mkdtemp(prefix = "mount", dir = dstdir)
src = random.choice(mounts + [None])
mount(src, dst, random.randint(0,100) > 50, random.randint(0,100) > 90, random.randint(0,100) > 50)
mounts.append(dst)