summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-06-08 17:05:16 +0000
committerGerrit Code Review <review@openstack.org>2020-06-08 17:05:16 +0000
commit80a6e1d489c5d650ea1ce47f4d81bd98bc803542 (patch)
treedd119a651ff71071d07a6f5f2418c0a467c4f314
parent174b29162d239bc3e9d74e689e9de7db01b3396c (diff)
parente57a1c829df3f77d2c3a9c2712f1decef6284500 (diff)
downloadoslo-concurrency-80a6e1d489c5d650ea1ce47f4d81bd98bc803542.tar.gz
Merge "Don't warn on lock removal if file doesn't exist"
-rw-r--r--oslo_concurrency/lockutils.py8
-rw-r--r--oslo_concurrency/tests/unit/test_lockutils.py19
2 files changed, 22 insertions, 5 deletions
diff --git a/oslo_concurrency/lockutils.py b/oslo_concurrency/lockutils.py
index e5798c5..67cf41e 100644
--- a/oslo_concurrency/lockutils.py
+++ b/oslo_concurrency/lockutils.py
@@ -14,6 +14,7 @@
# under the License.
import contextlib
+import errno
import functools
import logging
import os
@@ -199,9 +200,10 @@ def remove_external_lock_file(name, lock_file_prefix=None, lock_path=None,
lock_file_path = _get_lock_path(name, lock_file_prefix, lock_path)
try:
os.remove(lock_file_path)
- except OSError:
- LOG.info('Failed to remove file %(file)s',
- {'file': lock_file_path})
+ except OSError as exc:
+ if exc.errno != errno.ENOENT:
+ LOG.warning('Failed to remove file %(file)s',
+ {'file': lock_file_path})
def internal_lock(name, semaphores=None):
diff --git a/oslo_concurrency/tests/unit/test_lockutils.py b/oslo_concurrency/tests/unit/test_lockutils.py
index dd5127a..0097bdc 100644
--- a/oslo_concurrency/tests/unit/test_lockutils.py
+++ b/oslo_concurrency/tests/unit/test_lockutils.py
@@ -13,6 +13,7 @@
# under the License.
import collections
+import errno
import multiprocessing
import os
import signal
@@ -320,8 +321,8 @@ class LockTestCase(test_base.BaseTestCase):
remove_mock.assert_called_once_with(path_mock.return_value)
log_mock.assert_not_called()
- @mock.patch('logging.Logger.info')
- @mock.patch('os.remove', side_effect=OSError)
+ @mock.patch('logging.Logger.warning')
+ @mock.patch('os.remove', side_effect=OSError(errno.ENOENT, None))
@mock.patch('oslo_concurrency.lockutils._get_lock_path')
def test_remove_lock_external_file_doesnt_exists(self, path_mock,
remove_mock, log_mock):
@@ -332,6 +333,20 @@ class LockTestCase(test_base.BaseTestCase):
mock.sentinel.prefix,
mock.sentinel.lock_path)
remove_mock.assert_called_once_with(path_mock.return_value)
+ log_mock.assert_not_called()
+
+ @mock.patch('logging.Logger.warning')
+ @mock.patch('os.remove', side_effect=OSError(errno.EPERM, None))
+ @mock.patch('oslo_concurrency.lockutils._get_lock_path')
+ def test_remove_lock_external_file_permission_error(
+ self, path_mock, remove_mock, log_mock):
+ lockutils.remove_external_lock_file(mock.sentinel.name,
+ mock.sentinel.prefix,
+ mock.sentinel.lock_path)
+ path_mock.assert_called_once_with(mock.sentinel.name,
+ mock.sentinel.prefix,
+ mock.sentinel.lock_path)
+ remove_mock.assert_called_once_with(path_mock.return_value)
log_mock.assert_called()
def test_no_slash_in_b64(self):