diff options
author | Clark Williams <williams@redhat.com> | 2007-12-13 17:35:42 -0600 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2007-12-13 17:35:42 -0600 |
commit | 6b2d14f9afb39a955331f4a52a597b122f585166 (patch) | |
tree | 42e0863a785ba46d8c38be540307d850c4375a57 | |
parent | 076a90491cfc27c895618d950c4de828489c189c (diff) | |
download | mock-6b2d14f9afb39a955331f4a52a597b122f585166.tar.gz mock-6b2d14f9afb39a955331f4a52a597b122f585166.tar.xz mock-6b2d14f9afb39a955331f4a52a597b122f585166.zip |
changed more uses of .rootdir to makeChrootPath(); updated man page for --copyin and --copyout; updated plugins to use makeChrootPath(); updated releasetests.sh so that daemon tests uses --copyin
-rw-r--r-- | docs/mock.1 | 37 | ||||
-rwxr-xr-x | docs/releasetests.sh | 13 | ||||
-rwxr-xr-x | py/mock.py | 20 | ||||
-rw-r--r-- | py/mock/backend.py | 9 | ||||
-rw-r--r-- | py/mock/plugins/bind_mount.py | 6 | ||||
-rw-r--r-- | py/mock/plugins/ccache.py | 7 | ||||
-rw-r--r-- | py/mock/plugins/yum_cache.py | 7 |
7 files changed, 63 insertions, 36 deletions
diff --git a/docs/mock.1 b/docs/mock.1 index ac295e6..4afde95 100644 --- a/docs/mock.1 +++ b/docs/mock.1 @@ -17,6 +17,10 @@ mock [options] \fB\-\-install\fR PACKAGE mock [options] \fB\-\-update\fR .LP mock [options] \fB\-\-orphanskill\fR +.LP +mock [options] \fB\-\-copyin\fR \fIpath [\fIpath...\fR] \fIdestination\fR +.LP +mock [options] \fB\-\-copyout\fR \fIpath [\fIpath...\fR] \fIdestination\fR .SH "DESCRIPTION" .LP @@ -97,24 +101,41 @@ Show version number and exit. .SH "COMMANDS" .LP .TP -\fB\-\-clean\fR \- purge the chroot tree +\fB\-\-clean\fP +Purge the chroot tree .TP -\fB\-\-init\fR \- initialize a chroot (clean, install chroot packages, etc.) +\fB\-\-init\fP +Initialize a chroot (clean, install chroot packages, etc.) .TP -\fB\-\-rebuild\fR \- If no command is specified, rebuild is assumed. Rebuilds the specified SRPM(s). The buildroot is cleaned first, unless --no-clean is specified. +\fB\-\-rebuild\fP +If no command is specified, rebuild is assumed. Rebuilds the specified SRPM(s). The buildroot is cleaned first, unless --no-clean is specified. .TP -\fB\-\-shell\fR \- run the specified command interactively within the chroot (which must already be initialized -- no 'clean' is performed). If no command specified, /bin/sh is run. +\fB\-\-shell\fP +Run the specified command interactively within the chroot (which must already be initialized -- no 'clean' is performed). If no command specified, /bin/sh is run. .TP -\fB\-\-chroot\fR \- run the specified command non-interactively within the chroot (which must already be initialized -- no 'clean' is performed). Command output will be sent to the log files. +\fB\-\-chroot\fP +Run the specified command non-interactively within the chroot (which must already be initialized -- no 'clean' is performed). Command output will be sent to the log files. .TP -\fB\-\-installdeps\fR \- find out deps for SRPM or RPM, and do a yum install to put them in the buildroot. Buildroot must already be initialized -- no 'clean' is performed +\fB\-\-installdeps\fP +Find out deps for SRPM or RPM, and do a yum install to put them in the buildroot. Buildroot must already be initialized -- no 'clean' is performed .TP -\fB\-\-install\fR \- Do a yum install PACKAGE inside the buildroot. Buildroot must already be initialized -- no 'clean' is performed +\fB\-\-install\fP +Do a yum install PACKAGE inside the buildroot. Buildroot must already be initialized -- no 'clean' is performed .TP -\fB\-\-update\fR \- Do a yum update inside the buildroot. Buildroot must already be initialized -- no 'clean' is performed +\fB\-\-update\fP +Do a yum update inside the buildroot. Buildroot must already be initialized -- no 'clean' is performed .TP \fB\-\-orphanskill\fP Noop mode that simply checks that no stray processes are running in the chroot. Kills any processes that it finds using specified root. +.TP +\fB\-\-copyin\fP +Copies the source paths (files or directory trees) into the chroot at +the specified destination path. +.TP +\fB\-\-copyout\fP +Copies the source paths (files or directory trees) from the chroot to +the specified destination path. + .SH "FILES" .LP \fI/etc/mock/\fP \- default configuration directory diff --git a/docs/releasetests.sh b/docs/releasetests.sh index 5fb6537..55ed545 100755 --- a/docs/releasetests.sh +++ b/docs/releasetests.sh @@ -53,13 +53,6 @@ if [ ! -e $CHROOT/usr/include/python* ]; then exit 1 fi -# test the copyin command -time $MOCKCMD --copyin docs/release-instructions.txt /tmp -if [ ! -f $CHROOT/tmp/release-instructions.txt ]; then - echo "copyin test FAILED! could not find $CHROOT/tmp/release-instructions.txt" - exit 1 -fi - # test the copyout command time $MOCKCMD --copyout /etc/passwd /tmp/my-copyout-passwd if [ ! -f /tmp/my-copyout-passwd ]; then @@ -122,13 +115,14 @@ fi # # Test orphanskill feature (std) +# (also tests the --copyin feature) # if pgrep daemontest; then echo "Exiting because there is already a daemontest running." exit 1 fi time $MOCKCMD --offline --init -cp docs/daemontest $CHROOT/tmp +time $MOCKCMD --copyin docs/daemontest /tmp time $MOCKCMD --offline --chroot -- /tmp/daemontest if pgrep daemontest; then echo "Daemontest FAILED. found a daemontest process running after exit." @@ -137,9 +131,10 @@ fi # # Test orphanskill feature (explicit) +# (also tests --copyin) # time $MOCKCMD --offline --init -cp docs/daemontest $CHROOT/tmp +time $MOCKCMD --copyin docs/daemontest /tmp echo -e "#!/bin/sh\n/tmp/daemontest\nsleep 60\n" >> $CHROOT/tmp/try # the following should launch about three processes in the chroot: bash, sleep, daemontest $MOCKCMD --offline --chroot -- bash /tmp/try & @@ -25,6 +25,8 @@ mock [options] {--shell|--chroot} <cmd> mock [options] --installdeps {SRPM|RPM} mock [options] --install PACKAGE + mock [options] --copyin path [..path] destination + mock [options] --copyout path [..path] destination """ # library imports @@ -541,6 +543,7 @@ def main(ret): mock.util.orphansKill(chroot.rootdir) elif options.mode == 'copyin': chroot.tryLockBuildRoot() + chroot._resetLogging() uidManager.dropPrivsForever() if len(args) < 2: log.critical("Must have source and destinations for copyin") @@ -551,11 +554,15 @@ def main(ret): sys.exit(50) args = args[:-1] import shutil - for f in args: - print "copying %s to %s" % (f, dest) - shutil.copy(f, dest) + for src in args: + log.debug("copying %s to %s" % (src, dest)) + if os.path.isdir(src): + shutil.copytree(src, dest) + else: + shutil.copy(src, dest) elif options.mode == 'copyout': chroot.tryLockBuildRoot() + chroot._resetLogging() uidManager.dropPrivsForever() if len(args) < 2: log.critical("Must have source and destinations for copyout") @@ -568,8 +575,11 @@ def main(ret): import shutil for f in args: src = chroot.makeChrootPath(f) - print "copying %s to %s" % (src, dest) - shutil.copy(src, dest) + log.debug("copying %s to %s" % (src, dest)) + if os.path.isdir(src): + shutil.copytree(src, dest) + else: + shutil.copy(src, dest) if __name__ == '__main__': # fix for python 2.4 logging module bug: diff --git a/py/mock/backend.py b/py/mock/backend.py index ed283c9..c850118 100644 --- a/py/mock/backend.py +++ b/py/mock/backend.py @@ -143,6 +143,9 @@ class Root(object): decorate(traceLog()) def makeChrootPath(self, *args): + '''For safety reasons, self.rootdir should not be used directly. Instead + use this handy helper function anytime you want to reference a path in + relation to the chroot.''' tmp = self.rootdir + "/" + "/".join(args) return tmp.replace("//", "/") @@ -227,7 +230,7 @@ class Root(object): # files in /etc that need doing for key in self.chroot_file_contents: - p = self.makeChrootPath(*key.split('/')) + p = self.makeChrootPath(key) if not os.path.exists(p): # write file fo = open(p, 'w+') @@ -538,7 +541,7 @@ class Root(object): self.uidManager.becomeUser(self.chrootuid, self.chrootgid) try: # create dir structure - for subdir in ["%s" % self.makeChrootPath(self.builddir, s) for s in ('RPMS', 'SRPMS', 'SOURCES', 'SPECS', 'BUILD', 'originals')]: + for subdir in [self.makeChrootPath(self.builddir, s) for s in ('RPMS', 'SRPMS', 'SOURCES', 'SPECS', 'BUILD', 'originals')]: mock.util.mkdirIfAbsent(subdir) # change ownership so we can write to build home dir @@ -548,7 +551,7 @@ class Root(object): os.chmod(os.path.join(dirpath, path), 0755) # rpmmacros default - macrofile_out = '%s/.rpmmacros' % self.makeChrootPath(self.homedir) + macrofile_out = self.makeChrootPath(self.homedir, ".rpmmacros") rpmmacros = open(macrofile_out, 'w+') for key, value in self.macros.items(): rpmmacros.write( "%s %s\n" % (key, value) ) diff --git a/py/mock/plugins/bind_mount.py b/py/mock/plugins/bind_mount.py index 60f0f8b..df5e215 100644 --- a/py/mock/plugins/bind_mount.py +++ b/py/mock/plugins/bind_mount.py @@ -29,10 +29,10 @@ class BindMount(object): rootObj.bindMountObj = self rootObj.addHook("preinit", self._bindMountPreInitHook) for srcdir, destdir in self.bind_opts['dirs']: - rootObj.umountCmds.append('umount -n %s/%s' % (rootObj.rootdir, destdir)) - rootObj.mountCmds.append('mount -n --bind %s %s/%s' % (srcdir, rootObj.rootdir, destdir)) + rootObj.umountCmds.append('umount -n %s' % rootObj.makeChrootPath(destdir)) + rootObj.mountCmds.append('mount -n --bind %s %s' % (srcdir, rootObj.makeChrootPath(destdir))) decorate(traceLog()) def _bindMountPreInitHook(self): for srcdir, destdir in self.bind_opts['dirs']: - mock.util.mkdirIfAbsent("%s/%s" % (self.rootObj.rootdir, destdir)) + mock.util.mkdirIfAbsent(self.rootObj.makeChrootPath(destdir)) diff --git a/py/mock/plugins/ccache.py b/py/mock/plugins/ccache.py index 7974b1f..77a9130 100644 --- a/py/mock/plugins/ccache.py +++ b/py/mock/plugins/ccache.py @@ -25,13 +25,12 @@ class CCache(object): self.rootObj = rootObj self.ccache_opts = conf self.ccachePath = self.ccache_opts['dir'] % self.ccache_opts - self.rootdir = rootObj.rootdir rootObj.ccacheObj = self rootObj.preExistingDeps = rootObj.preExistingDeps + " ccache " rootObj.addHook("prebuild", self._ccacheBuildHook) rootObj.addHook("preinit", self._ccachePreInitHook) - rootObj.umountCmds.append('umount -n %s/tmp/ccache' % rootObj.rootdir) - rootObj.mountCmds.append('mount -n --bind %s %s/tmp/ccache' % (self.ccachePath, rootObj.rootdir)) + rootObj.umountCmds.append('umount -n %s' % rootObj.makeChrootPath("/tmp/ccache")) + rootObj.mountCmds.append('mount -n --bind %s %s' % (self.ccachePath, rootObj.makeChrootPath("/tmp/ccache"))) # ============= # 'Private' API @@ -49,7 +48,7 @@ class CCache(object): # cache. decorate(traceLog()) def _ccachePreInitHook(self): - mock.util.mkdirIfAbsent(os.path.join(self.rootdir, 'tmp/ccache')) + mock.util.mkdirIfAbsent(self.rootObj.makeChrootPath('/tmp/ccache')) mock.util.mkdirIfAbsent(self.ccachePath) os.environ['PATH'] = "/tmp/ccache:%s" % (os.environ['PATH']) os.environ['CCACHE_DIR'] = "/tmp/ccache" diff --git a/py/mock/plugins/yum_cache.py b/py/mock/plugins/yum_cache.py index 5b371bb..bcdf465 100644 --- a/py/mock/plugins/yum_cache.py +++ b/py/mock/plugins/yum_cache.py @@ -30,14 +30,13 @@ class YumCache(object): self.yum_cache_opts = conf self.yumSharedCachePath = self.yum_cache_opts['dir'] % self.yum_cache_opts self.state = rootObj.state - self.rootdir = rootObj.rootdir self.online = rootObj.online rootObj.yum_cacheObj = self rootObj.addHook("preyum", self._yumCachePreYumHook) rootObj.addHook("postyum", self._yumCachePostYumHook) rootObj.addHook("preinit", self._yumCachePreInitHook) - rootObj.umountCmds.append('umount -n %s/var/cache/yum' % rootObj.rootdir) - rootObj.mountCmds.append('mount -n --bind %s %s/var/cache/yum' % (self.yumSharedCachePath, rootObj.rootdir)) + rootObj.umountCmds.append('umount -n %s' % rootObj.makeChrootPath('/var/cache/yum')) + rootObj.mountCmds.append('mount -n --bind %s %s' % (self.yumSharedCachePath, rootObj.makeChrootPath('/var/cache/yum'))) mock.util.mkdirIfAbsent(self.yumSharedCachePath) self.yumCacheLock = open(os.path.join(self.yumSharedCachePath, "yumcache.lock"), "a+") @@ -65,7 +64,7 @@ class YumCache(object): decorate(traceLog()) def _yumCachePreInitHook(self): getLog().info("enabled yum cache") - mock.util.mkdirIfAbsent(os.path.join(self.rootdir, 'var/cache/yum')) + mock.util.mkdirIfAbsent(self.rootObj.makeChrootPath('/var/cache/yum')) # lock so others dont accidentally use yum cache while we operate on it. self._yumCachePreYumHook() |