Refactors HyperVException and subclasses
Moves HyperVException and subclasses from vmutils to oslo_windows.exceptions and updates all the references to the old class. This decouples a lot of the utils modules from vmutils.
This commit is contained in:
parent
ee0aff001d
commit
012aabcafd
|
@ -0,0 +1,39 @@
|
|||
# Copyright 2015 Cloudbase Solutions Srl
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Utility class for VM related operations on Hyper-V.
|
||||
"""
|
||||
|
||||
|
||||
class HyperVException(Exception):
|
||||
def __init__(self, message=None):
|
||||
super(HyperVException, self).__init__(message)
|
||||
|
||||
|
||||
# TODO(alexpilotti): Add a storage exception base class
|
||||
class VHDResizeException(HyperVException):
|
||||
def __init__(self, message=None):
|
||||
super(HyperVException, self).__init__(message)
|
||||
|
||||
|
||||
class HyperVAuthorizationException(HyperVException):
|
||||
def __init__(self, message=None):
|
||||
super(HyperVException, self).__init__(message)
|
||||
|
||||
|
||||
class UnsupportedConfigDriveFormatException(HyperVException):
|
||||
def __init__(self, message=None):
|
||||
super(HyperVException, self).__init__(message)
|
|
@ -21,6 +21,7 @@ import mock
|
|||
from oslo_config import cfg
|
||||
|
||||
from nova import test
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import hostutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
@ -50,7 +51,7 @@ class TestHyperVUtilsFactory(test.NoDBTestCase):
|
|||
mock_check_min_windows_version.return_value = os_supports_v2
|
||||
|
||||
if os_supports_v2 and force_v1:
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
utilsfactory.get_vmutils)
|
||||
else:
|
||||
actual_class = type(utilsfactory.get_vmutils())
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
import mock
|
||||
|
||||
from nova import test
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import networkutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
|
||||
class NetworkUtilsTestCase(test.NoDBTestCase):
|
||||
|
@ -47,7 +47,7 @@ class NetworkUtilsTestCase(test.NoDBTestCase):
|
|||
def test_get_external_vswitch_not_found(self):
|
||||
self._networkutils._conn.Msvm_VirtualEthernetSwitch.return_value = []
|
||||
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._networkutils.get_external_vswitch,
|
||||
mock.sentinel.FAKE_VSWITCH_NAME)
|
||||
|
||||
|
|
|
@ -17,9 +17,9 @@ import os
|
|||
import mock
|
||||
|
||||
from nova.tests.unit.virt.hyperv import test_base
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
|
||||
class PathUtilsTestCase(test_base.HyperVBaseTestCase):
|
||||
|
@ -165,6 +165,6 @@ class PathUtilsTestCase(test_base.HyperVBaseTestCase):
|
|||
side_effect=WindowsError(pathutils.ERROR_INVALID_NAME))
|
||||
with mock.patch('__builtin__.WindowsError',
|
||||
fake_windows_error, create=True):
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._pathutils._get_instances_sub_dir,
|
||||
fake_dir_name)
|
||||
|
|
|
@ -16,9 +16,9 @@ import mock
|
|||
from oslo_utils import units
|
||||
|
||||
from nova import test
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import vhdutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
|
||||
class VHDUtilsBaseTestCase(test.NoDBTestCase):
|
||||
|
@ -266,7 +266,7 @@ class VHDUtilsTestCase(VHDUtilsBaseTestCase):
|
|||
f = mock_open.return_value
|
||||
f.tell.return_value = 1024
|
||||
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vhdutils.get_vhd_format,
|
||||
self._FAKE_VHD_PATH)
|
||||
|
||||
|
@ -277,7 +277,7 @@ class VHDUtilsTestCase(VHDUtilsBaseTestCase):
|
|||
f = mock_open.return_value
|
||||
f.tell.return_value = 0
|
||||
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vhdutils.get_vhd_format,
|
||||
self._FAKE_VHD_PATH)
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
import mock
|
||||
|
||||
from oslo_windows import exceptions
|
||||
from nova.tests.unit.virt.hyperv import test_vhdutils
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import vhdutilsv2
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
|
||||
class VHDUtilsV2TestCase(test_vhdutils.VHDUtilsBaseTestCase):
|
||||
|
@ -134,7 +134,7 @@ class VHDUtilsV2TestCase(test_vhdutils.VHDUtilsBaseTestCase):
|
|||
self._vhdutils._get_vhd_info_xml = mock.Mock(
|
||||
return_value=fake_vhd_info_xml)
|
||||
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vhdutils.reconnect_parent_vhd,
|
||||
self._FAKE_VHD_PATH,
|
||||
mock.sentinel.new_parent_path)
|
||||
|
|
|
@ -17,8 +17,8 @@ import mock
|
|||
|
||||
from six.moves import range
|
||||
|
||||
from nova import exception
|
||||
from nova import test
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
|
@ -115,13 +115,13 @@ class VMUtilsTestCase(test.NoDBTestCase):
|
|||
def test_lookup_vm_multiple(self):
|
||||
mockvm = mock.MagicMock()
|
||||
self._vmutils._conn.Msvm_ComputerSystem.return_value = [mockvm, mockvm]
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vmutils._lookup_vm_check,
|
||||
self._FAKE_VM_NAME)
|
||||
|
||||
def test_lookup_vm_none(self):
|
||||
self._vmutils._conn.Msvm_ComputerSystem.return_value = []
|
||||
self.assertRaises(exception.NotFound,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vmutils._lookup_vm_check,
|
||||
self._FAKE_VM_NAME)
|
||||
|
||||
|
@ -278,7 +278,7 @@ class VMUtilsTestCase(test.NoDBTestCase):
|
|||
'get_attached_disks') as fake_get_attached_disks:
|
||||
fake_get_attached_disks.return_value = (
|
||||
[fake_drive] * constants.SCSI_CONTROLLER_SLOTS_NUMBER)
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vmutils.get_free_controller_slot,
|
||||
mock.sentinel.scsi_controller_path)
|
||||
|
||||
|
@ -421,7 +421,7 @@ class VMUtilsTestCase(test.NoDBTestCase):
|
|||
mock_wait_for_job.assert_called_once_with(self._FAKE_JOB_PATH)
|
||||
|
||||
def test_check_ret_val_exception(self):
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vmutils.check_ret_val,
|
||||
self._FAKE_RET_VAL_BAD,
|
||||
self._FAKE_JOB_PATH)
|
||||
|
@ -434,21 +434,21 @@ class VMUtilsTestCase(test.NoDBTestCase):
|
|||
def test_wait_for_job_exception_concrete_job(self):
|
||||
mock_job = self._prepare_wait_for_job()
|
||||
mock_job.path.return_value.Class = self._CONCRETE_JOB
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vmutils._wait_for_job,
|
||||
self._FAKE_JOB_PATH)
|
||||
|
||||
def test_wait_for_job_exception_with_error(self):
|
||||
mock_job = self._prepare_wait_for_job()
|
||||
mock_job.GetError.return_value = (self._FAKE_ERROR, self._FAKE_RET_VAL)
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vmutils._wait_for_job,
|
||||
self._FAKE_JOB_PATH)
|
||||
|
||||
def test_wait_for_job_exception_no_error(self):
|
||||
mock_job = self._prepare_wait_for_job()
|
||||
mock_job.GetError.return_value = (None, None)
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._vmutils._wait_for_job,
|
||||
self._FAKE_JOB_PATH)
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
import mock
|
||||
from oslo_config import cfg
|
||||
|
||||
from oslo_windows import exceptions
|
||||
from nova.tests.unit.virt.hyperv import test_basevolumeutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import volumeutils
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@ -95,7 +95,7 @@ class VolumeUtilsTestCase(test_basevolumeutils.BaseVolumeUtilsTestCase):
|
|||
['', '', '', self._FAKE_TARGET, ''])
|
||||
|
||||
if raise_exception:
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._volutils.login_storage_target,
|
||||
self._FAKE_LUN, self._FAKE_TARGET,
|
||||
fake_portal, username, password)
|
||||
|
@ -138,7 +138,7 @@ class VolumeUtilsTestCase(test_basevolumeutils.BaseVolumeUtilsTestCase):
|
|||
fake_execute.return_value = (output, None)
|
||||
|
||||
if raise_exception:
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._volutils.execute,
|
||||
*fake_cmd)
|
||||
else:
|
||||
|
|
|
@ -16,7 +16,7 @@ import mock
|
|||
from oslo_config import cfg
|
||||
|
||||
from nova import test
|
||||
from nova.virt.hyperv import vmutils
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import volumeutilsv2
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@ -102,7 +102,7 @@ class VolumeUtilsV2TestCase(test.NoDBTestCase):
|
|||
auth = {}
|
||||
|
||||
if raise_exception:
|
||||
self.assertRaises(vmutils.HyperVException,
|
||||
self.assertRaises(exceptions.HyperVException,
|
||||
self._volutilsv2.login_storage_target,
|
||||
self._FAKE_LUN, self._FAKE_TARGET, fake_portal)
|
||||
else:
|
||||
|
|
|
@ -20,9 +20,8 @@ if sys.platform == 'win32':
|
|||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from nova import exception
|
||||
from oslo_windows._i18n import _, _LE
|
||||
from nova.virt.hyperv import vmutils
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import vmutilsv2
|
||||
from nova.virt.hyperv import volumeutilsv2
|
||||
|
||||
|
@ -48,7 +47,7 @@ class LiveMigrationUtils(object):
|
|||
% host)
|
||||
else:
|
||||
msg = _('Live migration failed: %s') % ex.message
|
||||
raise vmutils.HyperVException(msg)
|
||||
raise exceptions.HyperVException(msg)
|
||||
|
||||
def check_live_migration_config(self):
|
||||
conn_v2 = self._get_conn_v2()
|
||||
|
@ -58,10 +57,10 @@ class LiveMigrationUtils(object):
|
|||
wmi_result_class='Msvm_VirtualSystemMigrationServiceSettingData')
|
||||
vsmssd = vsmssds[0]
|
||||
if not vsmssd.EnableVirtualSystemMigration:
|
||||
raise vmutils.HyperVException(
|
||||
raise exceptions.HyperVException(
|
||||
_('Live migration is not enabled on this host'))
|
||||
if not migration_svc.MigrationServiceListenerIPAddressList:
|
||||
raise vmutils.HyperVException(
|
||||
raise exceptions.HyperVException(
|
||||
_('Live migration networks are not configured on this host'))
|
||||
|
||||
def _get_vm(self, conn_v2, vm_name):
|
||||
|
@ -70,8 +69,8 @@ class LiveMigrationUtils(object):
|
|||
if not n:
|
||||
raise exception.NotFound(_('VM not found: %s') % vm_name)
|
||||
elif n > 1:
|
||||
raise vmutils.HyperVException(_('Duplicate VM name found: %s')
|
||||
% vm_name)
|
||||
raise exceptions.HyperVException(_('Duplicate VM name found: %s')
|
||||
% vm_name)
|
||||
return vms[0]
|
||||
|
||||
def _destroy_planned_vm(self, conn_v2_remote, planned_vm):
|
||||
|
|
|
@ -24,7 +24,7 @@ if sys.platform == 'win32':
|
|||
import wmi
|
||||
|
||||
from oslo_windows._i18n import _
|
||||
from nova.virt.hyperv import vmutils
|
||||
from oslo_windows import exceptions
|
||||
|
||||
|
||||
class NetworkUtils(object):
|
||||
|
@ -42,8 +42,8 @@ class NetworkUtils(object):
|
|||
vswitches = port.associators(wmi_result_class='Msvm_VirtualSwitch')
|
||||
|
||||
if not len(vswitches):
|
||||
raise vmutils.HyperVException(_('vswitch "%s" not found')
|
||||
% vswitch_name)
|
||||
raise exceptions.HyperVException(_('vswitch "%s" not found')
|
||||
% vswitch_name)
|
||||
return vswitches[0].path_()
|
||||
|
||||
def create_vswitch_port(self, vswitch_path, port_name):
|
||||
|
@ -55,11 +55,10 @@ class NetworkUtils(object):
|
|||
ScopeOfResidence="",
|
||||
VirtualSwitch=vswitch_path)
|
||||
if ret_val != 0:
|
||||
raise vmutils.HyperVException(_("Failed to create vswitch port "
|
||||
"%(port_name)s on switch "
|
||||
"%(vswitch_path)s") %
|
||||
{'port_name': port_name,
|
||||
'vswitch_path': vswitch_path})
|
||||
raise exceptions.HyperVException(
|
||||
_("Failed to create vswitch port %(port_name)s on switch "
|
||||
"%(vswitch_path)s") % {'port_name': port_name,
|
||||
'vswitch_path': vswitch_path})
|
||||
return new_port
|
||||
|
||||
def vswitch_port_needed(self):
|
||||
|
|
|
@ -25,8 +25,8 @@ if sys.platform == 'win32':
|
|||
import wmi
|
||||
|
||||
from oslo_windows._i18n import _
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import networkutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
|
||||
class NetworkUtilsV2(networkutils.NetworkUtils):
|
||||
|
@ -39,8 +39,8 @@ class NetworkUtilsV2(networkutils.NetworkUtils):
|
|||
vswitches = self._conn.Msvm_VirtualEthernetSwitch(
|
||||
ElementName=vswitch_name)
|
||||
if not len(vswitches):
|
||||
raise vmutils.HyperVException(_('vswitch "%s" not found')
|
||||
% vswitch_name)
|
||||
raise exceptions.HyperVException(_('vswitch "%s" not found')
|
||||
% vswitch_name)
|
||||
else:
|
||||
# Find the vswitch that is connected to the first physical nic.
|
||||
ext_port = self._conn.Msvm_ExternalEthernetPort(IsBound='TRUE')[0]
|
||||
|
@ -52,7 +52,8 @@ class NetworkUtilsV2(networkutils.NetworkUtils):
|
|||
wmi_result_class='Msvm_VirtualEthernetSwitch')
|
||||
|
||||
if not len(vswitches):
|
||||
raise vmutils.HyperVException(_('No external vswitch found'))
|
||||
raise exceptions.HyperVException(
|
||||
_('No external vswitch found'))
|
||||
|
||||
return vswitches[0].path_()
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ from oslo_config import cfg
|
|||
from oslo_log import log as logging
|
||||
|
||||
from oslo_windows._i18n import _
|
||||
from oslo_windows import exceptions
|
||||
from nova import utils
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -149,7 +149,7 @@ class PathUtils(object):
|
|||
return path
|
||||
except WindowsError as ex:
|
||||
if ex.winerror == ERROR_INVALID_NAME:
|
||||
raise vmutils.HyperVException(_(
|
||||
raise exceptions.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 "
|
||||
|
@ -246,7 +246,7 @@ class PathUtils(object):
|
|||
'Unable to mount SMBFS share: %(smbfs_share)s '
|
||||
'WMI exception: %(wmi_exc)s'), {'smbfs_share': smbfs_share,
|
||||
'wmi_exc': exc})
|
||||
raise vmutils.HyperVException(err_msg)
|
||||
raise exceptions.HyperVException(err_msg)
|
||||
|
||||
def unmount_smb_share(self, smbfs_share, force=False):
|
||||
mappings = self._smb_conn.Msft_SmbMapping(RemotePath=smbfs_share)
|
||||
|
@ -267,5 +267,5 @@ class PathUtils(object):
|
|||
# share, for which reason we'll simply ignore it in this
|
||||
# case.
|
||||
if force:
|
||||
raise vmutils.HyperVException(
|
||||
raise exceptions.HyperVException(
|
||||
_("Could not unmount share: %s"), smbfs_share)
|
||||
|
|
|
@ -32,6 +32,7 @@ if sys.platform == 'win32':
|
|||
from xml.etree import ElementTree
|
||||
|
||||
from oslo_windows._i18n import _
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
|
@ -63,8 +64,8 @@ class VHDUtils(object):
|
|||
|
||||
def create_dynamic_vhd(self, path, max_internal_size, format):
|
||||
if format != constants.DISK_FORMAT_VHD:
|
||||
raise vmutils.HyperVException(_("Unsupported disk format: %s") %
|
||||
format)
|
||||
raise exceptions.HyperVException(_("Unsupported disk format: %s") %
|
||||
format)
|
||||
|
||||
image_man_svc = self._conn.Msvm_ImageManagementService()[0]
|
||||
|
||||
|
@ -159,9 +160,9 @@ class VHDUtils(object):
|
|||
f.seek(blk_size_offset)
|
||||
version = f.read(4)
|
||||
except IOError:
|
||||
raise vmutils.HyperVException(_("Unable to obtain block size from"
|
||||
" VHD %(vhd_path)s") %
|
||||
{"vhd_path": vhd_path})
|
||||
raise exceptions.HyperVException(_("Unable to obtain block size "
|
||||
"from VHD %(vhd_path)s") %
|
||||
{"vhd_path": vhd_path})
|
||||
return struct.unpack('>i', version)[0]
|
||||
|
||||
def get_vhd_parent_path(self, vhd_path):
|
||||
|
@ -206,7 +207,7 @@ class VHDUtils(object):
|
|||
if f.read(8) == VHD_SIGNATURE:
|
||||
return constants.DISK_FORMAT_VHD
|
||||
|
||||
raise vmutils.HyperVException(_('Unsupported virtual disk format'))
|
||||
raise exceptions.HyperVException(_('Unsupported virtual disk format'))
|
||||
|
||||
def get_best_supported_vhd_format(self):
|
||||
return constants.DISK_FORMAT_VHD
|
||||
|
|
|
@ -29,9 +29,9 @@ from xml.etree import ElementTree
|
|||
from oslo_utils import units
|
||||
|
||||
from oslo_windows._i18n import _
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import vhdutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import vmutilsv2
|
||||
|
||||
|
||||
|
@ -62,8 +62,8 @@ class VHDUtilsV2(vhdutils.VHDUtils):
|
|||
def create_dynamic_vhd(self, path, max_internal_size, format):
|
||||
vhd_format = self._vhd_format_map.get(format)
|
||||
if not vhd_format:
|
||||
raise vmutils.HyperVException(_("Unsupported disk format: %s") %
|
||||
format)
|
||||
raise exceptions.HyperVException(_("Unsupported disk format: %s") %
|
||||
format)
|
||||
|
||||
self._create_vhd(self._VHD_TYPE_DYNAMIC, vhd_format, path,
|
||||
max_internal_size=max_internal_size)
|
||||
|
@ -109,7 +109,7 @@ class VHDUtilsV2(vhdutils.VHDUtils):
|
|||
"parent path property.") %
|
||||
{'child_vhd_path': child_vhd_path,
|
||||
'parent_vhd_path': parent_vhd_path})
|
||||
raise vmutils.HyperVException(msg)
|
||||
raise exceptions.HyperVException(msg)
|
||||
|
||||
vhd_info_xml = ElementTree.tostring(et)
|
||||
|
||||
|
@ -170,12 +170,10 @@ class VHDUtilsV2(vhdutils.VHDUtils):
|
|||
return max_internal_size - (max_internal_size % bs)
|
||||
|
||||
except IOError as ex:
|
||||
raise vmutils.HyperVException(_("Unable to obtain "
|
||||
"internal size from VHDX: "
|
||||
"%(vhd_path)s. Exception: "
|
||||
"%(ex)s") %
|
||||
{"vhd_path": vhd_path,
|
||||
"ex": ex})
|
||||
raise exceptions.HyperVException(
|
||||
_("Unable to obtain internal size from VHDX: "
|
||||
"%(vhd_path)s. Exception: %(ex)s") %
|
||||
{"vhd_path": vhd_path, "ex": ex})
|
||||
|
||||
def _get_vhdx_current_header_offset(self, vhdx_file):
|
||||
sequence_numbers = []
|
||||
|
|
|
@ -31,8 +31,8 @@ from oslo_utils import uuidutils
|
|||
import six
|
||||
from six.moves import range
|
||||
|
||||
from nova import exception
|
||||
from oslo_windows._i18n import _, _LW
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import hostutils
|
||||
|
||||
|
@ -40,29 +40,6 @@ CONF = cfg.CONF
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# TODO(alexpilotti): Move the exceptions to a separate module
|
||||
# TODO(alexpilotti): Add more domain exceptions
|
||||
class HyperVException(exception.NovaException):
|
||||
def __init__(self, message=None):
|
||||
super(HyperVException, self).__init__(message)
|
||||
|
||||
|
||||
# TODO(alexpilotti): Add a storage exception base class
|
||||
class VHDResizeException(HyperVException):
|
||||
def __init__(self, message=None):
|
||||
super(HyperVException, self).__init__(message)
|
||||
|
||||
|
||||
class HyperVAuthorizationException(HyperVException):
|
||||
def __init__(self, message=None):
|
||||
super(HyperVException, self).__init__(message)
|
||||
|
||||
|
||||
class UnsupportedConfigDriveFormatException(HyperVException):
|
||||
def __init__(self, message=None):
|
||||
super(HyperVException, self).__init__(message)
|
||||
|
||||
|
||||
class VMUtils(object):
|
||||
|
||||
# These constants can be overridden by inherited classes
|
||||
|
@ -151,8 +128,8 @@ class VMUtils(object):
|
|||
constants.VM_SUMMARY_UPTIME],
|
||||
settings_paths)
|
||||
if ret_val:
|
||||
raise HyperVException(_('Cannot get VM summary data for: %s')
|
||||
% vm_name)
|
||||
raise exceptions.HyperVException(
|
||||
_('Cannot get VM summary data for: %s') % vm_name)
|
||||
|
||||
si = summary_info[0]
|
||||
memory_usage = None
|
||||
|
@ -180,7 +157,8 @@ class VMUtils(object):
|
|||
|
||||
vm = self._lookup_vm(vm_name)
|
||||
if not vm:
|
||||
raise exception.NotFound(_('VM not found: %s') % vm_name)
|
||||
raise exceptions.HyperVException(
|
||||
_('VM not found: %s') % vm_name)
|
||||
return vm
|
||||
|
||||
def _lookup_vm(self, vm_name):
|
||||
|
@ -189,7 +167,8 @@ class VMUtils(object):
|
|||
if n == 0:
|
||||
return None
|
||||
elif n > 1:
|
||||
raise HyperVException(_('Duplicate VM name found: %s') % vm_name)
|
||||
raise exceptions.HyperVException(
|
||||
_('Duplicate VM name found: %s') % vm_name)
|
||||
else:
|
||||
return vms[0]
|
||||
|
||||
|
@ -580,8 +559,8 @@ class VMUtils(object):
|
|||
if ret_val == constants.WMI_JOB_STATUS_STARTED:
|
||||
return self._wait_for_job(job_path)
|
||||
elif ret_val not in success_values:
|
||||
raise HyperVException(_('Operation failed with return value: %s')
|
||||
% ret_val)
|
||||
raise exceptions.HyperVException(
|
||||
_('Operation failed with return value: %s') % ret_val)
|
||||
|
||||
def _wait_for_job(self, job_path):
|
||||
"""Poll WMI job state and wait for completion."""
|
||||
|
@ -596,27 +575,26 @@ class VMUtils(object):
|
|||
err_sum_desc = job.ErrorSummaryDescription
|
||||
err_desc = job.ErrorDescription
|
||||
err_code = job.ErrorCode
|
||||
raise HyperVException(_("WMI job failed with status "
|
||||
"%(job_state)d. Error details: "
|
||||
"%(err_sum_desc)s - %(err_desc)s - "
|
||||
"Error code: %(err_code)d") %
|
||||
{'job_state': job_state,
|
||||
'err_sum_desc': err_sum_desc,
|
||||
'err_desc': err_desc,
|
||||
'err_code': err_code})
|
||||
raise exceptions.HyperVException(
|
||||
_("WMI job failed with status %(job_state)d. "
|
||||
"Error details: %(err_sum_desc)s - %(err_desc)s - "
|
||||
"Error code: %(err_code)d") %
|
||||
{'job_state': job_state,
|
||||
'err_sum_desc': err_sum_desc,
|
||||
'err_desc': err_desc,
|
||||
'err_code': err_code})
|
||||
else:
|
||||
(error, ret_val) = job.GetError()
|
||||
if not ret_val and error:
|
||||
raise HyperVException(_("WMI job failed with status "
|
||||
"%(job_state)d. Error details: "
|
||||
"%(error)s") %
|
||||
{'job_state': job_state,
|
||||
'error': error})
|
||||
raise exceptions.HyperVException(
|
||||
_("WMI job failed with status %(job_state)d. "
|
||||
"Error details: %(error)s") %
|
||||
{'job_state': job_state,
|
||||
'error': error})
|
||||
else:
|
||||
raise HyperVException(_("WMI job failed with status "
|
||||
"%d. No error "
|
||||
"description available") %
|
||||
job_state)
|
||||
raise exceptions.HyperVException(
|
||||
_("WMI job failed with status %d. No error "
|
||||
"description available") % job_state)
|
||||
desc = job.Description
|
||||
elap = job.ElapsedTime
|
||||
LOG.debug("WMI job succeeded: %(desc)s, Elapsed=%(elap)s",
|
||||
|
@ -738,7 +716,8 @@ class VMUtils(object):
|
|||
for slot in range(constants.SCSI_CONTROLLER_SLOTS_NUMBER):
|
||||
if slot not in used_slots:
|
||||
return slot
|
||||
raise HyperVException(_("Exceeded the maximum number of slots"))
|
||||
raise exceptions.HyperVException(
|
||||
_("Exceeded the maximum number of slots"))
|
||||
|
||||
def enable_vm_metrics_collection(self, vm_name):
|
||||
raise NotImplementedError(_("Metrics collection is not supported on "
|
||||
|
|
|
@ -31,9 +31,9 @@ from oslo_log import log as logging
|
|||
from six.moves import range
|
||||
|
||||
from oslo_windows._i18n import _
|
||||
from oslo_windows import exceptions
|
||||
from nova import utils
|
||||
from nova.virt.hyperv import basevolumeutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -48,9 +48,9 @@ class VolumeUtils(basevolumeutils.BaseVolumeUtils):
|
|||
def execute(self, *args, **kwargs):
|
||||
stdout_value, stderr_value = utils.execute(*args, **kwargs)
|
||||
if stdout_value.find('The operation completed successfully') == -1:
|
||||
raise vmutils.HyperVException(_('An error has occurred when '
|
||||
'calling the iscsi initiator: %s')
|
||||
% stdout_value)
|
||||
raise exceptions.HyperVException(
|
||||
_('An error has occurred when calling the iscsi initiator: %s')
|
||||
% stdout_value)
|
||||
return stdout_value
|
||||
|
||||
def _login_target_portal(self, target_portal):
|
||||
|
@ -96,7 +96,7 @@ class VolumeUtils(basevolumeutils.BaseVolumeUtils):
|
|||
auth_username, auth_password)
|
||||
else:
|
||||
return
|
||||
except vmutils.HyperVException as exc:
|
||||
except exceptions.HyperVException as exc:
|
||||
LOG.debug("Attempt %(attempt)d to connect to target "
|
||||
"%(target_iqn)s failed. Retrying. "
|
||||
"Exceptipn: %(exc)s ",
|
||||
|
@ -105,8 +105,8 @@ class VolumeUtils(basevolumeutils.BaseVolumeUtils):
|
|||
'attempt': attempt})
|
||||
time.sleep(CONF.hyperv.volume_attach_retry_interval)
|
||||
|
||||
raise vmutils.HyperVException(_('Failed to login target %s') %
|
||||
target_iqn)
|
||||
raise exceptions.HyperVException(_('Failed to login target %s') %
|
||||
target_iqn)
|
||||
|
||||
def logout_storage_target(self, target_iqn):
|
||||
"""Logs out storage target through its session id."""
|
||||
|
|
|
@ -29,9 +29,9 @@ from oslo_log import log as logging
|
|||
from six.moves import range
|
||||
|
||||
from oslo_windows._i18n import _
|
||||
from oslo_windows import exceptions
|
||||
from nova import utils
|
||||
from nova.virt.hyperv import basevolumeutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
|
@ -107,8 +107,8 @@ class VolumeUtilsV2(basevolumeutils.BaseVolumeUtils):
|
|||
{'target_iqn': target_iqn,
|
||||
'exc': exc,
|
||||
'attempt': attempt})
|
||||
raise vmutils.HyperVException(_('Failed to login target %s') %
|
||||
target_iqn)
|
||||
raise exceptions.HyperVException(_('Failed to login target %s') %
|
||||
target_iqn)
|
||||
|
||||
def logout_storage_target(self, target_iqn):
|
||||
"""Logs out storage target through its session id."""
|
||||
|
|
|
@ -17,6 +17,7 @@ from oslo_config import cfg
|
|||
from oslo_log import log as logging
|
||||
|
||||
from oslo_windows._i18n import _
|
||||
from oslo_windows import exceptions
|
||||
from nova.virt.hyperv import hostutils
|
||||
from nova.virt.hyperv import hostutilsv2
|
||||
from nova.virt.hyperv import livemigrationutils
|
||||
|
@ -67,7 +68,7 @@ def _get_virt_utils_class(v1_class, v2_class):
|
|||
# (kernel version 6.3) or above.
|
||||
if (CONF.hyperv.force_hyperv_utils_v1 and
|
||||
utils.check_min_windows_version(6, 3)):
|
||||
raise vmutils.HyperVException(
|
||||
raise exceptions.HyperVException(
|
||||
_('The "force_hyperv_utils_v1" option cannot be set to "True" '
|
||||
'on Windows Server / Hyper-V Server 2012 R2 or above as the WMI '
|
||||
'"root/virtualization" namespace is no longer supported.'))
|
||||
|
|
Loading…
Reference in New Issue