Revision fe4f6dca
b/lib/pathutils.py | ||
---|---|---|
45 | 45 |
KVM_IFUP = _autoconf.PKGLIBDIR + "/kvm-ifup" |
46 | 46 |
SETUP_SSH = _autoconf.TOOLSDIR + "/setup-ssh" |
47 | 47 |
XM_CONSOLE_WRAPPER = _autoconf.PKGLIBDIR + "/tools/xm-console-wrapper" |
48 |
ETC_HOSTS = "/etc/hosts"
|
|
48 |
ETC_HOSTS = vcluster.ETC_HOSTS
|
|
49 | 49 |
|
50 | 50 |
# Top-level paths |
51 | 51 |
DATA_DIR = LOCALSTATEDIR + "/lib/ganeti" |
b/lib/vcluster.py | ||
---|---|---|
32 | 32 |
from ganeti import compat |
33 | 33 |
|
34 | 34 |
|
35 |
ETC_HOSTS = "/etc/hosts" |
|
36 |
|
|
35 | 37 |
_VIRT_PATH_PREFIX = "/###-VIRTUAL-PATH-###," |
36 | 38 |
_ROOTDIR_ENVNAME = "GANETI_ROOTDIR" |
37 | 39 |
_HOSTNAME_ENVNAME = "GANETI_HOSTNAME" |
38 | 40 |
|
41 |
#: List of paths which shouldn't be virtualized |
|
42 |
_VPATH_WHITELIST = frozenset([ |
|
43 |
ETC_HOSTS, |
|
44 |
]) |
|
45 |
|
|
39 | 46 |
|
40 | 47 |
def _GetRootDirectory(envname): |
41 | 48 |
"""Retrieves root directory from an environment variable. |
... | ... | |
236 | 243 |
""" |
237 | 244 |
assert os.path.isabs(path) |
238 | 245 |
|
239 |
if _noderoot: |
|
246 |
if _noderoot and path not in _VPATH_WHITELIST:
|
|
240 | 247 |
return _VIRT_PATH_PREFIX + _RemoveNodePrefix(path, _noderoot=_noderoot) |
241 | 248 |
else: |
242 | 249 |
return path |
... | ... | |
252 | 259 |
""" |
253 | 260 |
assert os.path.isabs(path) |
254 | 261 |
|
255 |
if _noderoot: |
|
262 |
if _noderoot and path not in _VPATH_WHITELIST:
|
|
256 | 263 |
if path.startswith(_VIRT_PATH_PREFIX): |
257 | 264 |
return AddNodePrefix(path[len(_VIRT_PATH_PREFIX):], _noderoot=_noderoot) |
258 | 265 |
else: |
b/test/ganeti.vcluster_unittest.py | ||
---|---|---|
27 | 27 |
from ganeti import utils |
28 | 28 |
from ganeti import compat |
29 | 29 |
from ganeti import vcluster |
30 |
from ganeti import pathutils |
|
30 | 31 |
|
31 | 32 |
import testutils |
32 | 33 |
|
... | ... | |
200 | 201 |
self.assertEqual(vcluster.MakeVirtualPath("/tmp/file", _noderoot=None), |
201 | 202 |
"/tmp/file") |
202 | 203 |
|
204 |
def testWhitelisted(self): |
|
205 |
mvp = vcluster.MakeVirtualPath |
|
206 |
for path in vcluster._VPATH_WHITELIST: |
|
207 |
self.assertEqual(mvp(path), path) |
|
208 |
self.assertEqual(mvp(path, _noderoot=None), path) |
|
209 |
self.assertEqual(mvp(path, _noderoot="/tmp"), path) |
|
210 |
|
|
203 | 211 |
|
204 | 212 |
class TestLocalizeVirtualPath(unittest.TestCase): |
205 | 213 |
def testWrongPrefix(self): |
... | ... | |
225 | 233 |
self.assertEqual(vcluster.LocalizeVirtualPath("/tmp/file", _noderoot=None), |
226 | 234 |
"/tmp/file") |
227 | 235 |
|
236 |
def testWhitelisted(self): |
|
237 |
lvp = vcluster.LocalizeVirtualPath |
|
238 |
for path in vcluster._VPATH_WHITELIST: |
|
239 |
self.assertEqual(lvp(path), path) |
|
240 |
self.assertEqual(lvp(path, _noderoot=None), path) |
|
241 |
self.assertEqual(lvp(path, _noderoot="/tmp"), path) |
|
242 |
|
|
228 | 243 |
|
229 | 244 |
class TestVirtualPathPrefix(unittest.TestCase): |
230 | 245 |
def test(self): |
Also available in: Unified diff