2 from neco.resources.base.linux_node import LinuxNode
3 from neco.design.box import Box
4 from neco.util.sshfuncs import RUNNING, FINISHED
11 class DummyEC(object):
14 class LinuxBoxTestCase(unittest.TestCase):
16 host = 'nepi2.pl.sophia.inria.fr'
18 self.node_fedora = self.create_node(host, user)
20 host = 'roseval.pl.sophia.inria.fr'
22 self.node_ubuntu = self.create_node(host, user)
24 self.target = 'nepi5.pl.sophia.inria.fr'
25 self.home = '${HOME}/test-app'
27 def create_node(self, host, user):
31 node = LinuxNode(box, ec)
37 def t_execute(self, node, target):
38 if not node.is_alive():
39 print "*** WARNING: Skipping test: Node %s is not alive\n" % (node.host)
42 command = "ping -qc3 %s" % target
43 out = node.execute(command)
45 expected = """3 packets transmitted, 3 received, 0% packet loss"""
47 self.assertTrue(out.find(expected) > 0)
49 def t_run(self, node, target):
50 if not node.is_alive():
51 print "*** WARNING: Skipping test: Node %s is not alive\n" % (node.host)
54 node.mkdir(self.home, clean = True)
56 command = "ping %s" % target
57 dst = os.path.join(self.home, "app.sh")
58 node.upload(command, dst)
61 node.run(cmd, self.home)
62 pid, ppid = node.checkpid(self.home)
64 status = node.status(pid, ppid)
65 self.assertTrue(status, RUNNING)
68 status = node.status(pid, ppid)
69 self.assertTrue(status, FINISHED)
73 def t_install(self, node, target):
74 if not node.is_alive():
75 print "*** WARNING: Skipping test: Node %s is not alive\n" % (node.host)
78 node.mkdir(self.home, clean = True)
80 prog = """#include <stdio.h>
85 printf ("Hello, world!\\n");
89 dst = os.path.join(self.home, "hello.c")
90 node.upload(prog, dst)
94 command = "cd %s; gcc -Wall hello.c -o hello" % self.home
95 out = node.execute(command)
97 command = "%s/hello" % self.home
98 out = node.execute(command)
100 self.assertEquals(out, "Hello, world!\n")
102 node.uninstall('gcc')
103 node.rmdir(self.home)
105 def test_execute_fedora(self):
106 self.t_execute(self.node_fedora, self.target)
108 def test_execute_ubuntu(self):
109 self.t_execute(self.node_ubuntu, self.target)
111 def test_run_fedora(self):
112 self.t_run(self.node_fedora, self.target)
114 def test_run_ubuntu(self):
115 self.t_run(self.node_ubuntu, self.target)
117 def test_intall_fedora(self):
118 self.t_install(self.node_fedora, self.target)
120 def test_install_ubuntu(self):
121 self.t_install(self.node_ubuntu, self.target)
123 if __name__ == '__main__':