[Trivial] Add HyperVvSwitchNotFound exception
At the moment, we're raising a generic HyperVException when attempting to retrieve a non-existent vSwitch. This change adds a 'HyperVvSwitchNotFound' exception, which will allow callers to better handle such situations. Change-Id: I221622bc050cf634f86edde49e26c09ee30b177e
This commit is contained in:
parent
c5ce9a6cf6
commit
11c92505d6
@ -95,6 +95,10 @@ class HyperVvNicNotFound(NotFound, HyperVException):
|
|||||||
msg_fmt = _("vNic not found: %(vnic_name)s")
|
msg_fmt = _("vNic not found: %(vnic_name)s")
|
||||||
|
|
||||||
|
|
||||||
|
class HyperVvSwitchNotFound(NotFound, HyperVException):
|
||||||
|
msg_fmt = _("vSwitch not found: %(vswitch_name)s.")
|
||||||
|
|
||||||
|
|
||||||
class Invalid(OSWinException):
|
class Invalid(OSWinException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ class NetworkUtilsTestCase(test_base.OsWinBaseTestCase):
|
|||||||
def test_get_vswitch_not_found(self):
|
def test_get_vswitch_not_found(self):
|
||||||
self.netutils._switches = {}
|
self.netutils._switches = {}
|
||||||
self.netutils._conn.Msvm_VirtualEthernetSwitch.return_value = []
|
self.netutils._conn.Msvm_VirtualEthernetSwitch.return_value = []
|
||||||
self.assertRaises(exceptions.HyperVException,
|
self.assertRaises(exceptions.HyperVvSwitchNotFound,
|
||||||
self.netutils._get_vswitch,
|
self.netutils._get_vswitch,
|
||||||
self._FAKE_VSWITCH_NAME)
|
self._FAKE_VSWITCH_NAME)
|
||||||
|
|
||||||
|
@ -202,9 +202,8 @@ class NetworkUtils(baseutils.BaseUtilsVirt):
|
|||||||
|
|
||||||
vswitch = self._conn.Msvm_VirtualEthernetSwitch(
|
vswitch = self._conn.Msvm_VirtualEthernetSwitch(
|
||||||
ElementName=vswitch_name)
|
ElementName=vswitch_name)
|
||||||
if not len(vswitch):
|
if not vswitch:
|
||||||
raise exceptions.HyperVException(_('VSwitch not found: %s') %
|
raise exceptions.HyperVvSwitchNotFound(vswitch_name=vswitch_name)
|
||||||
vswitch_name)
|
|
||||||
if self._enable_cache:
|
if self._enable_cache:
|
||||||
self._switches[vswitch_name] = vswitch[0]
|
self._switches[vswitch_name] = vswitch[0]
|
||||||
return vswitch[0]
|
return vswitch[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user