Salome HOME
[EDF28648] : non regression test of cm.SetCodeOnContainerStartUp
[modules/kernel.git] / src / Container / Test / testProxy.py
index 0dd0eeb38466fb0cae09f1339aeb2e711239afcd..ac0d47c8e2fd8146a8957b4266251e67f10d3373 100644 (file)
@@ -24,6 +24,7 @@ import salome
 import Engines
 import pickle
 import tempfile
+import pylauncher
 
 class TestProxy(unittest.TestCase):
     def testProxy(self):
@@ -33,27 +34,7 @@ class TestProxy(unittest.TestCase):
         - Management of proxy creation to manage big obj exchange between process (here between Container and the current process)
         """
         hostname = "localhost"
-        rp=Engines.ResourceParameters(name=hostname,
-                                        hostname=hostname,
-                                        can_launch_batch_jobs=False,
-                                        can_run_containers=True,
-                                        OS="Linux",
-                                        componentList=[],
-                                        nb_proc=1,
-                                        mem_mb=1000,
-                                        cpu_clock=1000,
-                                        nb_node=1,
-                                        nb_proc_per_node=1,
-                                        policy="first",
-                                        resList=[])
-
-        cp=Engines.ContainerParameters(container_name="container_test",
-                                        mode="start",
-                                        workingdir=os.getcwd(),
-                                        nb_proc=1,
-                                        isMPI=False,
-                                        parallelLib="",
-                                        resource_params=rp)
+        cp = pylauncher.GetRequestForGiveContainer(hostname,"container_test")
 
         with tempfile.TemporaryDirectory() as tmpdirname:
             val_for_jj = "3333"
@@ -101,6 +82,25 @@ j = a,b,c"""
             self.assertTrue( not os.path.exists( fn ) ) # at destruction of ret3 the corresponding pckl file must be destructed
             cont.Shutdown()
 
+    def testExecCodeAtInit(self):
+        """
+        [EDF28648] : allow initialisation script at startup
+        """
+        import os
+        with tempfile.NamedTemporaryFile() as tmpFileName:
+            tmpFileName.close()
+            salome.cm.SetCodeOnContainerStartUp("""
+with open("{}","w") as f:
+  f.write("coucou")
+""".format(tmpFileName.name) )# injection of python code expected to be executed at startup
+            cp = pylauncher.GetRequestForGiveContainer("localhost","gg")
+            cont = salome.cm.GiveContainer(cp) # code is expected to be executed in process abroad -> file is supposed to contain coucou
+            cont.Shutdown()
+            salome.cm.SetCodeOnContainerStartUp("") # no more startup code for other tests
+            with open(tmpFileName.name,"r") as f:
+                self.assertTrue(f.read()=="coucou")
+            os.unlink( tmpFileName.name ) # context manager do not clean file
+
 if __name__ == '__main__':
     salome.standalone()
     salome.salome_init()