Refactoring LinuGRETunnel
[nepi.git] / test / resources / omf / omf5_vlc_wrong_critical.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 as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
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.
15 #
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/>.
18 #
19 # Author: Julien Tribino <julien.tribino@inria.fr>
20
21
22 from nepi.execution.resource import ResourceFactory, ResourceManager, ResourceAction, ResourceState
23 from nepi.execution.ec import ExperimentController
24
25 from nepi.resources.omf.node import OMFNode
26 from nepi.resources.omf.application import OMFApplication
27 from nepi.resources.omf.interface import OMFWifiInterface
28 from nepi.resources.omf.channel import OMFChannel
29 from nepi.resources.omf.omf_api_factory import OMFAPIFactory
30
31 from nepi.util.timefuncs import *
32
33 import time
34 import unittest
35
36 class OMFVLCWrongCaseAllCritical(unittest.TestCase):
37
38     id = 1000
39
40     def setUp(self):
41         self.ec = ExperimentController(exp_id = str(OMFVLCWrongCaseAllCritical.id))
42         OMFVLCWrongCaseAllCritical.id += 1
43
44         self.node1 = self.ec.register_resource("OMFNode")
45         self.ec.set(self.node1, 'hostname', 'omf.plexus.wlab17')
46         self.ec.set(self.node1, 'xmppUser', "nepi")
47         self.ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
48         self.ec.set(self.node1, 'xmppPort', "5222")
49         self.ec.set(self.node1, 'xmppPassword', "1234")
50         self.ec.set(self.node1, 'version', "5")
51         
52         self.iface1 = self.ec.register_resource("OMFWifiInterface")
53         self.ec.set(self.iface1, 'name', "wlan0")
54         self.ec.set(self.iface1, 'mode', "adhoc")
55         self.ec.set(self.iface1, 'hw_mode', "g")
56         self.ec.set(self.iface1, 'essid', "vlcexp")
57         self.ec.set(self.iface1, 'ip', "10.0.0.17/24")
58         self.ec.set(self.iface1, 'version', "5")
59
60         self.app1 = self.ec.register_resource("OMFApplication")
61         self.ec.set(self.app1, 'appid', 'Vlc#1')
62         self.ec.set(self.app1, 'command', "/opt/vlc-1.1.13/cvlc /opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
63         self.ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
64         self.ec.set(self.app1, 'version', "5")
65
66         self.ec.register_connection(self.app1, self.node1)
67         self.ec.register_connection(self.node1, self.iface1)
68
69     def test_deploy_wo_node(self):
70         self.node2 = self.ec.register_resource("OMFNode")
71         self.ec.set(self.node2, 'version', "5")
72
73         self.iface2 = self.ec.register_resource("OMFWifiInterface")
74         self.ec.set(self.iface2, 'name', "wlan0")
75         self.ec.set(self.iface2, 'mode', "adhoc")
76         self.ec.set(self.iface2, 'hw_mode', "g")
77         self.ec.set(self.iface2, 'essid', "vlcexp")
78         self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
79         self.ec.set(self.iface2, 'version', "5")
80         
81         self.channel = self.ec.register_resource("OMFChannel")
82         self.ec.set(self.channel, 'channel', "6")
83         self.ec.set(self.channel, 'xmppUser', "nepi")
84         self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
85         self.ec.set(self.channel, 'xmppPort', "5222")
86         self.ec.set(self.channel, 'xmppPassword', "1234")
87         self.ec.set(self.channel, 'version', "5")
88
89         self.ec.register_connection(self.iface1, self.channel)
90         self.ec.register_connection(self.node2, self.iface2)
91         self.ec.register_connection(self.iface2, self.channel)
92
93         self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
94
95         self.ec.deploy()
96
97         self.ec.wait_finished([self.app1])
98
99         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.FAILED)
100
101         self.ec.shutdown()
102
103         self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
104         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
105         self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
106         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
107         self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
108         self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
109
110     def test_deploy_wo_hostname(self):
111
112         self.node2 = self.ec.register_resource("OMFNode")
113         self.ec.set(self.node2, 'xmppUser', "nepi")
114         self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
115         self.ec.set(self.node2, 'xmppPort', "5222")
116         self.ec.set(self.node2, 'xmppPassword', "1234")
117         self.ec.set(self.node2, 'version', "5")
118
119         self.iface2 = self.ec.register_resource("OMFWifiInterface")
120         self.ec.set(self.iface2, 'name', "wlan0")
121         self.ec.set(self.iface2, 'mode', "adhoc")
122         self.ec.set(self.iface2, 'hw_mode', "g")
123         self.ec.set(self.iface2, 'essid', "vlcexp")
124         self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
125         self.ec.set(self.iface2, 'version', "5")
126         
127         self.channel = self.ec.register_resource("OMFChannel")
128         self.ec.set(self.channel, 'channel', "6")
129         self.ec.set(self.channel, 'xmppUser', "nepi")
130         self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
131         self.ec.set(self.channel, 'xmppPort', "5222")
132         self.ec.set(self.channel, 'xmppPassword', "1234")
133         self.ec.set(self.channel, 'version', "5")
134
135         self.ec.register_connection(self.iface1, self.channel)
136         self.ec.register_connection(self.node2, self.iface2)
137         self.ec.register_connection(self.iface2, self.channel)
138
139         self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
140
141         self.ec.deploy()
142
143         self.ec.wait_finished([self.app1])
144
145         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.FAILED)
146
147         self.ec.shutdown()
148
149         self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
150         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
151         self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
152         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
153         self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
154         self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
155
156     def test_deploy_wo_iface(self):
157         self.node2 = self.ec.register_resource("OMFNode")
158         self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
159         self.ec.set(self.node2, 'xmppUser', "nepi")
160         self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
161         self.ec.set(self.node2, 'xmppPort', "5222")
162         self.ec.set(self.node2, 'xmppPassword', "1234")
163         self.ec.set(self.node2, 'version', "5")
164
165         self.iface2 = self.ec.register_resource("OMFWifiInterface")
166         self.ec.set(self.iface2, 'version', "5")
167         
168         self.channel = self.ec.register_resource("OMFChannel")
169         self.ec.set(self.channel, 'channel', "6")
170         self.ec.set(self.channel, 'xmppUser', "nepi")
171         self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
172         self.ec.set(self.channel, 'xmppPort', "5222")
173         self.ec.set(self.channel, 'xmppPassword', "1234")
174         self.ec.set(self.channel, 'version', "5")
175
176         self.ec.register_connection(self.iface1, self.channel)
177         self.ec.register_connection(self.node2, self.iface2)
178         self.ec.register_connection(self.iface2, self.channel)
179
180         self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
181
182         self.ec.deploy()
183
184         self.ec.wait_finished([self.app1])
185
186         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.FAILED)
187
188         self.ec.shutdown()
189
190         self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
191         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
192         self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
193         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
194         self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
195         self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
196
197     def test_deploy_wo_ip(self):
198         self.node2 = self.ec.register_resource("OMFNode")
199         self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
200         self.ec.set(self.node2, 'xmppUser', "nepi")
201         self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
202         self.ec.set(self.node2, 'xmppPort', "5222")
203         self.ec.set(self.node2, 'xmppPassword', "1234")
204         self.ec.set(self.node2, 'version', "5")
205
206         self.iface2 = self.ec.register_resource("OMFWifiInterface")
207         self.ec.set(self.iface2, 'name', "wlan0")
208         self.ec.set(self.iface2, 'mode', "adhoc")
209         self.ec.set(self.iface2, 'hw_mode', "g")
210         self.ec.set(self.iface2, 'essid', "vlcexp")
211         self.ec.set(self.iface2, 'version', "5")
212
213         self.channel = self.ec.register_resource("OMFChannel")
214         self.ec.set(self.channel, 'channel', "6")
215         self.ec.set(self.channel, 'xmppUser', "nepi")
216         self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
217         self.ec.set(self.channel, 'xmppPort', "5222")
218         self.ec.set(self.channel, 'xmppPassword', "1234")
219         self.ec.set(self.channel, 'version', "5")
220
221         self.ec.register_connection(self.iface1, self.channel)
222         self.ec.register_connection(self.node2, self.iface2)
223         self.ec.register_connection(self.iface2, self.channel)
224
225         self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
226
227         self.ec.deploy()
228
229         self.ec.wait_finished([self.app1])
230
231         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.FAILED)
232
233         self.ec.shutdown()
234
235         self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
236         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
237         self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
238         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
239         self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
240         self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
241
242     def test_deploy_wo_channel(self):
243         self.node2 = self.ec.register_resource("OMFNode")
244         self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
245         self.ec.set(self.node2, 'xmppUser', "nepi")
246         self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
247         self.ec.set(self.node2, 'xmppPort', "5222")
248         self.ec.set(self.node2, 'xmppPassword', "1234")
249         self.ec.set(self.node2, 'version', "5")
250
251         self.iface2 = self.ec.register_resource("OMFWifiInterface")
252         self.ec.set(self.iface2, 'name', "wlan0")
253         self.ec.set(self.iface2, 'mode', "adhoc")
254         self.ec.set(self.iface2, 'hw_mode', "g")
255         self.ec.set(self.iface2, 'essid', "vlcexp")
256         self.ec.set(self.iface2, 'version', "5")
257
258         self.channel = self.ec.register_resource("OMFChannel")
259         self.ec.set(self.channel, 'version', "5")
260
261         self.ec.register_connection(self.iface1, self.channel)
262         self.ec.register_connection(self.node2, self.iface2)
263         self.ec.register_connection(self.iface2, self.channel)
264
265         self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
266
267         self.ec.deploy()
268
269         self.ec.wait_finished([self.app1])
270
271         self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.FAILED)
272
273         self.ec.shutdown()
274
275         self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
276         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
277         self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
278         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
279         self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
280         self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
281
282     def test_deploy_wo_app(self):
283         self.node2 = self.ec.register_resource("OMFNode")
284         self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
285         self.ec.set(self.node2, 'xmppUser', "nepi")
286         self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
287         self.ec.set(self.node2, 'xmppPort', "5222")
288         self.ec.set(self.node2, 'xmppPassword', "1234")
289         self.ec.set(self.node2, 'version', "5")
290
291         self.iface2 = self.ec.register_resource("OMFWifiInterface")
292         self.ec.set(self.iface2, 'name', "wlan0")
293         self.ec.set(self.iface2, 'mode', "adhoc")
294         self.ec.set(self.iface2, 'hw_mode', "g")
295         self.ec.set(self.iface2, 'essid', "vlcexp")   
296         self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
297         self.ec.set(self.iface2, 'version', "5")
298
299         self.channel = self.ec.register_resource("OMFChannel")
300         self.ec.set(self.channel, 'channel', "6")
301         self.ec.set(self.channel, 'xmppUser', "nepi")
302         self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
303         self.ec.set(self.channel, 'xmppPort', "5222")
304         self.ec.set(self.channel, 'xmppPassword', "1234")
305         self.ec.set(self.channel, 'version', "5")
306
307         self.app2 = self.ec.register_resource("OMFApplication")
308         self.ec.set(self.app2, 'version', "5")
309
310         self.ec.register_connection(self.iface1, self.channel)
311         self.ec.register_connection(self.iface2, self.channel)
312         self.ec.register_connection(self.node2, self.iface2)
313         self.ec.register_connection(self.app2, self.node2)
314
315         self.ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "2s")
316         self.ec.register_condition([self.app1, self.app2], ResourceAction.STOP, self.app1, ResourceState.STARTED , "4s")
317
318         self.ec.deploy()
319
320         self.ec.wait_finished([self.app1, self.app2])
321
322         self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.FAILED)
323
324         self.ec.shutdown()
325
326         self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
327         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
328         self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
329         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
330         self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
331         self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
332         self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.RELEASED)
333
334     def test_deploy_wo_app_path(self):
335         self.node2 = self.ec.register_resource("OMFNode")
336         self.ec.set(self.node2, 'hostname', 'omf.plexus.wlab17')
337         self.ec.set(self.node2, 'xmppUser', "nepi")
338         self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
339         self.ec.set(self.node2, 'xmppPort', "5222")
340         self.ec.set(self.node2, 'xmppPassword', "1234")
341         self.ec.set(self.node2, 'version', "5")
342
343         self.iface2 = self.ec.register_resource("OMFWifiInterface")
344         self.ec.set(self.iface2, 'name', "wlan0")
345         self.ec.set(self.iface2, 'mode', "adhoc")
346         self.ec.set(self.iface2, 'hw_mode', "g")
347         self.ec.set(self.iface2, 'essid', "vlcexp")   
348         self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
349         self.ec.set(self.iface2, 'version', "5")
350
351         self.channel = self.ec.register_resource("OMFChannel")
352         self.ec.set(self.channel, 'channel', "6")
353         self.ec.set(self.channel, 'xmppUser', "nepi")
354         self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
355         self.ec.set(self.channel, 'xmppPort', "5222")
356         self.ec.set(self.channel, 'xmppPassword', "1234")
357         self.ec.set(self.channel, 'version', "5")
358
359         self.app2 = self.ec.register_resource("OMFApplication")
360         self.ec.set(self.app2, 'appid', 'Vlc#2')
361         self.ec.set(self.app2, 'version', "5")
362
363         self.ec.register_connection(self.iface1, self.channel)
364         self.ec.register_connection(self.iface2, self.channel)
365         self.ec.register_connection(self.node2, self.iface2)
366         self.ec.register_connection(self.app2, self.node2)
367
368         self.ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "2s")
369         self.ec.register_condition([self.app1, self.app2], ResourceAction.STOP, self.app1, ResourceState.STARTED , "4s")
370
371         self.ec.deploy()
372
373         self.ec.wait_finished([self.app1, self.app2])
374
375         self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.FAILED)
376
377         self.ec.shutdown()
378
379         self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
380         self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
381         self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
382         self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
383         self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
384         self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
385         self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.RELEASED)
386
387
388 if __name__ == '__main__':
389     unittest.main()
390
391
392