From: Julien Tribino Date: Fri, 7 Jun 2013 14:29:39 +0000 (+0200) Subject: upgrade OMF code and comment X-Git-Tag: nepi-3.0.0~110 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=035281100ca10f829cdf17c16e50f1e13e011e2a;p=nepi.git upgrade OMF code and comment --- diff --git a/src/nepi/execution/ec.py b/src/nepi/execution/ec.py index 13a3c056..f2a19251 100644 --- a/src/nepi/execution/ec.py +++ b/src/nepi/execution/ec.py @@ -94,6 +94,7 @@ class ExperimentController(object): return self.ecstate in [ECState.FAILED, ECState.TERMINATED] def wait_finished(self, guids): + # Take into account if only one guids is given in parameter while not all([self.state(guid) in [ResourceState.FINISHED, ResourceState.STOPPED, ResourceState.FAILED] \ diff --git a/src/nepi/execution/resource.py b/src/nepi/execution/resource.py index 5efc2c32..0263ee44 100644 --- a/src/nepi/execution/resource.py +++ b/src/nepi/execution/resource.py @@ -277,7 +277,7 @@ class ResourceManager(Logger): self._state = ResourceState.STARTED def stop(self): - """ Start the Resource Manager + """ Stop the Resource Manager """ if not self._state in [ResourceState.STARTED]: diff --git a/src/nepi/resources/omf/application.py b/src/nepi/resources/omf/application.py index 26191464..22c8dca4 100644 --- a/src/nepi/resources/omf/application.py +++ b/src/nepi/resources/omf/application.py @@ -89,21 +89,23 @@ class OMFApplication(ResourceManager): self._omf_api = None - def _validate_connection(self, guid): - """Check if the connection is available. + def valid_connection(self, guid): + """Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed. - :param guid: Guid of the current RM + :param guid: Guid of RM it will be connected :type guid: int :rtype: Boolean """ rm = self.ec.get_resource(guid) if rm.rtype() not in self._authorized_connections: - msg = "Connection between %s %s and %s %s refused : An Application can be connected only to a Node" % (self.rtype(), self._guid, rm.rtype(), guid) + msg = "Connection between %s %s and %s %s refused : An Application can be connected only to a Node" %\ + (self.rtype(), self._guid, rm.rtype(), guid) self.debug(msg) return False elif len(self.connections) != 0 : - msg = "Connection between %s %s and %s %s refused : Already Connected" % (self.rtype(), self._guid, rm.rtype(), guid) + msg = "Connection between %s %s and %s %s refused : This Application is already connected" % \ + (self.rtype(), self._guid, rm.rtype(), guid) self.debug(msg) return False else : @@ -112,45 +114,65 @@ class OMFApplication(ResourceManager): return True def deploy(self): - """Deploy the RM - + """Deploy the RM. It means nothing special for an application for now (later it will be upload sources, ...) + It becomes DEPLOYED after getting the xmpp client. """ - self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), - self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) + if not self._omf_api : + self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), + self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) + super(OMFApplication, self).deploy() def start(self): - """Send Xmpp Message Using OMF protocol to execute the application + """Start the RM. It means : Send Xmpp Message Using OMF protocol to execute the application + It becomes STARTED before the messages are sent (for coordination) """ super(OMFApplication, self).start() - msg = " " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + self.get('appid') + " : " + self.get('path') + " : " + self.get('args') + " : " + self.get('env') - self.info(msg) - - if self.get('appid') and self.get('path') and self.get('args') and self.get('env'): + if self.get('appid') and self.get('path') and self.get('args') and self.get('env') : + msg = " " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + \ + self.get('appid') + " : " + self.get('path') + " : " + \ + self.get('args') + " : " + self.get('env') + self.info(msg) rm_list = self.get_connected("OMFNode") - for rm_node in rm_list: - self._omf_api.execute(rm_node.get('hostname'),self.get('appid'), self.get('args'), self.get('path'), self.get('env')) + try: + for rm_node in rm_list: + if rm_node.get('hostname') : + self._omf_api.execute(rm_node.get('hostname'),self.get('appid'), \ + self.get('args'), self.get('path'), self.get('env')) + except AttributeError: + self._state = ResourceState.FAILED + msg = "Credentials are not initialzed. XMPP Connections impossible" + self.error(msg) + return else : + self._state = ResourceState.FAILED msg = "Application's information are not initialized" self.error(msg) def stop(self): - """Send Xmpp Message Using OMF protocol to kill the application + """Stop the RM. It means : Send Xmpp Message Using OMF protocol to kill the application + It becomes STOPPED after the message is sent. """ - - rm_list = self.get_connected("OMFNode") - for rm_node in rm_list : - self._omf_api.exit(rm_node.get('hostname'),self.get('appid')) + try: + rm_list = self.get_connected("OMFNode") + for rm_node in rm_list : + self._omf_api.exit(rm_node.get('hostname'),self.get('appid')) + except AttributeError: + self._state = ResourceState.FAILED + msg = "Credentials were not initialzed. XMPP Connections impossible" + self.error(msg) + return super(OMFApplication, self).stop() self._state = ResourceState.FINISHED def release(self): - """Clean the RM at the end of the experiment + """Clean the RM at the end of the experiment and release the API. """ - OMFAPIFactory.release_api(self.get('xmppSlice'), - self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) + if self._omf_api : + OMFAPIFactory.release_api(self.get('xmppSlice'), + self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) diff --git a/src/nepi/resources/omf/channel.py b/src/nepi/resources/omf/channel.py index db31d071..1eaef050 100644 --- a/src/nepi/resources/omf/channel.py +++ b/src/nepi/resources/omf/channel.py @@ -1,22 +1,21 @@ -# -# NEPI, a framework to manage network experiments -# Copyright (C) 2013 INRIA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Author: Alina Quereilhac -# Julien Tribino +""" + NEPI, a framework to manage network experiments + Copyright (C) 2013 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +c + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +""" from nepi.execution.resource import ResourceManager, clsinit, ResourceState from nepi.execution.attribute import Attribute, Flags @@ -77,8 +76,8 @@ class OMFChannel(ResourceManager): self._omf_api = None - def _validate_connection(self, guid): - """Check if the connection is available. + def valid_connection(self, guid): + """Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed. :param guid: Guid of the current RM :type guid: int @@ -96,7 +95,7 @@ class OMFChannel(ResourceManager): def _get_target(self, conn_set): """ - Get the couples (host, interface) that used this channel + Get the couples (host, interface) that uses this channel :param conn_set: Connections of the current Guid :type conn_set: set @@ -108,65 +107,79 @@ class OMFChannel(ResourceManager): rm_iface = self.ec.get_resource(elt) for conn in rm_iface.connections: rm_node = self.ec.get_resource(conn) - if rm_node.rtype() == "OMFNode": - if rm_iface.state < ResourceState.READY or rm_node.state < ResourceState.READY: + if rm_node.rtype() == "OMFNode" and rm_node.get('hostname'): + if rm_iface.state < ResourceState.READY or rm_node.state < ResourceState.READY: return "reschedule" couple = [rm_node.get('hostname'), rm_iface.get('alias')] #print couple self._nodes_guid.append(couple) return self._nodes_guid + def discover(self): + """ Discover the availables channels + + """ + pass + + def provision(self): + """ Provision some availables channels + + """ + pass + def deploy(self): - """Deploy the RM + """Deploy the RM. It means : Get the xmpp client and send messages using OMF 5.4 protocol to configure the channel + It becomes DEPLOYED after sending messages to configure the channel """ if not self._omf_api : self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) + if self.get('channel'): set_nodes = self._get_target(self._connections) if set_nodes == "reschedule" : self.ec.schedule(reschedule_delay, self.deploy) return print set_nodes - for couple in set_nodes: - #print "Couple node/alias : " + couple[0] + " , " + couple[1] - attrval = self.get('channel') - attrname = "net/%s/%s" % (couple[1], 'channel') - self._omf_api.configure(couple[0], attrname, attrval) + try: + for couple in set_nodes: + #print "Couple node/alias : " + couple[0] + " , " + couple[1] + attrval = self.get('channel') + attrname = "net/%s/%s" % (couple[1], 'channel') + self._omf_api.configure(couple[0], attrname, attrval) + except AttributeError: + self._state = ResourceState.FAILED + msg = "Credentials are not initialzed. XMPP Connections impossible" + self.debug(msg) + return + else : + msg = "Channel's value is not initialized" + self.error(msg) super(OMFChannel, self).deploy() - def discover(self): - """ Discover the availables channels - - """ - pass - - def provision(self): - """ Provision some availables channels - - """ - pass - def start(self): - """Send Xmpp Message Using OMF protocol to configure Channel + """Start the RM. It means nothing special for a channel for now + It becomes STARTED as soon as this method starts. """ super(OMFChannel, self).start() def stop(self): - """Send Xmpp Message Using OMF protocol to put down the interface + """Stop the RM. It means nothing special for a channel for now + It becomes STOPPED as soon as this method stops """ super(OMFChannel, self).stop() def release(self): - """Clean the RM at the end of the experiment + """Clean the RM at the end of the experiment and release the API """ - OMFAPIFactory.release_api(self.get('xmppSlice'), - self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) + if self._omf_api : + OMFAPIFactory.release_api(self.get('xmppSlice'), + self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) diff --git a/src/nepi/resources/omf/interface.py b/src/nepi/resources/omf/interface.py index 13469b8b..e9877a1c 100644 --- a/src/nepi/resources/omf/interface.py +++ b/src/nepi/resources/omf/interface.py @@ -86,8 +86,8 @@ class OMFWifiInterface(ResourceManager): self._omf_api = None self._alias = self.get('alias') - def _validate_connection(self, guid): - """ Check if the connection is available. + def valid_connection(self, guid): + """ Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed. :param guid: Guid of the current RM :type guid: int @@ -96,72 +96,73 @@ class OMFWifiInterface(ResourceManager): """ rm = self.ec.get_resource(guid) if rm.rtype() in self._authorized_connections: - msg = "Connection between %s %s and %s %s accepted" % (self.rtype(), self._guid, rm.rtype(), guid) + msg = "Connection between %s %s and %s %s accepted" % \ + (self.rtype(), self._guid, rm.rtype(), guid) self.debug(msg) return True - msg = "Connection between %s %s and %s %s refused" % (self.rtype(), self._guid, rm.rtype(), guid) + msg = "Connection between %s %s and %s %s refused" % \ + (self.rtype(), self._guid, rm.rtype(), guid) self.debug(msg) return False - def _get_nodes(self, conn_set): - """ Get the RM of the node to which the application is connected - - :param conn_set: Connections of the current Guid - :type conn_set: set - :rtype: ResourceManager - - """ - for elt in conn_set: - rm = self.ec.get_resource(elt) - if rm.rtype() == "OMFNode": - return rm - return None - def deploy(self): - """Deploy the RM - + """Deploy the RM. It means : Get the xmpp client and send messages using OMF 5.4 protocol to configure the interface + It becomes DEPLOYED after sending messages to configure the interface """ if not self._omf_api : self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) - self._logger.debug(" " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + - self.get('mode') + " : " + self.get('type') + " : " + - self.get('essid') + " : " + self.get('ip')) - #try: if self.get('mode') and self.get('type') and self.get('essid') and self.get('ip'): + self.debug(" " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + \ + self.get('mode') + " : " + self.get('type') + " : " + \ + self.get('essid') + " : " + self.get('ip')) rm_list = self.get_connected("OMFNode") for rm_node in rm_list: if rm_node.state < ResourceState.READY: self.ec.schedule(reschedule_delay, self.deploy) return - for attrname in ["mode", "type", "essid", "ip"]: - attrval = self.get(attrname) - attrname = "net/%s/%s" % (self._alias, attrname) - #print "Send the configure message" - self._omf_api.configure(rm_node.get('hostname'), attrname, attrval) + if rm_node.get('hostname') : + try : + for attrname in ["mode", "type", "essid", "ip"]: + attrval = self.get(attrname) + attrname = "net/%s/%s" % (self._alias, attrname) + #print "Send the configure message" + self._omf_api.configure(rm_node.get('hostname'), attrname, attrval) + except AttributeError: + self._state = ResourceState.FAILED + msg = "Credentials are not initialzed. XMPP Connections impossible" + self.debug(msg) + return + else : + msg = "The channel is connected with an undefined node" + self.error(msg) + else : + msg = "Interface's variable are not initialized" + self.error(msg) super(OMFWifiInterface, self).deploy() - def start(self): - """Send Xmpp Messages Using OMF protocol to configure Interface + """Start the RM. It means nothing special for an interface for now + It becomes STARTED as soon as this method starts. """ super(OMFWifiInterface, self).start() def stop(self): - """Send Xmpp Message Using OMF protocol to put down the interface + """Stop the RM. It means nothing special for an interface for now + It becomes STOPPED as soon as this method stops """ super(OMFWifiInterface, self).stop() def release(self): - """Clean the RM at the end of the experiment + """Clean the RM at the end of the experiment and release the API """ - OMFAPIFactory.release_api(self.get('xmppSlice'), - self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) - + if self._omf_api : + OMFAPIFactory.release_api(self.get('xmppSlice'), + self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) diff --git a/src/nepi/resources/omf/messages_5_4.py b/src/nepi/resources/omf/messages_5_4.py index d5a2d372..f3cde244 100644 --- a/src/nepi/resources/omf/messages_5_4.py +++ b/src/nepi/resources/omf/messages_5_4.py @@ -163,7 +163,7 @@ class MessageHandler(): return payload def alias_function(self, name, target): - """ Build a Alias Message + """ Build an Alias Message :param name: Name of the new alias :type name: str diff --git a/src/nepi/resources/omf/node.py b/src/nepi/resources/omf/node.py index fbea0dbb..156ba86d 100644 --- a/src/nepi/resources/omf/node.py +++ b/src/nepi/resources/omf/node.py @@ -95,18 +95,14 @@ class OMFNode(ResourceManager): :type ec: ExperimentController :param guid: guid of the RM :type guid: int - :param creds: Credentials to communicate with the rm (XmppClient for OMF) - :type creds: dict """ super(OMFNode, self).__init__(ec, guid) self._omf_api = None - # XXX: TO DISCUSS - - def _validate_connection(self, guid): - """Check if the connection is available. + def valid_connection(self, guid): + """Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed. :param guid: Guid of the current RM :type guid: int @@ -123,13 +119,22 @@ class OMFNode(ResourceManager): return False def deploy(self): - """Deploy the RM + """Deploy the RM. It means : Send Xmpp Message Using OMF protocol to enroll the node into the experiment + It becomes DEPLOYED after sending messages to enroll the node """ if not self._omf_api : self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), - self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) - self._omf_api.enroll_host(self.get('hostname')) + self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) + + if self.get('hostname') : + try: + self._omf_api.enroll_host(self.get('hostname')) + except AttributeError: + self._state = ResourceState.FAILED + msg = "Credentials are not initialzed. XMPP Connections impossible" + self.debug(msg) + return super(OMFNode, self).deploy() @@ -145,15 +150,17 @@ class OMFNode(ResourceManager): """ pass - def start(self): - """Send Xmpp Message Using OMF protocol to enroll the node into the experiment + def start(self): + """Start the RM. It means nothing special for an interface for now + It becomes STARTED as soon as this method starts. """ - super(OMFNode, self).start() + super(OMFNode, self).start() def stop(self): - """Send Xmpp Message Using OMF protocol to disconnect the node + """Stop the RM. It means nothing special for an interface for now + It becomes STOPPED as soon as this method stops """ super(OMFNode, self).stop() @@ -162,27 +169,8 @@ class OMFNode(ResourceManager): """Clean the RM at the end of the experiment """ - self._omf_api.release(self.get('hostname')) - OMFAPIFactory.release_api(self.get('xmppSlice'), - self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) - - - def configure(self): - #routes = self.tc._add_route.get(self.guid, []) - #iface_guids = self.tc.get_connected(self.guid, "devs", "node") - - for route in routes: - (destination, netprefix, nexthop, metric, device) = route - netmask = ipaddr2.ipv4_mask2dot(netprefix) - - # Validate that the interface is associated to the node - for iface_guid in iface_guids: - iface = self.tc.elements.get(iface_guid) - if iface.devname == device: - self._omf_api.execute(self.get('hostname'), - "Id#%s" % str(random.getrandbits(128)), - "add -net %s netmask %s dev %s" % (destination, netmask, iface.devname), - "/sbin/route", # path - None, # env - ) - break + if self._omf_api : + self._omf_api.release(self.get('hostname')) + OMFAPIFactory.release_api(self.get('xmppSlice'), + self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword')) + diff --git a/src/nepi/resources/omf/omf_api.py b/src/nepi/resources/omf/omf_api.py index 6740d352..4dfcc6fc 100644 --- a/src/nepi/resources/omf/omf_api.py +++ b/src/nepi/resources/omf/omf_api.py @@ -304,7 +304,7 @@ class OMFAPIFactory(object): @classmethod def get_api(cls, slice, host, port, password): - """ Get an Api + """ Get an OMF Api :param slice: Xmpp Slice Name :type slice: str @@ -332,7 +332,7 @@ class OMFAPIFactory(object): @classmethod def create_api(cls, slice, host, port, password): - """ Create an API if this one doesn't exist yet with this credentials + """ Create an OMF API if this one doesn't exist yet with this credentials :param slice: Xmpp Slice Name :type slice: str @@ -353,7 +353,7 @@ class OMFAPIFactory(object): @classmethod def release_api(cls, slice, host, port, password): - """ Release an API with this credentials + """ Release an OMF API with this credentials :param slice: Xmpp Slice Name :type slice: str diff --git a/test/resources/omf/vlc.py b/test/resources/omf/vlc.py index 4b337a61..aae3084a 100755 --- a/test/resources/omf/vlc.py +++ b/test/resources/omf/vlc.py @@ -1,3 +1,4 @@ + #!/usr/bin/env python # # NEPI, a framework to manage network experiments @@ -77,203 +78,147 @@ class OMFVLCTestCase(unittest.TestCase): ResourceFactory.register_type(OMFChannel) ResourceFactory.register_type(OMFApplication) + self.node1 = self.ec.register_resource("OMFNode") + self.ec.set(self.node1, 'hostname', 'omf.plexus.wlab17') + self.ec.set(self.node1, 'xmppSlice', "nepi") + self.ec.set(self.node1, 'xmppHost', "xmpp-plexus.onelab.eu") + self.ec.set(self.node1, 'xmppPort', "5222") + self.ec.set(self.node1, 'xmppPassword', "1234") + + self.node2 = self.ec.register_resource("OMFNode") + + self.iface1 = self.ec.register_resource("OMFWifiInterface") + self.ec.set(self.iface1, 'alias', "w0") + self.ec.set(self.iface1, 'mode', "adhoc") + self.ec.set(self.iface1, 'type', "g") + self.ec.set(self.iface1, 'essid', "vlcexp") + self.ec.set(self.iface1, 'ip', "10.0.0.17") + self.ec.set(self.iface1, 'xmppSlice', "nepi") + self.ec.set(self.iface1, 'xmppHost', "xmpp-plexus.onelab.eu") + self.ec.set(self.iface1, 'xmppPort', "5222") + self.ec.set(self.iface1, 'xmppPassword', "1234") + + self.iface2 = self.ec.register_resource("OMFWifiInterface") + + self.channel = self.ec.register_resource("OMFChannel") + self.ec.set(self.channel, 'channel', "6") + self.ec.set(self.channel, 'xmppSlice', "nepi") + self.ec.set(self.channel, 'xmppHost', "xmpp-plexus.onelab.eu") + self.ec.set(self.channel, 'xmppPort', "5222") + self.ec.set(self.channel, 'xmppPassword', "1234") + + self.app1 = self.ec.register_resource("OMFApplication") + self.ec.set(self.app1, 'appid', 'Vlc#1') + self.ec.set(self.app1, 'path', "/opt/vlc-1.1.13/cvlc") + self.ec.set(self.app1, 'args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'") + self.ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority") + self.ec.set(self.app1, 'xmppSlice', "nepi") + self.ec.set(self.app1, 'xmppHost', "xmpp-plexus.onelab.eu") + self.ec.set(self.app1, 'xmppPort', "5222") + self.ec.set(self.app1, 'xmppPassword', "1234") + + self.app2 = self.ec.register_resource("OMFApplication") + self.ec.set(self.app2, 'xmppSlice', "nepi") + self.ec.set(self.app2, 'xmppHost', "xmpp-plexus.onelab.eu") + self.ec.set(self.app2, 'xmppPort', "5222") + self.ec.set(self.app2, 'xmppPassword', "1234") + + self.app3 = self.ec.register_resource("OMFApplication") + self.app4 = self.ec.register_resource("OMFApplication") + + self.app5 = self.ec.register_resource("OMFApplication") + self.ec.set(self.app5, 'appid', 'Kill#2') + self.ec.set(self.app5, 'path', "/usr/bin/killall") + self.ec.set(self.app5, 'args', "vlc") + self.ec.set(self.app5, 'env', " ") + self.ec.set(self.app5, 'xmppSlice', "nepi") + self.ec.set(self.app5, 'xmppHost', "xmpp-plexus.onelab.eu") + self.ec.set(self.app5, 'xmppPort', "5222") + self.ec.set(self.app5, 'xmppPassword', "1234") + + self.ec.register_connection(self.app1, self.node1) + self.ec.register_connection(self.app2, self.node1) + self.ec.register_connection(self.app3, self.node1) + self.ec.register_connection(self.app4, self.node1) + self.ec.register_connection(self.app5, self.node1) + self.ec.register_connection(self.node1, self.iface1) + self.ec.register_connection(self.iface1, self.channel) + self.ec.register_connection(self.node2, self.iface2) + self.ec.register_connection(self.iface2, self.channel) + + self.ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "3s") + self.ec.register_condition(self.app3, ResourceAction.START, self.app2, ResourceState.STARTED , "2s") + self.ec.register_condition(self.app4, ResourceAction.START, self.app3, ResourceState.STARTED , "3s") + self.ec.register_condition(self.app5, ResourceAction.START, [self.app3, self.app2], ResourceState.STARTED , "2s") + self.ec.register_condition(self.app5, ResourceAction.START, self.app1, ResourceState.STARTED , "25s") + + self.ec.register_condition([self.app1, self.app2, self.app3,self.app4, self.app5], ResourceAction.STOP, self.app5, ResourceState.STARTED , "1s") + def tearDown(self): self.ec.shutdown() def test_creation_and_configuration_node(self): - - node1 = self.ec.register_resource("OMFNode") - self.ec.set(node1, 'hostname', 'omf.plexus.wlab17') - self.ec.set(node1, 'xmppSlice', "nepi") - self.ec.set(node1, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(node1, 'xmppPort', "5222") - self.ec.set(node1, 'xmppPassword', "1234") - - self.assertEquals(self.ec.get(node1, 'hostname'), 'omf.plexus.wlab17') - self.assertEquals(self.ec.get(node1, 'xmppSlice'), 'nepi') - self.assertEquals(self.ec.get(node1, 'xmppHost'), 'xmpp-plexus.onelab.eu') - self.assertEquals(self.ec.get(node1, 'xmppPort'), '5222') - self.assertEquals(self.ec.get(node1, 'xmppPassword'), '1234') + self.assertEquals(self.ec.get(self.node1, 'hostname'), 'omf.plexus.wlab17') + self.assertEquals(self.ec.get(self.node1, 'xmppSlice'), 'nepi') + self.assertEquals(self.ec.get(self.node1, 'xmppHost'), 'xmpp-plexus.onelab.eu') + self.assertEquals(self.ec.get(self.node1, 'xmppPort'), '5222') + self.assertEquals(self.ec.get(self.node1, 'xmppPassword'), '1234') def test_creation_and_configuration_interface(self): - - iface1 = self.ec.register_resource("OMFWifiInterface") - self.ec.set(iface1, 'alias', "w0") - self.ec.set(iface1, 'mode', "adhoc") - self.ec.set(iface1, 'type', "g") - self.ec.set(iface1, 'essid', "vlcexp") - self.ec.set(iface1, 'ip', "10.0.0.17") - self.ec.set(iface1, 'xmppSlice', "nepi") - self.ec.set(iface1, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(iface1, 'xmppPort', "5222") - self.ec.set(iface1, 'xmppPassword', "1234") - - self.assertEquals(self.ec.get(iface1, 'alias'), 'w0') - self.assertEquals(self.ec.get(iface1, 'mode'), 'adhoc') - self.assertEquals(self.ec.get(iface1, 'type'), 'g') - self.assertEquals(self.ec.get(iface1, 'essid'), 'vlcexp') - self.assertEquals(self.ec.get(iface1, 'ip'), '10.0.0.17') - self.assertEquals(self.ec.get(iface1, 'xmppSlice'), 'nepi') - self.assertEquals(self.ec.get(iface1, 'xmppHost'), 'xmpp-plexus.onelab.eu') - self.assertEquals(self.ec.get(iface1, 'xmppPort'), '5222') - self.assertEquals(self.ec.get(iface1, 'xmppPassword'), '1234') + self.assertEquals(self.ec.get(self.iface1, 'alias'), 'w0') + self.assertEquals(self.ec.get(self.iface1, 'mode'), 'adhoc') + self.assertEquals(self.ec.get(self.iface1, 'type'), 'g') + self.assertEquals(self.ec.get(self.iface1, 'essid'), 'vlcexp') + self.assertEquals(self.ec.get(self.iface1, 'ip'), '10.0.0.17') + self.assertEquals(self.ec.get(self.iface1, 'xmppSlice'), 'nepi') + self.assertEquals(self.ec.get(self.iface1, 'xmppHost'), 'xmpp-plexus.onelab.eu') + self.assertEquals(self.ec.get(self.iface1, 'xmppPort'), '5222') + self.assertEquals(self.ec.get(self.iface1, 'xmppPassword'), '1234') def test_creation_and_configuration_channel(self): - - channel = self.ec.register_resource("OMFChannel") - self.ec.set(channel, 'channel', "6") - self.ec.set(channel, 'xmppSlice', "nepi") - self.ec.set(channel, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(channel, 'xmppPort', "5222") - self.ec.set(channel, 'xmppPassword', "1234") - - self.assertEquals(self.ec.get(channel, 'channel'), '6') - self.assertEquals(self.ec.get(channel, 'xmppSlice'), 'nepi') - self.assertEquals(self.ec.get(channel, 'xmppHost'), 'xmpp-plexus.onelab.eu') - self.assertEquals(self.ec.get(channel, 'xmppPort'), '5222') - self.assertEquals(self.ec.get(channel, 'xmppPassword'), '1234') + self.assertEquals(self.ec.get(self.channel, 'channel'), '6') + self.assertEquals(self.ec.get(self.channel, 'xmppSlice'), 'nepi') + self.assertEquals(self.ec.get(self.channel, 'xmppHost'), 'xmpp-plexus.onelab.eu') + self.assertEquals(self.ec.get(self.channel, 'xmppPort'), '5222') + self.assertEquals(self.ec.get(self.channel, 'xmppPassword'), '1234') def test_creation_and_configuration_application(self): - - app1 = self.ec.register_resource("OMFApplication") - self.ec.set(app1, 'appid', 'Vlc#1') - self.ec.set(app1, 'path', "/opt/vlc-1.1.13/cvlc") - self.ec.set(app1, 'args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'") - self.ec.set(app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority") - self.ec.set(app1, 'xmppSlice', "nepi") - self.ec.set(app1, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(app1, 'xmppPort', "5222") - self.ec.set(app1, 'xmppPassword', "1234") - - self.assertEquals(self.ec.get(app1, 'appid'), 'Vlc#1') - self.assertEquals(self.ec.get(app1, 'path'), '/opt/vlc-1.1.13/cvlc') - self.assertEquals(self.ec.get(app1, 'args'), "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'") - self.assertEquals(self.ec.get(app1, 'env'), 'DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority') - self.assertEquals(self.ec.get(app1, 'xmppSlice'), 'nepi') - self.assertEquals(self.ec.get(app1, 'xmppHost'), 'xmpp-plexus.onelab.eu') - self.assertEquals(self.ec.get(app1, 'xmppPort'), '5222') - self.assertEquals(self.ec.get(app1, 'xmppPassword'), '1234') + self.assertEquals(self.ec.get(self.app1, 'appid'), 'Vlc#1') + self.assertEquals(self.ec.get(self.app1, 'path'), '/opt/vlc-1.1.13/cvlc') + self.assertEquals(self.ec.get(self.app1, 'args'), "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'") + self.assertEquals(self.ec.get(self.app1, 'env'), 'DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority') + self.assertEquals(self.ec.get(self.app1, 'xmppSlice'), 'nepi') + self.assertEquals(self.ec.get(self.app1, 'xmppHost'), 'xmpp-plexus.onelab.eu') + self.assertEquals(self.ec.get(self.app1, 'xmppPort'), '5222') + self.assertEquals(self.ec.get(self.app1, 'xmppPassword'), '1234') def test_connection(self): - - node1 = self.ec.register_resource("OMFNode") - iface1 = self.ec.register_resource("OMFWifiInterface") - channel = self.ec.register_resource("OMFChannel") - app1 = self.ec.register_resource("OMFApplication") - app2 = self.ec.register_resource("OMFApplication") - - self.ec.register_connection(app1, node1) - self.ec.register_connection(app2, node1) - self.ec.register_connection(node1, iface1) - self.ec.register_connection(iface1, channel) - - self.assertEquals(len(self.ec.get_resource(node1).connections), 3) - self.assertEquals(len(self.ec.get_resource(iface1).connections), 2) - self.assertEquals(len(self.ec.get_resource(channel).connections), 1) - self.assertEquals(len(self.ec.get_resource(app1).connections), 1) - self.assertEquals(len(self.ec.get_resource(app2).connections), 1) + self.assertEquals(len(self.ec.get_resource(self.node1).connections), 6) + self.assertEquals(len(self.ec.get_resource(self.iface1).connections), 2) + self.assertEquals(len(self.ec.get_resource(self.channel).connections), 2) + self.assertEquals(len(self.ec.get_resource(self.app1).connections), 1) + self.assertEquals(len(self.ec.get_resource(self.app2).connections), 1) def test_condition(self): - - node1 = self.ec.register_resource("OMFNode") - iface1 = self.ec.register_resource("OMFWifiInterface") - channel = self.ec.register_resource("OMFChannel") - app1 = self.ec.register_resource("OMFApplication") - app2 = self.ec.register_resource("OMFApplication") - - self.ec.register_connection(app1, node1) - self.ec.register_connection(app2, node1) - self.ec.register_connection(node1, iface1) - self.ec.register_connection(iface1, channel) - - self.ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "4s") - - self.assertEquals(len(self.ec.get_resource(app2).conditions), 1) + self.assertEquals(len(self.ec.get_resource(self.app1).conditions[ResourceAction.STOP]), 1) + self.assertEquals(len(self.ec.get_resource(self.app2).conditions[ResourceAction.START]), 1) + self.assertEquals(len(self.ec.get_resource(self.app3).conditions[ResourceAction.START]), 1) + self.assertEquals(len(self.ec.get_resource(self.app4).conditions[ResourceAction.STOP]), 1) + self.assertEquals(len(self.ec.get_resource(self.app5).conditions[ResourceAction.START]), 2) def test_deploy(self): - node1 = self.ec.register_resource("OMFNode") - self.ec.set(node1, 'hostname', 'omf.plexus.wlab17') - self.ec.set(node1, 'xmppSlice', "nepi") - self.ec.set(node1, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(node1, 'xmppPort', "5222") - self.ec.set(node1, 'xmppPassword', "1234") - - iface1 = self.ec.register_resource("OMFWifiInterface") - self.ec.set(iface1, 'alias', "w0") - self.ec.set(iface1, 'mode', "adhoc") - self.ec.set(iface1, 'type', "g") - self.ec.set(iface1, 'essid', "vlcexp") - self.ec.set(iface1, 'ip', "10.0.0.17") - self.ec.set(iface1, 'xmppSlice', "nepi") - self.ec.set(iface1, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(iface1, 'xmppPort', "5222") - self.ec.set(iface1, 'xmppPassword', "1234") - - channel = self.ec.register_resource("OMFChannel") - self.ec.set(channel, 'channel', "6") - self.ec.set(channel, 'xmppSlice', "nepi") - self.ec.set(channel, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(channel, 'xmppPort', "5222") - self.ec.set(channel, 'xmppPassword', "1234") - app1 = self.ec.register_resource("OMFApplication") - self.ec.set(app1, 'xmppSlice', "nepi") - self.ec.set(app1, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(app1, 'xmppPort', "5222") - self.ec.set(app1, 'xmppPassword', "1234") - - app2 = self.ec.register_resource("OMFApplication") - self.ec.set(app2, 'xmppSlice', "nepi") - self.ec.set(app2, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(app2, 'xmppPort', "5222") - self.ec.set(app2, 'xmppPassword', "1234") - - app3 = self.ec.register_resource("OMFApplication") - self.ec.set(app3, 'xmppSlice', "nepi") - self.ec.set(app3, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(app3, 'xmppPort', "5222") - self.ec.set(app3, 'xmppPassword', "1234") - - app4 = self.ec.register_resource("OMFApplication") - self.ec.set(app4, 'xmppSlice', "nepi") - self.ec.set(app4, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(app4, 'xmppPort', "5222") - self.ec.set(app4, 'xmppPassword', "1234") - - app5 = self.ec.register_resource("OMFApplication") - self.ec.set(app5, 'xmppSlice', "nepi") - self.ec.set(app5, 'xmppHost', "xmpp-plexus.onelab.eu") - self.ec.set(app5, 'xmppPort', "5222") - self.ec.set(app5, 'xmppPassword', "1234") - - self.ec.register_connection(app1, node1) - self.ec.register_connection(app2, node1) - self.ec.register_connection(app3, node1) - self.ec.register_connection(app4, node1) - self.ec.register_connection(app5, node1) - self.ec.register_connection(node1, iface1) - self.ec.register_connection(iface1, channel) - - self.ec.register_condition(app2, ResourceAction.START, app1, ResourceState.STARTED , "3s") - self.ec.register_condition(app3, ResourceAction.START, app2, ResourceState.STARTED , "2s") - self.ec.register_condition(app4, ResourceAction.START, app3, ResourceState.STARTED , "3s") - self.ec.register_condition(app5, ResourceAction.START, [app3, app2], ResourceState.STARTED , "2s") - self.ec.register_condition(app5, ResourceAction.START, app1, ResourceState.STARTED , "25s") - - self.ec.register_condition([app1, app2, app3,app4, app5], ResourceAction.STOP, app5, ResourceState.STARTED , "1s") - self.ec.deploy() - self.ec.wait_finished([app1, app2, app3,app4, app5]) - - self.assertEquals(round(strfdiff(self.ec.get_resource(app2).start_time, self.ec.get_resource(app1).start_time),1), 3.0) - self.assertEquals(round(strfdiff(self.ec.get_resource(app3).start_time, self.ec.get_resource(app2).start_time),1), 2.0) - self.assertEquals(round(strfdiff(self.ec.get_resource(app4).start_time, self.ec.get_resource(app3).start_time),1), 3.0) - self.assertEquals(round(strfdiff(self.ec.get_resource(app5).start_time, self.ec.get_resource(app3).start_time),1), 20.0) - self.assertEquals(round(strfdiff(self.ec.get_resource(app5).start_time, self.ec.get_resource(app1).start_time),1), 25.0) + self.ec.wait_finished([self.app1, self.app2, self.app3,self.app4, self.app5]) + self.assertEquals(round(strfdiff(self.ec.get_resource(self.app2).start_time, self.ec.get_resource(self.app1).start_time),1), 3.0) + self.assertEquals(round(strfdiff(self.ec.get_resource(self.app3).start_time, self.ec.get_resource(self.app2).start_time),1), 2.0) + self.assertEquals(round(strfdiff(self.ec.get_resource(self.app4).start_time, self.ec.get_resource(self.app3).start_time),1), 3.0) + self.assertEquals(round(strfdiff(self.ec.get_resource(self.app5).start_time, self.ec.get_resource(self.app3).start_time),1), 20.0) + self.assertEquals(round(strfdiff(self.ec.get_resource(self.app5).start_time, self.ec.get_resource(self.app1).start_time),1), 25.0) # Precision is at 1/10. So this one returns an error 7.03 != 7.0 - #self.assertEquals(strfdiff(self.ec.get_resource(app5).start_time, self.ec.get_resource(app1).start_time), 7) + #self.assertEquals(strfdiff(self.ec.get_resource(self.app5).start_time, self.ec.get_resource(self.app1).start_time), 7) #In order to release everythings time.sleep(1)