From: Anthony Geay Date: Thu, 5 Oct 2023 09:18:14 +0000 (+0200) Subject: [EDF28648] : non regression test of cm.SetCodeOnContainerStartUp X-Git-Tag: V9_12_0a1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e478c70ecdc8ab8b9c005fbc055a54f298755963;p=modules%2Fkernel.git [EDF28648] : non regression test of cm.SetCodeOnContainerStartUp --- diff --git a/src/Container/Test/testProxy.py b/src/Container/Test/testProxy.py index 0dd0eeb38..ac0d47c8e 100644 --- a/src/Container/Test/testProxy.py +++ b/src/Container/Test/testProxy.py @@ -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()