Fixing tickets http://newyans.pl.sophia.inria.fr/trac/ticket/37 and http://newyans...
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 5 Nov 2013 18:20:52 +0000 (19:20 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 5 Nov 2013 18:20:52 +0000 (19:20 +0100)
examples/linux/ccn/ccncat_extended_ring_topo.py
src/nepi/execution/ec.py
src/nepi/execution/resource.py
src/nepi/resources/linux/application.py
test/execution/resource.py

index 06f5ac6..a67075b 100755 (executable)
@@ -212,7 +212,7 @@ if __name__ == '__main__':
             app, ResourceState.STARTED, time = "10s")
     ec.register_condition(l5d, ResourceAction.STOP, 
             app, ResourceState.STARTED, time = "10s")
+
     # Register a collector to automatically collect traces
     collector = add_collector(ec, "stderr", results_dir)
     for ccnd in ccnds.values():
index 7fe523d..fe110e7 100644 (file)
@@ -325,8 +325,9 @@ class ExperimentController(object):
 
             if rstate >= state:
                 guids.remove(guid)
-                self.logger.debug(" guid %d DONE - state is %s, required is >= %s " % (
-                    guid, hrrstate, hrstate))
+                rm = self.get_resource(guid)
+                self.logger.debug(" %s guid %d DONE - state is %s, required is >= %s " % (
+                    rm.rtype(), guid, hrrstate, hrstate))
             else:
                 # Debug...
                 self.logger.debug(" WAITING FOR guid %d - state is %s, required is >= %s " % (
index 397dab4..c782416 100644 (file)
@@ -962,6 +962,11 @@ class ResourceManager(Logger):
         pass
 
     def do_finish(self):
+        # In case the RM passed from STARTED directly to FINISHED,
+        # we set the stop_time for consistency
+        if self.stop_time == None:
+            self.set_stopped()
+
         self.set_finished()
 
     def do_fail(self):
index 22ca769..c1de543 100644 (file)
@@ -633,10 +633,10 @@ class LinuxApplication(ResourceManager):
                     msg = " Failed to execute command '%s'" % self.get("command")
                     err = self._proc.stderr.read()
                     self.error(msg, out, err)
-                    self.fail()
+                    self.do_fail()
 
                 elif retcode == 0:
-                    self.finish()
+                    self.do_finish()
             else:
                 # We need to query the status of the command we launched in 
                 # background. In order to avoid overwhelming the remote host and
@@ -658,9 +658,9 @@ class LinuxApplication(ResourceManager):
                                 msg = "Failed to execute command '%s'" % \
                                         self.get("command")
                                 self.error(msg, out, err)
-                                self.fail()
+                                self.do_fail()
                             else:
-                                self.finish()
+                                self.do_finish()
 
                     self._last_state_check = tnow()
 
index f820f68..d6398eb 100755 (executable)
@@ -349,13 +349,67 @@ class ResourceManagerTestCase(unittest.TestCase):
 
         self.assertEquals(ec._fm._failure_level, FailureLevel.OK)
 
-    def ztest_start_with_condition(self):
-        # TODO!!!
-        pass
-    
-    def ztest_stop_with_condition(self):
-        # TODO!!!
-        pass
+    def test_start_with_condition(self):
+        from nepi.execution.resource import ResourceFactory
+        
+        ResourceFactory.register_type(Application)
+        ResourceFactory.register_type(Node)
+        ResourceFactory.register_type(Interface)
+
+        ec = ExperimentController()
+
+        node = ec.register_resource("Node")
+
+        app1 = ec.register_resource("Application")
+        ec.register_connection(app1, node)
+
+        app2 = ec.register_resource("Application")
+        ec.register_connection(app2, node)
+
+        ec.register_condition(app2, ResourceAction.START, app1, 
+                ResourceState.STARTED, time = "5s")
+
+        ec.deploy()
+
+        ec.wait_finished([app1, app2])
+        
+        rmapp1 = ec.get_resource(app1)
+        rmapp2 = ec.get_resource(app2)
+
+        self.assertTrue(rmapp2.start_time > rmapp1.start_time)
+        
+        ec.shutdown()
+
+    def test_stop_with_condition(self):
+        from nepi.execution.resource import ResourceFactory
+        
+        ResourceFactory.register_type(Application)
+        ResourceFactory.register_type(Node)
+        ResourceFactory.register_type(Interface)
+
+        ec = ExperimentController()
+
+        node = ec.register_resource("Node")
+
+        app1 = ec.register_resource("Application")
+        ec.register_connection(app1, node)
+
+        app2 = ec.register_resource("Application")
+        ec.register_connection(app2, node)
+
+        ec.register_condition(app2, ResourceAction.START, app1, 
+                ResourceState.STOPPED)
+
+        ec.deploy()
+
+        ec.wait_finished([app1, app2])
+        
+        rmapp1 = ec.get_resource(app1)
+        rmapp2 = ec.get_resource(app2)
+
+        self.assertTrue(rmapp2.start_time > rmapp1.stop_time)
+        
+        ec.shutdown()
 
     def ztest_set_with_condition(self):
         # TODO!!!