From: Sapan Bhatia <sapanb@cs.princeton.edu>
Date: Tue, 27 Jan 2015 03:54:29 +0000 (+0000)
Subject: Bugfix
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0e0fefeef274419765d740edacef7737adf75c77;p=plstackapi.git

Bugfix
---

diff --git a/planetstack/openstack_observer/toposort.py b/planetstack/openstack_observer/toposort.py
index a2c9389..c717718 100644
--- a/planetstack/openstack_observer/toposort.py
+++ b/planetstack/openstack_observer/toposort.py
@@ -41,23 +41,24 @@ def toposort(g, steps=None):
 
 		while (stack):
 			n = stack[0]
+			print stack
+			print "Trying %s"%n
 			add = True
 			try:
 				for m in g[n]:
 					if (m in unmarked):
-						if (m not in stack):
-							add = False
-							stack.insert(0,m)
-						else:
-							# Should not happen, if so there's a loop
-							print 'Loop at %s'%m
+					    add = False
+					    stack.insert(0,m)
 			except KeyError:
 				pass
 			if (add):
-				if (n in steps):
+				if (n in steps and n not in order):
 					order.append(n)
 				item = stack.pop(0)
-				unmarked.remove(item)
+				try:
+					unmarked.remove(item)
+				except ValueError:
+					pass
 
 	noorder = list(set(steps) - set(order))
 	return order + noorder