diff options
author | Colin Walters <walters@verbum.org> | 2012-05-03 11:16:08 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2012-05-04 16:16:16 -0400 |
commit | 9aa9397e422e4c29fc54d32d52f75364a7e9e313 (patch) | |
tree | fe1437c3680a6c8f28f94d41345c7fce3979ea45 | |
parent | 5560c0477026fd7ab2bfdd9932265e736c0965d7 (diff) | |
download | ostree-9aa9397e422e4c29fc54d32d52f75364a7e9e313.tar.gz |
ostbuild: Create deploy-qemu subcommand
-rw-r--r-- | Makefile-ostbuild.am | 2 | ||||
-rwxr-xr-x | gnomeos/gnomeos-qemu-create.sh | 74 | ||||
-rwxr-xr-x | gnomeos/gnomeos-qemu-pull.sh | 70 | ||||
-rwxr-xr-x | src/ostbuild/pyostbuild/builtin_deploy_qemu.py | 8 | ||||
-rwxr-xr-x | src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py | 86 | ||||
-rwxr-xr-x | src/ostbuild/pyostbuild/main.py | 4 | ||||
-rwxr-xr-x | src/ostbuild/pyostbuild/privileged_subproc.py | 4 |
7 files changed, 82 insertions, 166 deletions
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am index 0c87e65c..a6e97062 100644 --- a/Makefile-ostbuild.am +++ b/Makefile-ostbuild.am @@ -29,8 +29,10 @@ pyostbuild_PYTHON = \ src/ostbuild/pyostbuild/builtin_compose.py \ src/ostbuild/pyostbuild/builtin_chroot_compile_one.py \ src/ostbuild/pyostbuild/builtin_compile_one.py \ + src/ostbuild/pyostbuild/builtin_deploy_qemu.py \ src/ostbuild/pyostbuild/builtin_deploy_root.py \ src/ostbuild/pyostbuild/builtin_pull_components.py \ + src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py \ src/ostbuild/pyostbuild/builtin_git_mirror.py \ src/ostbuild/pyostbuild/builtin_prefix.py \ src/ostbuild/pyostbuild/builtin_resolve.py \ diff --git a/gnomeos/gnomeos-qemu-create.sh b/gnomeos/gnomeos-qemu-create.sh deleted file mode 100755 index bc0e6a57..00000000 --- a/gnomeos/gnomeos-qemu-create.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash -# -*- indent-tabs-mode: nil; -*- -# Create ostree-qemu.img file in the current directory, suitable -# for booting via qemu. -# -# Copyright (C) 2011,2012 Colin Walters <walters@verbum.org> -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -set -e -set -x - -SRCDIR=`dirname $0` -WORKDIR=`pwd` - -if test $(id -u) != 0; then - cat <<EOF -This script should be run as root. -EOF - exit 1 -fi - -usage () { - echo "$0" - exit 1 -} - -OBJ=ostree-qemu.img -if ! test -f ${OBJ}; then - # Hardcoded 6 gigabyte filesystem size here; 6 gigabytes should be - # enough for everybody. - qemu-img create $OBJ 6G - mkfs.ext4 -q -F $OBJ -fi - -mkdir -p fs -umount fs || true -sleep 1 # Avoid Linux kernel bug, pretty sure it's the new RCU pathname lookup -mount -o loop ostree-qemu.img fs - -cd fs - -if ! test -d ./ostree/repo/objects; then - mkdir -p ./ostree - - $SRCDIR/gnomeos-setup.sh $(pwd)/ostree -fi - -mkdir -p ./run ./home ./root ./sys -mkdir -p ./tmp -chmod 01777 ./tmp - -mkdir -p $(pwd)/ostree/modules -rsync -a -H -v --delete /ostree/modules/ ./ostree/modules/ - -cd .. -umount fs - -cat << EOF -Next, run gnomeos-qemu-pull.sh to copy data. -EOF diff --git a/gnomeos/gnomeos-qemu-pull.sh b/gnomeos/gnomeos-qemu-pull.sh deleted file mode 100755 index 29c87aa8..00000000 --- a/gnomeos/gnomeos-qemu-pull.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -# -*- indent-tabs-mode: nil; -*- -# Run built image in QEMU -# -# Copyright (C) 2011,2012 Colin Walters <walters@verbum.org> -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -set -e -set -x - -SRCDIR=`dirname $0` -WORKDIR=`pwd` - -if test $(id -u) != 0; then - cat <<EOF -This script should be run as root. -EOF - exit 1 -fi - -usage () { - cat <<EOF -usage: $0 SRC_REPO_PATH CURRENT_REF [REFS...] -EOF - exit 1 -} - -SRC_REPO_PATH=$1 -test -n "$SRC_REPO_PATH" || usage -shift - -CURRENT_REF=$1 -test -n "$CURRENT_REF" || usage -shift - -if ! test -f ostree-qemu.img; then - cat <<EOF -ostree-qemu.img not found; You must run gnomeos-qemu-create.sh first -EOF -fi - -mkdir -p fs -umount fs || true -sleep 1 # Avoid Linux kernel bug, pretty sure it's the new RCU pathname lookup -mount -o loop ostree-qemu.img fs - -cd fs -ostree --repo=./ostree/repo pull-local ${SRC_REPO_PATH} ${CURRENT_REF} "$@" - -cd ostree -ostree --repo=./repo checkout --atomic-retarget ${CURRENT_REF} -ln -sf ${CURRENT_REF} ${CURRENT_REF}.tmplink -mv -T ${CURRENT_REF}.tmplink current - -cd ${WORKDIR} -umount fs diff --git a/src/ostbuild/pyostbuild/builtin_deploy_qemu.py b/src/ostbuild/pyostbuild/builtin_deploy_qemu.py index 5afea833..549bbca4 100755 --- a/src/ostbuild/pyostbuild/builtin_deploy_qemu.py +++ b/src/ostbuild/pyostbuild/builtin_deploy_qemu.py @@ -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) diff --git a/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py b/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py index 16b6bbbb..2fc852c9 100755 --- a/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py +++ b/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py @@ -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) diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py index 35d150ad..7f91e385 100755 --- a/src/ostbuild/pyostbuild/main.py +++ b/src/ostbuild/pyostbuild/main.py @@ -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 diff --git a/src/ostbuild/pyostbuild/privileged_subproc.py b/src/ostbuild/pyostbuild/privileged_subproc.py index 982984bf..0116cef2 100755 --- a/src/ostbuild/pyostbuild/privileged_subproc.py +++ b/src/ostbuild/pyostbuild/privileged_subproc.py @@ -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) |