[pacman-dev] [PATCH 1] Simplify pmtest.generate and .run API (removed pacman parameter).
Previously pmtest.__init__ received and cached the pmenv.root, and generate and run received the pmenv.pacman. Now __init__ receives and caches the pmenv, allowing any method to fetch root, pacman, or other pmenv goodies directly instead of needing the extra parameter. Moved the "which fakeroot" and "which fakechroot" logic from pmtest up into pmenv. Repeating the probes and warnings for each test was a bit redundant. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail> --- test/pacman/pmenv.py | 28 +++++++++++++++-- test/pacman/pmrule.py | 10 +++--- test/pacman/pmtest.py | 87 +++++++++++++++++++++++---------------------------- 3 files changed, 70 insertions(+), 55 deletions(-) diff --git a/test/pacman/pmenv.py b/test/pacman/pmenv.py index f358285..3cfcfa5 100644 --- a/test/pacman/pmenv.py +++ b/test/pacman/pmenv.py @@ -21,6 +21,7 @@ import pmtest import tap +import util class pmenv(object): @@ -43,6 +44,27 @@ def __init__(self, root = "root"): "nolog": 0 } + if os.geteuid() != 0: + self.fakeroot = util.which("fakeroot") + if not self.fakeroot: + tap.diag("WARNING: fakeroot not found!") + else: + self.fakeroot = "fakeroot" + + self.fakechroot = util.which("fakechroot") + if not self.fakechroot: + tap.diag("WARNING: fakechroot not found!") + else: + self.fakechroot = "fakechroot" + + def cmdroot(self): + cmd = [] + if self.fakeroot: + cmd.append(self.fakeroot) + if self.fakechroot: + cmd.append(self.fakechroot) + return cmd + def __str__(self): return "root = %s\n" \ "pacman = %s" \ @@ -53,7 +75,7 @@ def addtest(self, testcase): """ if not os.path.isfile(testcase): raise IOError("test file %s not found" % testcase) - test = pmtest.pmtest(testcase, self.root) + test = pmtest.pmtest(testcase, self) self.testcases.append(test) def run(self): @@ -64,8 +86,8 @@ def run(self): tap.diag("Running '%s'" % t.testname) t.load() - t.generate(self.pacman) - t.run(self.pacman) + t.generate() + t.run() tap.diag("==> Checking rules") tap.todo = t.expectfailure diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py index c97a158..718c87c 100644 --- a/test/pacman/pmrule.py +++ b/test/pacman/pmrule.py @@ -56,7 +56,7 @@ def check(self, test): if test.retcode != int(key): success = 0 elif case == "OUTPUT": - logfile = os.path.join(test.root, util.LOGFILE) + logfile = os.path.join(test.env.root, util.LOGFILE) if not os.access(logfile, os.F_OK): tap.diag("LOGFILE not found, cannot validate 'OUTPUT' rule") success = 0 @@ -112,7 +112,7 @@ def check(self, test): tap.diag("PKG rule '%s' not found" % case) success = -1 elif kind == "FILE": - filename = os.path.join(test.root, key) + filename = os.path.join(test.env.root, key) if case == "EXIST": if not os.path.isfile(filename): success = 0 @@ -152,7 +152,7 @@ def check(self, test): tap.diag("FILE rule '%s' not found" % case) success = -1 elif kind == "DIR": - filename = os.path.join(test.root, key) + filename = os.path.join(test.env.root, key) if case == "EXIST": if not os.path.isdir(filename): success = 0 @@ -160,7 +160,7 @@ def check(self, test): tap.diag("DIR rule '%s' not found" % case) success = -1 elif kind == "LINK": - filename = os.path.join(test.root, key) + filename = os.path.join(test.env.root, key) if case == "EXIST": if not os.path.islink(filename): success = 0 @@ -168,7 +168,7 @@ def check(self, test): tap.diag("LINK rule '%s' not found" % case) success = -1 elif kind == "CACHE": - cachedir = os.path.join(test.root, util.PM_CACHEDIR) + cachedir = os.path.join(test.env.root, util.PM_CACHEDIR) if case == "EXISTS": pkg = test.findpkg(key, value, allow_local=True) if not pkg or not os.path.isfile( diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index b343d55..63d25e8 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -35,20 +35,20 @@ class pmtest(object): """Test object """ - def __init__(self, name, root): + def __init__(self, name, env): self.name = name self.testname = os.path.basename(name).replace('.py', '') - self.root = root + self.env = env self.cachepkgs = True def __str__(self): return "name = %s\n" \ "testname = %s\n" \ - "root = %s" % (self.name, self.testname, self.root) + "root = %s" % (self.name, self.testname, self.env.root) def addpkg2db(self, treename, pkg): if not treename in self.db: - self.db[treename] = pmdb.pmdb(treename, self.root) + self.db[treename] = pmdb.pmdb(treename, self.env.root) self.db[treename].pkgs.append(pkg) def addpkg(self, pkg): @@ -83,7 +83,7 @@ def load(self): self.args = "" self.retcode = 0 self.db = { - "local": pmdb.pmdb("local", self.root) + "local": pmdb.pmdb("local", self.env.root) } self.localpkgs = [] self.createlocalpkgs = False @@ -104,37 +104,40 @@ def load(self): else: raise IOError("file %s does not exist!" % self.name) - def generate(self, pacman): + def generate(self): tap.diag("==> Generating test environment") + root = self.env.root + pacman = self.env.pacman + # Cleanup leftover files from a previous test session - if os.path.isdir(self.root): - shutil.rmtree(self.root) - vprint("\t%s" % self.root) + if os.path.isdir(root): + shutil.rmtree(root) + vprint("\t%s" % root) # Create directory structure vprint(" Creating directory structure:") - dbdir = os.path.join(self.root, util.PM_SYNCDBPATH) - cachedir = os.path.join(self.root, util.PM_CACHEDIR) - syncdir = os.path.join(self.root, util.SYNCREPO) - tmpdir = os.path.join(self.root, util.TMPDIR) - logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE)) - etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF)) - bindir = os.path.join(self.root, "bin") + dbdir = os.path.join(root, util.PM_SYNCDBPATH) + cachedir = os.path.join(root, util.PM_CACHEDIR) + syncdir = os.path.join(root, util.SYNCREPO) + tmpdir = os.path.join(root, util.TMPDIR) + logdir = os.path.join(root, os.path.dirname(util.LOGFILE)) + etcdir = os.path.join(root, os.path.dirname(util.PACCONF)) + bindir = os.path.join(root, "bin") ldconfig = os.path.basename(pacman["ldconfig"]) - ldconfigdir = os.path.join(self.root, os.path.dirname(pacman["ldconfig"][1:])) + ldconfigdir = os.path.join(root, os.path.dirname(pacman["ldconfig"][1:])) shell = pacman["scriptlet-shell"][1:] - shelldir = os.path.join(self.root, os.path.dirname(shell)) + shelldir = os.path.join(root, os.path.dirname(shell)) sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir, ldconfigdir, shelldir] for sys_dir in sys_dirs: if not os.path.isdir(sys_dir): - vprint("\t%s" % sys_dir[len(self.root)+1:]) + vprint("\t%s" % sys_dir[len(root)+1:]) os.makedirs(sys_dir, 0755) # Only the dynamically linked binary is needed for fakechroot shutil.copy("/bin/sh", bindir) if shell != "bin/sh": - shutil.copy("/bin/sh", os.path.join(self.root, shell)) + shutil.copy("/bin/sh", os.path.join(root, shell)) shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"), os.path.join(ldconfigdir, ldconfig)) ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w") @@ -142,7 +145,7 @@ def generate(self, pacman): # Configuration file vprint(" Creating configuration file") - util.mkcfgfile(util.PACCONF, self.root, self.option, self.db) + util.mkcfgfile(util.PACCONF, root, self.option, self.db) # Creating packages vprint(" Creating package archives") @@ -174,24 +177,24 @@ def generate(self, pacman): vprint(" Populating file system") for f in self.filesystem: vprint("\t%s" % f) - util.mkfile(self.root, f, f) - path = os.path.join(self.root, f) + util.mkfile(root, f, f) + path = os.path.join(root, f) if os.path.isfile(path): os.utime(path, (355, 355)) for pkg in self.db["local"].pkgs: vprint("\tinstalling %s" % pkg.fullname()) - pkg.install_package(self.root) + pkg.install_package(root) # Done. vprint(" Taking a snapshot of the file system") - for roots, dirs, files in os.walk(self.root): + for roots, dirs, files in os.walk(root): for i in files: filename = os.path.join(roots, i) - f = pmfile.PacmanFile(self.root, filename.replace(self.root + "/", "")) + f = pmfile.PacmanFile(root, filename.replace(root + "/", "")) self.files.append(f) vprint("\t%s" % f.name) - def run(self, pacman): + def run(self): if os.path.isfile(util.PM_LOCK): tap.bail("\tERROR: another pacman session is on-going -- skipping") return @@ -199,19 +202,9 @@ def run(self, pacman): tap.diag("==> Running test") vprint("\tpacman %s" % self.args) - cmd = [] - if os.geteuid() != 0: - fakeroot = util.which("fakeroot") - if not fakeroot: - tap.diag("WARNING: fakeroot not found!") - else: - cmd.append("fakeroot") - - fakechroot = util.which("fakechroot") - if not fakechroot: - tap.diag("WARNING: fakechroot not found!") - else: - cmd.append("fakechroot") + root = self.env.root + pacman = self.env.pacman + cmd = self.env.cmdroot() if pacman["gdb"]: cmd.extend(["libtool", "execute", "gdb", "--args"]) @@ -223,17 +216,17 @@ def run(self, pacman): "--show-reachable=yes", "--suppressions=%s" % suppfile]) cmd.extend([pacman["bin"], - "--config", os.path.join(self.root, util.PACCONF), - "--root", self.root, - "--dbpath", os.path.join(self.root, util.PM_DBPATH), - "--cachedir", os.path.join(self.root, util.PM_CACHEDIR)]) + "--config", os.path.join(root, util.PACCONF), + "--root", root, + "--dbpath", os.path.join(root, util.PM_DBPATH), + "--cachedir", os.path.join(root, util.PM_CACHEDIR)]) if not pacman["manual-confirm"]: cmd.append("--noconfirm") if pacman["debug"]: cmd.append("--debug=%s" % pacman["debug"]) cmd.extend(shlex.split(self.args)) if not (pacman["gdb"] or pacman["valgrind"] or pacman["nolog"]): - output = open(os.path.join(self.root, util.LOGFILE), 'w') + output = open(os.path.join(root, util.LOGFILE), 'w') else: output = None vprint("\trunning: %s" % " ".join(cmd)) @@ -242,7 +235,7 @@ def run(self, pacman): # archives are made available more easily. time_start = time.time() self.retcode = subprocess.call(cmd, stdout=output, stderr=output, - cwd=os.path.join(self.root, util.TMPDIR), env={'LC_ALL': 'C'}) + cwd=os.path.join(root, util.TMPDIR), env={'LC_ALL': 'C'}) time_end = time.time() vprint("\ttime elapsed: %.2fs" % (time_end - time_start)) @@ -256,7 +249,7 @@ def run(self, pacman): tap.diag("\tERROR: %s not removed" % util.PM_LOCK) os.unlink(util.PM_LOCK) # Look for a core file - if os.path.isfile(os.path.join(self.root, util.TMPDIR, "core")): + if os.path.isfile(os.path.join(root, util.TMPDIR, "core")): tap.diag("\tERROR: pacman dumped a core file") def check(self): -- 1.8.4
On 30/09/13 10:12, Jeremy Heiner wrote:
Previously pmtest.__init__ received and cached the pmenv.root, and generate and run received the pmenv.pacman. Now __init__ receives and caches the pmenv, allowing any method to fetch root, pacman, or other pmenv goodies directly instead of needing the extra parameter.
Moved the "which fakeroot" and "which fakechroot" logic from pmtest up into pmenv. Repeating the probes and warnings for each test was a bit redundant.
I have not reviewed these patches as you said you were going to resend them without the format mangled. But this looks like two spearate changes to the test-suite and so should be two different patches. A
On Mon, Sep 30, 2013 at 10:43 PM, Allan McRae <allan@archlinux.org> wrote:
I have not reviewed these patches as you said you were going to resend them without the format mangled. But this looks like two spearate changes to the test-suite and so should be two different patches.
They are not independent, though. The 2nd can't work without the 1st. And the changes in the 1st don't have (in my estimation) sufficient motivation without the 2nd. Status update: I've got the mtree generation code working and have one basic test working. I'll send the complete suite of patches (probably 4) in after I find time to add more tests to cover all the possible things the mtree check can discover. I saw your excellent questions back on the original thread, and I'll answer them right after I finish this mtree stuff. Jeremy
participants (2)
-
Allan McRae
-
Jeremy Heiner