X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=test%2Fresources%2Flinux%2Fnode.py;h=c9fb8aef8bb1ddc2589b576fea7965be584ef1a6;hb=1d2350d56f314a6e3de43517a66f7e2f48128d44;hp=259f57830eedb2fffb9cca9be718b80ef9755ec9;hpb=1df0acb80ba1c737280390c1277a4a751843eac4;p=nepi.git diff --git a/test/resources/linux/node.py b/test/resources/linux/node.py index 259f5783..c9fb8aef 100755 --- a/test/resources/linux/node.py +++ b/test/resources/linux/node.py @@ -4,9 +4,8 @@ # Copyright (C) 2013 INRIA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,6 +23,7 @@ from nepi.util.sshfuncs import ProcStatus from test_utils import skipIfNotAlive, skipInteractive, create_node +import shutil import os import time import tempfile @@ -35,7 +35,7 @@ class LinuxNodeTestCase(unittest.TestCase): self.fedora_user = "inria_nepi" self.ubuntu_host = "roseval.pl.sophia.inria.fr" - self.ubuntu_user = "alina" + self.ubuntu_user = "inria_nepi" self.target = "nepi5.pl.sophia.inria.fr" @@ -55,6 +55,7 @@ class LinuxNodeTestCase(unittest.TestCase): def t_run(self, host, user): node, ec = create_node(host, user) + node.find_home() app_home = os.path.join(node.exp_home, "my-app") node.mkdir(app_home, clean = True) @@ -83,6 +84,7 @@ class LinuxNodeTestCase(unittest.TestCase): node, ec = create_node(host, user) + node.find_home() app_home = os.path.join(node.exp_home, "my-app") node.mkdir(app_home, clean = True) @@ -96,19 +98,21 @@ class LinuxNodeTestCase(unittest.TestCase): # get the pid of the process ecode = node.exitcode(app_home) - self.assertEquals(ecode, ExitCode.OK) + self.assertEqual(ecode, ExitCode.OK) @skipIfNotAlive def t_exitcode_kill(self, host, user): node, ec = create_node(host, user) + node.find_home() app_home = os.path.join(node.exp_home, "my-app") node.mkdir(app_home, clean = True) # Upload command that will not finish command = "ping localhost" - (out, err), proc = node.upload_command(command, app_home, - shfile = "cmd.sh", + shfile = os.path.join(app_home, "cmd.sh") + (out, err), proc = node.upload_command(command, + shfile = shfile, ecodefile = "exitcode") (out, err), proc = node.run(command, app_home, @@ -121,17 +125,17 @@ class LinuxNodeTestCase(unittest.TestCase): # The process is still running, so no retfile has been created yet ecode = node.exitcode(app_home) - self.assertEquals(ecode, ExitCode.FILENOTFOUND) + self.assertEqual(ecode, ExitCode.FILENOTFOUND) (out, err), proc = node.check_errors(app_home) - self.assertEquals(err, "") + self.assertEqual(err, "") # Now kill the app pid, ppid = node.getpid(app_home) node.kill(pid, ppid) (out, err), proc = node.check_errors(app_home) - self.assertEquals(err, "") + self.assertEqual(err, "") @skipIfNotAlive def t_exitcode_error(self, host, user): @@ -140,6 +144,7 @@ class LinuxNodeTestCase(unittest.TestCase): node, ec = create_node(host, user) + node.find_home() app_home = os.path.join(node.exp_home, "my-app") node.mkdir(app_home, clean = True) @@ -153,48 +158,83 @@ class LinuxNodeTestCase(unittest.TestCase): # get the pid of the process ecode = node.exitcode(app_home) + # bash erro 127 - command not found - self.assertEquals(ecode, 127) + self.assertEqual(ecode, 127) (out, err), proc = node.check_errors(app_home) - self.assertNotEquals(out, "") + + self.assertTrue(err.find("cmd.sh: line 1: unexistent-command: command not found") > -1) @skipIfNotAlive def t_install(self, host, user): node, ec = create_node(host, user) + node.find_home() (out, err), proc = node.mkdir(node.node_home, clean = True) - self.assertEquals(out, "") + self.assertEqual(err, "") (out, err), proc = node.install_packages("gcc", node.node_home) - self.assertEquals(out, "") + self.assertEqual(err, "") (out, err), proc = node.remove_packages("gcc", node.node_home) - self.assertEquals(out, "") + self.assertEqual(err, "") (out, err), proc = node.rmdir(node.exp_home) - self.assertEquals(out, "") + self.assertEqual(err, "") + + @skipIfNotAlive + def t_clean(self, host, user): + node, ec = create_node(host, user) + + node.find_home() + node.mkdir(node.lib_dir) + node.mkdir(node.node_home) + + command1 = " [ -d %s ] && echo 'Found'" % node.lib_dir + (out, err), proc = node.execute(command1) + + self.assertEqual(out.strip(), "Found") + + command2 = " [ -d %s ] && echo 'Found'" % node.node_home + (out, err), proc = node.execute(command2) + + self.assertEqual(out.strip(), "Found") + + node.clean_experiment() + + (out, err), proc = node.execute(command2) + + self.assertEqual(out.strip(), "") + + node.clean_home() + + (out, err), proc = node.execute(command1) + + self.assertEqual(out.strip(), "") @skipIfNotAlive def t_xterm(self, host, user): node, ec = create_node(host, user) + node.find_home() (out, err), proc = node.mkdir(node.node_home, clean = True) - self.assertEquals(out, "") + self.assertEqual(err, "") node.install_packages("xterm", node.node_home) - self.assertEquals(out, "") + self.assertEqual(err, "") (out, err), proc = node.execute("xterm", forward_x11 = True) - self.assertEquals(out, "") + self.assertEqual(err, "") (out, err), proc = node.remove_packages("xterm", node.node_home) - self.assertEquals(out, "") + self.assertEqual(err, "") @skipIfNotAlive def t_compile(self, host, user): node, ec = create_node(host, user) + node.find_home() app_home = os.path.join(node.exp_home, "my-app") node.mkdir(app_home, clean = True) @@ -222,7 +262,7 @@ main (void) command = "%s/hello" % app_home (out, err), proc = node.execute(command) - self.assertEquals(out, "Hello, world!\n") + self.assertEqual(out, "Hello, world!\n") # execute the program and get the output from a file command = "%(home)s/hello > %(home)s/hello.out" % { @@ -239,11 +279,59 @@ main (void) node.remove_packages("gcc", app_home) node.rmdir(app_home) - f = open(dst, "r") - out = f.read() + with open(dst, "r") as f: + out = f.read() + + self.assertEqual(out, "Hello, world!\n") + + @skipIfNotAlive + def t_copy_files(self, host, user): + node, ec = create_node(host, user) + + node.find_home() + app_home = os.path.join(node.exp_home, "my-app") + node.mkdir(app_home, clean = True) + + # 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 + + source = [dirpath, f1.name] + destdir = "test" + node.mkdir(destdir, clean = True) + dest = "%s@%s:test" % (user, host) + node.copy(source, dest) + + command = "ls %s" % destdir - self.assertEquals(out, "Hello, world!\n") + (out, err), proc = node.execute(command) + + os.remove(f1.name) + shutil.rmtree(dirpath) + + self.assertTrue(out.find(os.path.basename(dirpath)) > -1) + self.assertTrue(out.find(os.path.basename(f1.name)) > -1) + + f2 = tempfile.NamedTemporaryFile(delete=False) + f2.close() + f2.name + + node.mkdir(destdir, clean = True) + dest = "%s@%s:test" % (user, host) + node.copy(f2.name, dest) + + command = "ls %s" % destdir + + (out, err), proc = node.execute(command) + + os.remove(f2.name) + + self.assertTrue(out.find(os.path.basename(f2.name)) > -1) def test_execute_fedora(self): self.t_execute(self.fedora_host, self.fedora_user) @@ -286,12 +374,23 @@ main (void) def test_exitcode_error_ubuntu(self): self.t_exitcode_error(self.ubuntu_host, self.ubuntu_user) - + + def test_clean_fedora(self): + self.t_clean(self.fedora_host, self.fedora_user) + + def test_clean_ubuntu(self): + self.t_clean(self.ubuntu_host, self.ubuntu_user) + @skipInteractive def test_xterm_ubuntu(self): """ 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()