From: Alina Quereilhac Date: Tue, 18 Feb 2014 18:45:00 +0000 (+0100) Subject: Fix #120 Put nepi-exp and nepi-usr inside .nepi folder X-Git-Tag: nepi-3.1.0~117 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=5857fa2d26b3aa135391cf936ccde907b9ff8c68;p=nepi.git Fix #120 Put nepi-exp and nepi-usr inside .nepi folder --- diff --git a/src/nepi/resources/linux/application.py b/src/nepi/resources/linux/application.py index d391086c..302e9fd9 100644 --- a/src/nepi/resources/linux/application.py +++ b/src/nepi/resources/linux/application.py @@ -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} |- / --> 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 diff --git a/src/nepi/resources/linux/node.py b/src/nepi/resources/linux/node.py index 214c4ef0..f9c016a8 100644 --- a/src/nepi/resources/linux/node.py +++ b/src/nepi/resources/linux/node.py @@ -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 = [] diff --git a/src/nepi/util/sshfuncs.py b/src/nepi/util/sshfuncs.py index d1952bcf..ac43099b 100644 --- a/src/nepi/util/sshfuncs.py +++ b/src/nepi/util/sshfuncs.py @@ -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 @: diff --git a/test/resources/linux/application.py b/test/resources/linux/application.py index ad76973b..a1f1397b 100755 --- a/test/resources/linux/application.py +++ b/test/resources/linux/application.py @@ -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() diff --git a/test/resources/linux/node.py b/test/resources/linux/node.py index 69222112..e46f6673 100755 --- a/test/resources/linux/node.py +++ b/test/resources/linux/node.py @@ -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)