Merge "Fix circular import in nova.privsep.utils"
This commit is contained in:
commit
ba76e6de08
|
@ -23,23 +23,32 @@
|
||||||
import errno
|
import errno
|
||||||
import mmap
|
import mmap
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
|
||||||
from nova import utils as nova_utils
|
# NOTE(mriedem): Avoid importing nova.utils since that can cause a circular
|
||||||
|
# import with the privsep code. In fact, avoid importing anything outside
|
||||||
|
# of nova/privsep/ if possible.
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_string():
|
||||||
|
return str(random.randint(0, sys.maxsize))
|
||||||
|
|
||||||
|
|
||||||
def supports_direct_io(dirpath):
|
def supports_direct_io(dirpath):
|
||||||
|
|
||||||
if not hasattr(os, 'O_DIRECT'):
|
if not hasattr(os, 'O_DIRECT'):
|
||||||
LOG.debug("This python runtime does not support direct I/O")
|
LOG.debug("This python runtime does not support direct I/O")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
file_name = "%s.%s" % (".directio.test",
|
# Use a random filename to avoid issues with $dirpath being on shared
|
||||||
nova_utils.generate_random_string())
|
# storage.
|
||||||
|
file_name = "%s.%s" % (".directio.test", generate_random_string())
|
||||||
testfile = os.path.join(dirpath, file_name)
|
testfile = os.path.join(dirpath, file_name)
|
||||||
|
|
||||||
hasDirectIO = True
|
hasDirectIO = True
|
||||||
|
|
|
@ -36,15 +36,15 @@ class SupportDirectIOTestCase(test.NoDBTestCase):
|
||||||
self.einval.errno = errno.EINVAL
|
self.einval.errno = errno.EINVAL
|
||||||
self.enoent = OSError()
|
self.enoent = OSError()
|
||||||
self.enoent.errno = errno.ENOENT
|
self.enoent.errno = errno.ENOENT
|
||||||
self.test_path = os.path.join('.', '.directio.test.abc123')
|
self.test_path = os.path.join('.', '.directio.test.123')
|
||||||
self.io_flags = os.O_CREAT | os.O_WRONLY | os.O_DIRECT
|
self.io_flags = os.O_CREAT | os.O_WRONLY | os.O_DIRECT
|
||||||
|
|
||||||
open_patcher = mock.patch('os.open')
|
open_patcher = mock.patch('os.open')
|
||||||
write_patcher = mock.patch('os.write')
|
write_patcher = mock.patch('os.write')
|
||||||
close_patcher = mock.patch('os.close')
|
close_patcher = mock.patch('os.close')
|
||||||
unlink_patcher = mock.patch('os.unlink')
|
unlink_patcher = mock.patch('os.unlink')
|
||||||
random_string_patcher = mock.patch('nova.utils.generate_random_string',
|
random_string_patcher = mock.patch(
|
||||||
return_value='abc123')
|
'nova.privsep.utils.generate_random_string', return_value='123')
|
||||||
self.addCleanup(open_patcher.stop)
|
self.addCleanup(open_patcher.stop)
|
||||||
self.addCleanup(write_patcher.stop)
|
self.addCleanup(write_patcher.stop)
|
||||||
self.addCleanup(close_patcher.stop)
|
self.addCleanup(close_patcher.stop)
|
||||||
|
|
Loading…
Reference in New Issue