def fakeroot_create():
test_root = os.path.join(g_tempdir, "ips.test.{0:d}".format(os.getpid()))
fakeroot = os.path.join(test_root, "fakeroot")
cmd_path = os.path.join(fakeroot, "pkg")
try:
os.stat(cmd_path)
except OSError as e:
pass
else:
# fakeroot already exists
raise RuntimeError("The fakeroot shouldn't already exist.\n"
"Path is:{0}".format(cmd_path))
# when creating the fakeroot we want to make sure pkg doesn't
# touch the real root.
env_sanitize(cmd_path)
#
# When accessing images via the pkg apis those apis will try
# to access the image containing the command from which the
# apis were invoked. Normally when running the test suite the
# command is run.py in a developers workspace, and that
# workspace lives in the root image. But accessing the root
# image during a test suite run is verboten. Hence, here we
# create a temporary image from which we can run the pkg
# command.
#
# create directories
mkdir_eexist_ok(test_root)
mkdir_eexist_ok(fakeroot)
debug("fakeroot image create {0}".format(fakeroot))
progtrack = pkg.client.progress.NullProgressTracker()
api_inst = pkg.client.api.image_create(PKG_CLIENT_NAME,
CLIENT_API_VERSION, fakeroot,
pkg.client.api.IMG_TYPE_ENTIRE, False,
progtrack=progtrack, cmdpath=cmd_path)
#
# put a copy of the pkg command in our fake root directory.
# we do this because when recursive linked image commands are
# run, the pkg interfaces may fork and exec additional copies
# of pkg(1), and in this case we want them to run the copy of
# pkg from the fake root.
#
fakeroot_cmdpath = os.path.join(fakeroot, "pkg")
shutil.copy(os.path.join(g_pkg_path, "usr", "bin", "pkg"),
fakeroot_cmdpath)
return fakeroot, fakeroot_cmdpath
评论列表
文章目录