Merge "Fix circular import in nova.privsep.utils"

This commit is contained in:
Zuul 2019-01-07 17:55:37 +00:00 committed by Gerrit Code Review
commit ba76e6de08
2 changed files with 15 additions and 6 deletions

View File

@ -23,23 +23,32 @@
import errno
import mmap
import os
import random
import sys
from oslo_log import log as logging
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__)
def generate_random_string():
return str(random.randint(0, sys.maxsize))
def supports_direct_io(dirpath):
if not hasattr(os, 'O_DIRECT'):
LOG.debug("This python runtime does not support direct I/O")
return False
file_name = "%s.%s" % (".directio.test",
nova_utils.generate_random_string())
# Use a random filename to avoid issues with $dirpath being on shared
# storage.
file_name = "%s.%s" % (".directio.test", generate_random_string())
testfile = os.path.join(dirpath, file_name)
hasDirectIO = True

View File

@ -36,15 +36,15 @@ class SupportDirectIOTestCase(test.NoDBTestCase):
self.einval.errno = errno.EINVAL
self.enoent = OSError()
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
open_patcher = mock.patch('os.open')
write_patcher = mock.patch('os.write')
close_patcher = mock.patch('os.close')
unlink_patcher = mock.patch('os.unlink')
random_string_patcher = mock.patch('nova.utils.generate_random_string',
return_value='abc123')
random_string_patcher = mock.patch(
'nova.privsep.utils.generate_random_string', return_value='123')
self.addCleanup(open_patcher.stop)
self.addCleanup(write_patcher.stop)
self.addCleanup(close_patcher.stop)