[apparmor] [patch] Add tempdir and tempfile handling to AATest

Christian Boltz apparmor at cboltz.de
Fri May 29 10:58:58 UTC 2015


Hello,

Am Donnerstag, 28. Mai 2015 schrieb Steve Beattie:
> On Sun, May 17, 2015 at 10:33:47PM +0200, Christian Boltz wrote:
> > this patch adds writeTmpfile() to AATest to write a file into the
> > tmpdir. If no tmpdir exists yet, automatically create one.
> > 
> > createTmpdir() is a separate function so that it's possible to
> > manually create the tmpdir (for example, if a test needs an empty
> > tmpdir).
> > 
> > Also add a tearDown() function to delete the tmpdir again. This
> > function calls self.AATeardown() to avoid the need for super() in
> > child classes.
> > 
> > Finally, simplify AaTestWithTempdir in test-aa.py to use
> > createTmpdir() and add an example for AATeardown() to
> > test-example.py.
> > 
> > 
> > [ 10-tests-tempdir.diff ]
> > 
> > === modified file utils/test/common_test.py
> > --- utils/test/common_test.py   2015-05-17 22:22:19.266683216 +0200
> > +++ utils/test/common_test.py   2015-05-17 22:24:41.240395607 +0200
> > @@ -16,7 +16,9 @@
> > 
> >  import inspect
> >  import os
> >  import re
> > 
> > +import shutil
> > 
> >  import sys
> > 
> > +import tempfile
> > 
> >  import apparmor.common
> >  import apparmor.config
> > 
> > @@ -47,7 +49,27 @@
> > 
> >          '''override this function if a test needs additional setup
> >          steps (instead of overriding setUp())''' pass
> > 
> > +    def tearDown(self):
> > +        if self.tmpdir:
> > +            if os.path.exists(self.tmpdir):
> > +                shutil.rmtree(self.tmpdir)
> 
> No need to nest this deep, the following will work.
> 
>         if self.tmpdir and os.path.exists(self.tmpdir):
>             shutil.rmtree(self.tmpdir)

Right ;-)

> With that change, Acked-by: Steve Beattie <steve at nxnw.org>.

Thanks, comited.

What about the 2.9 branch? I wouldn't be surprised if some future 
changes rely on the automagic tempdir handling, so should I also commit 
this patch to the 2.9 branch?

> A feature to add would be a .debug field defaulting to False, and
> which if True doesn't delete the directory tree, leaving it behind
> for after the fact inspection.

Sounds like a good idea - added to my TODO list ;-)


Regards,

Christian Boltz
-- 
> beim Übersetzen von qcad steigt die Prozessorauslastung von
> cc1plus bis auf 98% an. Dasist doch nicht üblich, oder?
Warum stört Dich das? Du hast doch die ganze CPU bezahlt, oder?
Oder hast Du nur 'ne  halbe?
[> Stefan Schlörholz und Andreas Kyek in suse-linux]




More information about the AppArmor mailing list