From 3ce0546302001755828c8476425a60c6ab61ac92 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 21 Jun 2024 09:30:13 +0200 Subject: [PATCH] [EDF30399] : Steer directory hosting replay files --- idl/SALOME_Component.idl | 2 + idl/SALOME_ContainerManager.idl | 2 + src/Basics/KernelBasis.cxx | 12 + src/Basics/KernelBasis.hxx | 2 + src/Basics/KernelBasis.i | 12 + src/Container/Container_i.cxx | 5 + src/Container/SALOME_ContainerManager.cxx | 6 + src/Container/SALOME_ContainerManager.hxx | 2 + src/Container/SALOME_Container_i.hxx | 2 + src/Container/SALOME_PyNode.py | 13 +- src/Launcher/Test/testCrashProofContainer.py | 225 ++++++++++--------- 11 files changed, 170 insertions(+), 113 deletions(-) diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 8911badd9..e73f0b9bc 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -89,6 +89,8 @@ module Engines void set_big_obj_on_disk_threshold(in long thresholdInByte); void set_big_obj_on_disk_directory(in string directory); + + void set_directory_for_replay_files(in string directory); void set_number_of_retry(in long nbRetry); diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index 110c5b419..49ff21501 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -112,6 +112,8 @@ interface ContainerManager void SetBigObjOnDiskDirectory(in string directory); + void SetDirectoryForReplayFiles(in string directory); + void SetNumberOfRetry(in long nbRetry); long GetNumberOfRetry(); diff --git a/src/Basics/KernelBasis.cxx b/src/Basics/KernelBasis.cxx index d06fe8365..ed6837dc8 100644 --- a/src/Basics/KernelBasis.cxx +++ b/src/Basics/KernelBasis.cxx @@ -146,6 +146,8 @@ constexpr int SALOME_BIG_OBJ_ON_DISK_THRES_DFT = 50000000; static int SALOME_BIG_OBJ_ON_DISK_THRES = SALOME_BIG_OBJ_ON_DISK_THRES_DFT; +std::string SALOME_REPLAY_FILES_DIR; + int SALOME::GetBigObjOnDiskThreshold() { return SALOME_BIG_OBJ_ON_DISK_THRES; @@ -227,6 +229,16 @@ std::string SALOME::GetBigObjOnDiskDirectoryCoarse() return SALOME_FILE_BIG_OBJ_DIR; } +std::string SALOME::GetDirectoryForReplayFiles() +{ + return SALOME_REPLAY_FILES_DIR; +} + +void SALOME::SetDirectoryForReplayFiles(const std::string& directory) +{ + SALOME_REPLAY_FILES_DIR = directory; +} + void SALOME::SetBigObjOnDiskDirectory(const std::string& directory) { SALOME_FILE_BIG_OBJ_DIR = directory; diff --git a/src/Basics/KernelBasis.hxx b/src/Basics/KernelBasis.hxx index 360efc375..121bf978c 100644 --- a/src/Basics/KernelBasis.hxx +++ b/src/Basics/KernelBasis.hxx @@ -52,6 +52,8 @@ namespace SALOME std::vector BASICS_EXPORT GetAllPyExecutionModes(); std::string BASICS_EXPORT GetPyExecutionModeStr(); PyExecutionMode BASICS_EXPORT GetPyExecutionMode(); + std::string BASICS_EXPORT GetDirectoryForReplayFiles(); + void BASICS_EXPORT SetDirectoryForReplayFiles(const std::string& directory); int BASICS_EXPORT GetBigObjOnDiskThreshold(); void BASICS_EXPORT SetBigObjOnDiskThreshold(int newThresholdInByte); std::string BASICS_EXPORT BigObjOnDiskProtocolToStr(BigObjTransferProtocol protocol); diff --git a/src/Basics/KernelBasis.i b/src/Basics/KernelBasis.i index 3f2ed7dab..8b6ae421e 100644 --- a/src/Basics/KernelBasis.i +++ b/src/Basics/KernelBasis.i @@ -58,6 +58,8 @@ using namespace SALOME; %rename (BigObjOnDiskProtocolToStr) BigObjOnDiskProtocolToStrSwig; %rename (SetBigObjOnDiskDirectory) SetBigObjOnDiskDirectorySwig; %rename (BigObjOnDiskDirectoryDefined) BigObjOnDiskDirectoryDefinedSwig; +%rename (GetDirectoryForReplayFiles) GetDirectoryForReplayFilesSwig; +%rename (SetDirectoryForReplayFiles) SetDirectoryForReplayFilesSwig; %rename (SetNumberOfRetry) SetNumberOfRetrySwig; %rename (GetNumberOfRetry) GetNumberOfRetrySwig; @@ -151,6 +153,16 @@ int GetNumberOfRetrySwig() return SALOME::GetNumberOfRetry( ); } +std::string GetDirectoryForReplayFilesSwig() +{ + return SALOME::GetDirectoryForReplayFiles(); +} + +void SetDirectoryForReplayFilesSwig(const std::string& directory) +{ + SALOME::SetDirectoryForReplayFiles(directory); +} + std::string BigObjOnDiskProtocolToStrSwig( int protocol ) { return SALOME::BigObjOnDiskProtocolToStr( SALOME::FromIntToBigObjOnDiskProtocol( protocol ) ); diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 4841ee2a0..173633db4 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -1185,6 +1185,11 @@ void Abstract_Engines_Container_i::set_number_of_retry(CORBA::Long nbRetry) SALOME::SetNumberOfRetry( nbRetry ); } +void Abstract_Engines_Container_i::set_directory_for_replay_files(const char *directory) +{ + SALOME::SetDirectoryForReplayFiles( directory ); +} + void Abstract_Engines_Container_i::set_startup_code(const char *codeAtStartUp) { _code_at_startup = codeAtStartUp; diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 8a322b92d..688358c1e 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -246,6 +246,11 @@ void SALOME_ContainerManager::SetBigObjOnDiskDirectory(const char *directory) SALOME::SetBigObjOnDiskDirectory(directory); } +void SALOME_ContainerManager::SetDirectoryForReplayFiles(const char *directory) +{ + SALOME::SetDirectoryForReplayFiles( directory ); +} + void SALOME_ContainerManager::SetNumberOfRetry(CORBA::Long nbRetry) { SALOME::SetNumberOfRetry( nbRetry ); @@ -551,6 +556,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con INFOS("[GiveContainer] container " << containerNameInNS << " override " << envInfo.str()); cont->set_big_obj_on_disk_directory( SALOME::GetBigObjOnDiskDirectoryCoarse().c_str() ); cont->set_big_obj_on_disk_threshold( SALOME::GetBigObjOnDiskThreshold() ); + cont->set_directory_for_replay_files( SALOME::GetDirectoryForReplayFiles().c_str() ); cont->set_number_of_retry( SALOME::GetNumberOfRetry() ); Engines::FieldsDict envCorba; { diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index a02bd9258..1fa3fa3ce 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -83,6 +83,8 @@ public: void SetBigObjOnDiskDirectory(const char *directory) override; + void SetDirectoryForReplayFiles(const char *directory) override; + void SetNumberOfRetry(CORBA::Long nbRetry) override; CORBA::Long GetNumberOfRetry() override; diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index b6ace750d..4acef01d2 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -87,6 +87,8 @@ public: void set_big_obj_on_disk_directory(const char *directory) override; void set_number_of_retry(CORBA::Long nbRetry) override; + + void set_directory_for_replay_files(const char *directory) override; void set_startup_code(const char *codeAtStartUp) override; diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index 5e70f9999..d71e57c44 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -953,7 +953,10 @@ def ExecCrashProofGeneric( code, context, outargsname, containerRef, instanceOfL EXEC_CODE_FNAME_PXF = "execsafe_" def RetrieveUniquePartFromPfx( fname ): return os.path.splitext( os.path.basename(fname)[len(EXEC_CODE_FNAME_PXF):] )[0] - with tempfile.NamedTemporaryFile(dir=os.getcwd(),prefix=EXEC_CODE_FNAME_PXF,suffix=".py", mode="w", delete = False) as codeFd: + dirForReplayFiles = KernelBasis.GetDirectoryForReplayFiles() + if not dirForReplayFiles: + raise RuntimeError("You are in context of exec resistant you have to position Directory hosting these files properly") + with tempfile.NamedTemporaryFile(dir=dirForReplayFiles,prefix=EXEC_CODE_FNAME_PXF,suffix=".py", mode="w", delete = False) as codeFd: codeFd.write( "{}\n".format( containerRef.get_startup_code() ) ) codeFd.write( code ) if closeEyesOnErrorAtExit: @@ -963,17 +966,17 @@ sys.stderr.write({!r}) sys.stderr.flush()""".format( MY_KEY_TO_DETECT_FINISH ) ) codeFd.flush() codeFileName = os.path.basename( codeFd.name ) - contextFileName = "contextsafe_{}.pckl".format( RetrieveUniquePartFromPfx( codeFileName ) ) + contextFileName = os.path.join( dirForReplayFiles, "contextsafe_{}.pckl".format( RetrieveUniquePartFromPfx( codeFileName ) ) ) with open(contextFileName,"wb") as contextFd: pickle.dump( context, contextFd) - resFileName = "outcontextsafe_{}.pckl".format( RetrieveUniquePartFromPfx( codeFileName ) ) - mainExecFileName = os.path.abspath( "mainexecsafe_{}.py".format( RetrieveUniquePartFromPfx( codeFileName ) ) ) + resFileName = os.path.join( dirForReplayFiles, "outcontextsafe_{}.pckl".format( RetrieveUniquePartFromPfx( codeFileName ) ) ) + mainExecFileName = os.path.join( dirForReplayFiles, "mainexecsafe_{}.py".format( RetrieveUniquePartFromPfx( codeFileName ) ) ) with open(mainExecFileName,"w") as f: f.write( FinalCode.format( codeFileName, contextFileName, resFileName, outargsname, iorScriptLog ) ) for iTry in range( KernelBasis.GetNumberOfRetry() ): if iTry > 0: print( "WARNING : Retry # {}. Following code has generated non zero return code ( {} ). Trying again ... \n{}".format( iTry, returnCode, code ) ) - p = sp.Popen(["python3", mainExecFileName],stdout = sp.PIPE, stderr = sp.PIPE) + p = sp.Popen(["python3", mainExecFileName],cwd = dirForReplayFiles,stdout = sp.PIPE, stderr = sp.PIPE) stdout, stderr = p.communicate() returnCode = p.returncode if returnCode == 0: diff --git a/src/Launcher/Test/testCrashProofContainer.py b/src/Launcher/Test/testCrashProofContainer.py index e494959d4..00bc32b76 100644 --- a/src/Launcher/Test/testCrashProofContainer.py +++ b/src/Launcher/Test/testCrashProofContainer.py @@ -27,6 +27,7 @@ import SALOME_PyNode import KernelBasis import SALOME +import tempfile import glob import pickle import tempfile @@ -72,129 +73,137 @@ class testPerfLogManager1(unittest.TestCase): """ EDF29852 : Kill container with OutOfProcessNoReplay mode and see if container still responds. """ - salome.salome_init() - assert(isinstance(KernelBasis.GetAllPyExecutionModes(),tuple)) - KernelBasis.SetPyExecutionMode("OutOfProcessNoReplay") # the aim of test is here - hostname = "localhost" - cp = pylauncher.GetRequestForGiveContainer(hostname,"container_crash_test") - salome.cm.SetBigObjOnDiskThreshold(1000) - salome.cm.SetOverrideEnvForContainersSimple(env = []) - cont = salome.cm.GiveContainer(cp) - poa = salome.orb.resolve_initial_references("RootPOA") - obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) - pyscript2 = cont.createPyScriptNode("testScript2",killMeCode) - pyscript2.executeFirst(refPtr) - self.assertRaises(SALOME.SALOME_Exception,pyscript2.executeSecond,["j"]) # an agressive SIGKILL has been received and container is still alive :) - it throws an exception :) - pyscript2.UnRegister() - pyscript3 = cont.createPyScriptNode("testScript3",normalCode) - obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) - pyscript3.executeFirst(refPtr) - ret = pyscript3.executeSecond(["j"]) - ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) - self.assertEqual(ret,24) # container has received a SIGKILL but it kindly continue to respond :) - a = salome.logm.NaiveFetch() - self.assertEqual(a[0][2][0].get().freestyle,[('a',777)]) - cont.Shutdown() + with tempfile.TemporaryDirectory() as tmpdirname: + salome.salome_init() + assert(isinstance(KernelBasis.GetAllPyExecutionModes(),tuple)) + KernelBasis.SetPyExecutionMode("OutOfProcessNoReplay") # the aim of test is here + hostname = "localhost" + cp = pylauncher.GetRequestForGiveContainer(hostname,"container_crash_test") + salome.cm.SetBigObjOnDiskThreshold(1000) + salome.cm.SetOverrideEnvForContainersSimple(env = []) + salome.cm.SetDirectoryForReplayFiles( str( tmpdirname ) ) + cont = salome.cm.GiveContainer(cp) + poa = salome.orb.resolve_initial_references("RootPOA") + obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) + pyscript2 = cont.createPyScriptNode("testScript2",killMeCode) + pyscript2.executeFirst(refPtr) + self.assertRaises(SALOME.SALOME_Exception,pyscript2.executeSecond,["j"]) # an agressive SIGKILL has been received and container is still alive :) - it throws an exception :) + pyscript2.UnRegister() + pyscript3 = cont.createPyScriptNode("testScript3",normalCode) + obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) + pyscript3.executeFirst(refPtr) + ret = pyscript3.executeSecond(["j"]) + ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) + self.assertEqual(ret,24) # container has received a SIGKILL but it kindly continue to respond :) + a = salome.logm.NaiveFetch() + self.assertEqual(a[0][2][0].get().freestyle,[('a',777)]) + cont.Shutdown() def test1(self): """ EDF29852 : Same than test0 Kill container with OutOfProcessWithReplay mode and see if container still responds. But in addition we test if the python script is runnable ! """ - salome.salome_init() - assert(isinstance(KernelBasis.GetAllPyExecutionModes(),tuple)) - KernelBasis.SetPyExecutionMode("OutOfProcessWithReplay") # the aim of test is here - hostname = "localhost" - cp = pylauncher.GetRequestForGiveContainer(hostname,"container_crash_test") - salome.cm.SetBigObjOnDiskThreshold(1000) - salome.cm.SetOverrideEnvForContainersSimple(env = []) - cont = salome.cm.GiveContainer(cp) - poa = salome.orb.resolve_initial_references("RootPOA") - obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) - pyscript2 = cont.createPyScriptNode("testScript2",killMeCode) - pyscript2.executeFirst(refPtr) - self.assertRaises(SALOME.SALOME_Exception,pyscript2.executeSecond,["j"]) # an agressive SIGKILL has been received and container is still alive :) - it throws an exception :) - pyscript2.UnRegister() - pyscript3 = cont.createPyScriptNode("testScript3",normalCode) - obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) - pyscript3.executeFirst(refPtr) - ret = pyscript3.executeSecond(["j"]) - ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) - self.assertEqual(ret,24) # container has received a SIGKILL but it kindly continue to respond :) - a = salome.logm.NaiveFetch() - self.assertEqual(a[0][2][0].get().freestyle,[('a',777)]) - grpsOfLogToKill = cont.getAllLogFileNameGroups() - self.assertEqual(1,len(grpsOfLogToKill)) - replayInput = grpsOfLogToKill[0] - # now try to replay the failing case - p = sp.Popen(["python3",os.path.basename(replayInput[0])],cwd = os.path.dirname(replayInput[0]),stdout=sp.PIPE,stderr=sp.PIPE) - out,err = p.communicate() - self.assertNotEqual(p.returncode,0) # very important ! The failing case must continue to fail :) - self.assertEqual("21".encode(),out) # very important to check that the reported case is standalone enough to be replayable poste mortem - # cleanup - dn = os.path.dirname(replayInput[0]) - for elt in replayInput: - zeFile = os.path.join( dn, os.path.basename(elt) ) - if os.path.exists( zeFile ): - os.unlink( zeFile ) - cont.Shutdown() + with tempfile.TemporaryDirectory() as tmpdirname: + salome.salome_init() + assert(isinstance(KernelBasis.GetAllPyExecutionModes(),tuple)) + KernelBasis.SetPyExecutionMode("OutOfProcessWithReplay") # the aim of test is here + hostname = "localhost" + cp = pylauncher.GetRequestForGiveContainer(hostname,"container_crash_test") + salome.cm.SetBigObjOnDiskThreshold(1000) + salome.cm.SetOverrideEnvForContainersSimple(env = []) + salome.cm.SetDirectoryForReplayFiles(str( tmpdirname )) + cont = salome.cm.GiveContainer(cp) + poa = salome.orb.resolve_initial_references("RootPOA") + obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) + pyscript2 = cont.createPyScriptNode("testScript2",killMeCode) + pyscript2.executeFirst(refPtr) + self.assertRaises(SALOME.SALOME_Exception,pyscript2.executeSecond,["j"]) # an agressive SIGKILL has been received and container is still alive :) - it throws an exception :) + pyscript2.UnRegister() + pyscript3 = cont.createPyScriptNode("testScript3",normalCode) + obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) + pyscript3.executeFirst(refPtr) + ret = pyscript3.executeSecond(["j"]) + ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) + self.assertEqual(ret,24) # container has received a SIGKILL but it kindly continue to respond :) + a = salome.logm.NaiveFetch() + self.assertEqual(a[0][2][0].get().freestyle,[('a',777)]) + grpsOfLogToKill = cont.getAllLogFileNameGroups() + self.assertEqual(1,len(grpsOfLogToKill)) + replayInput = grpsOfLogToKill[0] + # now try to replay the failing case + p = sp.Popen(["python3",os.path.basename(replayInput[0])],cwd = os.path.dirname(replayInput[0]),stdout=sp.PIPE,stderr=sp.PIPE) + out,err = p.communicate() + self.assertNotEqual(p.returncode,0) # very important ! The failing case must continue to fail :) + self.assertEqual("21".encode(),out) # very important to check that the reported case is standalone enough to be replayable poste mortem + # cleanup + dn = os.path.dirname(replayInput[0]) + for elt in replayInput: + zeFile = os.path.join( dn, os.path.basename(elt) ) + if os.path.exists( zeFile ): + os.unlink( zeFile ) + cont.Shutdown() def test2(self): """ Aim of test is to check that CPU/mem retrieved in log is OK even in OutOfProcessNoReplay mode. """ - salome.salome_init() - salome.logm.clear() - assert(isinstance(KernelBasis.GetAllPyExecutionModes(),tuple)) - KernelBasis.SetPyExecutionMode("OutOfProcessNoReplay") # the aim of test is here - hostname = "localhost" - PROXY_THRES = -1 - # - salome.cm.SetBigObjOnDiskThreshold(PROXY_THRES) - salome.cm.SetOverrideEnvForContainersSimple(env = []) - salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 250 ) - cp = pylauncher.GetRequestForGiveContainer(hostname,"container_cpu_mem_out_process_test") - cont = salome.cm.GiveContainer(cp) - poa = salome.orb.resolve_initial_references("RootPOA") - obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) - pyscript2 = cont.createPyScriptNode("testScript3",heatCPUCode) - pyscript2.executeFirst(refPtr) - ret = pyscript2.executeSecond(["j"]) - ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) - self.assertEqual(ret,24) - pyscript2.UnRegister() - a = salome.logm.NaiveFetch() - cpu_mem_to_test = a[0][1][0].get()._cpu_mem_during_exec.data # normally even in OutOfProcessNoReplay mode the CPU must report somehing greater than 100 - self.assertGreater(len(cpu_mem_to_test),10) # 5 second of run 250 ms of interval between measures -> 20. In case of problem in HeatMarcel -> 10 - logging.debug("CPU mem measured (even in OutOfProcessNoReplay) : {}".format(cpu_mem_to_test)) - greater_than_100 = [a for a,b in cpu_mem_to_test if a > 100] - self.assertGreater(len(greater_than_100),1) # At minimum one measure must report CPU load > 100% - cont.Shutdown() + with tempfile.TemporaryDirectory() as tmpdirname: + salome.salome_init() + salome.logm.clear() + assert(isinstance(KernelBasis.GetAllPyExecutionModes(),tuple)) + KernelBasis.SetPyExecutionMode("OutOfProcessNoReplay") # the aim of test is here + hostname = "localhost" + PROXY_THRES = -1 + # + salome.cm.SetBigObjOnDiskThreshold(PROXY_THRES) + salome.cm.SetOverrideEnvForContainersSimple(env = []) + salome.cm.SetDirectoryForReplayFiles(str( tmpdirname )) + salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 250 ) + cp = pylauncher.GetRequestForGiveContainer(hostname,"container_cpu_mem_out_process_test") + cont = salome.cm.GiveContainer(cp) + poa = salome.orb.resolve_initial_references("RootPOA") + obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) + pyscript2 = cont.createPyScriptNode("testScript3",heatCPUCode) + pyscript2.executeFirst(refPtr) + ret = pyscript2.executeSecond(["j"]) + ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) + self.assertEqual(ret,24) + pyscript2.UnRegister() + a = salome.logm.NaiveFetch() + cpu_mem_to_test = a[0][1][0].get()._cpu_mem_during_exec.data # normally even in OutOfProcessNoReplay mode the CPU must report somehing greater than 100 + self.assertGreater(len(cpu_mem_to_test),10) # 5 second of run 250 ms of interval between measures -> 20. In case of problem in HeatMarcel -> 10 + logging.debug("CPU mem measured (even in OutOfProcessNoReplay) : {}".format(cpu_mem_to_test)) + greater_than_100 = [a for a,b in cpu_mem_to_test if a > 100] + self.assertGreater(len(greater_than_100),1) # At minimum one measure must report CPU load > 100% + cont.Shutdown() def test3(self): """ [EDF29150] : test that we can resist to a crash at exit """ - salome.salome_init() - KernelBasis.SetPyExecutionMode("OutOfProcessWithReplayFT") - hostname = "localhost" - cp = pylauncher.GetRequestForGiveContainer(hostname,"container_crash_test") - salome.cm.SetNumberOfRetry( 3 ) - salome.cm.SetCodeOnContainerStartUp("""a = 2""") - salome.cm.SetBigObjOnDiskThreshold(1000) - salome.cm.SetOverrideEnvForContainersSimple(env = []) - cont = salome.cm.GiveContainer(cp) - poa = salome.orb.resolve_initial_references("RootPOA") - obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) - pyscript = cont.createPyScriptNode("testScript4",killMeAtTheEnd) - pyscript.executeFirst(refPtr) - ret = pyscript.executeSecond(["j"]) - ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) - self.assertEqual(ret,54) - with open(cont.locallogfilename) as f: - logCont = f.read( ) - self.assertTrue( "WARNING : Retry #" in logCont) - self.assertTrue( "WARNING : Following code has generated non zero return code" in logCont )# should report something into the container - cont.Shutdown() + with tempfile.TemporaryDirectory() as tmpdirname: + salome.salome_init() + KernelBasis.SetPyExecutionMode("OutOfProcessWithReplayFT") + hostname = "localhost" + cp = pylauncher.GetRequestForGiveContainer(hostname,"container_crash_test") + salome.cm.SetNumberOfRetry( 3 ) + salome.cm.SetCodeOnContainerStartUp("""a = 2""") + salome.cm.SetBigObjOnDiskThreshold(1000) + salome.cm.SetOverrideEnvForContainersSimple(env = []) + salome.cm.SetDirectoryForReplayFiles(str( tmpdirname )) + cont = salome.cm.GiveContainer(cp) + poa = salome.orb.resolve_initial_references("RootPOA") + obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o) + pyscript = cont.createPyScriptNode("testScript4",killMeAtTheEnd) + pyscript.executeFirst(refPtr) + ret = pyscript.executeSecond(["j"]) + ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) + self.assertEqual(ret,54) + with open(cont.locallogfilename) as f: + logCont = f.read( ) + self.assertTrue( "WARNING : Retry #" in logCont) + self.assertTrue( "WARNING : Following code has generated non zero return code" in logCont )# should report something into the container + cont.Shutdown() if __name__ == '__main__': from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose -- 2.39.2