diff --git a/networking_generic_switch/generic_switch_mech.py b/networking_generic_switch/generic_switch_mech.py index 13621c21..72303108 100644 --- a/networking_generic_switch/generic_switch_mech.py +++ b/networking_generic_switch/generic_switch_mech.py @@ -394,16 +394,17 @@ def update_port_postcommit(self, context): if (trunk_details and not switch.support_trunk_on_bond_ports): raise ngs_exc.GenericSwitchNotSupported( - "Trunks are not supported by " - "networking-generic-switch %s.", - switch.device_name) + feature="trunks", + switch=switch.device_name, + error="Trunks are not supported on bond ports.") switch.plug_bond_to_network(port_id, segmentation_id, **plug_kwargs) else: if trunk_details and not switch.support_trunk_on_ports: raise ngs_exc.GenericSwitchNotSupported( feature="trunks", - switch=switch.device_name) + switch=switch.device_name, + error="Trunks are not supported on ports.") switch.plug_port_to_network(port_id, segmentation_id, **plug_kwargs) LOG.info("Successfully plugged port %(port_id)s in segment " diff --git a/networking_generic_switch/tests/unit/test_generic_switch_mech.py b/networking_generic_switch/tests/unit/test_generic_switch_mech.py index 2f946b0c..05c616bb 100644 --- a/networking_generic_switch/tests/unit/test_generic_switch_mech.py +++ b/networking_generic_switch/tests/unit/test_generic_switch_mech.py @@ -854,7 +854,12 @@ def test_update_port_postcommit_trunk_not_supported(self, m_pc, m_list): self.switch_mock.support_trunk_on_bond_ports = False self.switch_mock.support_trunk_on_ports = False - with self.assertRaises(exceptions.GenericSwitchNotSupported): + exception_regex = ( + 'Requested feature trunks is not supported by ' + 'networking-generic-switch on the .*. Trunks are not supported on ' + 'ports.') + with self.assertRaisesRegex(exceptions.GenericSwitchNotSupported, + exception_regex): driver.update_port_postcommit(mock_context) self.switch_mock.plug_port_to_network.assert_not_called() m_pc.assert_not_called() diff --git a/releasenotes/notes/fix-genericswitchnotsupported-exceptions-80fcdcaadb16ca7b.yaml b/releasenotes/notes/fix-genericswitchnotsupported-exceptions-80fcdcaadb16ca7b.yaml new file mode 100644 index 00000000..90b6d0c2 --- /dev/null +++ b/releasenotes/notes/fix-genericswitchnotsupported-exceptions-80fcdcaadb16ca7b.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes incorrect instantiations of GenericSwitchNotSupported exceptions. See + `LP#2147055 + `__ for + details. diff --git a/tox.ini b/tox.ini index 6f7683d5..e3c265a3 100644 --- a/tox.ini +++ b/tox.ini @@ -35,6 +35,7 @@ deps = bashate~=2.1.0 # Apache-2.0 pycodestyle>=2.0.0,<3.0.0 # MIT doc8~=1.1.0 # Apache-2.0 + setuptools<81.0.0 allowlist_externals = bash {toxinidir}/tools/run_bashate.sh commands =