mock cross_connect test added to test/core/integration.py
[nepi.git] / src / nepi / testbeds / netns / execute.py
index 8636677..67dee91 100644 (file)
@@ -3,12 +3,12 @@
 
 from constants import TESTBED_ID
 from nepi.core import testbed_impl
-from nepi.util.constants import AF_INET, AF_INET6
+from nepi.util.constants import TIME_NOW
 import os
 
-class TestbedInstance(testbed_impl.TestbedInstance):
+class TestbedController(testbed_impl.TestbedController):
     def __init__(self, testbed_version):
-        super(TestbedInstance, self).__init__(TESTBED_ID, testbed_version)
+        super(TestbedController, self).__init__(TESTBED_ID, testbed_version)
         self._netns = None
         self._home_directory = None
         self._traces = dict()
@@ -25,45 +25,31 @@ class TestbedInstance(testbed_impl.TestbedInstance):
         self._home_directory = self._attributes.\
             get_attribute_value("homeDirectory")
         self._netns = self._load_netns_module()
+        super(TestbedController, self).do_setup()
 
-    def do_configure(self):
-        # TODO: add traces!
-        # configure addressess
-        for guid, addresses in self._add_address.iteritems():
-            element = self._elements[guid]
-            for address in addresses:
-                (family, address, netprefix, broadcast) = address
-                if family == AF_INET:
-                    element.add_v4_address(address, netprefix)
-        # configure routes
-        for guid, routes in self._add_route.iteritems():
-            element = self._elements[guid]
-            for route in routes:
-                (destination, netprefix, nexthop) = route
-                element.add_route(prefix = destination, prefix_len = netprefix,
-                        nexthop = nexthop)
-
-    def set(self, time, guid, name, value):
-        super(TestbedInstance, self).set(time, guid, name, value)
+    def set(self, guid, name, value, time = TIME_NOW):
+        super(TestbedController, self).set(guid, name, value, time)
         # TODO: take on account schedule time for the task 
-        element = self._elements[guid]
+        element = self._elements.get(guid)
         if element:
             setattr(element, name, value)
 
-    def get(self, time, guid, name):
+    def get(self, guid, name, time = TIME_NOW):
+        value = super(TestbedController, self).get(guid, name, time)
         # TODO: take on account schedule time for the task
-        element = self._elements[guid]
-        return getattr(element, name)
+        factory_id = self._create[guid]
+        factory = self._factories[factory_id]
+        if factory.box_attributes.is_attribute_design_only(name):
+            return value
+        element = self._elements.get(guid)
+        try:
+            return getattr(element, name)
+        except KeyError, AttributeError:
+            return value
 
     def action(self, time, guid, action):
         raise NotImplementedError
 
-    def trace(self, guid, trace_id):
-        f = open(self.trace_filename(guid, trace_id), "r")
-        content = f.read()
-        f.close()
-        return content
-
     def shutdown(self):
         for trace in self._traces.values():
             trace.close()