Commit 35237d2a authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm.py: Move more stuff into ns root

Things added are:

1. /usr directories (links to respective / ones)
2. /sbin dir
3. per-test dependencies that are listed in .desc file as 'deps': [<list>]
Signed-off-by: 's avatarPavel Emelyanov <xemul@openvz.org>
Acked-by: 's avatarAndrew Vagin <avagin@odin.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 858c30e1
...@@ -66,7 +66,7 @@ class host_flavor: ...@@ -66,7 +66,7 @@ class host_flavor:
self.ns = False self.ns = False
self.root = None self.root = None
def init(self, test_bin): def init(self, test_bin, deps):
pass pass
def fini(self): def fini(self):
...@@ -79,20 +79,21 @@ class ns_flavor: ...@@ -79,20 +79,21 @@ class ns_flavor:
self.uns = False self.uns = False
self.root = make_tests_root() self.root = make_tests_root()
def init(self, test_bin): def __copy_one(self, fname):
print "Construct root for %s" % test_bin tfname = self.root + fname
subprocess.check_call(["mount", "--make-private", "--bind", ".", self.root]) if not os.access(tfname, os.F_OK):
# Copying should be atomic as tests can be
if not os.access(self.root + "/.constructed", os.F_OK): # run in parallel
for dir in ["/bin", "/etc", "/lib", "/lib64", "/dev", "/tmp"]: try:
os.mkdir(self.root + dir) os.makedirs(self.root + os.path.dirname(fname))
os.chmod(self.root + dir, 0777) except:
pass
os.mknod(self.root + "/dev/tty", stat.S_IFCHR, os.makedev(5, 0)) dst = tempfile.mktemp(".tso", "", self.root + os.path.dirname(fname))
os.chmod(self.root + "/dev/tty", 0666) shutil.copy2(fname, dst)
os.mknod(self.root + "/.constructed", stat.S_IFREG | 0600) os.rename(dst, tfname)
ldd = subprocess.Popen(["ldd", test_bin], stdout = subprocess.PIPE) def __copy_libs(self, binary):
ldd = subprocess.Popen(["ldd", binary], stdout = subprocess.PIPE)
xl = re.compile('^(linux-gate.so|linux-vdso(64)?.so|not a dynamic)') xl = re.compile('^(linux-gate.so|linux-vdso(64)?.so|not a dynamic)')
# This Mayakovsky-style code gets list of libraries a binary # This Mayakovsky-style code gets list of libraries a binary
...@@ -105,13 +106,27 @@ class ns_flavor: ...@@ -105,13 +106,27 @@ class ns_flavor:
ldd.wait() ldd.wait()
for lib in libs: for lib in libs:
tlib = self.root + lib self.__copy_one(lib)
if not os.access(tlib, os.F_OK):
# Copying should be atomic as tests can be def init(self, test_bin, deps):
# run in parallel print "Construct root for %s" % test_bin
dst = tempfile.mktemp(".tso", "", self.root + os.path.dirname(lib)) subprocess.check_call(["mount", "--make-private", "--bind", ".", self.root])
shutil.copy2(lib, dst)
os.rename(dst, tlib) if not os.access(self.root + "/.constructed", os.F_OK):
for dir in ["/bin", "/sbin", "/etc", "/lib", "/lib64", "/dev", "/tmp", "/usr"]:
os.mkdir(self.root + dir)
os.chmod(self.root + dir, 0777)
os.mknod(self.root + "/dev/tty", stat.S_IFCHR, os.makedev(5, 0))
os.chmod(self.root + "/dev/tty", 0666)
os.mknod(self.root + "/.constructed", stat.S_IFREG | 0600)
for ldir in [ "/bin", "/sbin", "/lib", "/lib64" ]:
os.symlink(".." + ldir, self.root + "/usr" + ldir)
self.__copy_libs(test_bin)
for dep in deps:
self.__copy_one(dep)
self.__copy_libs(dep)
def fini(self): def fini(self):
subprocess.check_call(["mount", "--make-private", self.root]) subprocess.check_call(["mount", "--make-private", self.root])
...@@ -209,7 +224,7 @@ class zdtm_test: ...@@ -209,7 +224,7 @@ class zdtm_test:
def start(self): def start(self):
env = {} env = {}
self.__flavor.init(self.__name) self.__flavor.init(self.__name, self.__desc.get('deps', []))
print "Start test" print "Start test"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment