From e2a37be73da7bbc0ab562eabef69bfe69dc7cfa1 Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Wed, 20 Jan 2016 13:53:20 +0300 Subject: [PATCH] OVS agent should fail if it can't get DVR mac address Currently agent will fall back to non-dvr mode in case it can't. However neutron server does not check dvr mode of ovs agents when scheduling routers. So in a DVR enabled cluster all ovs agents should run in DVR mode. Otherwise it will lead to undefined behavior which is hard to debug. Closes-Bug: #1536110 Change-Id: I6c31aabf1852c688e9c27fc1859d3fdd830caa68 --- .../agent/ovs_dvr_neutron_agent.py | 18 ++++++++---------- .../agent/test_ovs_neutron_agent.py | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py index 2023c36dac2..a4158ff10a9 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import sys + from oslo_config import cfg from oslo_log import log as logging import oslo_messaging @@ -165,20 +167,16 @@ class OVSDVRNeutronAgent(object): try: self.get_dvr_mac_address_with_retry() except oslo_messaging.RemoteError as e: - LOG.warning(_LW('L2 agent could not get DVR MAC address at ' - 'startup due to RPC error. It happens when the ' - 'server does not support this RPC API. Detailed ' - 'message: %s'), e) + LOG.error(_LE('L2 agent could not get DVR MAC address at ' + 'startup due to RPC error. It happens when the ' + 'server does not support this RPC API. Detailed ' + 'message: %s'), e) except oslo_messaging.MessagingTimeout: LOG.error(_LE('DVR: Failed to obtain a valid local ' - 'DVR MAC address - L2 Agent operating ' - 'in Non-DVR Mode')) + 'DVR MAC address')) if not self.in_distributed_mode(): - # switch all traffic using L2 learning - # REVISIT(yamamoto): why to install the same flow as - # setup_integration_br? - self.int_br.install_normal() + sys.exit(1) def get_dvr_mac_address_with_retry(self): # Get the local DVR MAC Address from the Neutron Server. diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py index 87ef62c5150..9ed1a0a6697 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py @@ -2599,10 +2599,10 @@ class TestOvsDvrNeutronAgent(object): side_effect=oslo_messaging.RemoteError),\ mock.patch.object(self.agent, 'int_br', new=int_br),\ mock.patch.object(self.agent.dvr_agent, 'int_br', new=int_br): - self.agent.dvr_agent.get_dvr_mac_address() - self.assertIsNone(self.agent.dvr_agent.dvr_mac_address) - self.assertFalse(self.agent.dvr_agent.in_distributed_mode()) - self.assertEqual([mock.call.install_normal()], int_br.mock_calls) + with testtools.ExpectedException(SystemExit): + self.agent.dvr_agent.get_dvr_mac_address() + self.assertIsNone(self.agent.dvr_agent.dvr_mac_address) + self.assertFalse(self.agent.dvr_agent.in_distributed_mode()) def test_get_dvr_mac_address_retried(self): valid_entry = {'host': 'cn1', 'mac_address': 'aa:22:33:44:55:66'} @@ -2633,11 +2633,12 @@ class TestOvsDvrNeutronAgent(object): mock.patch.object(utils, "execute"),\ mock.patch.object(self.agent, 'int_br', new=int_br),\ mock.patch.object(self.agent.dvr_agent, 'int_br', new=int_br): - self.agent.dvr_agent.get_dvr_mac_address() - self.assertIsNone(self.agent.dvr_agent.dvr_mac_address) - self.assertFalse(self.agent.dvr_agent.in_distributed_mode()) - self.assertEqual(self.agent.dvr_agent.plugin_rpc. - get_dvr_mac_address_by_host.call_count, 5) + with testtools.ExpectedException(SystemExit): + self.agent.dvr_agent.get_dvr_mac_address() + self.assertIsNone(self.agent.dvr_agent.dvr_mac_address) + self.assertFalse(self.agent.dvr_agent.in_distributed_mode()) + self.assertEqual(self.agent.dvr_agent.plugin_rpc. + get_dvr_mac_address_by_host.call_count, 5) def test_dvr_mac_address_update(self): self._setup_for_dvr_test()