|
45 | 45 |
|
46 | 46 | from neutron.common.ovn import acl as ovn_acl
|
47 | 47 | from neutron.common.ovn import constants as ovn_const
|
| 48 | +from neutron.common.ovn import exceptions as ovn_exceptions |
48 | 49 | from neutron.common.ovn import hash_ring_manager
|
49 | 50 | from neutron.common.ovn import utils as ovn_utils
|
50 | 51 | from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
|
@@ -1960,6 +1961,116 @@ def test_update_port_postcommit_live_migration(
|
1960 | 1961 | self.plugin.update_port_status.assert_called_once_with(
|
1961 | 1962 | fake_context, fake_port['id'], const.PORT_STATUS_ACTIVE)
|
1962 | 1963 |
|
| 1964 | + @mock.patch.object(mech_driver.OVNMechanismDriver, |
| 1965 | + '_is_port_provisioning_required', lambda *_: True) |
| 1966 | + @mock.patch.object(mech_driver.OVNMechanismDriver, '_notify_dhcp_updated') |
| 1967 | + @mock.patch.object(ovn_client.OVNClient, 'update_port') |
| 1968 | + def test_update_port_postcommit_live_migration_revision_mismatch_always( |
| 1969 | + self, mock_update_port, mock_notify_dhcp): |
| 1970 | + self.plugin.update_port_status = mock.Mock() |
| 1971 | + self.plugin.get_port = mock.Mock(return_value=mock.MagicMock()) |
| 1972 | + |
| 1973 | + fake_context = mock.MagicMock() |
| 1974 | + fake_port = fakes.FakePort.create_one_port( |
| 1975 | + attrs={ |
| 1976 | + 'status': const.PORT_STATUS_ACTIVE, |
| 1977 | + portbindings.PROFILE: {}, |
| 1978 | + portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info() |
| 1979 | + original_fake_port = fakes.FakePort.create_one_port( |
| 1980 | + attrs={ |
| 1981 | + 'status': const.PORT_STATUS_ACTIVE, |
| 1982 | + portbindings.PROFILE: { |
| 1983 | + ovn_const.MIGRATING_ATTR: fake_port[portbindings.HOST_ID]}, |
| 1984 | + portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info() |
| 1985 | + |
| 1986 | + fake_ctx = mock.Mock(current=fake_port, original=original_fake_port, |
| 1987 | + _plugin_context=fake_context) |
| 1988 | + mock_update_port.side_effect = ovn_exceptions.RevisionConflict( |
| 1989 | + resource_id=fake_port['id'], |
| 1990 | + resource_type=ovn_const.TYPE_PORTS) |
| 1991 | + |
| 1992 | + self.mech_driver.update_port_postcommit(fake_ctx) |
| 1993 | + |
| 1994 | + self.plugin.update_port_status.assert_not_called() |
| 1995 | + self.plugin.get_port.assert_called_once_with( |
| 1996 | + mock.ANY, fake_port['id']) |
| 1997 | + self.assertEqual(2, mock_update_port.call_count) |
| 1998 | + mock_notify_dhcp.assert_called_with(fake_port['id']) |
| 1999 | + |
| 2000 | + @mock.patch.object(mech_driver.OVNMechanismDriver, |
| 2001 | + '_is_port_provisioning_required', lambda *_: True) |
| 2002 | + @mock.patch.object(mech_driver.OVNMechanismDriver, '_notify_dhcp_updated') |
| 2003 | + @mock.patch.object(ovn_client.OVNClient, 'update_port') |
| 2004 | + def test_update_port_postcommit_live_migration_revision_mismatch_once( |
| 2005 | + self, mock_update_port, mock_notify_dhcp): |
| 2006 | + self.plugin.update_port_status = mock.Mock() |
| 2007 | + self.plugin.get_port = mock.Mock(return_value=mock.MagicMock()) |
| 2008 | + |
| 2009 | + fake_context = mock.MagicMock() |
| 2010 | + fake_port = fakes.FakePort.create_one_port( |
| 2011 | + attrs={ |
| 2012 | + 'status': const.PORT_STATUS_ACTIVE, |
| 2013 | + portbindings.PROFILE: {}, |
| 2014 | + portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info() |
| 2015 | + original_fake_port = fakes.FakePort.create_one_port( |
| 2016 | + attrs={ |
| 2017 | + 'status': const.PORT_STATUS_ACTIVE, |
| 2018 | + portbindings.PROFILE: { |
| 2019 | + ovn_const.MIGRATING_ATTR: fake_port[portbindings.HOST_ID]}, |
| 2020 | + portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info() |
| 2021 | + |
| 2022 | + fake_ctx = mock.Mock(current=fake_port, original=original_fake_port, |
| 2023 | + _plugin_context=fake_context) |
| 2024 | + mock_update_port.side_effect = [ |
| 2025 | + ovn_exceptions.RevisionConflict( |
| 2026 | + resource_id=fake_port['id'], |
| 2027 | + resource_type=ovn_const.TYPE_PORTS), |
| 2028 | + None] |
| 2029 | + |
| 2030 | + self.mech_driver.update_port_postcommit(fake_ctx) |
| 2031 | + |
| 2032 | + self.plugin.update_port_status.assert_not_called() |
| 2033 | + self.plugin.get_port.assert_called_once_with( |
| 2034 | + mock.ANY, fake_port['id']) |
| 2035 | + self.assertEqual(2, mock_update_port.call_count) |
| 2036 | + mock_notify_dhcp.assert_called_with(fake_port['id']) |
| 2037 | + |
| 2038 | + @mock.patch.object(mech_driver.OVNMechanismDriver, |
| 2039 | + '_is_port_provisioning_required', lambda *_: True) |
| 2040 | + @mock.patch.object(mech_driver.OVNMechanismDriver, '_notify_dhcp_updated') |
| 2041 | + @mock.patch.object(ovn_client.OVNClient, 'update_port') |
| 2042 | + def test_update_port_postcommit_revision_mismatch_not_after_live_migration( |
| 2043 | + self, mock_update_port, mock_notify_dhcp): |
| 2044 | + self.plugin.update_port_status = mock.Mock() |
| 2045 | + self.plugin.get_port = mock.Mock(return_value=mock.MagicMock()) |
| 2046 | + |
| 2047 | + fake_context = mock.MagicMock() |
| 2048 | + fake_port = fakes.FakePort.create_one_port( |
| 2049 | + attrs={ |
| 2050 | + 'status': const.PORT_STATUS_ACTIVE, |
| 2051 | + portbindings.PROFILE: {}, |
| 2052 | + portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info() |
| 2053 | + original_fake_port = fakes.FakePort.create_one_port( |
| 2054 | + attrs={ |
| 2055 | + 'status': const.PORT_STATUS_DOWN, |
| 2056 | + portbindings.PROFILE: {}, |
| 2057 | + portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS}).info() |
| 2058 | + |
| 2059 | + fake_ctx = mock.Mock(current=fake_port, original=original_fake_port, |
| 2060 | + _plugin_context=fake_context) |
| 2061 | + mock_update_port.side_effect = [ |
| 2062 | + ovn_exceptions.RevisionConflict( |
| 2063 | + resource_id=fake_port['id'], |
| 2064 | + resource_type=ovn_const.TYPE_PORTS), |
| 2065 | + None] |
| 2066 | + |
| 2067 | + self.mech_driver.update_port_postcommit(fake_ctx) |
| 2068 | + |
| 2069 | + self.plugin.update_port_status.assert_not_called() |
| 2070 | + self.plugin.get_port.assert_not_called() |
| 2071 | + self.assertEqual(1, mock_update_port.call_count) |
| 2072 | + mock_notify_dhcp.assert_called_with(fake_port['id']) |
| 2073 | + |
1963 | 2074 | def _add_chassis(self, nb_cfg):
|
1964 | 2075 | chassis_private = mock.Mock()
|
1965 | 2076 | chassis_private.nb_cfg = nb_cfg
|
|
0 commit comments