1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2023 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
28 class TestProxy(unittest.TestCase):
31 [EDF27816] : This test checks two things :
32 - Capability of ContainerManager to launch a Container with overriden environement
33 - Management of proxy creation to manage big obj exchange between process (here between Container and the current process)
35 hostname = "localhost"
36 rp=Engines.ResourceParameters(name=hostname,
38 can_launch_batch_jobs=False,
39 can_run_containers=True,
50 cp=Engines.ContainerParameters(container_name="container_test",
52 workingdir=os.getcwd(),
58 with tempfile.TemporaryDirectory() as tmpdirname:
60 val_for_big_obj = str( tmpdirname )
61 val_for_thres = "100" # force proxy file
62 # Override environement for all containers launched
63 salome.cm.SetOverrideEnvForContainersSimple(env = [("jj",val_for_jj),("SALOME_FILE_BIG_OBJ_DIR",val_for_big_obj),("SALOME_BIG_OBJ_ON_DISK_THRES",val_for_thres)])
64 cont = salome.cm.GiveContainer(cp)
66 script_st = """import os
67 a = os.environ["SALOME_FILE_BIG_OBJ_DIR"]
69 c = os.environ["SALOME_BIG_OBJ_ON_DISK_THRES"]
71 pyscript = cont.createPyScriptNode("testScript",script_st)
72 a,b,c = pickle.loads(pyscript.execute(["j"],pickle.dumps(([],{}))))[0]
73 self.assertTrue( a == val_for_big_obj )
74 self.assertTrue( b == val_for_jj )
75 self.assertTrue( c == val_for_thres )
76 # check environment using POSIX API in the container process
77 for k,v in [("SALOME_FILE_BIG_OBJ_DIR",val_for_big_obj),("SALOME_BIG_OBJ_ON_DISK_THRES",val_for_thres),("jj",val_for_jj)]:
78 assert( {elt.key:elt.value.value() for elt in cont.get_os_environment()}[k] == v )
81 poa = salome.orb.resolve_initial_references("RootPOA")
82 obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( ([],{}) ))
83 id_o = poa.activate_object(obj)
84 refPtr = poa.id_to_reference(id_o)
85 script_st2 = """ob = list( range(100) )""" # size of pickled ob must be greater than val_for_thres
86 pyscript2 = cont.createPyScriptNode("testScript2",script_st2)
87 pyscript2.executeFirst(refPtr)
88 ret2 = pyscript2.executeSecond(["ob"])
89 self.assertTrue( len(ret2) == 1)
91 ret3 = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret2).data() )
92 self.assertTrue( isinstance( ret3, SALOME_PyNode.BigObjectOnDiskList ) )
93 self.assertTrue( val_for_big_obj == os.path.dirname( ret3.getFileName() ) )# very important part of test
94 self.assertTrue( ret3.get() == list(range(100)) )
95 fn = ret3.getFileName()
96 self.assertTrue( os.path.exists( fn ) )
97 ret3.unlinkOnDestructor()
101 self.assertTrue( not os.path.exists( fn ) ) # at destruction of ret3 the corresponding pckl file must be destructed
104 if __name__ == '__main__':