Merge from multihop_ssh to nepi-3-dev
authorLucia Guevgeozian Odizzio <lucia.guevgeozian_odizzio@inria.fr>
Thu, 30 Jan 2014 15:17:47 +0000 (16:17 +0100)
committerLucia Guevgeozian Odizzio <lucia.guevgeozian_odizzio@inria.fr>
Thu, 30 Jan 2014 15:17:47 +0000 (16:17 +0100)
20 files changed:
src/nepi/execution/resource.py
src/nepi/resources/omf/application.py
src/nepi/resources/omf/channel.py
src/nepi/resources/omf/interface.py
src/nepi/resources/omf/node.py
src/nepi/resources/planetlab/node.py
src/nepi/resources/planetlab/plcapi.py
test/execution/resource.py
test/resources/linux/application.py
test/resources/linux/ccn/ccnping.py
test/resources/linux/ccn/fibentry.py
test/resources/linux/interface.py
test/resources/linux/mtr.py
test/resources/linux/node.py
test/resources/linux/nping.py
test/resources/linux/ping.py
test/resources/linux/tcpdump.py
test/resources/linux/traceroute.py
test/resources/linux/udptest.py
test/resources/omf/vlc_wrong_non_critical.py

index 9c236ea..49b842b 100644 (file)
@@ -980,6 +980,8 @@ class ResourceManager(Logger):
         self.set_state(ResourceState.PROVISIONED, "_provision_time")
 
     def set_state(self, state, state_time_attr):
+        """ Set the state of the RM while keeping a trace of the time """
+
         # Ensure that RM state will not change after released
         if self._state == ResourceState.RELEASED:
             return 
index 65f1f4a..bc4d0e7 100644 (file)
@@ -36,13 +36,6 @@ class OMFApplication(OMFResource):
         :type ec: ExperimentController
         :param guid: guid of the RM
         :type guid: int
-        :param creds: Credentials to communicate with the rm (XmppClient)
-        :type creds: dict
-
-    .. note::
-
-       This class is used only by the Experiment Controller through the 
-       Resource Factory
 
     """
     _rtype = "OMFApplication"
@@ -107,10 +100,17 @@ class OMFApplication(OMFResource):
         return None
 
     def stdin_hook(self, old_value, new_value):
+        """ Set a hook to the stdin attribute in order to send a message at each time
+        the value of this parameter is changed
+
+        """
         self._omf_api.send_stdin(self.node.get('hostname'), new_value, self.get('appid'))
         return new_value
 
     def add_set_hook(self):
+        """ Initialize the hooks
+
+        """
         attr = self._attrs["stdin"]
         attr.set_hook = self.stdin_hook
 
index 17478fd..6a0b02b 100644 (file)
@@ -38,10 +38,6 @@ class OMFChannel(OMFResource):
         :param creds: Credentials to communicate with the rm (XmppClient for OMF)
         :type creds: dict
 
-    .. note::
-
-       This class is used only by the Experiment Controller through the Resource Factory
-
     """
     _rtype = "OMFChannel"
     _authorized_connections = ["OMFWifiInterface", "OMFNode"]
@@ -60,8 +56,6 @@ class OMFChannel(OMFResource):
         :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(OMFChannel, self).__init__(ec, guid)
index cd2fb9d..1fcd59b 100644 (file)
@@ -36,13 +36,6 @@ class OMFWifiInterface(OMFResource):
         :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
-
-    .. note::
-
-       This class is used only by the Experiment Controller through the Resource 
-       Factory
 
     """
     _rtype = "OMFWifiInterface"
index a028d7b..de00a07 100644 (file)
@@ -38,10 +38,6 @@ class OMFNode(OMFResource):
         :param creds: Credentials to communicate with the rm (XmppClient for OMF)
         :type creds: dict
 
-    .. note::
-
-       This class is used only by the Experiment Controller through the Resource Factory
-
     """
     _rtype = "OMFNode"
     _authorized_connections = ["OMFApplication" , "OMFWifiInterface"]
index f50526a..c24cb12 100644 (file)
@@ -237,10 +237,9 @@ class PlanetlabNode(LinuxNode):
         hostname = self._get_hostname()
         if hostname:
             # the user specified one particular node to be provisioned
-            # check with PLCAPI if it is alive
             self._hostname = True
-            node_id = self._query_if_alive(hostname=hostname)
-            node_id = node_id.pop()
+            node_id = self._get_nodes_id({'hostname':hostname})
+            node_id = node_id.pop()['node_id']
 
             # check that the node is not blacklisted or being provisioned
             # by other RM
@@ -267,12 +266,11 @@ class PlanetlabNode(LinuxNode):
             # the user specifies constraints based on attributes, zero, one or 
             # more nodes can match these constraints 
             nodes = self._filter_based_on_attributes()
-            nodes_alive = self._query_if_alive(nodes)
 
             # nodes that are already part of user's slice have the priority to
             # provisioned
-            nodes_inslice = self._check_if_in_slice(nodes_alive)
-            nodes_not_inslice = list(set(nodes_alive) - set(nodes_inslice))
+            nodes_inslice = self._check_if_in_slice(nodes)
+            nodes_not_inslice = list(set(nodes) - set(nodes_inslice))
             
             node_id = None
             if nodes_inslice:
@@ -415,13 +413,11 @@ class PlanetlabNode(LinuxNode):
                     nodes_id = self._filter_by_range_attr(attr_name, attr_value, filters, nodes_id)
 
         if not filters:
-            nodes = self.plapi.get_nodes()
+            nodes = self._get_nodes_id()
             for node in nodes:
                 nodes_id.append(node['node_id'])
-        
         return nodes_id
                     
-
     def _filter_by_fixed_attr(self, filters, nodes_id):
         """
         Query PLCAPI for nodes ids matching fixed attributes defined by the
@@ -505,45 +501,6 @@ class PlanetlabNode(LinuxNode):
 
         return nodes_id
         
-    def _query_if_alive(self, nodes_id=None, hostname=None):
-        """
-        Query PLCAPI for nodes that register activity recently, using filters 
-        related to the state of the node, e.g. last time it was contacted
-        """
-        if nodes_id is None and hostname is None:
-            msg = "Specify nodes_id or hostname"
-            raise RuntimeError, msg
-
-        if nodes_id is not None and hostname is not None:
-            msg = "Specify either nodes_id or hostname"
-            raise RuntimeError, msg
-
-        # define PL filters to check the node is alive
-        filters = dict()
-        filters['run_level'] = 'boot'
-        filters['boot_state'] = 'boot'
-        filters['node_type'] = 'regular' 
-        #filters['>last_contact'] =  int(time.time()) - 2*3600
-
-        # adding node_id or hostname to the filters to check for the particular
-        # node
-        if nodes_id:
-            filters['node_id'] = list(nodes_id)
-            alive_nodes_id = self._get_nodes_id(filters)
-        elif hostname:
-            filters['hostname'] = hostname
-            alive_nodes_id = self._get_nodes_id(filters)
-
-        if len(alive_nodes_id) == 0:
-            self.fail_node_not_alive(hostname)
-        else:
-            nodes_id = list()
-            for node_id in alive_nodes_id:
-                nid = node_id['node_id']
-                nodes_id.append(nid)
-
-            return nodes_id
-
     def _choose_random_node(self, nodes):
         """
         From the possible nodes for provision, choose randomly to decrese the
@@ -573,7 +530,7 @@ class PlanetlabNode(LinuxNode):
                         self._put_node_in_provision(node_id)
                         return node_id
 
-    def _get_nodes_id(self, filters):
+    def _get_nodes_id(self, filters=None):
         return self.plapi.get_nodes(filters, fields=['node_id'])
 
     def _add_node_to_slice(self, node_id):
index fed1a02..742c3f0 100644 (file)
@@ -144,6 +144,7 @@ class PLCAPI(object):
         self._blacklist = set()
         self._reserved = set()
         self._nodes_cache = None
+        self._already_cached = False
 
         if session_key is not None:
             self.auth = dict(AuthMethod='session', session=session_key)
@@ -340,8 +341,12 @@ class PLCAPI(object):
             filters.update(kw)
 
             if not filters and not fieldstuple:
-                if not self._nodes_cache:
+                if not self._nodes_cache and not self._already_cached:
+                    self._already_cached = True
                     self._nodes_cache = _retry(self.mcapi.GetNodes)(self.auth)
+                elif not self._nodes_cache:
+                    while not self._nodes_cache:
+                        time.sleep(10)
                 return self._nodes_cache
 
             return _retry(self.mcapi.GetNodes)(self.auth, filters, *fieldstuple)
index fa3277a..d3cc911 100755 (executable)
@@ -117,7 +117,7 @@ class Application(ResourceManager):
     def do_start(self):
         super(Application, self).do_start()
         time.sleep(random.random() * 3)
-        self.ec.schedule("0.5s", self.finish)
+        self.ec.schedule("0.5s", self.stop)
 
 class ErrorApplication(ResourceManager):
     _rtype = "ErrorApplication"
@@ -280,7 +280,7 @@ class ResourceManagerTestCase(unittest.TestCase):
         
         self.assertTrue(ec.state(node) == ResourceState.STARTED)
         self.assertTrue(
-               all([ec.state(guid) == ResourceState.FINISHED \
+               all([ec.state(guid) == ResourceState.STOPPED \
                 for guid in apps])
                 )
 
@@ -343,7 +343,7 @@ class ResourceManagerTestCase(unittest.TestCase):
 
         for app in apps:
             state = ec.state(app)
-            self.assertEquals(state, ResourceState.FINISHED)
+            self.assertEquals(state, ResourceState.STOPPED)
         
         ec.shutdown()
 
index 934081c..edbc2ba 100755 (executable)
@@ -32,7 +32,7 @@ import unittest
 class LinuxApplicationTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
@@ -60,7 +60,7 @@ class LinuxApplicationTestCase(unittest.TestCase):
         ec.wait_finished(app)
 
         self.assertTrue(ec.state(node) == ResourceState.STARTED)
-        self.assertTrue(ec.state(app) == ResourceState.FINISHED)
+        self.assertTrue(ec.state(app) == ResourceState.STOPPED)
 
         stdout = ec.trace(app, "stdout")
         self.assertTrue(stdout.strip() == "HOLA")
@@ -89,7 +89,7 @@ class LinuxApplicationTestCase(unittest.TestCase):
         ec.wait_finished(app)
 
         self.assertTrue(ec.state(node) == ResourceState.STARTED)
-        self.assertTrue(ec.state(app) == ResourceState.FINISHED)
+        self.assertTrue(ec.state(app) == ResourceState.STOPPED)
 
         stdout = ec.trace(app, "stdout")
         size = ec.trace(app, "stdout", attr = TraceAttr.SIZE)
@@ -169,7 +169,7 @@ main (void)
 
         self.assertTrue(ec.state(node) == ResourceState.STARTED)
         self.assertTrue(
-               all([ec.state(guid) == ResourceState.FINISHED \
+               all([ec.state(guid) == ResourceState.STOPPED \
                 for guid in apps])
                 )
 
@@ -219,8 +219,8 @@ main (void)
         ec.wait_finished(apps)
 
         self.assertTrue(ec.state(node) == ResourceState.STARTED)
-        self.assertTrue(ec.state(server) == ResourceState.FINISHED)
-        self.assertTrue(ec.state(client) == ResourceState.FINISHED)
+        self.assertTrue(ec.state(server) == ResourceState.STOPPED)
+        self.assertTrue(ec.state(client) == ResourceState.STOPPED)
 
         stdout = ec.trace(client, "stdout")
         self.assertTrue(stdout.strip() == "HOLA")
@@ -251,7 +251,7 @@ main (void)
         ec.wait_finished([app])
 
         self.assertTrue(ec.state(node) == ResourceState.STARTED)
-        self.assertTrue(ec.state(app) == ResourceState.FINISHED)
+        self.assertTrue(ec.state(app) == ResourceState.STOPPED)
 
         exitcode = ec.trace(app, "deploy_exitcode")
         self.assertTrue(exitcode.strip() == "0")
@@ -284,7 +284,7 @@ main (void)
 
         ec.wait_finished([app])
 
-        self.assertTrue(ec.state(app) == ResourceState.FINISHED)
+        self.assertTrue(ec.state(app) == ResourceState.STOPPED)
 
         ec.shutdown()
 
index a740128..672a11c 100644 (file)
@@ -29,7 +29,7 @@ import unittest
 class LinuxCCNPingTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index cf2f8bb..00ac5e8 100644 (file)
@@ -29,10 +29,10 @@ import unittest
 class LinuxFIBEntryTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
-        self.ubuntu_user = "alina"
+        self.ubuntu_user = "nepi"
         
         self.target = "nepi5.pl.sophia.inria.fr"
 
index 379f92e..bd4d74d 100755 (executable)
@@ -35,7 +35,7 @@ import unittest
 class LinuxInterfaceTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index a34068d..c62848a 100755 (executable)
@@ -29,7 +29,7 @@ import unittest
 class LinuxMtrTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index e7d44e1..cebf0d8 100755 (executable)
@@ -32,7 +32,7 @@ import unittest
 class LinuxNodeTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index 19c4ef4..b6af3dc 100755 (executable)
@@ -29,7 +29,7 @@ import unittest
 class LinuxNPingTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index 6530276..8846690 100755 (executable)
@@ -29,7 +29,7 @@ import unittest
 class LinuxPingTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index 6ba7375..6c9a9be 100755 (executable)
@@ -29,7 +29,7 @@ import unittest
 class LinuxTcpdumpTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index 996472e..dfdae42 100755 (executable)
@@ -29,7 +29,7 @@ import unittest
 class LinuxTracerouteTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index 37bfc88..aeafe6a 100755 (executable)
@@ -29,7 +29,7 @@ import unittest
 class LinuxUdpTestTestCase(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_user = "inria_nepi"
+        self.fedora_user = "inria_test"
 
         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
         self.ubuntu_user = "alina"
index a43c23b..4293264 100755 (executable)
@@ -410,8 +410,9 @@ class OMFVLCWrongCaseWithNonCriticalDep(unittest.TestCase):
 
         self.ec.wait_finished([self.app1, self.app2, self.app3])
 
+        self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.STOPPED)
         self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.FAILED)
-        self.assertEquals(self.ec.get_resource(self.app3).state, ResourceState.FAILED)
+        self.assertEquals(self.ec.get_resource(self.app3).state, ResourceState.STOPPED)
 
         self.ec.shutdown()
 
@@ -494,10 +495,12 @@ class OMFVLCWrongCaseWithNonCriticalDep(unittest.TestCase):
 
         self.ec.wait_finished([self.app1, self.app2, self.app3, self.app4, self.app5, self.app6])
 
+        self.assertEquals(self.ec.get_resource(self.app3).state, ResourceState.STOPPED)
         self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.FAILED)
-        self.assertEquals(self.ec.get_resource(self.app3).state, ResourceState.FAILED)
+        self.assertEquals(self.ec.get_resource(self.app3).state, ResourceState.STOPPED)
+        self.assertEquals(self.ec.get_resource(self.app3).state, ResourceState.STOPPED)
         self.assertEquals(self.ec.get_resource(self.app5).state, ResourceState.FAILED)
-        self.assertEquals(self.ec.get_resource(self.app6).state, ResourceState.FAILED)
+        self.assertEquals(self.ec.get_resource(self.app6).state, ResourceState.STOPPED)
 
         self.ec.shutdown()