2 from neco.resources.linux.node import LinuxNode
3 from neco.util.sshfuncs import RUNNING, FINISHED
10 def skipIfNotAlive(func):
12 def wrapped(*args, **kwargs):
15 if not node.is_alive():
16 print "*** WARNING: Skipping test %s: Node %s is not alive\n" % (
17 name, node.get("hostname"))
20 return func(*args, **kwargs)
24 def skipInteractive(func):
26 def wrapped(*args, **kwargs):
27 mode = os.environ.get("NEPI_INTERACTIVE", False) in ['True', 'true', 'yes', 'YES']
29 print "*** WARNING: Skipping test %s: Interactive mode off \n" % name
32 return func(*args, **kwargs)
36 class DummyEC(object):
39 class LinuxNodeTestCase(unittest.TestCase):
41 host = 'nepi2.pl.sophia.inria.fr'
43 self.node_fedora = self.create_node(host, user)
45 host = 'roseval.pl.sophia.inria.fr'
47 self.node_ubuntu = self.create_node(host, user)
49 self.target = 'nepi5.pl.sophia.inria.fr'
50 self.home = '/tmp/nepi-home/test-app'
52 def create_node(self, host, user):
55 node = LinuxNode(ec, 1)
56 node.set("hostname", host)
57 node.set("username", user)
62 def t_xterm(self, node):
63 node.install_packages('xterm')
65 (out, err), proc = node.execute('xterm', forward_x11 = True)
67 self.assertEquals(out, "")
69 (out, err), proc = node.remove_packages('xterm')
71 self.assertEquals(out, "")
74 def t_execute(self, node):
75 command = "ping -qc3 %s" % self.target
77 (out, err), proc = node.execute(command)
79 expected = """3 packets transmitted, 3 received, 0% packet loss"""
81 self.assertTrue(out.find(expected) > 0)
84 def t_run(self, node):
85 node.mkdir(self.home, clean = True)
87 command = "ping %s" % self.target
88 dst = os.path.join(self.home, "app.sh")
89 node.upload(command, dst)
92 node.run(cmd, self.home)
93 pid, ppid = node.checkpid(self.home)
95 status = node.status(pid, ppid)
96 self.assertTrue(status, RUNNING)
99 status = node.status(pid, ppid)
100 self.assertTrue(status, FINISHED)
102 (out, err), proc = node.check_run_output(self.home)
104 expected = """64 bytes from"""
106 self.assertTrue(out.find(expected) > 0)
108 node.rmdir(self.home)
111 def t_install(self, node):
112 node.mkdir(self.home, clean = True)
114 prog = """#include <stdio.h>
119 printf ("Hello, world!\\n");
123 # upload the test program
124 dst = os.path.join(self.home, "hello.c")
125 node.upload(prog, dst)
128 node.install_packages('gcc')
130 # compile the program using gcc
131 command = "cd %s; gcc -Wall hello.c -o hello" % self.home
132 (out, err), proc = node.execute(command)
134 # execute the program and get the output from stdout
135 command = "%s/hello" % self.home
136 (out, err), proc = node.execute(command)
138 self.assertEquals(out, "Hello, world!\n")
140 # execute the program and get the output from a file
141 command = "%(home)s/hello > %(home)s/hello.out" % {'home':self.home}
142 (out, err), proc = node.execute(command)
144 # retrieve the output file
145 src = os.path.join(self.home, "hello.out")
146 f = tempfile.NamedTemporaryFile(delete=False)
148 node.download(src, dst)
151 node.remove_packages('gcc')
152 node.rmdir(self.home)
158 self.assertEquals(out, "Hello, world!\n")
160 def test_execute_fedora(self):
161 self.t_execute(self.node_fedora)
163 def test_execute_ubuntu(self):
164 self.t_execute(self.node_ubuntu)
166 def test_run_fedora(self):
167 self.t_run(self.node_fedora)
169 def test_run_ubuntu(self):
170 self.t_run(self.node_ubuntu)
172 def test_intall_fedora(self):
173 self.t_install(self.node_fedora)
175 def test_install_ubuntu(self):
176 self.t_install(self.node_ubuntu)
179 def test_xterm_ubuntu(self):
180 """ Interactive test. Should not run automatically """
181 self.t_xterm(self.node_ubuntu)
184 if __name__ == '__main__':