OVSInterfaceDriver.plug_new should catch correct exceptions

Now that "IPWrapper.add_device_to_namespace" is implemented with
Pyroute2, the function should catch the correct exceptions:
- NetlinkError in case of duplicated interface
- OSError in case of corrupted namespace

Change-Id: I12b5710dc3bfdcc4c6b1e96bbfbfab9e59684065
Closes-Bug: #1856853
This commit is contained in:
Rodolfo Alonso Hernandez 2019-12-18 15:10:23 +00:00
parent 33919fbd50
commit e54b64f725
2 changed files with 23 additions and 22 deletions

View File

@ -21,6 +21,7 @@ from neutron_lib import constants
from neutron_lib import exceptions
from oslo_log import log as logging
from oslo_utils import excutils
from pyroute2.netlink import exceptions as pyroute2_exc
import six
from neutron.agent.common import ovs_lib
@ -379,13 +380,11 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
try:
namespace_obj = ip.ensure_namespace(namespace)
namespace_obj.add_device_to_namespace(ns_dev)
except exceptions.ProcessExecutionError:
# To prevent the namespace failure from blasting
# ovs, the ovs port created should be reverted
# When the namespace is corrupted, the ProcessExecutionError
# has execption message as:
# Exit code: 2; Stdin: ; Stdout: ; Stderr: RTNETLINK
# answers: Invalid argument
except (pyroute2_exc.NetlinkError, OSError):
# To prevent the namespace failure from blasting OVS, the OVS
# port creation should be reverted. Possible exceptions:
# - NetlinkError in case of duplicated interface
# - OSError in case of corrupted namespace
LOG.warning("Failed to plug interface %s into bridge %s, "
"cleaning up", device_name, bridge)
with excutils.save_and_reraise_exception():

View File

@ -15,8 +15,8 @@
import mock
from neutron_lib import constants
from neutron_lib import exceptions
from oslo_utils import excutils
from pyroute2.netlink import exceptions as pyroute2_exc
from neutron.agent.common import ovs_lib
from neutron.agent.linux import interface
@ -476,20 +476,22 @@ class TestOVSInterfaceDriver(TestBase):
reraise = mock.patch.object(
excutils, 'save_and_reraise_exception')
reraise.start()
proEr = exceptions.ProcessExecutionError('', 2)
processExecutionError = mock.Mock(side_effect=proEr)
ip = self.ip.return_value
ip.ensure_namespace.side_effect = processExecutionError
ovs.plug_new(
'01234567-1234-1234-99',
'port-1234',
'tap0',
'aa:bb:cc:dd:ee:ff',
bridge=bridge,
namespace=namespace,
prefix='veth',
mtu=9000)
delete_port.assert_called_once_with('tap0')
ip_wrapper = mock.Mock()
for exception in (OSError(),
pyroute2_exc.NetlinkError(22)):
ip_wrapper.ensure_namespace.side_effect = exception
self.ip.return_value = ip_wrapper
delete_port.reset_mock()
ovs.plug_new(
'01234567-1234-1234-99',
'port-1234',
'tap0',
'aa:bb:cc:dd:ee:ff',
bridge=bridge,
namespace=namespace,
prefix='veth',
mtu=9000)
delete_port.assert_called_once_with('tap0')
def test_unplug(self):
with mock.patch('neutron.agent.common.ovs_lib.OVSBridge') as ovs_br: