LinuxBridge: Use ifindex for logical 'timestamp'

With Xenial (and maybe older versions), the modified timestamps
in /sys/class/net/(device_name) are not stable. They appear to
work for a period of time, and then when some kind of cache clears
on the kernel side, all of the timestamps are reset to the latest
access time.

This was causing the Linux Bridge agent to think that the interfaces
were experiencing local changes much more frequently than they actually
were, resulting in more polling to the Neutron server and subsequently
more BUILD->ACTIVE->BUILD->ACTIVE transitions in the logical model.

The purpose of the timestamp patch was to catch rapid server REBUILD
operations where the interface would be deleted and re-added within
a polling interval. Without it, these would be stuck in the BUILD
state since the agent wouldn't realize it needed to wire the ports.

This patch switches to looking at the IFINDEX of the interfaces to
use as a sort of logical timestamp. If an interface gets removed
and readded, it will get a different index, so the original timestamp
comparison logic will still work.

In the future, the agent should undergo a larger refactor to just
watch 'ip monitor' for netlink events to replace the polling of the
interface listing and the timestamp logic entirely. However, this
approach was taken due to the near term release and the ability to
back-port it to older releases.

This was verified with both Nova rebuild actions and Nova interface
attach/detach actions.

Change-Id: I016019885446bff6806268ab49cd5476d93ec61f
Closes-Bug: #1622833
This commit is contained in:
Kevin Benton 2016-09-12 22:27:33 -07:00
parent dedb632ba5
commit a2bd0b4b53
4 changed files with 22 additions and 13 deletions

View File

@ -39,10 +39,11 @@ def is_bridged_interface(interface):
return os.path.exists(BRIDGE_PORT_FS_FOR_DEVICE % interface)
def get_interface_bridged_time(interface):
def get_interface_ifindex(interface):
try:
return os.stat(BRIDGE_PORT_FS_FOR_DEVICE % interface).st_mtime
except OSError:
with open(os.path.join(BRIDGE_FS, interface, 'ifindex'), 'r') as fh:
return int(fh.read().strip())
except (IOError, ValueError):
pass

View File

@ -597,7 +597,12 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase):
LOG.debug("Done deleting interface %s", interface)
def get_devices_modified_timestamps(self, devices):
return {d: bridge_lib.get_interface_bridged_time(d) for d in devices}
# NOTE(kevinbenton): we aren't returning real timestamps here. We
# are returning interface indexes instead which change when the
# interface is removed/re-added. This works for the direct
# comparison the common agent loop performs with these.
# See bug/1622833 for details.
return {d: bridge_lib.get_interface_ifindex(d) for d in devices}
def get_all_devices(self):
devices = set()

View File

@ -857,10 +857,11 @@ class LinuxBridgePortFixture(PortFixture):
super(LinuxBridgePortFixture, self)._setUp()
br_port_name = self._get_port_name()
if br_port_name:
self.br_port, self.port = self.useFixture(
NamedVethFixture(veth0_prefix=br_port_name)).ports
self.veth_fixture = self.useFixture(
NamedVethFixture(veth0_prefix=br_port_name))
else:
self.br_port, self.port = self.useFixture(VethFixture()).ports
self.veth_fixture = self.useFixture(VethFixture())
self.br_port, self.port = self.veth_fixture.ports
if self.mac:
self.port.link.set_address(self.mac)

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import uuidutils
from neutron.agent.linux import bridge_lib
from neutron.tests.common import net_helpers
@ -28,7 +29,8 @@ class BridgeLibTestCase(base.BaseSudoTestCase):
bridge = self.useFixture(
net_helpers.LinuxBridgeFixture(namespace=None)).bridge
port_fixture = self.useFixture(
net_helpers.LinuxBridgePortFixture(bridge))
net_helpers.LinuxBridgePortFixture(
bridge, port_id=uuidutils.generate_uuid()))
return bridge, port_fixture
def test_is_bridged_interface(self):
@ -42,12 +44,12 @@ class BridgeLibTestCase(base.BaseSudoTestCase):
def test_get_bridge_names(self):
self.assertIn(self.bridge.name, bridge_lib.get_bridge_names())
def test_get_interface_bridged_time(self):
def test_get_interface_ifindex(self):
port = self.port_fixture.br_port
t1 = bridge_lib.get_interface_bridged_time(port)
self.bridge.delif(port)
self.bridge.addif(port)
t2 = bridge_lib.get_interface_bridged_time(port)
t1 = bridge_lib.get_interface_ifindex(str(port))
self.port_fixture.veth_fixture.destroy()
self.port_fixture.veth_fixture._setUp()
t2 = bridge_lib.get_interface_ifindex(str(port))
self.assertIsNotNone(t1)
self.assertIsNotNone(t2)
self.assertGreaterEqual(t2, t1)