From d5ea62c53a03ffa8dba1c4326054d4f2ab405649 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Tue, 28 Oct 2014 15:15:44 +0000 Subject: [PATCH] lockutils-wrapper cleanup There were a couple of issues with the lockutils wrapper. Most importantly, lockutils silently did nothing if it was called in the same way as the old incubator lockutils module. This had the potential to cause problems when simply doing a find and replace to migrate to oslo.concurrency. The problem is fixed by making lockutils raise an exception if it is called directly. There was also a name mismatch in the docstring for the console entry point, which is also fixed in this change. Closes-Bug: 1386734 Change-Id: I8868820ca314eb8d6fee83cc66fea886c1e74e27 --- oslo/concurrency/lockutils.py | 10 ++++++++-- tests/unit/test_lockutils.py | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/oslo/concurrency/lockutils.py b/oslo/concurrency/lockutils.py index 95f9ffe..15e3984 100644 --- a/oslo/concurrency/lockutils.py +++ b/oslo/concurrency/lockutils.py @@ -358,10 +358,10 @@ def _lock_wrapper(argv): """Create a dir for locks and pass it to command from arguments This is exposed as a console script entry point named - oslo-concurrency-lock-wrapper + lockutils-wrapper If you run this: - oslo-concurrency-lock-wrapper python setup.py testr + lockutils-wrapper python setup.py testr a temporary directory will be created for all your locks and passed to all your tests in an environment variable. The temporary dir will be deleted @@ -379,3 +379,9 @@ def _lock_wrapper(argv): def main(): sys.exit(_lock_wrapper(sys.argv)) + + +if __name__ == '__main__': + raise NotImplementedError(_('Calling lockutils directly is no longer ' + 'supported. Please use the ' + 'lockutils-wrapper console script instead.')) diff --git a/tests/unit/test_lockutils.py b/tests/unit/test_lockutils.py index 7d85029..57a2f9e 100644 --- a/tests/unit/test_lockutils.py +++ b/tests/unit/test_lockutils.py @@ -18,6 +18,7 @@ import multiprocessing import os import shutil import signal +import subprocess import sys import tempfile import threading @@ -520,6 +521,13 @@ class LockutilsModuleTestCase(test_base.BaseTestCase): retval = lockutils._lock_wrapper(argv) self.assertEqual(retval, 1) + def test_direct_call_explodes(self): + cmd = [sys.executable, '-m', 'oslo.concurrency.lockutils'] + with open(os.devnull, 'w') as devnull: + retval = subprocess.call(cmd, stderr=devnull) + # 1 for Python 2.7 and 3.x, 255 for 2.6 + self.assertIn(retval, [1, 255]) + class TestLockFixture(test_base.BaseTestCase):