Use method ensure_tree from oslo.utils
we don't have to def ensure_tree, because Oslo.utils 1.8 provides the function and just use it.I also deleted the code in tests/unit/. Change-Id: I61e9d87e6dde5b7a52e7b6399f4be6e8d5fca340
This commit is contained in:
parent
5082989968
commit
af7d1cdedb
|
@ -29,6 +29,7 @@ import muranoclient.v1.client as muranoclient
|
|||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_log import versionutils
|
||||
from oslo_utils import fileutils
|
||||
import six
|
||||
|
||||
from murano.common import auth_utils
|
||||
|
@ -190,7 +191,7 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader):
|
|||
uuid.uuid4().hex))
|
||||
|
||||
if not os.path.isdir(directory):
|
||||
m_utils.ensure_tree(directory)
|
||||
fileutils.ensure_tree(directory)
|
||||
|
||||
LOG.debug('Cache for package loader is located at: {dir}'.format(
|
||||
dir=directory))
|
||||
|
|
|
@ -13,9 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import errno
|
||||
import mock
|
||||
import os
|
||||
from webob import exc
|
||||
|
||||
from murano.services import states
|
||||
|
@ -186,35 +184,3 @@ class TestUtils(test_base.MuranoTestCase):
|
|||
def _test_verify_session(self, request):
|
||||
"""Helper function for testing above decorator."""
|
||||
pass
|
||||
|
||||
@mock.patch('murano.utils.os')
|
||||
def test_ensure_tree_except_os_error(self, mock_os):
|
||||
"""Test ensure tree throws the expected exceptions.
|
||||
|
||||
Because OSError is a built-in exception, setattr() can't be called
|
||||
to change its errno.
|
||||
"""
|
||||
mock_os.path.isdir.return_value = False
|
||||
os_error = None
|
||||
path = os.path.realpath(__file__)
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as e:
|
||||
os_error = e
|
||||
self.assertEqual(errno.EEXIST, os_error.errno)
|
||||
self.assertFalse(os.path.isdir(path))
|
||||
mock_os.makedirs.side_effect = os_error
|
||||
self.assertRaises(OSError, utils.ensure_tree, path)
|
||||
|
||||
@mock.patch('murano.utils.os')
|
||||
def test_ensure_tree_with_return_false(self, mock_os):
|
||||
mock_os.path.isdir.return_value = True
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as e:
|
||||
os_error = e
|
||||
self.assertEqual(errno.EEXIST, os_error.errno)
|
||||
self.assertTrue(os.path.isdir(path))
|
||||
mock_os.makedirs.side_effect = os_error
|
||||
self.assertFalse(utils.ensure_tree(path))
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
# under the License.
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
import functools
|
||||
import os
|
||||
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import fileutils
|
||||
from webob import exc
|
||||
|
||||
from murano.common.i18n import _
|
||||
|
@ -130,28 +130,6 @@ def verify_session(func):
|
|||
return __inner
|
||||
|
||||
|
||||
def ensure_tree(path):
|
||||
"""Create a directory (and any ancestor directories required).
|
||||
|
||||
:param path: Directory to create
|
||||
:return: bool, whether the directory has actually been created
|
||||
"""
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as e:
|
||||
if e.errno == errno.EEXIST:
|
||||
if not os.path.isdir(path):
|
||||
raise
|
||||
else:
|
||||
return False
|
||||
elif e.errno == errno.EISDIR:
|
||||
return False
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
ExclusiveInterProcessLock = lockutils.InterProcessLock
|
||||
if os.name == 'nt':
|
||||
# no shared locks on windows
|
||||
|
@ -169,7 +147,7 @@ else:
|
|||
# to be overridden
|
||||
basedir = os.path.dirname(self.path)
|
||||
if basedir:
|
||||
made_basedir = ensure_tree(basedir)
|
||||
made_basedir = fileutils.ensure_tree(basedir)
|
||||
if made_basedir:
|
||||
self.logger.debug(
|
||||
'Created lock base path `%s`', basedir)
|
||||
|
|
Loading…
Reference in New Issue