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
|
command = self.replace_paths(command)
if sources:
- sources = ' '.join(sources)
+ sources = ';'.join(sources)
self.node.upload(sources, src_dir, overwrite = False)
return command
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):
@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):
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:
"""
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)
""" 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 = []
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>
from test_utils import skipIfNotAlive, skipInteractive
import os
+import shutil
import time
import tempfile
import unittest
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)
""" 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()
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)