ostbuild: Create deploy-qemu subcommand
This commit is contained in:
1 parent
5560c04770
commit
9aa9397e42
7 files changed
+81
-165
No files matched your search
@@ -50,9 +50,9 @@ class OstbuildDeployQemu(builtins.Builtin):
|
||||
target_names.append(target['name'])
|
||||
|
||||
helper = privileged_subproc.PrivilegedSubprocess()
|
||||
sys_repo = os.path.join(self.ostree_dir, 'repo')
|
||||
shadow_path = os.path.join(self.workdir, 'shadow-repo')
|
||||
helper.spawn_sync(['ostree', '--repo=' + sys_repo,
|
||||
'pull-local', shadow_path])
|
||||
child_args = ['ostbuild', 'privhelper-deploy-qemu', shadow_path]
|
||||
child_args.extend(target_names)
|
||||
helper.spawn_sync(child_args)
|
||||
|
||||
builtins.register(OstbuildDeployRoot)
|
||||
builtins.register(OstbuildDeployQemu)
|
||||
@@ -24,8 +24,9 @@ from StringIO import StringIO
|
||||
|
||||
from . import builtins
|
||||
from .ostbuildlog import log, fatal
|
||||
from .subprocess_helpers import run_sync
|
||||
from . import ostbuildrc
|
||||
from . import privileged_subproc
|
||||
from . import fileutil
|
||||
|
||||
class OstbuildPrivhelperDeployQemu(builtins.Builtin):
|
||||
name = "privhelper-deploy-qemu"
|
||||
@@ -34,23 +35,76 @@ class OstbuildPrivhelperDeployQemu(builtins.Builtin):
|
||||
def __init__(self):
|
||||
builtins.Builtin.__init__(self)
|
||||
|
||||
def _create_qemu_disk(self):
|
||||
log("%s not found, creating" % (self.qemu_path, ))
|
||||
success = False
|
||||
tmppath = self.qemu_path + '.tmp'
|
||||
if os.path.exists(tmppath):
|
||||
os.unlink(tmppath)
|
||||
subprocess.check_call(['qemu-img', 'create', tmppath, '6G'])
|
||||
subprocess.check_call(['mkfs.ext4', '-q', '-F', tmppath])
|
||||
|
||||
subprocess.call(['umount', self.mountpoint], stderr=open('/dev/null', 'w'))
|
||||
try:
|
||||
subprocess.check_call(['mount', '-o', 'loop', tmppath, self.mountpoint])
|
||||
|
||||
for topdir in ['mnt', 'sys', 'root', 'home', 'opt', 'tmp', 'run',
|
||||
'ostree']:
|
||||
path = os.path.join(self.mountpoint, topdir)
|
||||
fileutil.ensure_dir(path)
|
||||
os.chmod(os.path.join(self.mountpoint, 'root'), 0700)
|
||||
os.chmod(os.path.join(self.mountpoint, 'tmp'), 01777)
|
||||
|
||||
varpath = os.path.join(self.mountpoint, 'ostree', 'var')
|
||||
fileutil.ensure_dir(varpath)
|
||||
modulespath = os.path.join(self.mountpoint, 'ostree', 'modules')
|
||||
fileutil.ensure_dir(modulespath)
|
||||
|
||||
repo_path = os.path.join(self.mountpoint, 'ostree', 'repo')
|
||||
fileutil.ensure_dir(repo_path)
|
||||
subprocess.check_call(['ostree', '--repo=' + repo_path, 'init'])
|
||||
success = True
|
||||
finally:
|
||||
subprocess.call(['umount', self.mountpoint])
|
||||
if success:
|
||||
os.rename(tmppath, self.qemu_path)
|
||||
|
||||
def execute(self, argv):
|
||||
parser = argparse.ArgumentParser(description=self.short_description)
|
||||
parser.add_argument('srcrepo')
|
||||
parser.add_argument('targets', nargs='+')
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
self.args = args
|
||||
|
||||
self.parse_config()
|
||||
self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
|
||||
|
||||
target_names = []
|
||||
for target in self.bin_snapshot['targets']:
|
||||
target_names.append(target['name'])
|
||||
|
||||
helper = privileged_subproc.PrivilegedSubprocess()
|
||||
sys_repo = os.path.join(self.ostree_dir, 'repo')
|
||||
shadow_path = os.path.join(self.workdir, 'shadow-repo')
|
||||
helper.spawn_sync(['ostree', '--repo=' + sys_repo,
|
||||
'pull-local', shadow_path])
|
||||
if os.geteuid() != 0:
|
||||
fatal("This helper can only be run as root")
|
||||
|
||||
self.ostree_dir = self.find_ostree_dir()
|
||||
self.qemu_path = os.path.join(self.ostree_dir, "ostree-qemu.img")
|
||||
|
||||
self.mountpoint = os.path.join(self.ostree_dir, 'ostree-qemu-mnt')
|
||||
fileutil.ensure_dir(self.mountpoint)
|
||||
|
||||
if not os.path.exists(self.qemu_path):
|
||||
self._create_qemu_disk()
|
||||
|
||||
subprocess.call(['umount', self.mountpoint], stderr=open('/dev/null', 'w'))
|
||||
repo_path = os.path.join(self.mountpoint, 'ostree', 'repo')
|
||||
try:
|
||||
subprocess.check_call(['mount', '-o', 'loop', self.qemu_path, self.mountpoint])
|
||||
child_args = ['ostree', '--repo=' + repo_path, 'pull-local', args.srcrepo]
|
||||
child_args.extend(args.targets)
|
||||
run_sync(child_args)
|
||||
|
||||
first_target = args.targets[0]
|
||||
for target in args.targets:
|
||||
run_sync(['ostree', '--repo=' + repo_path, 'checkout', '--atomic-retarget', target],
|
||||
cwd=os.path.join(self.mountpoint, 'ostree'))
|
||||
current_link_path = os.path.join(self.mountpoint, 'ostree', 'current')
|
||||
os.symlink(first_target, current_link_path + '.tmp')
|
||||
os.rename(current_link_path + '.tmp', current_link_path)
|
||||
finally:
|
||||
subprocess.call(['umount', self.mountpoint])
|
||||
|
||||
|
||||
builtins.register(OstbuildDeployRoot)
|
||||
builtins.register(OstbuildPrivhelperDeployQemu)
|
||||
@@ -30,8 +30,10 @@ from . import builtin_chroot_compile_one
|
||||
from . import builtin_compose
|
||||
from . import builtin_compile_one
|
||||
from . import builtin_deploy_root
|
||||
from . import builtin_deploy_qemu
|
||||
from . import builtin_git_mirror
|
||||
from . import builtin_pull_components
|
||||
from . import builtin_privhelper_deploy_qemu
|
||||
from . import builtin_prefix
|
||||
from . import builtin_resolve
|
||||
from . import builtin_modify_snapshot
|
||||
@@ -42,6 +44,8 @@ from . import builtin_status
|
||||
def usage(ecode):
|
||||
print "Builtins:"
|
||||
for builtin in builtins.get_all():
|
||||
if builtin.name.startswith('privhelper'):
|
||||
continue
|
||||
print " %s - %s" % (builtin.name, builtin.short_description)
|
||||
return ecode
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import os,sys,subprocess
|
||||
|
||||
from .ostbuildlog import log, fatal
|
||||
from . import ostbuildrc
|
||||
from .subprocess_helpers import run_sync
|
||||
|
||||
class PrivilegedSubprocess(object):
|
||||
|
||||
@@ -35,5 +36,4 @@ class PrivilegedSubprocess(object):
|
||||
|
||||
def _pkexec_spawn_sync(self, argv):
|
||||
pkexec_argv = ['pkexec'] + argv
|
||||
log("Running: %s" % (subprocess.list2cmdline(pkexec_argv), ))
|
||||
subprocess.check_call(pkexec_argv)
|
||||
run_sync(pkexec_argv)
|
||||
Reference in new issue
Block a user