Browse Source

Merge "OVN Metadata: Fix registration after Chassis entry is recreated" into stable/rocky

changes/03/675603/1
Zuul 1 month ago
parent
commit
5b05739fcc

+ 6
- 2
networking_ovn/agent/metadata/agent.py View File

@@ -125,6 +125,10 @@ class ChassisCreateEvent(row_event.RowEvent):
125 125
         if self.first_time:
126 126
             self.first_time = False
127 127
         else:
128
+            # NOTE(lucasagomes): Re-register the ovn metadata agent
129
+            # with the local chassis in case its entry was re-created
130
+            # (happens when restarting the ovn-controller)
131
+            self.agent.register_metadata_agent()
128 132
             LOG.info("Connection to OVSDB established, doing a full sync")
129 133
             self.agent.sync()
130 134
 
@@ -186,11 +190,11 @@ class MetadataAgent(object):
186 190
         self.sync()
187 191
 
188 192
         # Register the agent with its corresponding Chassis
189
-        self._register_metadata_agent()
193
+        self.register_metadata_agent()
190 194
 
191 195
         proxy.wait()
192 196
 
193
-    def _register_metadata_agent(self):
197
+    def register_metadata_agent(self):
194 198
         # NOTE(lucasagomes): db_add() will not overwrite the UUID if
195 199
         # it's already set.
196 200
         ext_ids = {

+ 7
- 2
networking_ovn/tests/functional/base.py View File

@@ -287,13 +287,15 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
287 287
         self._start_ovsdb_server_and_idls()
288 288
         self._start_ovn_northd()
289 289
 
290
-    def add_fake_chassis(self, host, physical_nets=None, external_ids=None):
290
+    def add_fake_chassis(self, host, physical_nets=None, external_ids=None,
291
+                         name=None):
291 292
         physical_nets = physical_nets or []
292 293
         external_ids = external_ids or {}
293 294
 
294 295
         bridge_mapping = ",".join(["%s:br-provider%s" % (phys_net, i)
295 296
                                   for i, phys_net in enumerate(physical_nets)])
296
-        name = uuidutils.generate_uuid()
297
+        if name is None:
298
+            name = uuidutils.generate_uuid()
297 299
         external_ids['ovn-bridge-mappings'] = bridge_mapping
298 300
         # We'll be using different IP addresses every time for the Encap of
299 301
         # the fake chassis as the SB schema doesn't allow to have two entries
@@ -307,3 +309,6 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
307 309
             name, ['geneve'], '172.24.4.%d' % self._counter,
308 310
             external_ids=external_ids, hostname=host).execute(check_error=True)
309 311
         return name
312
+
313
+    def del_fake_chassis(self, name):
314
+        self.sb_api.chassis_del(name).execute(check_error=True)

+ 31
- 1
networking_ovn/tests/functional/test_metadata_agent.py View File

@@ -20,6 +20,7 @@ from neutron.common import utils as n_utils
20 20
 from oslo_config import fixture as fixture_config
21 21
 from oslo_utils import uuidutils
22 22
 from ovsdbapp.backend.ovs_idl import event
23
+from ovsdbapp.backend.ovs_idl import idlutils
23 24
 from ovsdbapp import event as ovsdb_event
24 25
 
25 26
 from networking_ovn.agent.metadata import agent
@@ -69,6 +70,7 @@ class WaitForPortBindingEvent(event.WaitEvent):
69 70
 
70 71
 class TestMetadataAgent(base.TestOVNFunctionalBase):
71 72
     OVN_BRIDGE = 'br-int'
73
+    FAKE_CHASSIS_HOST = 'ovn-host-fake'
72 74
 
73 75
     def setUp(self):
74 76
         super(TestMetadataAgent, self).setUp()
@@ -98,7 +100,7 @@ class TestMetadataAgent(base.TestOVNFunctionalBase):
98 100
         p.start()
99 101
         self.addCleanup(p.stop)
100 102
 
101
-        self.chassis_name = self.add_fake_chassis('ovs-host-fake')
103
+        self.chassis_name = self.add_fake_chassis(self.FAKE_CHASSIS_HOST)
102 104
         with mock.patch.object(agent.MetadataAgent,
103 105
                                '_get_own_chassis_name') as mock_get_ch_name:
104 106
             mock_get_ch_name.return_value = self.chassis_name
@@ -198,3 +200,31 @@ class TestMetadataAgent(base.TestOVNFunctionalBase):
198 200
             lambda: BR_NEW == self.agent.ovn_bridge,
199 201
             timeout=10,
200 202
             exception=exc)
203
+
204
+    def test_agent_registration_at_chassis_create_event(self):
205
+        chassis = self.sb_api.lookup('Chassis', self.chassis_name)
206
+        self.assertIn(ovn_const.OVN_AGENT_METADATA_ID_KEY,
207
+                      chassis.external_ids)
208
+
209
+        # Delete Chassis and assert
210
+        self.del_fake_chassis(chassis.name)
211
+        self.assertRaises(idlutils.RowNotFound, self.sb_api.lookup,
212
+                          'Chassis', self.chassis_name)
213
+
214
+        # Re-add the Chassis
215
+        self.add_fake_chassis(self.FAKE_CHASSIS_HOST, name=self.chassis_name)
216
+
217
+        def check_for_metadata():
218
+            chassis = self.sb_api.lookup('Chassis', self.chassis_name)
219
+            return ovn_const.OVN_AGENT_METADATA_ID_KEY in chassis.external_ids
220
+
221
+        exc = Exception('Agent metadata failed to re-register itself '
222
+                        'after the Chassis %s was re-created' %
223
+                        self.chassis_name)
224
+
225
+        # Check if metadata agent was re-registered
226
+        chassis = self.sb_api.lookup('Chassis', self.chassis_name)
227
+        n_utils.wait_until_true(
228
+            check_for_metadata,
229
+            timeout=10,
230
+            exception=exc)

Loading…
Cancel
Save