Added metods to obtain factory_id, testbed_id and testbed_version for a box using...
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 24 May 2011 10:44:45 +0000 (12:44 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 24 May 2011 10:44:45 +0000 (12:44 +0200)
src/nepi/core/execute.py
src/nepi/core/testbed_impl.py
src/nepi/util/proxy.py
test/core/execute.py
test/core/integration.py

index c7919d5..d2d21c5 100644 (file)
@@ -329,7 +329,7 @@ class TestbedController(object):
     def get_attribute_list(self, guid):
         raise NotImplementedError
 
-    def get_tags(self, guid):
+    def get_factory_id(self, guid):
         raise NotImplementedError
 
     def action(self, time, guid, action):
@@ -420,7 +420,7 @@ class ExperimentController(object):
             self._parallel([testbed.do_setup 
                             for guid,testbed in self._testbeds.iteritems()
                             if guid in allowed_guids])
-            
+       
             # perform create-connect in parallel, wait
             # (internal connections only)
             self._parallel([testbed.do_create
@@ -438,9 +438,10 @@ class ExperimentController(object):
             self._parallel([testbed.do_preconfigure
                             for guid,testbed in self._testbeds.iteritems()
                             if guid in allowed_guids])
-            
+            self._clear_caches()
+
         steps_to_configure(self, self._testbeds)
-        
+
         if self._netreffed_testbeds:
             # initally resolve netrefs
             self.do_netrefs(data, fail_if_undefined=False)
@@ -466,7 +467,8 @@ class ExperimentController(object):
         self._parallel([testbed.do_configure
                         for testbed in self._testbeds.itervalues()])
 
-        
+        self._clear_caches()
+
         #print >>sys.stderr, "DO IT"
         #import time
         #time.sleep(60)
@@ -479,17 +481,24 @@ class ExperimentController(object):
             cross_data = self._get_cross_data(guid)
             testbed.do_cross_connect_compl(cross_data)
        
+        self._clear_caches()
+
         # Last chance to configure (parallel on all testbeds)
         self._parallel([testbed.do_prestart
                         for testbed in self._testbeds.itervalues()])
 
-        # After this point no new elements will be craeted. Cleaning cache for safety.
-        self._guids_in_testbed_cache = dict()
+        self._clear_caches()
 
         # start experiment (parallel start on all testbeds)
         self._parallel([testbed.start
                         for testbed in self._testbeds.itervalues()])
 
+        self._clear_caches()
+
+    def _clear_caches(self):
+        # Cleaning cache for safety.
+        self._guids_in_testbed_cache = dict()
+
     def _persist_testbed_proxies(self):
         TRANSIENT = ('Recover',)
         
@@ -579,10 +588,22 @@ class ExperimentController(object):
             return testbed.get(guid, name, time)
         raise RuntimeError("No element exists with guid %d" % guid)    
 
-    def get_tags(self, guid):
+    def get_factory_id(self, guid):
+        testbed = self._testbed_for_guid(guid)
+        if testbed != None:
+            return testbed.get_factory_id(guid)
+        raise RuntimeError("No element exists with guid %d" % guid)    
+
+    def get_testbed_id(self, guid):
+        testbed = self._testbed_for_guid(guid)
+        if testbed != None:
+            return testbed.testbed_id
+        raise RuntimeError("No element exists with guid %d" % guid)    
+
+    def get_testbed_version(self, guid):
         testbed = self._testbed_for_guid(guid)
         if testbed != None:
-            return testbed.get_tags(guid)
+            return testbed.testbed_version
         raise RuntimeError("No element exists with guid %d" % guid)    
 
     def shutdown(self):
index b34b8fe..663851d 100644 (file)
@@ -392,15 +392,15 @@ class TestbedController(execute.TestbedController):
         
         return addresses[index][attribute_index]
 
-    def get_tags(self, guid):
-        factory = self._get_factory(guid)
-        return factory.tags
-
     def get_attribute_list(self, guid):
         factory = self._get_factory(guid)
         attribute_list = list()
         return factory.box_attributes.attributes_list
 
+    def get_factory_id(self, guid):
+        factory = self._get_factory(guid)
+        return factory.factory_id
+
     def start(self, time = TIME_NOW):
         self._do_in_factory_order(
             'start_function',
index 8db9dd7..7ed34ce 100644 (file)
@@ -53,10 +53,10 @@ DO_CONNECT_COMPL    = 33
 DO_CROSS_CONNECT_COMPL  = 34
 TESTBED_ID  = 35
 TESTBED_VERSION  = 36
-EXPERIMENT_SET = 37
-EXPERIMENT_GET = 38
-DO_PRESTART = 39
-GET_TAGS = 40
+DO_PRESTART = 37
+GET_FACTORY_ID = 38
+GET_TESTBED_ID = 39
+GET_TESTBED_VERSION = 40
 
 instruction_text = dict({
     OK:     "OK",
@@ -90,14 +90,14 @@ instruction_text = dict({
     GET_ROUTE: "GET_ROUTE",
     GET_ADDRESS: "GET_ADDRESS",
     GET_ATTRIBUTE_LIST: "GET_ATTRIBUTE_LIST",
+    GET_FACTORY_ID: "GET_FACTORY_ID",
+    GET_TESTBED_ID: "GET_TESTBED_ID",
+    GET_TESTBED_VERSION: "GET_TESTBED_VERSION",
     ACTION: "ACTION",
     STATUS: "STATUS",
     GUIDS:  "GUIDS",
     TESTBED_ID: "TESTBED_ID",
     TESTBED_VERSION: "TESTBED_VERSION",
-    EXPERIMENT_SET: "EXPERIMENT_SET",
-    EXPERIMENT_GET: "EXPERIMENT_GET",
-    GET_TAGS: "GET_TAGS",
     })
 
 def log_msg(server, params):
@@ -645,11 +645,11 @@ class TestbedControllerServer(BaseServer):
     def get_attribute_list(self, guid):
         return self._testbed.get_attribute_list(guid)
 
-    @Marshalling.handles(GET_TAGS)
+    @Marshalling.handles(GET_FACTORY_ID)
     @Marshalling.args(int)
-    @Marshalling.retval( Marshalling.pickled_data )
-    def get_tags(self, guid):
-        return self._testbed.get_tags(guid)
+    @Marshalling.retval()
+    def get_factory_id(self, guid):
+        return self._testbed.get_factory_id(guid)
 
 class ExperimentControllerServer(BaseServer):
     def __init__(self, root_dir, log_level, experiment_xml):
@@ -686,24 +686,18 @@ class ExperimentControllerServer(BaseServer):
     def is_finished(self, guid):
         return self._controller.is_finished(guid)
 
-    @Marshalling.handles(EXPERIMENT_GET)
+    @Marshalling.handles(GET)
     @Marshalling.args(int, Marshalling.base64_data, str)
     @Marshalling.retval( Marshalling.pickled_data )
     def get(self, guid, name, time):
         return self._controller.get(guid, name, time)
 
-    @Marshalling.handles(EXPERIMENT_SET)
+    @Marshalling.handles(SET)
     @Marshalling.args(int, Marshalling.base64_data, Marshalling.pickled_data, str)
     @Marshalling.retvoid
     def set(self, guid, name, value, time):
         self._controller.set(guid, name, value, time)
 
-    @Marshalling.handles(GET_TAGS)
-    @Marshalling.args(int)
-    @Marshalling.retval( Marshalling.pickled_data )
-    def get_tags(self, guid):
-        return self._controller.get_tags(guid)
-
     @Marshalling.handles(START)
     @Marshalling.args()
     @Marshalling.retvoid
@@ -728,6 +722,24 @@ class ExperimentControllerServer(BaseServer):
     def shutdown(self):
         self._controller.shutdown()
 
+    @Marshalling.handles(GET_TESTBED_ID)
+    @Marshalling.args(int)
+    @Marshalling.retval()
+    def get_testbed_id(self, guid):
+        return self._controller.get_testbed_id(guid)
+
+    @Marshalling.handles(GET_FACTORY_ID)
+    @Marshalling.args(int)
+    @Marshalling.retval()
+    def get_factory_id(self, guid):
+        return self._controller.get_factory_id(guid)
+
+    @Marshalling.handles(GET_TESTBED_VERSION)
+    @Marshalling.args(int)
+    @Marshalling.retval()
+    def get_testbed_version(self, guid):
+        return self._controller.get_testbed_version(guid)
+
 class BaseProxy(object):
     _ServerClass = None
     _ServerClassModule = "nepi.util.proxy"
index 2f39379..8055e99 100755 (executable)
@@ -50,7 +50,6 @@ class ExecuteTestCase(unittest.TestCase):
 """
         
         self.assertTrue(app_result.startswith(comp_result))
-        self.assertEquals(instance.get_tags(4), [tags.MOBILE])
 
         instance.stop()
         instance.shutdown()
index 2bd0d9b..c135b5f 100755 (executable)
@@ -2,7 +2,7 @@
 # -*- coding: utf-8 -*-
 
 from nepi.core.design import ExperimentDescription, FactoriesProvider
-from nepi.util import proxy, tags
+from nepi.util import proxy
 from nepi.util.constants import STATUS_FINISHED, DeploymentConfiguration as DC
 import mock
 import mock.metadata_v01
@@ -100,7 +100,10 @@ class ExecuteTestCase(unittest.TestCase):
 1 packets transmitted, 1 received, 0% packet loss, time 0ms
 """
         self.assertTrue(fake_result.startswith(comp_result))
-        self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+        self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+        self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+        self.assertEquals(controller.get_factory_id(node1.guid), "Node")
 
         controller.stop()
         controller.shutdown()
@@ -123,7 +126,10 @@ class ExecuteTestCase(unittest.TestCase):
 1 packets transmitted, 1 received, 0% packet loss, time 0ms
 """
         self.assertTrue(fake_result.startswith(comp_result))
-        self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+        self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+        self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+        self.assertEquals(controller.get_factory_id(node1.guid), "Node")
 
         controller.stop()
         controller.shutdown()
@@ -148,7 +154,10 @@ class ExecuteTestCase(unittest.TestCase):
 1 packets transmitted, 1 received, 0% packet loss, time 0ms
 """
         self.assertTrue(fake_result.startswith(comp_result))
-        self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+        self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+        self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+        self.assertEquals(controller.get_factory_id(node1.guid), "Node")
 
         controller.stop()
         controller.shutdown()
@@ -178,7 +187,10 @@ class ExecuteTestCase(unittest.TestCase):
 1 packets transmitted, 1 received, 0% packet loss, time 0ms
 """
         self.assertTrue(fake_result.startswith(comp_result))
-        self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+        self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+        self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+        self.assertEquals(controller.get_factory_id(node1.guid), "Node")
 
         controller.stop()
         controller.shutdown()
@@ -208,7 +220,10 @@ class ExecuteTestCase(unittest.TestCase):
 1 packets transmitted, 1 received, 0% packet loss, time 0ms
 """
         self.assertTrue(fake_result.startswith(comp_result))
-        self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+        self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+        self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+        self.assertEquals(controller.get_factory_id(node1.guid), "Node")
 
         # controller dies
         del controller