3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Author: Julien Tribino <julien.tribino@inria.fr>
22 from nepi.execution.resource import ResourceFactory, clsinit_copy, ResourceManager, ResourceAction, ResourceState
23 from nepi.execution.ec import ExperimentController
24 from nepi.execution.attribute import Attribute, Flags
26 from nepi.resources.omf.node import OMFNode
27 from nepi.resources.omf.application import OMFApplication
29 from nepi.util.timefuncs import *
34 class DummyEC(ExperimentController):
38 class DummyOMFApplication(OMFApplication):
39 _rtype = "DummyOMFApplication"
42 def _register_attributes(cls):
43 test = Attribute("test", "Input of the application", default = 0, set_hook = cls.test_hook)
44 cls._register_attribute(test)
47 def test_hook(cls, old_value, new_value):
49 print "Change the value of test from "+ str(old_value) +" to : " + str(new_value)
53 class OMFTestSet(unittest.TestCase):
55 def test_set_hook(self):
56 self.ec = DummyEC(exp_id = "30")
58 ResourceFactory.register_type(DummyOMFApplication)
60 self.node1 = self.ec.register_resource("OMFNode")
61 self.ec.set(self.node1, 'hostname', 'omf.plexus.wlab17')
62 self.ec.set(self.node1, 'xmppSlice', "nepi")
63 self.ec.set(self.node1, 'xmppHost', "xmpp-plexus.onelab.eu")
64 self.ec.set(self.node1, 'xmppPort', "5222")
65 self.ec.set(self.node1, 'xmppPassword', "1234")
67 self.app1 = self.ec.register_resource("DummyOMFApplication")
68 self.ec.set(self.app1, 'appid', 'Test#1')
69 self.ec.set(self.app1, 'path', "/usr/bin/ping")
70 self.ec.set(self.app1, 'args', "")
71 self.ec.set(self.app1, 'env', "")
72 self.ec.set(self.app1, 'xmppSlice', "nepi")
73 self.ec.set(self.app1, 'xmppHost', "xmpp-plexus.onelab.eu")
74 self.ec.set(self.app1, 'xmppPort', "5222")
75 self.ec.set(self.app1, 'xmppPassword', "1234")
77 self.ec.register_connection(self.app1, self.node1)
79 self.ec.register_condition(self.app1, ResourceAction.STOP, self.app1, ResourceState.STARTED , "10s")
84 print "First try to change the STDIN"
85 self.ec.set(self.app1, 'test', 3)
87 self.assertEquals(self.ec.get(self.app1, 'test'), 30)
90 print "Second try to change the STDIN"
91 self.ec.set(self.app1, 'test', 101)
92 self.assertEquals(self.ec.get(self.app1, 'test'), 1010)
94 self.ec.wait_finished([self.app1])
100 if __name__ == '__main__':