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 version 2 as
8 # published by the Free Software Foundation;
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.
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/>.
18 # Author: Julien Tribino <julien.tribino@inria.fr>
20 from __future__ import print_function
22 from nepi.execution.resource import (ResourceFactory, clsinit_copy,
23 ResourceManager, ResourceAction, ResourceState)
24 from nepi.execution.ec import ExperimentController
25 from nepi.execution.attribute import Attribute, Flags
27 from nepi.resources.omf.node import OMFNode
28 from nepi.resources.omf.application import OMFApplication
30 from nepi.util.timefuncs import *
35 class DummyEC(ExperimentController):
39 class OMFDummyApplication(OMFApplication):
40 _rtype = "omf::DummyApplication"
43 def _register_attributes(cls):
44 test = Attribute("test", "Input of the application", default = 0, set_hook = cls.test_hook)
45 cls._register_attribute(test)
48 def test_hook(cls, old_value, new_value):
50 print("Change the value of test from "+ str(old_value) +" to : " + str(new_value))
54 class OMFTestSet(unittest.TestCase):
56 def test_set_hook(self):
57 self.ec = DummyEC(exp_id = "30")
59 ResourceFactory.register_type(OMFDummyApplication)
61 self.node1 = self.ec.register_resource("omf::Node")
62 self.ec.set(self.node1, 'hostname', 'omf.plexus.wlab17')
63 self.ec.set(self.node1, 'xmppSlice', "nepi")
64 self.ec.set(self.node1, 'xmppHost', "xmpp-plexus.onelab.eu")
65 self.ec.set(self.node1, 'xmppPort', "5222")
66 self.ec.set(self.node1, 'xmppPassword', "1234")
68 self.app1 = self.ec.register_resource("omf::DummyApplication")
69 self.ec.set(self.app1, 'appid', 'Test#1')
70 self.ec.set(self.app1, 'path', "/usr/bin/ping")
71 self.ec.set(self.app1, 'args', "")
72 self.ec.set(self.app1, 'env', "")
73 self.ec.set(self.app1, 'xmppSlice', "nepi")
74 self.ec.set(self.app1, 'xmppHost', "xmpp-plexus.onelab.eu")
75 self.ec.set(self.app1, 'xmppPort', "5222")
76 self.ec.set(self.app1, 'xmppPassword', "1234")
78 self.ec.register_connection(self.app1, self.node1)
80 self.ec.register_condition(self.app1, ResourceAction.STOP, self.app1, ResourceState.STARTED , "10s")
85 print("First try to change the STDIN")
86 self.ec.set(self.app1, 'test', 3)
88 self.assertEqual(self.ec.get(self.app1, 'test'), 30)
91 print("Second try to change the STDIN")
92 self.ec.set(self.app1, 'test', 101)
93 self.assertEqual(self.ec.get(self.app1, 'test'), 1010)
95 self.ec.wait_finished([self.app1])
101 if __name__ == '__main__':