35a98cc14ef6ded7648d9e7b2b8fa8eb4c3e6ce3
[nepi.git] / test / resources / linux / ccn / ccnpeek.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License version 2 as
8 #    published by the Free Software Foundation;
9 #
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #    GNU General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.resource import ResourceState, ResourceAction 
21 from nepi.execution.ec import ExperimentController 
22 from test_utils import skipIfAnyNotAlive
23
24 import os
25 import time
26 import tempfile
27 import unittest
28
29 class LinuxCCNPeekTestCase(unittest.TestCase):
30     def setUp(self):
31         #self.fedora_host = "nepi2.pl.sophia.inria.fr"
32         #self.fedora_user = "inria_nepi"
33         self.fedora_identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
34
35         self.fedora_host = "mimas.inria.fr"
36         self.fedora_user = "aquereil"
37
38     @skipIfAnyNotAlive
39     def test_ccnpeek(self):
40         ec = ExperimentController(exp_id = "test-linux-ccnpeek")
41         
42         node = ec.register_resource("linux::Node")
43         ec.set(node, "hostname", self.fedora_host)
44         ec.set(node, "username", self.fedora_user)
45         ec.set(node, "identity", self.fedora_identity)
46         #ec.set(node, "cleanProcesses", True)
47         #ec.set(node, "cleanExperiment", True)
48
49         ccnd = ec.register_resource("linux::CCND")
50         ec.register_connection(ccnd, node)
51
52         peek = ec.register_resource("linux::CCNPeek")
53         ec.set(peek, "contentName", "ccnx:/chunk0")
54         ec.register_connection(peek, ccnd)
55
56         poke = ec.register_resource("linux::CCNPoke")
57         ec.set(poke, "contentName", "ccnx:/chunk0")
58         ec.set(poke, "content", "DATA")
59         ec.register_connection(poke, ccnd)
60
61         ec.register_condition(peek, ResourceAction.START, poke,
62             ResourceState.STARTED)
63  
64         ec.deploy()
65
66         ec.wait_finished(peek)
67
68         stdout = ec.trace(peek, "stdout")
69         print stdout
70         expected = "DATA"
71         self.assertTrue(stdout.find(expected) > -1)
72
73         ec.shutdown()
74
75 if __name__ == '__main__':
76     unittest.main()
77