Ticket 87: "[NEPI] Experiment started on..."
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Wed, 17 Aug 2011 15:31:36 +0000 (17:31 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Wed, 17 Aug 2011 15:31:36 +0000 (17:31 +0200)
src/nepi/core/execute.py
src/nepi/util/proxy.py
test/core/integration.py

index b7d369d..a729ba6 100644 (file)
@@ -12,6 +12,7 @@ import ConfigParser
 import os
 import collections
 import functools
+import time
 
 ATTRIBUTE_PATTERN_BASE = re.compile(r"\{#\[(?P<label>[-a-zA-Z0-9._]*)\](?P<expr>(?P<component>\.addr\[[0-9]+\]|\.route\[[0-9]+\]|\.trace\[[0-9]+\])?.\[(?P<attribute>[-a-zA-Z0-9._]*)\])#}")
 ATTRIBUTE_PATTERN_GUID_SUB = r"{#[%(guid)s]%(expr)s#}"
@@ -236,6 +237,8 @@ class ExperimentController(object):
         self._netreffed_testbeds = set()
         self._guids_in_testbed_cache = dict()
         self._failed_testbeds = set()
+        self._started_time = None
+        self._stopped_time = None
         
         if experiment_xml is None and root_dir is not None:
             # Recover
@@ -252,6 +255,14 @@ class ExperimentController(object):
     def experiment_execute_xml(self):
         return self._experiment_execute_xml
 
+    @property
+    def started_time(self):
+        return self._started_time
+
+    @property
+    def stopped_time(self):
+        return self._stopped_time
+
     @property
     def guids(self):
         guids = list()
@@ -322,6 +333,7 @@ class ExperimentController(object):
             raise eTyp, eVal, eLoc
 
     def start(self):
+        self._started_time = time.time() 
         self._start()
 
     def _start(self, recover = False):
@@ -570,6 +582,7 @@ class ExperimentController(object):
        for testbed in self._testbeds.values():
            testbed.stop()
        self._unpersist_testbed_proxies()
+       self._stopped_time = time.time() 
    
     def recover(self):
         # reload perviously persisted testbed access configurations
index 4fe9061..6b6bf3f 100644 (file)
@@ -62,6 +62,8 @@ GET_TESTBED_VERSION = 40
 TRACES_INFO = 41
 EXEC_XML = 42
 TESTBED_STATUS  = 43
+STARTED_TIME  = 44
+STOPPED_TIME  = 45
 
 instruction_text = dict({
     OK:     "OK",
@@ -105,6 +107,9 @@ instruction_text = dict({
     TESTBED_ID: "TESTBED_ID",
     TESTBED_VERSION: "TESTBED_VERSION",
     TRACES_INFO: "TRACES_INFO",
+    STARTED_TIME: "STARTED_TIME",
+    STOPPED_TIME: "STOPPED_TIME",
+
     })
 
 def log_msg(server, params):
@@ -278,7 +283,7 @@ class Marshalling:
         @staticmethod
         def nullint(sdata):
             return None if sdata == "None" else int(sdata)
-        
+
         @staticmethod
         def bool(sdata):
             return sdata == 'True'
@@ -718,6 +723,18 @@ class ExperimentControllerServer(BaseServer):
     def guids(self):
         return self._experiment.guids
 
+    @Marshalling.handles(STARTED_TIME)
+    @Marshalling.args()
+    @Marshalling.retval( Marshalling.pickled_data )
+    def started_time(self):
+        return self._experiment.started_time
+
+    @Marshalling.handles(STOPPED_TIME)
+    @Marshalling.args()
+    @Marshalling.retval( Marshalling.pickled_data )
+    def stopped_time(self):
+        return self._experiment.stopped_time
+
     @Marshalling.handles(XML)
     @Marshalling.args()
     @Marshalling.retval()
index 1c1e11a..3f22eb4 100755 (executable)
@@ -90,6 +90,8 @@ class ExecuteTestCase(unittest.TestCase):
         controller = proxy.create_experiment_controller(xml, access_config)
 
         controller.start()
+        started_time = controller.started_time
+        self.assertTrue(started_time < time.time())
         while not controller.is_finished(app.guid):
             time.sleep(0.5)
         fake_result = controller.trace(app.guid, "fake")
@@ -105,6 +107,8 @@ class ExecuteTestCase(unittest.TestCase):
         self.assertEquals(controller.get_factory_id(node1.guid), "Node")
 
         controller.stop()
+        stopped_time = controller.stopped_time
+        self.assertTrue(stopped_time < time.time())
         controller.shutdown()
 
     def test_daemonized_controller_integration(self):
@@ -116,6 +120,8 @@ class ExecuteTestCase(unittest.TestCase):
         controller = proxy.create_experiment_controller(xml, access_config)
 
         controller.start()
+        started_time = controller.started_time
+        self.assertTrue(started_time < time.time())
         while not controller.is_finished(app.guid):
             time.sleep(0.5)
         fake_result = controller.trace(app.guid, "fake")
@@ -131,6 +137,8 @@ class ExecuteTestCase(unittest.TestCase):
         self.assertEquals(controller.get_factory_id(node1.guid), "Node")
 
         controller.stop()
+        stopped_time = controller.stopped_time
+        self.assertTrue(stopped_time < time.time())
         controller.shutdown()
 
     def test_daemonized_testbed_integration(self):