From: Mukund Sivaraman Date: Fri, 25 May 2012 06:29:29 +0000 (+0530) Subject: [1704] Test remove_lock_files() X-Git-Tag: trac2351_base~226^2~60^2^2~39 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e95197a4b47847b4ec85e83bdb1fb5edf685cd0;p=thirdparty%2Fkea.git [1704] Test remove_lock_files() --- diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in index 6b6bd64b08..0091eac591 100755 --- a/src/bin/bind10/bind10_src.py.in +++ b/src/bin/bind10/bind10_src.py.in @@ -1138,7 +1138,9 @@ def remove_lock_files(): lpath = os.environ["B10_FROM_SOURCE_LOCALSTATEDIR"] for f in lockfiles: - os.unlink(lpath + '/' + f) + fname = lpath + '/' + f + if os.path.isfile(fname): + os.unlink(fname) return diff --git a/src/bin/bind10/tests/Makefile.am b/src/bin/bind10/tests/Makefile.am index d54ee56be1..82958af82c 100644 --- a/src/bin/bind10/tests/Makefile.am +++ b/src/bin/bind10/tests/Makefile.am @@ -23,6 +23,7 @@ endif chmod +x $(abs_builddir)/$$pytest ; \ $(LIBRARY_PATH_PLACEHOLDER) \ PYTHONPATH=$(COMMON_PYTHON_PATH):$(abs_top_srcdir)/src/bin:$(abs_top_builddir)/src/bin/bind10:$(abs_top_builddir)/src/lib/util/io/.libs \ + LOCKFILE_TESTPATH=$(abs_top_builddir)/src/bin/bind10/tests/lockfile_test \ BIND10_MSGQ_SOCKET_FILE=$(abs_top_builddir)/msgq_socket \ $(PYCOVERAGE_RUN) $(abs_builddir)/$$pytest || exit ; \ done diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in index 84a9da968d..345e053cd4 100644 --- a/src/bin/bind10/tests/bind10_test.py.in +++ b/src/bin/bind10/tests/bind10_test.py.in @@ -1463,6 +1463,43 @@ class SocketSrvTest(unittest.TestCase): self.assertEqual({}, self.__boss._unix_sockets) self.assertTrue(sock.closed) +class TestFunctions(unittest.TestCase): + def test_remove_lock_files(self): + if not os.path.isdir(os.environ["LOCKFILE_TESTPATH"]): + os.mkdir(os.environ["LOCKFILE_TESTPATH"]) + + if "B10_FROM_BUILD" in os.environ: + oldenv = os.environ["B10_FROM_BUILD"] + else: + oldenv = None + + os.environ["B10_FROM_BUILD"] = os.environ["LOCKFILE_TESTPATH"] + + # create lockfiles for the testcase + lockfiles = ["logger_lockfile"] + for f in lockfiles: + fname = os.environ["B10_FROM_BUILD"] + '/' + f + if not os.path.isfile(fname): + open(fname, "w").close() + + # first call should clear up all the lockfiles + bind10_src.remove_lock_files() + + # check if the lockfiles exist + for f in lockfiles: + fname = os.environ["B10_FROM_BUILD"] + '/' + f + self.assertFalse(os.path.isfile(fname)) + + # second call should not assert anyway + bind10_src.remove_lock_files() + + os.rmdir(os.environ["LOCKFILE_TESTPATH"]) + + if oldenv is not None: + os.environ["B10_FROM_BUILD"] = oldenv + else: + os.environ.pop("B10_FROM_BUILD") + if __name__ == '__main__': # store os.environ for test_unchanged_environment original_os_environ = copy.deepcopy(os.environ)