Added unit tests for linux application
[nepi.git] / test / execution / resource.py
index d90b137..128c6df 100755 (executable)
@@ -43,14 +43,6 @@ class ResourceFactoryTestCase(unittest.TestCase):
 
         self.assertEquals(len(ResourceFactory.resource_types()), 2)
 
-def get_connected(connections, rtype, ec):
-    connected = []
-    for guid in connections:
-        rm = ec.get_resource(guid)
-        if rm.rtype() == rtype:
-            connected.append(rm)
-    return connected
-
 class Channel(ResourceManager):
     _rtype = "Channel"
 
@@ -69,8 +61,8 @@ class Interface(ResourceManager):
         super(Interface, self).__init__(ec, guid)
 
     def deploy(self):
-        node = get_connected(self.connections, Node.rtype(), self.ec)[0]
-        chan = get_connected(self.connections, Channel.rtype(), self.ec)[0]
+        node = self.get_connected(Node.rtype())[0]
+        chan = self.get_connected(Channel.rtype())[0]
 
         if node.state < ResourceState.PROVISIONED:
             self.ec.schedule("0.5s", self.deploy)
@@ -94,7 +86,7 @@ class Node(ResourceManager):
             self.logger.debug(" -------- PROVISIONED ------- ")
             self.ec.schedule("3s", self.deploy)
         elif self.state == ResourceState.PROVISIONED:
-            ifaces = get_connected(self.connections, Interface.rtype(), self.ec)
+            ifaces = self.get_connected(Interface.rtype())
             for rm in ifaces:
                 if rm.state < ResourceState.READY:
                     self.ec.schedule("0.5s", self.deploy)
@@ -110,7 +102,7 @@ class Application(ResourceManager):
         super(Application, self).__init__(ec, guid)
 
     def deploy(self):
-        node = get_connected(self.connections, Node.rtype(), self.ec)[0]
+        node = self.get_connected(Node.rtype())[0]
         if node.state < ResourceState.READY:
             self.ec.schedule("0.5s", self.deploy)
         else:
@@ -155,15 +147,14 @@ class ResourceManagerTestCase(unittest.TestCase):
         ec.register_connection(iface1, chan)
         ec.register_connection(iface2, chan)
 
-        try:
-            ec.deploy()
+        ec.deploy()
 
-            while not all([ ec.state(guid) == ResourceState.STARTED \
-                    for guid in [app1, app2, node1, node2, iface1, iface2, chan]]):
-                time.sleep(0.5)
+        while not all([ ec.state(guid) == ResourceState.STARTED \
+                for guid in [app1, app2, node1, node2, iface1, iface2, chan]]) \
+                and not ec.finished:
+            time.sleep(0.5)
 
-        finally:
-            ec.shutdown()
+        ec.shutdown()
 
         rmapp1 = ec.get_resource(app1)
         rmapp2 = ec.get_resource(app2)