-
Committer:
Ryan Harper
-
Date:
2016-07-29 15:53:22 UTC
-
mfrom:
(401.1.4 trunk.subp_chroot)
-
Revision ID:
ryan.harper@canonical.com-20160729155322-1v99hgzttdcywfxv
util: add target (chroot) support to subp, add target_path helper.
This does primarily 3 things:
a.) adds 'chroot' support directly to subp
subp will now chroot itself if target is provided and is not /.
subp(['/bin/true'], target="/my/chroot")
b.) adds helper 'target_path' and uses for things that support target
this makes it easier for things to operate on a target or on /
and support target=None.
target_path also takes care of the oddities of os.path.join
(os.path.join("/etc", "/passwd") == "/passwd")
c.) replaces RunInChroot with ChrootableTarget
replace:
with RunInChroot("/target") as i:
i(["program"])
with:
with ChrootableTarget("/target") as i:
i.subp(["program"])
The difference between ChrootableTarget and subp is that the former
sets some things up. You need ChrootableTarget with sys_resolvconf=True
if you need networking (specifically dns). ChrootableTarget also adds the
system mounts.
Some things though dont need additional mounts or network.