execute tests running ok
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 7 Mar 2011 10:12:58 +0000 (11:12 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 7 Mar 2011 10:12:58 +0000 (11:12 +0100)
src/nepi/core/execute_impl.py
src/nepi/testbeds/netns/metadata_v01.py
src/nepi/util/constants.py
test/testbeds/netns/execute.py

index 61e0175..f92bf5c 100644 (file)
@@ -5,7 +5,7 @@ from nepi.core import execute
 from nepi.core.attributes import Attribute
 from nepi.core.metadata import Metadata
 from nepi.util import validation
-from nepi.util.constants import AF_INET, AF_INET6
+from nepi.util.constants import AF_INET, AF_INET6, STATUS_UNDETERMINED
 
 TIME_NOW = "0s"
 
@@ -135,11 +135,14 @@ class TestbedInstance(execute.TestbedInstance):
 
     def do_create(self):
         guids = dict()
+        # order guids (elements) according to factory_id
         for guid, factory_id in self._create.iteritems():
             if not factory_id in guids:
                guids[factory_id] = list()
             guids[factory_id].append(guid)
+        # create elements following the factory_id order
         for factory_id in self._metadata.factories_order:
+            # omit the factories that have no element to create
             if factory_id not in guids:
                 continue
             factory = self._factories[factory_id]
@@ -218,11 +221,12 @@ class TestbedInstance(execute.TestbedInstance):
                 stop_function(self, guid, traces)
 
     def status(self, guid):
-          for guid, factory_id in self._create.iteritems():
+        for guid, factory_id in self._create.iteritems():
             factory = self._factories[factory_id]
             status_function = factory.status_function
             if status_function:
-                result = status_function(self, guid)
+                return status_function(self, guid)
+        return STATUS_UNDETERMINED
 
     def trace(self, guid, trace_id):
         raise NotImplementedError
index e5c27e9..b5a8369 100644 (file)
@@ -5,7 +5,8 @@ from constants import TESTBED_ID
 from nepi.core import metadata
 from nepi.core.attributes import Attribute
 from nepi.util import validation
-from nepi.util.constants import AF_INET
+from nepi.util.constants import AF_INET, STATUS_NOT_STARTED, STATUS_RUNNING, \
+        STATUS_FINISHED
 
 NODE = "Node"
 P2PIFACE = "P2PNodeInterface"
@@ -45,6 +46,9 @@ def create_node(testbed_instance, guid, parameters):
     testbed_instance.elements[guid] = element
 
 def create_p2piface(testbed_instance, guid, parameters):
+    if guid in testbed_instance.elements:
+        # The interface pair was already instantiated
+        return
     # search for the node asociated with the p2piface
     node1_guid = testbed_instance.get_connected(guid, "node", "devs")
     if len(node1_guid) == 0:
@@ -120,9 +124,11 @@ def start_application(testbed_instance, guid, parameters, traces):
 
 def status_application(testbed_instance, guid):
     if guid not in testbed_instance.elements.keys():
-        return None
-    app = testbed.elements[guid]
-    return app.poll()
+        return STATUS_NOT_STARTED
+    app = testbed_instance.elements[guid]
+    if app.poll() == None:
+        return STATUS_RUNNING
+    return STATUS_FINISHED
 
 ### Factory information ###
 
index da609f2..56cba7a 100644 (file)
@@ -4,3 +4,7 @@
 AF_INET = 0
 AF_INET6 = 1
 
+STATUS_NOT_STARTED = 0
+STATUS_RUNNING = 1
+STATUS_FINISHED = 2
+STATUS_UNDETERMINED = 3
index 208457a..9ce0b71 100755 (executable)
@@ -2,7 +2,7 @@
 # -*- coding: utf-8 -*-
 
 import getpass
-from nepi.core.design import AF_INET
+from nepi.util.constants import AF_INET, STATUS_FINISHED
 from nepi.testbeds import netns
 import os
 import shutil
@@ -48,7 +48,8 @@ class NetnsExecuteTestCase(unittest.TestCase):
         instance.do_connect()
         instance.do_configure()
         instance.start()
-        time.sleep(2)
+        while instance.status(7) != STATUS_FINISHED:
+            time.sleep(0.5)
         ping_result = instance.trace(7, "stdout")
         comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
 
@@ -82,12 +83,12 @@ class NetnsExecuteTestCase(unittest.TestCase):
         instance.create_set(6, "user", user)
         instance.add_trace(6, "stdout")
         instance.connect(6, "node", 2, "apps")
-
         instance.do_create()
         instance.do_connect()
         instance.do_configure()
         instance.start()
-        time.sleep(2)
+        while instance.status(6) != STATUS_FINISHED:
+            time.sleep(0.5)
         ping_result = instance.trace(6, "stdout")
         comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
 
@@ -145,11 +146,12 @@ class NetnsExecuteTestCase(unittest.TestCase):
         instance.do_connect()
         instance.do_configure()
         instance.start()
-        time.sleep(2)
+        while instance.status(11) != STATUS_FINISHED:
+            time.sleep(0.5)
         ping_result = instance.trace(11, "stdout")
-        comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
+        comp_result = """PING 10.0.1.2 (10.0.1.2) 56(84) bytes of data.
 
---- 10.0.0.2 ping statistics ---
+--- 10.0.1.2 ping statistics ---
 1 packets transmitted, 1 received, 0% packet loss, time 0ms
 """
         self.assertTrue(ping_result.startswith(comp_result))