Merge "Fix remove_lock test"
This commit is contained in:
commit
27f8a5d01c
@ -22,6 +22,7 @@ import tempfile
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslotest import base as test_base
|
from oslotest import base as test_base
|
||||||
import six
|
import six
|
||||||
@ -311,28 +312,34 @@ class LockTestCase(test_base.BaseTestCase):
|
|||||||
with lockutils.lock("test") as sem2:
|
with lockutils.lock("test") as sem2:
|
||||||
self.assertEqual(sem, sem2)
|
self.assertEqual(sem, sem2)
|
||||||
|
|
||||||
def _test_remove_lock_external_file(self, lock_dir, use_external=False):
|
@mock.patch('logging.Logger.info')
|
||||||
lock_name = 'mylock'
|
@mock.patch('os.remove')
|
||||||
lock_pfix = 'mypfix-remove-lock-test-'
|
@mock.patch('oslo_concurrency.lockutils._get_lock_path')
|
||||||
|
def test_remove_lock_external_file_exists(self, path_mock, remove_mock,
|
||||||
|
log_mock):
|
||||||
|
lockutils.remove_external_lock_file(mock.sentinel.name,
|
||||||
|
mock.sentinel.prefix,
|
||||||
|
mock.sentinel.lock_path)
|
||||||
|
|
||||||
if use_external:
|
path_mock.assert_called_once_with(mock.sentinel.name,
|
||||||
lock_path = lock_dir
|
mock.sentinel.prefix,
|
||||||
else:
|
mock.sentinel.lock_path)
|
||||||
lock_path = None
|
remove_mock.assert_called_once_with(path_mock.return_value)
|
||||||
|
log_mock.assert_not_called()
|
||||||
|
|
||||||
lockutils.remove_external_lock_file(lock_name, lock_pfix, lock_path)
|
@mock.patch('logging.Logger.info')
|
||||||
|
@mock.patch('os.remove', side_effect=OSError)
|
||||||
for ent in os.listdir(lock_dir):
|
@mock.patch('oslo_concurrency.lockutils._get_lock_path')
|
||||||
self.assertRaises(OSError, ent.startswith, lock_pfix)
|
def test_remove_lock_external_file_doesnt_exists(self, path_mock,
|
||||||
|
remove_mock, log_mock):
|
||||||
def test_remove_lock_external_file(self):
|
lockutils.remove_external_lock_file(mock.sentinel.name,
|
||||||
lock_dir = tempfile.mkdtemp()
|
mock.sentinel.prefix,
|
||||||
self.config(lock_path=lock_dir, group='oslo_concurrency')
|
mock.sentinel.lock_path)
|
||||||
self._test_remove_lock_external_file(lock_dir)
|
path_mock.assert_called_once_with(mock.sentinel.name,
|
||||||
|
mock.sentinel.prefix,
|
||||||
def test_remove_lock_external_file_lock_path(self):
|
mock.sentinel.lock_path)
|
||||||
self._test_remove_lock_external_file(tempfile.mkdtemp(),
|
remove_mock.assert_called_once_with(path_mock.return_value)
|
||||||
use_external=True)
|
log_mock.assert_called()
|
||||||
|
|
||||||
def test_no_slash_in_b64(self):
|
def test_no_slash_in_b64(self):
|
||||||
# base64(sha1(foobar)) has a slash in it
|
# base64(sha1(foobar)) has a slash in it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user