use print() - import print_function - should be fine for both py2 and py3
[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 __future__ import print_function
21
22 from nepi.execution.resource import ResourceState, ResourceAction 
23 from nepi.execution.ec import ExperimentController 
24 from test_utils import skipIfAnyNotAlive
25
26 import os
27 import time
28 import tempfile
29 import unittest
30
31 class LinuxCCNPeekTestCase(unittest.TestCase):
32     def setUp(self):
33         #self.fedora_host = "nepi2.pl.sophia.inria.fr"
34         #self.fedora_user = "inria_nepi"
35         self.fedora_identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
36
37         self.fedora_host = "mimas.inria.fr"
38         self.fedora_user = "aquereil"
39
40     @skipIfAnyNotAlive
41     def test_ccnpeek(self):
42         ec = ExperimentController(exp_id = "test-linux-ccnpeek")
43         
44         node = ec.register_resource("linux::Node")
45         ec.set(node, "hostname", self.fedora_host)
46         ec.set(node, "username", self.fedora_user)
47         ec.set(node, "identity", self.fedora_identity)
48         #ec.set(node, "cleanProcesses", True)
49         #ec.set(node, "cleanExperiment", True)
50
51         ccnd = ec.register_resource("linux::CCND")
52         ec.register_connection(ccnd, node)
53
54         peek = ec.register_resource("linux::CCNPeek")
55         ec.set(peek, "contentName", "ccnx:/chunk0")
56         ec.register_connection(peek, ccnd)
57
58         poke = ec.register_resource("linux::CCNPoke")
59         ec.set(poke, "contentName", "ccnx:/chunk0")
60         ec.set(poke, "content", "DATA")
61         ec.register_connection(poke, ccnd)
62
63         ec.register_condition(peek, ResourceAction.START, poke,
64             ResourceState.STARTED)
65  
66         ec.deploy()
67
68         ec.wait_finished(peek)
69
70         stdout = ec.trace(peek, "stdout")
71         print(stdout)
72         expected = "DATA"
73         self.assertTrue(stdout.find(expected) > -1)
74
75         ec.shutdown()
76
77 if __name__ == '__main__':
78     unittest.main()
79