Salome HOME
Merge class BatchManager_eClient into class BatchManager
[tools/libbatch.git] / src / Local / Test / Test_Local_SSH.cxx
index b82740ea94968afca4295eab69ed1d56f66ded45..673a8946f0811b85c1287ffd60513b47b37ac356 100644 (file)
@@ -65,14 +65,12 @@ int main(int argc, char** argv)
     Job job;
     // ... and its parameters ...
     Parametre p;
-    p[EXECUTABLE]    = "source copied-test-script.sh";
+    p[EXECUTABLE]    = "test-script.sh";
     p[NAME]          = "Test_Local_SSH";
     p[WORKDIR]       = workdir;
-    p[INFILE]        = Couple("seta.sh", "copied-seta.sh");
-    p[INFILE]       += Couple("setb.sh", "copied-setb.sh");
-    p[INFILE]       += Couple("test-script.sh", "copied-test-script.sh");
-    p[OUTFILE]       = Couple("result.txt", "orig-result.txt");
-    p[EXECUTIONHOST] = exechost;
+    p[INFILE]        = Couple("seta.sh", workdir + "/copied-seta.sh");
+    p[INFILE]       += Couple("setb.sh", workdir + "/copied-setb.sh");
+    p[OUTFILE]       = Couple("result.txt", workdir + "/orig-result.txt");
     p[USER]          = user;
     job.setParametre(p);
     // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication)
@@ -86,12 +84,12 @@ int main(int argc, char** argv)
     BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
 
     // Create a BatchManager of type Local_SSH on localhost
-    FactBatchManager * fbm = c("SSH");
+    FactBatchManager * fbm = c("LOCAL");
     if (fbm == NULL) {
       cerr << "Can't get SSH batch manager factory" << endl;
       return 1;
     }
-    BatchManager * bm = (*fbm)("localhost");
+    BatchManager * bm = (*fbm)(exechost.c_str(), user.c_str(), SSH);
 
     // Submit the job to the BatchManager
     JobId jobid = bm->submitJob(job);
@@ -100,13 +98,18 @@ int main(int argc, char** argv)
     // Wait for the end of the job
     string state = bm->waitForJobEnd(jobid, timeout);
 
-    if (state != FINISHED && state != FAILED) {
-      cerr << "Error: Job not finished after timeout" << endl;
+    if (state == FINISHED) {
+      cout << "Job " << jobid.__repr__() << " is done" << endl;
+      bm->importOutputFiles(job, "resultdir/seconddirname");
+    } else if (state == FAILED) {
+      cerr << "Job " << jobid.__repr__() << " finished in error" << endl;
+      bm->importOutputFiles(job, "resultdir/seconddirname");
+      return 1;
+    } else {
+      cerr << "Timeout while executing job" << endl;
       return 1;
     }
 
-    cout << "Job " << jobid.__repr__() << " is done" << endl;
-
   } catch (GenericException e) {
     cerr << "Error: " << e << endl;
     return 1;
@@ -118,7 +121,7 @@ int main(int argc, char** argv)
   // test the result file
   string exp = "c = 12";
   string res;
-  ifstream f("result.txt");
+  ifstream f("resultdir/seconddirname/result.txt");
   getline(f, res);
   f.close();