Browse Source

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

stable/rocky
Zuul 4 weeks ago
parent
commit
aef1c3ef1e

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

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

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

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

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

@@ -1498,6 +1498,30 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase):
1498 1498
             passed_fake_port, port_object=passed_fake_port_orig)
1499 1499
         mock_notify_dhcp.assert_called_once_with(fake_port['id'])
1500 1500
 
1501
+    @mock.patch.object(mech_driver.OVNMechanismDriver,
1502
+                       '_is_port_provisioning_required', lambda *_: True)
1503
+    @mock.patch.object(mech_driver.OVNMechanismDriver, '_notify_dhcp_updated')
1504
+    @mock.patch.object(ovn_client.OVNClient, 'update_port')
1505
+    @mock.patch.object(context, 'get_admin_context')
1506
+    def test_update_port_postcommit_live_migration(
1507
+            self, mock_admin_context, mock_update_port, mock_notify_dhcp):
1508
+        self.plugin.update_port_status = mock.Mock()
1509
+        foo_admin_context = mock.Mock()
1510
+        mock_admin_context.return_value = foo_admin_context
1511
+        fake_port = fakes.FakePort.create_one_port(
1512
+            attrs={
1513
+                'status': const.PORT_STATUS_DOWN,
1514
+                portbindings.PROFILE: {ovn_const.MIGRATING_ATTR: 'foo'},
1515
+                portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info()
1516
+        fake_ctx = mock.Mock(current=fake_port, original=fake_port)
1517
+
1518
+        self.mech_driver.update_port_postcommit(fake_ctx)
1519
+
1520
+        mock_update_port.assert_not_called()
1521
+        mock_notify_dhcp.assert_not_called()
1522
+        self.plugin.update_port_status.assert_called_once_with(
1523
+            foo_admin_context, fake_port['id'], const.PORT_STATUS_ACTIVE)
1524
+
1501 1525
     def _add_chassis_agent(self, nb_cfg, agent_type, updated_at=None):
1502 1526
         chassis = mock.Mock()
1503 1527
         chassis.nb_cfg = nb_cfg

Loading…
Cancel
Save