guard RefreshPeer():sync() not to insert the same record twice.
[plcapi.git] / PLC / Methods / RefreshPeer.py
index 49ef25f..3d48cf2 100644 (file)
@@ -124,6 +124,10 @@ class RefreshPeer(Method):
             for peer_object_id, peer_object in peer_objects.iteritems():
                 message_verbose ('DBG %s peer_object_id=%d (%d/%d)'%(classname,peer_object_id,count,total))
                 count += 1
+                if peer_object_id in synced:
+                    message("Warning: %s Skipping already added %s: %r"%(
+                            peer['peername'], classname, peer_object))
+                    continue
                 if classname == 'Node':
                     message_verbose ('DBG>> hostname=%s'%peer_object['hostname'])
                 elif classname == "Slice":
@@ -471,7 +475,7 @@ class RefreshPeer(Method):
 
             # Nodes that are currently part of the slice
            old_slice_node_ids = [ node_transcoder[node_id] for node_id in slice['node_ids'] \
-                                  if node_transcoder[node_id] in peer_nodes]
+                                  if node_id in node_transcoder and node_transcoder[node_id] in peer_nodes]
 
             # Nodes that should be part of the slice
            slice_node_ids = [ node_id for node_id in peer_slice['node_ids'] if node_id in peer_nodes]