Remove and recreate interface if already exists

If the dhcp-agent machine restarts when openvswitch comes up it logs the
following warning messages for all tap interfaces that do not exist:

bridge|WARN|could not open network device tap2cf7dbad-9d (No such device)

Once the dhcp-agent starts it recreates the interfaces and re-adds them to the
ovs-bridge. Unfortunately, ovs does not reinitialize the interfaces as they
are already in ovsdb and does not assign them a ofport number.

This situation corrects itself though the next time a port is added to the
ovs-bridge which is why no one has probably noticed this issue till now.

In order to correct this we should first remove interface that exist and
then readd them.

Closes-bug: #1268762

Change-Id: I4bb0019135ab7fa7cdfa6d5db3bff6eafe22fc85
(cherry picked from commit b78eea6146)
This commit is contained in:
Aaron Rosen 2014-01-13 13:57:04 -08:00
parent 5f959d76a0
commit c7596bf8c9
2 changed files with 5 additions and 3 deletions

View File

@ -140,7 +140,7 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
def _ovs_add_port(self, bridge, device_name, port_id, mac_address, def _ovs_add_port(self, bridge, device_name, port_id, mac_address,
internal=True): internal=True):
cmd = ['ovs-vsctl', '--', '--may-exist', cmd = ['ovs-vsctl', '--', '--if-exists', 'del-port', device_name, '--',
'add-port', bridge, device_name] 'add-port', bridge, device_name]
if internal: if internal:
cmd += ['--', 'set', 'Interface', device_name, 'type=internal'] cmd += ['--', 'set', 'Interface', device_name, 'type=internal']

View File

@ -119,7 +119,8 @@ class TestOVSInterfaceDriver(TestBase):
def device_exists(dev, root_helper=None, namespace=None): def device_exists(dev, root_helper=None, namespace=None):
return dev == bridge return dev == bridge
vsctl_cmd = ['ovs-vsctl', '--', '--may-exist', 'add-port', vsctl_cmd = ['ovs-vsctl', '--', '--if-exists', 'del-port',
'tap0', '--', 'add-port',
bridge, 'tap0', '--', 'set', 'Interface', 'tap0', bridge, 'tap0', '--', 'set', 'Interface', 'tap0',
'type=internal', '--', 'set', 'Interface', 'tap0', 'type=internal', '--', 'set', 'Interface', 'tap0',
'external-ids:iface-id=port-1234', '--', 'set', 'external-ids:iface-id=port-1234', '--', 'set',
@ -206,7 +207,8 @@ class TestOVSInterfaceDriverWithVeth(TestOVSInterfaceDriver):
mock.call().add_veth('tap0', devname, mock.call().add_veth('tap0', devname,
namespace2=namespace)] namespace2=namespace)]
vsctl_cmd = ['ovs-vsctl', '--', '--may-exist', 'add-port', vsctl_cmd = ['ovs-vsctl', '--', '--if-exists', 'del-port',
'tap0', '--', 'add-port',
bridge, 'tap0', '--', 'set', 'Interface', 'tap0', bridge, 'tap0', '--', 'set', 'Interface', 'tap0',
'external-ids:iface-id=port-1234', '--', 'set', 'external-ids:iface-id=port-1234', '--', 'set',
'Interface', 'tap0', 'Interface', 'tap0',