2 from neco.resources.linux.node import LinuxNode
3 from neco.design.box import Box
4 from neco.util.sshfuncs import RUNNING, FINISHED
12 class DummyEC(object):
15 class LinuxBoxTestCase(unittest.TestCase):
17 host = 'nepi2.pl.sophia.inria.fr'
19 self.node_fedora = self.create_node(host, user)
21 host = 'roseval.pl.sophia.inria.fr'
23 self.node_ubuntu = self.create_node(host, user)
25 self.target = 'nepi5.pl.sophia.inria.fr'
26 self.home = '${HOME}/test-app'
28 def create_node(self, host, user):
32 node = LinuxNode(box, ec)
38 def t_xterm(self, node):
39 if not node.is_alive():
40 print "*** WARNING: Skipping test: Node %s is not alive\n" % (node.host)
43 node.enable_x11 = True
47 out = node.execute('xterm')
49 node.uninstall('xterm')
51 self.assertEquals(out, "")
53 def t_execute(self, node, target):
54 if not node.is_alive():
55 print "*** WARNING: Skipping test: Node %s is not alive\n" % (node.host)
58 command = "ping -qc3 %s" % target
59 out = node.execute(command)
61 expected = """3 packets transmitted, 3 received, 0% packet loss"""
63 self.assertTrue(out.find(expected) > 0)
65 def t_run(self, node, target):
66 if not node.is_alive():
67 print "*** WARNING: Skipping test: Node %s is not alive\n" % (node.host)
70 node.mkdir(self.home, clean = True)
72 command = "ping %s" % target
73 dst = os.path.join(self.home, "app.sh")
74 node.upload(command, dst)
77 node.run(cmd, self.home)
78 pid, ppid = node.checkpid(self.home)
80 status = node.status(pid, ppid)
81 self.assertTrue(status, RUNNING)
84 status = node.status(pid, ppid)
85 self.assertTrue(status, FINISHED)
89 def t_install(self, node):
90 if not node.is_alive():
91 print "*** WARNING: Skipping test: Node %s is not alive\n" % (node.host)
94 node.mkdir(self.home, clean = True)
96 prog = """#include <stdio.h>
101 printf ("Hello, world!\\n");
105 # upload the test program
106 dst = os.path.join(self.home, "hello.c")
107 node.upload(prog, dst)
112 # compile the program using gcc
113 command = "cd %s; gcc -Wall hello.c -o hello" % self.home
114 out = node.execute(command)
116 # execute the program and get the output from stout
117 command = "%s/hello" % self.home
118 out = node.execute(command)
120 # execute the program and get the output from a file
121 command = "%s/hello > %s/hello.out" % (self.home, self.home)
122 node.execute(command)
124 # retrieve the output file
125 src = os.path.join(self.home, "hello.out")
126 f = tempfile.NamedTemporaryFile(delete=False)
128 node.download(src, dst)
131 node.uninstall('gcc')
132 node.rmdir(self.home)
134 self.assertEquals(out, "Hello, world!\n")
140 self.assertEquals(out, "Hello, world!\n")
142 def test_execute_fedora(self):
143 self.t_execute(self.node_fedora, self.target)
145 def test_execute_ubuntu(self):
146 self.t_execute(self.node_ubuntu, self.target)
148 def test_run_fedora(self):
149 self.t_run(self.node_fedora, self.target)
151 def test_run_ubuntu(self):
152 self.t_run(self.node_ubuntu, self.target)
154 def test_intall_fedora(self):
155 self.t_install(self.node_fedora)
157 def test_install_ubuntu(self):
158 self.t_install(self.node_ubuntu)
160 def xtest_xterm_fedora(self):
161 """ PlanetLab doesn't currently support X11 forwarding.
162 Interactive test. Should not run automatically """
163 self.t_xterm(self.node_fedora)
165 def xtest_xterm_ubuntu(self):
166 """ Interactive test. Should not run automatically """
167 self.t_xterm(self.node_ubuntu)
170 if __name__ == '__main__':