Browse Source

make restart robust

a controller, channel and bridge is made if it does not exist.
contoller name and chennel name is related to bridge name
for this purpose.
this patch includes a bug fix and some cleanups too.

Change-Id: I58c449953ae7fb696e93b87432c069998a72c7de
Itsuro Oda 1 year ago
parent
commit
2859b3f61a

+ 8
- 0
networking_lagopus/agent/lagopus_lib.py View File

@@ -47,6 +47,14 @@ class LagopusCommand(object):
47 47
         cmd = "bridge\n"
48 48
         return self._lagosh(cmd)
49 49
 
50
+    def show_channels(self):
51
+        cmd = "channel\n"
52
+        return self._lagosh(cmd)
53
+
54
+    def show_controllers(self):
55
+        cmd = "controller\n"
56
+        return self._lagosh(cmd)
57
+
50 58
     @log_helpers.log_method_call
51 59
     def create_channel(self, name):
52 60
         cmd = "channel %s create -dst-addr 127.0.0.1 -protocol tcp\n" % name

+ 42
- 20
networking_lagopus/ml2/agent/lagopus_agent.py View File

@@ -40,16 +40,13 @@ LOG = logging.getLogger(__name__)
40 40
 
41 41
 LAGOPUS_AGENT_BINARY = 'neutron-lagopus-agent'
42 42
 AGENT_TYPE_LAGOPUS = 'Lagopus agent'
43
-EXTENSION_DRIVER_TYPE = 'lagopus'
44
-LAGOPUS_FS = "/sys/class/net/"
45
-RESOURCE_ID_LENGTH = 11
46
-
43
+MAX_WAIT_LAGOPUS_RETRY = 5
47 44
 OFPP_MAX = 0xffffff00
48 45
 
49 46
 
50 47
 class LagopusBridge(object):
51 48
 
52
-    def __init__(self, ryu_app, name, dpid, port_data, wait_connection=True):
49
+    def __init__(self, ryu_app, name, dpid, port_data):
53 50
         LOG.debug("LagopusBridge: %s %s", name, dpid)
54 51
         self.ryu_app = ryu_app
55 52
         self.name = name
@@ -183,11 +180,7 @@ class LagopusManager(object):
183 180
         self.bridge_mappings = bridge_mappings
184 181
         self.ryu_app = ryu_app
185 182
 
186
-        raw_bridges = self.lagopus_client.show_bridges()
187
-        if not raw_bridges:
188
-            LOG.error("Lagopus isn't running")
189
-            sys.exit(1)
190
-        LOG.debug("bridges: %s", raw_bridges)
183
+        raw_bridges = self._get_init_bridges()
191 184
 
192 185
         self.bridges = {}
193 186
         name_to_dpid = {}
@@ -233,6 +226,17 @@ class LagopusManager(object):
233 226
         self.num_pipe = len(pipe_interfaces)
234 227
         # TODO(hichihara) pipe interface does not remove now.
235 228
 
229
+    def _get_init_bridges(self):
230
+        for retry in range(MAX_WAIT_LAGOPUS_RETRY):
231
+            raw_bridges = self.lagopus_client.show_bridges()
232
+            if raw_bridges:
233
+                LOG.debug("bridges: %s", raw_bridges)
234
+                return raw_bridges
235
+            LOG.debug("Lagopus may not be initialized. waiting")
236
+            eventlet.sleep(10)
237
+        LOG.error("Lagopus isn't running")
238
+        sys.exit(1)
239
+
236 240
     def get_vhost_interface(self):
237 241
         if self.num_vhost == len(self.used_vhost_id):
238 242
             # create new vhost interface
@@ -287,6 +291,24 @@ class LagopusManager(object):
287 291
         LOG.debug("get_all_devices: %s", devices)
288 292
         return devices
289 293
 
294
+    def _create_channel(self, channel):
295
+        data = self.lagopus_client.show_channels()
296
+        names = [d['name'] for d in data]
297
+        if channel not in names:
298
+            self.lagopus_client.create_channel(channel)
299
+
300
+    def _create_controller(self, controller, channel):
301
+        data = self.lagopus_client.show_controllers()
302
+        names = [d['name'] for d in data]
303
+        if controller not in names:
304
+            self.lagopus_client.create_controller(controller, channel)
305
+
306
+    def _create_bridge(self, brname, controller, dpid):
307
+        data = self.lagopus_client.show_bridges()
308
+        names = [d['name'] for d in data]
309
+        if brname not in names:
310
+            self.lagopus_client.create_bridge(brname, controller, dpid)
311
+
290 312
     def get_bridge(self, segment):
291 313
         vlan_id = (segment['segmentation_id']
292 314
                    if segment['network_type'] == p_constants.TYPE_VLAN
@@ -304,15 +326,14 @@ class LagopusManager(object):
304 326
 
305 327
         # bridge for vlan physical_network does not exist.
306 328
         # so create the bridge.
307
-        bridge_id = len(self.bridges) + 1
308
-        channel = "channel%d" % bridge_id
309
-        self.lagopus_client.create_channel(channel)
310
-        controller = "controller%d" % bridge_id
311
-        self.lagopus_client.create_controller(controller, channel)
312
-        name = "%s_%d" % (phys_net, vlan_id)
313
-        self.lagopus_client.create_bridge(name, controller, dpid)
314
-
315
-        bridge = LagopusBridge(self.ryu_app, name, dpid, None, False)
329
+        brname = "%s_%d" % (phys_net, vlan_id)
330
+        channel = "ch-%s" % brname
331
+        self._create_channel(channel)
332
+        controller = "con-%s" % brname
333
+        self._create_controller(controller, channel)
334
+        self._create_bridge(brname, controller, dpid)
335
+
336
+        bridge = LagopusBridge(self.ryu_app, brname, dpid, None)
316 337
         self.bridges[dpid] = bridge
317 338
 
318 339
         pipe1, pipe2 = self.get_pipe()
@@ -436,7 +457,8 @@ class LagopusAgent(service.Service):
436 457
     def _report_state(self):
437 458
         try:
438 459
             devices = len(self.manager.get_all_devices())
439
-            self.agent_state.get('configurations')['devices'] = devices
460
+            self.agent_state['configurations']['devices'] = devices
461
+            self.state_rpc.report_state(self.context, self.agent_state, True)
440 462
             # we only want to update resource versions on startup
441 463
             self.agent_state.pop('resource_versions', None)
442 464
             self.agent_state.pop('start_flag', None)

Loading…
Cancel
Save