Commit d26e263b authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component:

- Fix Topological Sort of sub_devices
parent 9a605506
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -302,18 +302,18 @@ def populate_endpoints(
    for dev_uuid, sub_device in new_sub_devices.items():
        ctrl_uuid = get_device_controller_uuid(sub_device)
        LOGGER.info('dev_uuid={:s}, ctrl_uuid={:s}'.format(str(dev_uuid), str(ctrl_uuid)))

        if dev_uuid == device_uuid: continue # current device has no dependencies
        if ctrl_uuid is None: continue # sub_device has no controller
        if ctrl_uuid == device_uuid: continue # current device has no dependencies
        predecesors = graph.setdefault(dev_uuid, set())
        LOGGER.info('dev_uuid={:s} predecesors={:s}'.format(str(dev_uuid), str(predecesors)))
        predecesors.add(ctrl_uuid)

        LOGGER.info('graph={:s}'.format(str(graph)))

    LOGGER.info('final graph={:s}'.format(str(graph)))

    try:
        ts = TopologicalSorter(graph)
        sorted_sub_device_uuids.extend(list(ts.static_order()))
        sorted_sub_device_uuids.remove(device_uuid)
    except CycleError:
        MSG = 'Topological sort failed due to cycle among sub-devices({:s}), graph({:s})'
        msg = MSG.format(str(new_sub_devices), str(graph))