forked from amir73il/unionmount-testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
193 lines (179 loc) · 6.91 KB
/
settings.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#
# Class of object containing current test configuration
#
__copyright__ = """
Copyright (C) 2014 Red Hat, Inc. All Rights Reserved.
Written by David Howells ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public Licence version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
import os
class config:
def __init__(self, progname):
self.__progname = progname
self.__testing_overlayfs = False
self.__testing_none = False
self.__base_mntroot = os.getenv('UNIONMOUNT_BASEDIR')
self.__lower_mntroot = os.getenv('UNIONMOUNT_LOWERDIR')
self.__union_mntroot = os.getenv('UNIONMOUNT_MNTPOINT')
self.__mntopts = os.getenv('UNIONMOUNT_MNTOPTIONS')
print("Environment variables:")
if self.__base_mntroot:
print("UNIONMOUNT_BASEDIR='" + self.__base_mntroot + "'")
if self.__lower_mntroot:
print("UNIONMOUNT_LOWERDIR='" + self.__lower_mntroot + "'")
if self.__union_mntroot:
print("UNIONMOUNT_MNTPOINT='" + self.__union_mntroot + "'")
if self.__mntopts:
print("UNIONMOUNT_MNTOPTIONS='" + self.__mntopts + "'")
# Allow user provided options with or without -o
if not self.__mntopts.startswith("-o"):
self.__mntopts = "-o" + self.__mntopts
else: # Use arbitrary non empty options to simplify add_mntopt()
self.__mntopts = "-orw"
print()
if self.__base_mntroot and not self.__lower_mntroot:
# Empty UNIONMOUNT_LOWERDIR with non-empty UNIONMOUNT_BASEDIR imply --samefs
# unless user requests maxfs=<N>
self.__maxfs = -1
else:
self.__maxfs = 0
self.__verbose = False
self.__verify = False
self.__squashfs = False
self.__erofs = False
self.__metacopy = False
self.__nested = False
self.__xino = False
self.__fusefs = False
self.__fstype = "overlay"
self.__fsname = "overlay"
def progname(self):
return self.__progname
def testing_none(self):
return self.__testing_none
def testing_overlayfs(self):
return self.__testing_overlayfs
def set_testing_none(self):
self.__testing_none = True
def set_testing_overlayfs(self):
self.__testing_overlayfs = True
# base dir is used only for --ov --samefs, in which case:
# BASEDIR/l is lowermost layer
# BASEDIR/0/u is the first layer above it, which starts as upper layer
# and may later be rotated to lower layers.
# BASEDIR/m is the union mount point.
# user provided UNIONMOUNT_BASEDIR should already be mounted.
def should_use_base(self):
return self.__base_mntroot or (self.testing_overlayfs() and self.is_samefs())
def should_mount_base(self):
return not self.__base_mntroot and self.should_use_base()
def base_mntroot(self):
return self.__base_mntroot or "/base"
def env_base_mntroot(self):
return self.__base_mntroot
# lower dir is mounted ro for --ov (without --samefs) ...
def should_mount_lower_ro(self):
return self.testing_overlayfs() and not self.is_samefs() and not self.__lower_mntroot
# ... and mounted rw for --no
# user provided UNIONMOUNT_LOWERDIR should already be mounted.
def should_mount_lower_rw(self):
return self.testing_none() and not self.__lower_mntroot
def should_mount_lower(self):
return self.should_mount_lower_ro() or self.should_mount_lower_rw()
# lowermost layer is either at UNIONMOUNT_LOWERDIR, /lower or BASEDIR/l
def lower_mntroot(self):
if self.__lower_mntroot:
return self.__lower_mntroot
if self.should_use_base():
return self.base_mntroot() + "/l"
return self.old_lower_mntroot()
def old_lower_mntroot(self):
return self.__lower_mntroot or "/lower"
def env_lower_mntroot(self):
return self.__lower_mntroot
# upper dir is mounted for --ov (without --samefs)
def should_mount_upper(self):
return self.testing_overlayfs() and not self.is_samefs() and not self.__base_mntroot
# layers (0..N) above lowermost are either at /upper/N or at BASEDIR/N
def upper_mntroot(self):
if self.should_use_base():
return self.base_mntroot()
return self.old_upper_mntroot()
def old_upper_mntroot(self):
return self.__base_mntroot or "/upper"
# union mount point is either at /mnt or at BASEDIR/m
def union_mntroot(self):
if self.__union_mntroot:
return self.__union_mntroot
if self.should_use_base():
return self.base_mntroot() + "/m"
return self.old_union_mntroot()
def old_union_mntroot(self):
return self.__union_mntroot or "/mnt"
def env_union_mntroot(self):
return self.__union_mntroot
def lowerdir(self):
return self.lower_mntroot() + "/a"
def lowerimg(self):
return self.lower_mntroot() + "/a.img"
def testdir(self):
return self.union_mntroot() + "/a"
def set_verbose(self, to=True):
self.__verbose = to
def is_verbose(self):
return self.__verbose
def set_verify(self, to=True):
self.__verify = to
def is_verify(self):
return self.__verify
def set_maxfs(self, to):
self.__maxfs = to
def maxfs(self):
return self.__maxfs
def is_samefs(self):
return self.__maxfs < 0
def set_squashfs(self, to=True):
self.__squashfs = to
def is_squashfs(self):
return self.__squashfs
def set_erofs(self, to=True):
self.__erofs = to
def is_erofs(self):
return self.__erofs
def set_xino(self, to=True):
self.__xino = to
def is_xino(self):
return self.__xino
def set_metacopy(self, to=True):
self.__metacopy = to
def is_metacopy(self):
return self.__metacopy
def set_nested(self, to=True):
self.__nested = to
def is_nested(self):
return self.__nested
def add_mntopt(self, opt):
self.__mntopts += "," + opt
def set_mntopts(self, opts):
self.__mntopts = opts
def mntopts(self):
return self.__mntopts
def fsname(self):
return self.__fsname
def fstype(self):
return self.__fstype
def set_fusefs(self, to):
self.__fusefs = True
self.__fsname = to
self.__fstype = "fuse." + to
def is_fusefs(self):
return self.__fusefs