Beispiel #1
0
 def test_store_and_load_methods(self):
     map = CoordInfo.CoordinationMap()
     c = CoordInfo.CoordinationMapController(map)
     map.add_new_machine('machine')
     map.add_new_instance('machine','instance')
     map.add_new_server(
             'machine',
             'instance',
             'server1',
             ServerType.Login,
             ()
         )
     where = StringIO.StringIO()
     c.store(where)
     c2 = CoordInfo.CoordinationMapController()
     where2 = StringIO.StringIO(where.getvalue())
     c2.load(where2)
     # If this works, everything seems to work :-)
     machine   = c2._map['machine']
     instance  = machine['instance']
     server    = instance['server1']
     server_type_name = server.server_type
     self.assertEquals(
             server_type_name,
             'Login'
         )
     # Let's check locks, too
     the_lock = server._accesses_lock
     self.assertEquals(
             type(the_lock),
             lock.RWLock
         )
Beispiel #2
0
    def __init__(self, cfg_manager, map=None, map_file=None, *args, **kwargs):
        """
        session_type: member of voodoo.sessions.session_type
        map: voodoo.gen.coordinator.CoordinationInformation.CoordinationMap
        map_file: file object

        The parameter session_type must be provided; if "map" parameter is provided, the CoordinatorServer
        uses this map. If map_file is provided, a new CoordinatorMap is created, and loaded from the map_file.
        If no one of these two parameters is provided, a new CoordinatorMap is created, waiting for the method
        "load" to be called. Finally, if both parameters are provided, an exception is raised.
        """
        super(CoordinatorServer, self).__init__(*args, **kwargs)
        session_type = cfg_manager.get_value(
            COORDINATOR_SERVER_SESSION_TYPE,
            DEFAULT_COORDINATOR_SERVER_SESSION_TYPE)
        session_pool_id = cfg_manager.get_value(
            COORDINATOR_SERVER_SESSION_POOL_ID,
            DEFAULT_COORDINATOR_SERVER_SESSION_POOL_ID)
        if session_type in SessionType.getSessionTypeValues():
            self._session_manager = SessionManager.SessionManager(
                cfg_manager, session_type, session_pool_id)
        else:
            raise CoordinatorServerErrors.NotASessionTypeError(
                "Not a session_type: %s" % session_type)
        if map is not None and map_file is None:
            self._coordination_map_controller = CoordinationInformation.CoordinationMapController(
                map)
        elif map is None and map_file is not None:
            self._coordination_map_controller = CoordinationInformation.CoordinationMapController(
            )
            self._coordination_map_controller.load(map_file)
        elif map is not None and map_file is not None:
            raise CoordinatorServerErrors.BothMapAndMapFileProvidedError(
                "Can't provide both map_file and map to CoordinatorServer")
        elif map is None and map_file is None:
            raise CoordinatorServerErrors.NeitherMapNorFileProvidedError(
                "Can't build the Coordination Map if neither map nor map_file fields are provided!"
            )
        else:
            raise RuntimeError(
                "This possibility should never happen -voodoo.gen.coordinator.CoordinatorServer.__init__-"
            )