Fix #120 Put nepi-exp and nepi-usr inside .nepi folder
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 18 Feb 2014 18:45:00 +0000 (19:45 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 18 Feb 2014 18:45:00 +0000 (19:45 +0100)
src/nepi/resources/linux/application.py
src/nepi/resources/linux/node.py
src/nepi/util/sshfuncs.py
test/resources/linux/application.py
test/resources/linux/node.py

index d391086..302e9fd 100644 (file)
@@ -63,14 +63,14 @@ class LinuxApplication(ResourceManager):
         The directory structure used by LinuxApplication RM at the Linux
         host is the following:
 
-        ${HOME}/nepi-usr --> Base directory for multi-experiment files
+        ${HOME}/.nepi/nepi-usr --> Base directory for multi-experiment files
                       |
         ${LIB}        |- /lib --> Base directory for libraries
         ${BIN}        |- /bin --> Base directory for binary files
         ${SRC}        |- /src --> Base directory for sources
         ${SHARE}      |- /share --> Base directory for other files
 
-        ${HOME}/nepi-exp --> Base directory for single-experiment files
+        ${HOME}/.nepi/nepi-exp --> Base directory for single-experiment files
                       |
         ${EXP_HOME}   |- /<exp-id>  --> Base directory for experiment exp-id
                           |
@@ -412,7 +412,7 @@ class LinuxApplication(ResourceManager):
             command = self.replace_paths(command)
        
             if sources:
-                sources = ' '.join(sources)
+                sources = ';'.join(sources)
                 self.node.upload(sources, src_dir, overwrite = False)
 
         return command
index 214c4ef..f9c016a 100644 (file)
@@ -233,9 +233,13 @@ class LinuxNode(ResourceManager):
            home = os.path.join(self._home_dir, home) 
         return home
 
+    @property
+    def nepi_home(self):
+        return os.path.join(self.home_dir, ".nepi")
+
     @property
     def usr_dir(self):
-        return os.path.join(self.home_dir, "nepi-usr")
+        return os.path.join(self.nepi_home, "nepi-usr")
 
     @property
     def lib_dir(self):
@@ -255,7 +259,7 @@ class LinuxNode(ResourceManager):
 
     @property
     def exp_dir(self):
-        return os.path.join(self.home_dir, "nepi-exp")
+        return os.path.join(self.nepi_home, "nepi-exp")
 
     @property
     def exp_home(self):
@@ -406,7 +410,6 @@ class LinuxNode(ResourceManager):
         
         if self.get("username") != 'root':
             cmd = ("sudo -S killall tcpdump || /bin/true ; " +
-                "sudo -S kill $(ps aux | grep '[n]epi' | awk '{print $2}') || /bin/true ; " +
                 "sudo -S killall -u %s || /bin/true ; " % self.get("username"))
         else:
             if self.state >= ResourceState.READY:
@@ -435,7 +438,7 @@ class LinuxNode(ResourceManager):
         """
         self.info("Cleaning up home")
         
-        cmd = "cd %s ; find . -maxdepth 1 \( -name 'nepi-usr' -o -name 'nepi-exp' \) -execdir rm -rf {} + " % (
+        cmd = "cd %s ; find . -maxdepth 1 -name \.nepi -execdir rm -rf {} + " % (
                 self.home_dir )
 
         return self.execute(cmd, with_lock = True)
@@ -1058,8 +1061,7 @@ class LinuxNode(ResourceManager):
         """ Removes files that already exist in the Linux host from src list
         """
         # construct a dictionary with { dst: src }
-        dests = dict(map(
-            lambda s: (os.path.join(dst, os.path.basename(s)), s ), s)) \
+        dests = dict(map(lambda s: (os.path.join(dst, os.path.basename(s)), s), src)) \
                     if len(src) > 1 else dict({dst: src[0]})
 
         command = []
index d1952bc..ac43099 100644 (file)
@@ -316,8 +316,7 @@ def rcopy(source, dest,
     
     Source can be a list of files to copy to a single destination, 
     (in which case it is advised that the destination be a folder),
-    a single file in a string or a semi-colon separated list of files
-    in a string.
+    or a single file in a string.
     """
 
     # Parse destination as <user>@<server>:<path>
index ad76973..a1f1397 100755 (executable)
@@ -25,6 +25,7 @@ from nepi.execution.trace import TraceAttr
 from test_utils import skipIfNotAlive, skipInteractive
 
 import os
+import shutil
 import time
 import tempfile
 import unittest
@@ -295,6 +296,44 @@ main (void)
 
         ec.shutdown()
 
+    @skipIfNotAlive
+    def t_copy_files(self, host, user):
+        # create some temp files and directories to copy
+        dirpath = tempfile.mkdtemp()
+        f = tempfile.NamedTemporaryFile(dir=dirpath, delete=False)
+        f.close()
+      
+        f1 = tempfile.NamedTemporaryFile(delete=False)
+        f1.close()
+        f1.name
+
+        ec = ExperimentController(exp_id="test-copyfile")
+        
+        node = ec.register_resource("LinuxNode")
+        ec.set(node, "hostname", host)
+        ec.set(node, "username", user)
+        ec.set(node, "cleanHome", True)
+        ec.set(node, "cleanProcesses", True)
+
+        app = ec.register_resource("LinuxApplication")
+        ec.set(app, "command", "ls ${SRC}")
+        ec.set(app, "sources", "%s;%s" % (dirpath, f1.name))
+        ec.register_connection(app, node)
+
+        ec.deploy()
+
+        ec.wait_finished([app])
+
+        stdout = ec.trace(app, "stdout")
+        
+        self.assertTrue(stdout.find(os.path.basename(dirpath)) > -1)
+        self.assertTrue(stdout.find(os.path.basename(f1.name)) > -1)
+
+        ec.shutdown()
+        
+        os.remove(f1.name)
+        shutil.rmtree(dirpath)
+
     def test_stdout_fedora(self):
         self.t_stdout(self.fedora_host, self.fedora_user)
 
@@ -336,6 +375,11 @@ main (void)
         """ Interactive test. Should not run automatically """
         self.t_xterm(self.ubuntu_host, self.ubuntu_user)
 
+    def test_copy_files_fedora(self):
+        self.t_copy_files(self.fedora_host, self.fedora_user)
+
+    def test_copy_files_ubuntu(self):
+        self.t_copy_files(self.ubuntu_host, self.ubuntu_user)
 
 if __name__ == '__main__':
     unittest.main()
index 6922211..e46f667 100755 (executable)
@@ -303,7 +303,7 @@ main (void)
         f1.close()
         f1.name
 
-        source = "%s;%s" % (dirpath, f1.name)
+        source = [dirpath, f1.name]
         destdir = "test"
         node.mkdir(destdir, clean = True)
         dest = "%s@%s:test" % (user, host)