Browse Source

Merge "Create br-tun if missing after agent restart"

Zuul 10 months ago
parent
commit
6e14522680

+ 5
- 1
networking_vsphere/agent/ovsvapp_agent.py View File

@@ -522,13 +522,17 @@ class OVSvAppAgent(agent.Agent, ovs_agent.OVSNeutronAgent):
522 522
                 LOG.error(_LE("Tunneling cannot be enabled without a valid "
523 523
                               "local_ip."))
524 524
                 raise SystemExit(1)
525
+
526
+            existing_bridges = (ovs_lib.BaseOVS()).get_bridges()
527
+
525 528
             if not self.tun_br:
526 529
                 self.tun_br = self.br_tun_cls(CONF.OVSVAPP.tunnel_bridge)
527 530
             if self.tun_br is not None:
528 531
                 self.set_openflow_version(self.tun_br)
529 532
             self.agent_state['configurations']['tunneling_ip'] = self.local_ip
530 533
             self.agent_state['configurations']['l2_population'] = self.l2_pop
531
-            if not self.ovsvapp_agent_restarted:
534
+            if not (self.ovsvapp_agent_restarted
535
+                    and CONF.OVSVAPP.tunnel_bridge in existing_bridges):
532 536
                 self.setup_tunnel_br(CONF.OVSVAPP.tunnel_bridge)
533 537
                 self.setup_tunnel_br_flows()
534 538
                 self._add_rarp_flow_to_int_br()

+ 40
- 1
networking_vsphere/tests/unit/agent/test_ovsvapp_agent.py View File

@@ -194,6 +194,7 @@ class TestOVSvAppAgentRestart(base.TestCase):
194 194
         self.agent.run_refresh_firewall_loop = False
195 195
         self.LOG = ovsvapp_agent.LOG
196 196
         self.agent.monitor_log = logging.getLogger('monitor')
197
+        self.agent.agent_state = {'configurations': {'l2_population': False}}
197 198
 
198 199
     @mock.patch('neutron.agent.common.ovs_lib.OVSBridge')
199 200
     def test_reconfigure_interface(self, mock_ovs_bridge):
@@ -298,6 +299,35 @@ class TestOVSvAppAgentRestart(base.TestCase):
298 299
             self.assertTrue(mock_delete_port.called)
299 300
             self.assertTrue(mock_int_del_port.called)
300 301
 
302
+    @mock.patch('neutron.agent.ovsdb.api.from_config')
303
+    def test_setup_ovs_bridges_vxlan_restart(self, mock_ovsdb_api):
304
+        self.agent.local_ip = "10.10.10.10"
305
+        bridge_tunnel = 'br-tunnel'
306
+        cfg.CONF.set_override('tunnel_bridge',
307
+                              bridge_tunnel, 'OVSVAPP')
308
+        self.agent.tun_br = mock.Mock()
309
+        self.agent.int_br = mock.Mock()
310
+        self.agent.tenant_network_types = [p_const.TYPE_VXLAN]
311
+        self.agent.l2_pop = False
312
+        with mock.patch.object(self.agent, 'setup_tunnel_br'
313
+                               ) as mock_setup_tunnel_br, \
314
+                mock.patch.object(self.agent, '_add_rarp_flow_to_int_br'
315
+                                  ) as mock_rarp_flow, \
316
+                mock.patch.object(ovs_lib.BaseOVS,
317
+                                  "get_bridges",
318
+                                  return_value=['br-eth1']
319
+                                  ), \
320
+                mock.patch.object(self.agent, 'recover_tunnel_bridge'
321
+                                  ) as mock_recover_tunnel_bridge, \
322
+                mock.patch.object(self.agent, 'setup_tunnel_br_flows'
323
+                                  ) as mock_setup_tunnel_br_flows:
324
+            self.agent.ovsvapp_agent_restarted = True
325
+            self.agent.setup_ovs_bridges()
326
+            mock_setup_tunnel_br.assert_called_with(bridge_tunnel)
327
+            self.assertTrue(mock_setup_tunnel_br_flows.called)
328
+            self.assertTrue(mock_rarp_flow.called)
329
+            self.assertFalse(mock_recover_tunnel_bridge.called)
330
+
301 331
 
302 332
 class TestOVSvAppAgent(base.TestCase):
303 333
 
@@ -629,6 +659,8 @@ class TestOVSvAppAgent(base.TestCase):
629 659
                                ) as mock_setup_tunnel_br, \
630 660
                 mock.patch.object(self.agent, '_add_rarp_flow_to_int_br'
631 661
                                   ) as mock_rarp_flow, \
662
+                mock.patch.object(ovs_lib.BaseOVS, 'get_bridges',
663
+                                  return_value=[]), \
632 664
                 mock.patch.object(self.agent, 'setup_tunnel_br_flows'
633 665
                                   ) as mock_setup_tunnel_br_flows:
634 666
             self.agent.setup_ovs_bridges()
@@ -636,7 +668,8 @@ class TestOVSvAppAgent(base.TestCase):
636 668
             self.assertTrue(mock_setup_tunnel_br_flows.called)
637 669
             self.assertTrue(mock_rarp_flow.called)
638 670
 
639
-    def test_setup_ovs_bridges_vxlan_ofport(self):
671
+    @mock.patch('neutron.agent.ovsdb.api.from_config')
672
+    def test_setup_ovs_bridges_vxlan_ofport(self, mock_ovsdb_api):
640 673
         cfg.CONF.set_override('tenant_network_types',
641 674
                               "vxlan", 'OVSVAPP')
642 675
         cfg.CONF.set_override('local_ip',
@@ -654,6 +687,9 @@ class TestOVSvAppAgent(base.TestCase):
654 687
                                   "add_patch_port",
655 688
                                   return_value=6), \
656 689
                 mock.patch.object(self.agent, '_add_rarp_flow_to_int_br'), \
690
+                mock.patch.object(ovs_lib.BaseOVS,
691
+                                  "get_bridges",
692
+                                  return_value=[]), \
657 693
                 mock.patch.object(self.agent, 'setup_tunnel_br_flows'
658 694
                                   ) as mock_setup_tunnel_br_flows:
659 695
             self.agent.setup_ovs_bridges()
@@ -733,6 +769,9 @@ class TestOVSvAppAgent(base.TestCase):
733 769
                                   ) as mock_remove_device, \
734 770
                 mock.patch.object(self.agent.monitor_log, "warning"
735 771
                                   ) as monitor_warning, \
772
+                mock.patch.object(ovs_lib.BaseOVS,
773
+                                  "get_bridges",
774
+                                  return_value=[]), \
736 775
                 mock.patch.object(self.agent.monitor_log, "info"
737 776
                                   ) as monitor_info:
738 777
             self.agent.mitigate_ovs_restart()

Loading…
Cancel
Save