aboutsummaryrefslogtreecommitdiff
path: root/mount_union.py
blob: e5db16b80639a0e18a86264e769e984f5fae7184 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
from tool_box import *

def mount_union(ctx):
    cfg = ctx.config()
    union_mntroot = cfg.union_mntroot()
    testdir = cfg.testdir()
    if cfg.testing_none():
        lower_mntroot = cfg.lower_mntroot()
        system("mount -o remount,rw " + lower_mntroot)
        system("mount -o bind " + lower_mntroot + " " + union_mntroot)
        ctx.note_upper_fs(lower_mntroot, testdir)

    elif cfg.testing_unionmount():
        system("/root/util-linux-union/mount/mount -i -t tmpfs upper_layer " +
               union_mntroot + " -o union")
        ctx.note_upper_fs(testdir, testdir)

        if ctx.lower_fs() == ctx.upper_fs():
            raise TestError("Upper (" + ctx.upper_fs() + " and lower (" + ctx.lower_fs() +
                            ") shouldn't be the same")

    else:
        lower_mntroot = cfg.lower_mntroot()
        upper_mntroot = cfg.upper_mntroot()
        if not os.path.exists(upper_mntroot):
            os.makedirs(upper_mntroot)
        system("mount -t tmpfs upper_layer " + upper_mntroot)
        upperdir = upper_mntroot + "/upper"
        workdir = upper_mntroot + "/work"
        os.mkdir(upperdir)
        os.mkdir(workdir)
        system("mount -t overlay overlayfs " + union_mntroot +
               " -olowerdir=" + lower_mntroot + ",upperdir=" + upperdir + ",workdir=" + workdir)
        ctx.note_upper_fs(upper_mntroot, testdir)