Salome HOME
Test for python node with cache.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 2 Jun 2020 16:27:10 +0000 (18:27 +0200)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 2 Jun 2020 16:27:10 +0000 (18:27 +0200)
src/engine/Executor.cxx
src/engine/Executor.hxx
src/yacsloader_swig/Test/CMakeLists.txt
src/yacsloader_swig/Test/CTestTestfileInstall.cmake
src/yacsloader_swig/Test/runUnitTest.sh
src/yacsloader_swig/Test/testWorkloadManager.py [new file with mode: 0755]

index 8af044080cf03e8ceeea95530cb5177606155fcb..c46ebf2e8a9affb3644b60b6b3ac9db462059783 100644 (file)
@@ -1691,6 +1691,7 @@ public:
   NewTask(Executor& executor, YACS::ENGINE::Task* yacsTask);
   const WorkloadManager::ContainerType& type()const override;
   void run(const WorkloadManager::RunInfo& runInfo)override;
+  bool isAccepted(const WorkloadManager::Resource& r)override;
 private:
   WorkloadManager::ContainerType _type;
   Executor& _executor;
@@ -1736,9 +1737,19 @@ void NewTask::run(const WorkloadManager::RunInfo& runInfo)
   delete this; // provisoire
 }
 
-void Executor::newRun(Scheduler *graph,int debug, bool fromScratch)
+bool NewTask::isAccepted(const WorkloadManager::Resource& r)
 {
-  DEBTRACE("Executor::newRun debug: "<< graph->getName() <<" "<< debug<<" fromScratch: "<<fromScratch);
+  Container * yacsContainer = _yacsTask->getContainer();
+  std::string hostname = yacsContainer->getProperty("hostname");
+  bool accept = true;
+  if(!hostname.empty())
+    accept = (hostname == r.name);
+  return accept;
+}
+
+void Executor::runWlm(Scheduler *graph,int debug, bool fromScratch)
+{
+  DEBTRACE("Executor::runWlm debug: "<< graph->getName() <<" "<< debug<<" fromScratch: "<<fromScratch);
   { // --- Critical section
     YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&_mutexForSchedulerUpdate);
     _mainSched = graph;
@@ -1889,7 +1900,7 @@ void Executor::RunW(Scheduler *graph,int debug, bool fromScratch)
      || str_value == "WORKLOADMANAGER"
      || str_value == "workloadmanager"
      || str_value == "WorkLoadManager")
-    newRun(graph, debug, fromScratch);
+    runWlm(graph, debug, fromScratch);
   else
     RunB(graph, debug, fromScratch);
 }
index c83b4159f36cd3efd1a7cd7011d471cbc752bbf1..dfa37fa038569855275a99cb938b1599eab6a477 100644 (file)
@@ -101,7 +101,7 @@ namespace YACS
       void RunA(Scheduler *graph,int debug=0, bool fromScratch=true);
       void RunW(Scheduler *graph,int debug=0, bool fromScratch=true);
       void RunB(Scheduler *graph,int debug=0, bool fromScratch=true);
-      void newRun(Scheduler *graph,int debug=0, bool fromScratch=true);
+      void runWlm(Scheduler *graph,int debug=0, bool fromScratch=true);
       void setKeepGoingProperty(bool newVal) { _keepGoingOnFail=newVal; }
       bool getKeepGoingProperty() const { return _keepGoingOnFail; }
       void setDPLScopeSensitive(bool newVal) { _DPLScopeSensitive=newVal; }
index d8cb4ff360ee2a103db5d00cd54917631c2f724e..e33ec979cea18e79d14235dbd8a3bed898aa60bf 100644 (file)
@@ -46,6 +46,7 @@ IF(NOT WIN32)
     testProgress.py
     testExecForEachGeoMesh.py
     async_plugin.py
+    testWorkloadManager.py
    )
   INSTALL(PROGRAMS ${LOCAL_TEST_FILES}
         DESTINATION ${LOCAL_TEST_DIR})
index ff5955c46ec0930d869924025fdef21d79276c4d..c8117f7634ce7d998aab4ce968849a7b1b56704d 100644 (file)
@@ -30,4 +30,10 @@ IF(NOT WIN32)
                                     LABELS "${COMPONENT_NAME}"
                                    )
 
+  SET(TEST_NAME ${COMPONENT_NAME}_WorkloadManager_swig)
+  ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} testWorkloadManager.py)
+  SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES
+                                    LABELS "${COMPONENT_NAME}"
+                                   )
+
 ENDIF()
index 51a9d35c6c02f111661352b3e2459d0e52dd5d54..5c3c745c0d26fd73cf321ef14b91a61f7223a98e 100755 (executable)
@@ -27,10 +27,14 @@ sleep 3
 
 export TESTCOMPONENT_ROOT_DIR=`pwd`/../runtime
 
-python3 -m unittest discover
+#python3 -m unittest discover
+MODULES_TO_TEST=testEdit testExec testFEDyn testFEDyn2 testLoader testProgress \
+testRefcount testResume testSave testSaveLoadRun  testValidationChecks
+
+python3 -m unittest $MODULES_TO_TEST
 ret=$?
 echo "exec status salome_test_driver " $ret
 
 kill -9 $pidecho
 
-exit $ret
\ No newline at end of file
+exit $ret
diff --git a/src/yacsloader_swig/Test/testWorkloadManager.py b/src/yacsloader_swig/Test/testWorkloadManager.py
new file mode 100755 (executable)
index 0000000..ae91978
--- /dev/null
@@ -0,0 +1,86 @@
+#!/usr/bin/env python3
+# Copyright (C) 2006-2020  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import sys
+import pilot
+import SALOMERuntime
+import loader
+import unittest
+import tempfile
+import os
+
+class TestEdit(unittest.TestCase):
+
+    def setUp(self):
+        SALOMERuntime.RuntimeSALOME_setRuntime()
+        self.r = pilot.getRuntime()
+        self.l = loader.YACSLoader()
+        self.e = pilot.ExecutorSwig()
+        pass
+
+    def test1(self):
+      """ Test the conservation of the python context between two nodes sharing
+          the same container.
+          Schema: n1 -> n2
+      """
+      runtime=self.r
+      executor=self.e
+      proc=runtime.createProc("MySchema")
+      ti=proc.createType("int","int")
+      cont=proc.createContainer("MyContainer","Salome")
+      # type "multi" : the workload manager chooses the resource
+      # type "mono" : the workload manager does not choose the resource
+      cont.setProperty("type","multi")
+      # number of cores used by the container
+      cont.setProperty("nb_parallel_procs", "1")
+      n1=runtime.createScriptNode("","n1")
+      n2=runtime.createScriptNode("","n2")
+      n1.setExecutionMode("remote")
+      n2.setExecutionMode("remote")
+      n1.setContainer(cont)
+      n2.setContainer(cont)
+      n1.setScript("v=42")
+      res_port=n2.edAddOutputPort("v", ti)
+      proc.edAddChild(n1)
+      proc.edAddChild(n2)
+      proc.edAddCFLink(n1,n2)
+      # set the default execution mode using the workload manager
+      proc.setProperty("executor", "workloadmanager")
+      # reuse the same python context for every execution
+      cont.setStoreContext(True)
+      #proc.saveSchema("mini_wlm.xml")
+      executor=pilot.ExecutorSwig()
+      # default run method of the executor which uses the property "executor"
+      # in order to choose the actual run method
+      executor.RunW(proc,0)
+      # you can also impose the executor, ignoring the property "executor"
+      #executor.RunB(proc,0) # use the "historical" executor
+      #executor.runWlm(proc,0) # use the workload manager based executor
+      
+      self.assertEqual(res_port.getPyObj(), 42)
+
+if __name__ == '__main__':
+  dir_test = tempfile.mkdtemp(suffix=".yacstest")
+  file_test = os.join(dir_test,"UnitTestsResult")
+  with open(file_test, 'a') as f:
+      f.write("  --- TEST src/yacsloader: testWorkloadManager.py\n")
+      suite = unittest.makeSuite(TestEdit)
+      result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
+  sys.exit(not result.wasSuccessful())