Merge "Fixes Hyper-V should log a clear error message"
This commit is contained in:
commit
219059fe5a
|
@ -19,6 +19,7 @@ import mock
|
|||
from nova.tests.unit.virt.hyperv import test_base
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
|
||||
class PathUtilsTestCase(test_base.HyperVBaseTestCase):
|
||||
|
@ -116,3 +117,20 @@ class PathUtilsTestCase(test_base.HyperVBaseTestCase):
|
|||
|
||||
def test_force_unmount_smb_share(self):
|
||||
self._test_unmount_smb_share(force=True)
|
||||
|
||||
@mock.patch('os.path.join')
|
||||
def test_get_instances_sub_dir(self, fake_path_join):
|
||||
|
||||
class WindowsError(Exception):
|
||||
def __init__(self, winerror=None):
|
||||
self.winerror = winerror
|
||||
|
||||
fake_dir_name = "fake_dir_name"
|
||||
fake_windows_error = WindowsError
|
||||
self._pathutils._check_create_dir = mock.MagicMock(
|
||||
side_effect=WindowsError(pathutils.ERROR_INVALID_NAME))
|
||||
with mock.patch('__builtin__.WindowsError',
|
||||
fake_windows_error, create=True):
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self._pathutils._get_instances_sub_dir,
|
||||
fake_dir_name)
|
||||
|
|
|
@ -44,6 +44,8 @@ CONF = cfg.CONF
|
|||
CONF.register_opts(hyperv_opts, 'hyperv')
|
||||
CONF.import_opt('instances_path', 'nova.compute.manager')
|
||||
|
||||
ERROR_INVALID_NAME = 123
|
||||
|
||||
|
||||
class PathUtils(object):
|
||||
def __init__(self):
|
||||
|
@ -112,11 +114,22 @@ class PathUtils(object):
|
|||
create_dir=True, remove_dir=False):
|
||||
instances_path = self.get_instances_dir(remote_server)
|
||||
path = os.path.join(instances_path, dir_name)
|
||||
if remove_dir:
|
||||
self._check_remove_dir(path)
|
||||
if create_dir:
|
||||
self._check_create_dir(path)
|
||||
return path
|
||||
try:
|
||||
if remove_dir:
|
||||
self._check_remove_dir(path)
|
||||
if create_dir:
|
||||
self._check_create_dir(path)
|
||||
return path
|
||||
except WindowsError as ex:
|
||||
if ex.winerror == ERROR_INVALID_NAME:
|
||||
raise vmutils.HyperVException(_(
|
||||
"Cannot access \"%(instances_path)s\", make sure the "
|
||||
"path exists and that you have the proper permissions. "
|
||||
"In particular Nova-Compute must not be executed with the "
|
||||
"builtin SYSTEM account or other accounts unable to "
|
||||
"authenticate on a remote host.") %
|
||||
{'instances_path': instances_path})
|
||||
raise
|
||||
|
||||
def get_instance_migr_revert_dir(self, instance_name, create_dir=False,
|
||||
remove_dir=False):
|
||||
|
|
Loading…
Reference in New Issue