On 11/11/13 at 06:47am, Jeremy Heiner wrote:
pmpkg.install_package (which is called by the framework to populate the filesystem with "local" db packages) now executes any pre_install and/or post_install scripts it finds. Prior to this commit no unit test had a "local" package with such a script. The two new tests in this commit use post_install to remove some installed files.
As with the previous commit, the -Qk test (003) validates the filesystem (warning about the missing files), while the -Qkk test (004) can only check for the warning about the lack of an mtree.
Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmpkg.py | 13 +++++++++++++ test/pacman/tests/TESTS | 2 ++ test/pacman/tests/querycheck003.py | 19 +++++++++++++++++++ test/pacman/tests/querycheck004.py | 17 +++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 test/pacman/tests/querycheck003.py create mode 100644 test/pacman/tests/querycheck004.py
diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 6f7ae6e..fd469b1 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -22,6 +22,7 @@ import stat import shutil from StringIO import StringIO +import subprocess import tarfile
import util @@ -177,13 +178,25 @@ def makepkg(self, path):
tar.close()
+ def runscript(self, root, name): + script = self.install[name] + if script: + util.vprint("running %s script: %s" % (name, script)) + # note: there are differences between the environment the script + # gets from here versus the one the pacman binary would give it. + # in particular there's no chroot, so use relative paths. + subprocess.call(["sh", "-c", script], + cwd=os.path.join(root,util.TMPDIR)) +
One of the main reasons I suggested adding install script support for this was so that they would work the same as scripts run by pacman and therefore be easy to write and understand. At the very least, they should be run in root, not TMPDIR and honor env["scriptlet-shell"]. This should also be run with fakeroot (use -i and -s to save state between invocations) and be run inside a fake chroot. The only downside I see is the need to copy binaries into the test chroot. It looks like your tests would require us to copy at least chown, chmod, rm, touch, and ln into the chroot. Is there any problem with copying the additional binaries?
def install_package(self, root): """Install the package in the given root.""" + self.runscript(root, "pre_install") for f in self.files: util.mkfile(root, f, f) path = os.path.join(root, f) if os.path.isfile(path): os.utime(path, (355, 355)) + self.runscript(root, "post_install")
def filelist(self): """Generate a list of package files."""