From cc889dbb4ed40909ffd6c29bc29623cfcf1a1ca5 Mon Sep 17 00:00:00 2001 From: Michael E Brown Date: Tue, 8 Jan 2008 13:59:05 -0600 Subject: add initfailed hook so tmpfs plugin can properly unmount tmpfs on failure. make sure we call postbuild hooks even on failure. --- py/mock/backend.py | 12 ++++++++++-- py/mock/plugins/tmpfs.py | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/py/mock/backend.py b/py/mock/backend.py index 0ae7076..f0cf4a6 100644 --- a/py/mock/backend.py +++ b/py/mock/backend.py @@ -147,6 +147,14 @@ class Root(object): decorate(traceLog()) def init(self): + try: + self._init() + except (KeyboardInterrupt, Exception): + self._callHooks('initfailed') + raise + + decorate(traceLog()) + def _init(self): self.state("init") # NOTE: removed the following stuff vs mock v0: @@ -425,8 +433,8 @@ class Root(object): self.uidManager.restorePrivs() self._umountall() - # tell caching we are done building - self._callHooks('postbuild') + # tell caching we are done building + self._callHooks('postbuild') # ============= # 'Private' API diff --git a/py/mock/plugins/tmpfs.py b/py/mock/plugins/tmpfs.py index b725fb9..74c39a1 100644 --- a/py/mock/plugins/tmpfs.py +++ b/py/mock/plugins/tmpfs.py @@ -26,6 +26,7 @@ class Tmpfs(object): self.conf = conf rootObj.addHook("preinit", self._tmpfsPreInitHook) rootObj.addHook("postbuild", self._tmpfsPostBuildHook) + rootObj.addHook("initfailed", self._tmpfsPostBuildHook) decorate(traceLog()) def _tmpfsPreInitHook(self): @@ -33,6 +34,7 @@ class Tmpfs(object): mountCmd = "mount -n -t tmpfs mock_chroot_tmpfs %s" % self.rootObj.makeChrootPath() mock.util.do(mountCmd) + decorate(traceLog()) def _tmpfsPostBuildHook(self): getLog().info("unmounting tmpfs.") mountCmd = "umount -n %s" % self.rootObj.makeChrootPath() -- cgit