diff --git a/os_win/exceptions.py b/os_win/exceptions.py index 7a1b0b20..8c1b0024 100644 --- a/os_win/exceptions.py +++ b/os_win/exceptions.py @@ -95,6 +95,10 @@ class HyperVvNicNotFound(NotFound, HyperVException): msg_fmt = _("vNic not found: %(vnic_name)s") +class HyperVvSwitchNotFound(NotFound, HyperVException): + msg_fmt = _("vSwitch not found: %(vswitch_name)s.") + + class Invalid(OSWinException): pass diff --git a/os_win/tests/unit/utils/network/test_networkutils.py b/os_win/tests/unit/utils/network/test_networkutils.py index be782e25..849024f3 100644 --- a/os_win/tests/unit/utils/network/test_networkutils.py +++ b/os_win/tests/unit/utils/network/test_networkutils.py @@ -366,7 +366,7 @@ class NetworkUtilsTestCase(test_base.OsWinBaseTestCase): def test_get_vswitch_not_found(self): self.netutils._switches = {} self.netutils._conn.Msvm_VirtualEthernetSwitch.return_value = [] - self.assertRaises(exceptions.HyperVException, + self.assertRaises(exceptions.HyperVvSwitchNotFound, self.netutils._get_vswitch, self._FAKE_VSWITCH_NAME) diff --git a/os_win/utils/network/networkutils.py b/os_win/utils/network/networkutils.py index b56ab09f..cf51116e 100644 --- a/os_win/utils/network/networkutils.py +++ b/os_win/utils/network/networkutils.py @@ -202,9 +202,8 @@ class NetworkUtils(baseutils.BaseUtilsVirt): vswitch = self._conn.Msvm_VirtualEthernetSwitch( ElementName=vswitch_name) - if not len(vswitch): - raise exceptions.HyperVException(_('VSwitch not found: %s') % - vswitch_name) + if not vswitch: + raise exceptions.HyperVvSwitchNotFound(vswitch_name=vswitch_name) if self._enable_cache: self._switches[vswitch_name] = vswitch[0] return vswitch[0]