Providing a test case can remove the temporary directory that it created

(Platform: Linux, specifically Fedora and Red Hat Enterprise Linux 6)

I have an integration test written in Python that does the following:

  • creates a temporary directory
  • tells the web service (running apache) to run the rsync job, which copies the files to this directory
  • Verifies that the files were copied correctly (i.e., the configuration was correctly transferred from the client to rsync through the web service).
  • (trying) delete the temporary directory

At the moment, the last step is failing because rsync creates files with their ownership rights set with apache user rights, and therefore in the test case there are no necessary permissions to delete the files.

This Server Fault question provides a good explanation of why the cleanup step is currently failing, given the situation that the integration test sets up.

What I'm doing now: I just don’t delete the temporary directory when cleaning the test, so these integration tests leave stub files around that need to be cleaned out /tmpmanually.

The main solution that I'm considering right now is to add a setuid script specifically to handle the cleanup operation for the test suite. This should work, but I hope someone else can offer a more elegant solution. In particular, I would really like it if nothing in the test integration client cared about the uid of the apache process.

The approaches I considered but rejected for various reasons:

  • root. , , root .
  • , . , rsync , . , , .
  • apache. rsync , .
  • Apache . ( , , apache ), , Apache, , . , , , , , .

, , , rsync, . , , , .

+3
2

setfacl.

, , ( unittest.TestCase, , addCleanup):

local_path = tempfile.mkdtemp().decode("utf-8")
self.addCleanup(shutil.rmtree, local_path)
acl = "d:u:{0}:rwX".format(os.geteuid())
subprocess.check_call(["setfacl", "-m", acl, local_path])

, .

ACL , - , - .

+1

apache ( httpd, , ).

+1

All Articles