Browse Source

Merge "Update port_status to ACTIVE during live-migration" into stable/queens

stable/queens
Zuul 2 weeks ago
parent
commit
5504b1dc9a

+ 1
- 0
networking_ovn/common/constants.py View File

@@ -44,6 +44,7 @@ OVN_PORT_BINDING_PROFILE_PARAMS = [{'parent_name': six.string_types,
44 44
                                     'tag': six.integer_types},
45 45
                                    {'vtep-physical-switch': six.string_types,
46 46
                                     'vtep-logical-switch': six.string_types}]
47
+MIGRATING_ATTR = 'migrating_to'
47 48
 OVN_ROUTER_PORT_OPTION_KEYS = ['router-port', 'nat-addresses']
48 49
 OVN_GATEWAY_CHASSIS_KEY = 'redirect-chassis'
49 50
 OVN_GATEWAY_NAT_ADDRESSES_KEY = 'nat-addresses'

+ 20
- 0
networking_ovn/ml2/mech_driver.py View File

@@ -529,6 +529,26 @@ class OVNMechanismDriver(api.MechanismDriver):
529 529
         port['network'] = context.network.current
530 530
         original_port = copy.deepcopy(context.original)
531 531
         original_port['network'] = context.network.current
532
+
533
+        # NOTE(mjozefcz): Check if port is in migration state. If so update
534
+        # the port status from DOWN to UP in order to generate 'fake'
535
+        # vif-interface-plugged event. This workaround is needed to
536
+        # perform live-migration with live_migration_wait_for_vif_plug=True.
537
+        if ((port['status'] == const.PORT_STATUS_DOWN and
538
+             ovn_const.MIGRATING_ATTR in port[portbindings.PROFILE].keys() and
539
+             port[portbindings.VIF_TYPE] == portbindings.VIF_TYPE_OVS)):
540
+            admin_context = n_context.get_admin_context()
541
+            LOG.info("Setting port %s status from DOWN to UP in order "
542
+                     "to emit vif-interface-plugged event.",
543
+                     port['id'])
544
+            self._plugin.update_port_status(admin_context, port['id'],
545
+                                            const.PORT_STATUS_ACTIVE)
546
+            # The revision has been changed. In the meantime
547
+            # port-update event already updated the OVN configuration,
548
+            # So there is no need to update it again here. Anyway it
549
+            # will fail that OVN has port with bigger revision.
550
+            return
551
+
532 552
         self._ovn_client.update_port(port, port_object=original_port)
533 553
         self._notify_dhcp_updated(port['id'])
534 554
 

+ 24
- 0
networking_ovn/tests/unit/ml2/test_mech_driver.py View File

@@ -1493,6 +1493,30 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase):
1493 1493
             passed_fake_port, port_object=passed_fake_port_orig)
1494 1494
         mock_notify_dhcp.assert_called_once_with(fake_port['id'])
1495 1495
 
1496
+    @mock.patch.object(mech_driver.OVNMechanismDriver,
1497
+                       '_is_port_provisioning_required', lambda *_: True)
1498
+    @mock.patch.object(mech_driver.OVNMechanismDriver, '_notify_dhcp_updated')
1499
+    @mock.patch.object(ovn_client.OVNClient, 'update_port')
1500
+    @mock.patch.object(context, 'get_admin_context')
1501
+    def test_update_port_postcommit_live_migration(
1502
+            self, mock_admin_context, mock_update_port, mock_notify_dhcp):
1503
+        self.plugin.update_port_status = mock.Mock()
1504
+        foo_admin_context = mock.Mock()
1505
+        mock_admin_context.return_value = foo_admin_context
1506
+        fake_port = fakes.FakePort.create_one_port(
1507
+            attrs={
1508
+                'status': const.PORT_STATUS_DOWN,
1509
+                portbindings.PROFILE: {ovn_const.MIGRATING_ATTR: 'foo'},
1510
+                portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info()
1511
+        fake_ctx = mock.Mock(current=fake_port, original=fake_port)
1512
+
1513
+        self.mech_driver.update_port_postcommit(fake_ctx)
1514
+
1515
+        mock_update_port.assert_not_called()
1516
+        mock_notify_dhcp.assert_not_called()
1517
+        self.plugin.update_port_status.assert_called_once_with(
1518
+            foo_admin_context, fake_port['id'], const.PORT_STATUS_ACTIVE)
1519
+
1496 1520
     def _test__update_dnat_entry_if_needed(self, up=True):
1497 1521
         ovn_config.cfg.CONF.set_override(
1498 1522
             'enable_distributed_floating_ip', True, group='ovn')

Loading…
Cancel
Save