Ejemplo n.º 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
         )
Ejemplo n.º 2
0
 def test_errors_on_getitems(self):
     map = CoordInfo.CoordinationMap()
     map.add_new_machine('machine')
     map.add_new_instance('machine','instance')
     map.add_new_server(
             'machine',
             'instance',
             'server1',
             ServerType.Login,
             ()
         )
     self.assertRaises(
         CoordErrors.CoordMachineNotFound,
         map.__getitem__,
         'whatever'
     )
     self.assertRaises(
         CoordErrors.CoordInstanceNotFound,
         map['machine'].__getitem__,
         'whatever'
     )
     self.assertRaises(
         CoordErrors.CoordServerNotFound,
         map['machine']['instance'].__getitem__,
         'whatever'
     )
Ejemplo n.º 3
0
    def test_map_operations(self):
        map = CoordInfo.CoordinationMap()
        map.add_new_machine('machine')
        map.add_new_instance('machine','instance')
        map.add_new_server(
                'machine',
                'instance',
                'server1',
                ServerType.Login,
                ()
            )

        machine  = map['machine']
        instance = machine['instance']
        server1  = instance['server1']



        self.assertEquals(server1.status,False)

        server1_copy = server1.copy()
        map.set_status('machine','instance','server1',True)

        self.assertEquals(server1.status,True)
        self.assertEquals(server1_copy.status,False)
Ejemplo n.º 4
0
    def build(self, global_configuration):
        map = CoordInfo.CoordinationMap()

        for machine_name in global_configuration.machines.keys():
            map.add_new_machine(machine_name)
            self._fill_machine(map,
                               global_configuration.machines[machine_name],
                               machine_name)
        return map
Ejemplo n.º 5
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__-"
            )
Ejemplo n.º 6
0
    def test_coord_machine(self):
        map = CoordInfo.CoordinationMap()

        #Creators
        map.add_new_machine('machine')
        map.add_new_instance('machine','instance')
        map.add_new_server(
                'machine',
                'instance',
                'server1',
                ServerType.Login,
                ()
            )

        #Basic __getitem__
        machine     = map['machine']
        instance    = machine['instance']
        server1     = instance['server1']

        #parents
        self.assertEquals(machine.parent,   map)
        self.assertEquals(instance.parent,  machine)
        self.assertEquals(server1.parent,   instance)

        #addresses
        machine_address = CoordAddress.CoordAddress(
                    'machine'
                )

        instance_address = CoordAddress.CoordAddress(
                    'machine',
                    'instance'
                )
        server_address = CoordAddress.CoordAddress(
                    'machine',
                    'instance',
                    'server1'
                )

        self.assertEquals(machine.address,  machine_address)
        self.assertEquals(instance.address, instance_address)
        self.assertEquals(server1.address,  server_address)

        # machine's __getitem__
        self.assertEquals(machine[server_address],server1)
        self.assertEquals(machine['instance'],instance)
        self.assertEquals(
                machine[server_address.get_instance_address()],
                instance
            )

        # instance's __getitem__
        self.assertEquals(instance['server1'],server1)
        self.assertEquals(instance[server_address],server1)
Ejemplo n.º 7
0
    def test_iterators(self):
        map = CoordInfo.CoordinationMap()

        #Creators
        map.add_new_machine('machine')
        map.add_new_instance('machine','instance')
        map.add_new_server(
                'machine',
                'instance',
                'server1',
                ServerType.Login,
                ()
            )


        machine     = map['machine']
        instance    = machine['instance']
        server1     = instance['server1']

        y = instance.get_servers()

        next = y.next()
        self.assertEquals(next,server1)

        map.add_new_server(
                'machine',
                'instance',
                'server2',
                ServerType.Login,
                ()
            )
        server2     = instance['server2']

        next = y.next()
        self.assertEquals(next,server2)
        self.assertRaises(StopIteration,y.next)
Ejemplo n.º 8
0
def create_coordinator_map():
    map = CoordInfo.CoordinationMap()

    login_t = SampleServerType.Login
    map.add_new_machine('machine0')
    map.add_new_instance('machine0', 'instance0')
    map.add_new_server('machine0', 'instance0', 'server0', login_t, ())
    map.add_new_server('machine0', 'instance0', 'server1', login_t, ())

    map.add_new_instance('machine0', 'instance1')
    map.add_new_server('machine0', 'instance1', 'server0', login_t, ())

    map.add_new_machine('machine1')
    map.add_new_instance('machine1', 'instance0')
    map.add_new_server('machine1', 'instance0', 'server0', login_t, ())

    # 4 servers
    # We are in machine0, instance0, server0

    # They all have Direct

    # 1st: address
    address1 = map['machine0']['instance0']['server0'].address
    address2 = map['machine0']['instance0']['server1'].address
    address3 = map['machine0']['instance1']['server0'].address
    address4 = map['machine1']['instance0']['server0'].address

    # 2nd: network
    direct_network1 = DirectNetwork.DirectNetwork(
        DirectAddress.from_coord_address(address1))
    direct_network2 = DirectNetwork.DirectNetwork(
        DirectAddress.from_coord_address(address2))
    direct_network3 = DirectNetwork.DirectNetwork(
        DirectAddress.from_coord_address(address3))
    direct_network4 = DirectNetwork.DirectNetwork(
        DirectAddress.from_coord_address(address4))

    # 3rd: accesses
    access_direct1 = Access.Access(Protocols.Direct, AccessLevel.instance,
                                   (direct_network1, ))
    access_direct2 = Access.Access(Protocols.Direct, AccessLevel.instance,
                                   (direct_network2, ))
    access_direct3 = Access.Access(Protocols.Direct, AccessLevel.instance,
                                   (direct_network3, ))
    access_direct4 = Access.Access(Protocols.Direct, AccessLevel.instance,
                                   (direct_network4, ))

    # 4th: appending accesses
    map.append_accesses('machine0', 'instance0', 'server0', (access_direct1, ))
    map.append_accesses('machine0', 'instance0', 'server1', (access_direct2, ))
    map.append_accesses('machine0', 'instance1', 'server0', (access_direct3, ))
    map.append_accesses('machine1', 'instance0', 'server0', (access_direct4, ))

    # They all have SOAP

    # 1st: address
    server_ip_address1 = SOAPAddress.Address('127.0.0.1:9025@NETWORK')
    server_ip_address2 = SOAPAddress.Address('127.0.0.1:9026@NETWORK')
    server_ip_address3 = SOAPAddress.Address('127.0.0.1:9027@NETWORK')
    server_ip_address4 = SOAPAddress.Address('127.0.0.1:9028@NETWORK')

    # 2nd: network
    soap_network1 = SOAPNetwork.SOAPNetwork(server_ip_address1)
    soap_network2 = SOAPNetwork.SOAPNetwork(server_ip_address2)
    soap_network3 = SOAPNetwork.SOAPNetwork(server_ip_address3)
    soap_network4 = SOAPNetwork.SOAPNetwork(server_ip_address4)

    # 3rd: accesses
    access_soap1 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                 (soap_network1, ))
    access_soap2 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                 (soap_network2, ))
    access_soap3 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                 (soap_network3, ))
    access_soap4 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                 (soap_network4, ))

    # 4th: appending accesses
    map.append_accesses('machine0', 'instance0', 'server0', (access_soap1, ))
    map.append_accesses('machine0', 'instance0', 'server1', (access_soap2, ))
    map.append_accesses('machine0', 'instance1', 'server0', (access_soap3, ))
    map.append_accesses('machine1', 'instance0', 'server0', (access_soap4, ))
    return map
Ejemplo n.º 9
0
        def test_simple_soap_server(self):
            cfg_manager = ConfigurationManager.ConfigurationManager()
            cfg_manager.append_module(configuration_module)

            map = CoordInfo.CoordinationMap()

            login_t = SampleServerType.Login
            coordinator_t = SampleServerType.Coordinator
            map.add_new_machine('machine0')
            map.add_new_instance('machine0', 'instance0')
            map.add_new_server('machine0', 'instance0', 'server0',
                               coordinator_t, ())
            map.add_new_server('machine0', 'instance0', 'server1', login_t, ())

            # 1st: address
            server_ip_address1 = SOAPAddress.Address('127.0.0.1:12349@NETWORK')
            server_ip_address2 = SOAPAddress.Address('127.0.0.1:12350@NETWORK')

            # 2nd: network
            soap_network1 = SOAPNetwork.SOAPNetwork(server_ip_address1)
            soap_network2 = SOAPNetwork.SOAPNetwork(server_ip_address2)

            # 3rd: accesses
            access_soap1 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network1, ))
            access_soap2 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network2, ))

            # 4th: appending accesses
            map.append_accesses('machine0', 'instance0', 'server0',
                                (access_soap1, ))
            map.append_accesses('machine0', 'instance0', 'server1',
                                (access_soap2, ))

            # Generating real servers
            # Coordinator must implement Protocols.Direct too
            # in order to be used by the local locator
            generated_coordinator = ServerSkel.factory(
                cfg_manager, (Protocols.Direct, Protocols.SOAP),
                coordinator_methods)

            class RealCoordinatorServer(CoordinatorServer.CoordinatorServer,
                                        generated_coordinator):
                def __init__(self, cfg_manager, map, *args, **kargs):
                    CoordinatorServer.CoordinatorServer.__init__(
                        self, cfg_manager, map, *args, **kargs)

            coordinator_server_address = DirectAddress.Address(
                "machine0", "instance0", "server0")

            s1 = RealCoordinatorServer(
                cfg_manager,
                map,
                Direct=(coordinator_server_address.address, ),
                SOAP=('', 12349))
            s1.start()

            generated_login = ServerSkel.factory(cfg_manager, Protocols.SOAP,
                                                 login_methods)

            class RealLoginServer(generated_login):
                def do_method1(self, arg):
                    return arg * 3

            s2 = RealLoginServer(SOAP=('', 12350))
            s2.start()

            server_type_handler = ServerTypeHandler.ServerTypeHandler(
                SampleServerType, {
                    'Login': login_methods,
                    'Coordinator': coordinator_methods,
                    'YetAnother': []
                })

            locator = ServerLocator.ServerLocator(coordinator_server_address,
                                                  server_type_handler)
            login_server = locator.get_server(
                coordinator_server_address.address, SampleServerType.Login,
                None)

            msg = "test_simple_soap_server"
            answer = login_server.method1(msg)
            self.assertEquals(msg * 3, answer)
Ejemplo n.º 10
0
        def test_with_coordinator(self):
            cfg_manager = ConfigurationManager.ConfigurationManager()
            cfg_manager.append_module(configuration_module)

            map = CoordInfo.CoordinationMap()

            login_t = SampleServerType.Login
            map.add_new_machine('machine0')
            map.add_new_instance('machine0', 'instance0')
            map.add_new_server('machine0', 'instance0', 'server0', login_t, ())
            map.add_new_server('machine0', 'instance0', 'server1', login_t, ())

            map.add_new_instance('machine0', 'instance1')
            map.add_new_server('machine0', 'instance1', 'server0', login_t, ())

            map.add_new_machine('machine1')
            map.add_new_instance('machine1', 'instance0')
            map.add_new_server('machine1', 'instance0', 'server0', login_t, ())

            # 4 servers
            # We are in machine0, instance0, server0

            # They all have Direct

            # 1st: address
            address1 = map['machine0']['instance0']['server0'].address
            address2 = map['machine0']['instance0']['server1'].address
            address3 = map['machine0']['instance1']['server0'].address
            address4 = map['machine1']['instance0']['server0'].address

            # 2nd: network
            direct_network1 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address1))
            direct_network2 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address2))
            direct_network3 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address3))
            direct_network4 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address4))

            # 3rd: accesses
            access_direct1 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network1, ))
            access_direct2 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network2, ))
            access_direct3 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network3, ))
            access_direct4 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network4, ))

            # 4th: appending accesses
            map.append_accesses('machine0', 'instance0', 'server0',
                                (access_direct1, ))
            map.append_accesses('machine0', 'instance0', 'server1',
                                (access_direct2, ))
            map.append_accesses('machine0', 'instance1', 'server0',
                                (access_direct3, ))
            map.append_accesses('machine1', 'instance0', 'server0',
                                (access_direct4, ))

            # They all have SOAP

            # 1st: address
            server_ip_address1 = SOAPAddress.Address('127.0.0.1:12345@NETWORK')
            server_ip_address2 = SOAPAddress.Address('127.0.0.1:12346@NETWORK')
            server_ip_address3 = SOAPAddress.Address('127.0.0.1:12347@NETWORK')
            server_ip_address4 = SOAPAddress.Address('127.0.0.1:12348@NETWORK')

            # 2nd: network
            soap_network1 = SOAPNetwork.SOAPNetwork(server_ip_address1)
            soap_network2 = SOAPNetwork.SOAPNetwork(server_ip_address2)
            soap_network3 = SOAPNetwork.SOAPNetwork(server_ip_address3)
            soap_network4 = SOAPNetwork.SOAPNetwork(server_ip_address4)

            # 3rd: accesses
            access_soap1 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network1, ))
            access_soap2 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network2, ))
            access_soap3 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network3, ))
            access_soap4 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network4, ))

            # 4th: appending accesses
            map.append_accesses('machine0', 'instance0', 'server0',
                                (access_soap1, ))
            map.append_accesses('machine0', 'instance0', 'server1',
                                (access_soap2, ))
            map.append_accesses('machine0', 'instance1', 'server0',
                                (access_soap3, ))
            map.append_accesses('machine1', 'instance0', 'server0',
                                (access_soap4, ))

            direct_coordinator = ServerSkel.factory(
                cfg_manager, (Protocols.Direct, Protocols.SOAP),
                coordinator_methods)

            class YetAnother(CoordinatorServer.CoordinatorServer,
                             direct_coordinator):
                def __init__(self, cfg_manager, map, *args, **kargs):
                    CoordinatorServer.CoordinatorServer.__init__(
                        self, cfg_manager, map, *args, **kargs)

            direct_login = ServerSkel.factory(
                cfg_manager, (Protocols.Direct, Protocols.SOAP), login_methods)
            coordinator_server_address = DirectAddress.Address(
                "machine0", "instance0", "server0")

            s1 = YetAnother(cfg_manager,
                            map,
                            Direct=(coordinator_server_address.address, ),
                            SOAP=('', 12345))
            s1.start()

            class YetAnother2(direct_login):
                def do_method1(self, arg):
                    return arg * 3

            s2 = YetAnother2(Direct=(address2.address, ), SOAP=('', 12346))
            s2.start()

            server_type_handler = ServerTypeHandler.ServerTypeHandler(
                SampleServerType, {
                    'Login': login_methods,
                    'Coordinator': coordinator_methods,
                    'YetAnother': []
                })

            locator = ServerLocator.ServerLocator(coordinator_server_address,
                                                  server_type_handler)
            login_server = locator.get_server(
                coordinator_server_address.address, SampleServerType.Login,
                None)

            full_name = '%s.%s' % (login_server.__class__.__module__,
                                   login_server.__class__.__name__)
            self.assertEquals(
                'voodoo.gen.protocols.Direct.ClientDirect.ClientDirect',
                full_name)

            msg = "hello"
            answer = login_server.method1(msg)
            self.assertEquals(msg * 3, answer)

            other_login_server = locator.get_server(
                coordinator_server_address.address, SampleServerType.Login,
                None)

            # It will ask for it from the cache
            self.assertEquals(login_server, other_login_server)

            # Let's say that the login server is broken
            locator.inform_server_not_working(login_server,
                                              SampleServerType.Login, None)

            old_test_me = YetAnother2.do_test_me

            def wrong_test_me(self, arg):
                YetAnother2.do_test_me = old_test_me
                return arg * 2

            YetAnother2.do_test_me = wrong_test_me

            yet_another_login_server = locator.get_server(
                coordinator_server_address.address, SampleServerType.Login,
                None)

            self.assertNotEquals(login_server, yet_another_login_server)

            full_name = '%s.%s' % (
                yet_another_login_server.__class__.__module__,
                yet_another_login_server.__class__.__name__)
            self.assertEquals(
                'voodoo.gen.protocols.SOAP.ClientSOAP.ClientSOAP', full_name)

            answer = yet_another_login_server.method1(msg)
            self.assertEquals(msg * 3, answer)

            def wrong_test_me_forever(self, arg):
                return arg * 2

            YetAnother2.do_test_me = wrong_test_me_forever

            locator.inform_server_not_working(yet_another_login_server,
                                              SampleServerType.Login, None)

            return  # TODO:

            # YetAnother2 doesn't work anymore, and the other two ports are not going to work
            self.assertRaises(LocatorErrors.NoServerFoundError,
                              locator.get_server,
                              coordinator_server_address.address,
                              SampleServerType.Login, None)
Ejemplo n.º 11
0
    def test_get_servers(self):
        # Create map, machine and instance
        map = CoordInfo.CoordinationMap()


        # Create servers

        # There are gonna be:
        # 2 machines, each machine with:
        # 2 instances, each instance with:
        # 2 servers, one of Login, the other of Coordinator. each one has:
        # 2 protocols
        #
        # 1st protocol) direct network
        # 2nd protocol) SOAP network, with IP number:
        #       192.168.0.$(machine_number):$(PORT):NETWORK
        #

        for machine_num in range(2):
            map.add_new_machine('machine' + str(machine_num))
            for instance_num in range(2):
                map.add_new_instance(
                        'machine' + str(machine_num),
                        'instance' + str(instance_num)
                    )
                for server_num in range(2):
                    if server_num % 2 == 0:
                        server_type = ServerType.Login
                    else:
                        server_type = ServerType.Coordinator

                    map.add_new_server(
                        'machine' + str(machine_num),
                        'instance' + str(instance_num),
                        'server' + str(server_num),
                        server_type,
                        ()
                    )
                    # 1st: address
                    address = map['machine' + str(machine_num)
                        ]['instance' + str(instance_num)
                        ]['server' + str(server_num)
                        ].address
                    # 2nd: network
                    dir_addr = DirectAddress.from_coord_address(address)
                    network = DirectNetwork.DirectNetwork(
                        dir_addr
                    )

                    # 3rd: access
                    access_direct = Access.Access(
                                Protocols.Direct,
                                AccessLevel.instance,
                                (network,)
                            )
                    # 1st: address
                    server_ip_address1 = SOAPAddress.Address(
                        '192.168.0.%i:%i@NETWORK'
                        % (
                            machine_num + 1,
                            8000 + machine_num * 100
                            + instance_num * 10
                            + server_num
                        )
                    )
                    # 2nd: network
                    server_soap_network1 = SOAPNetwork.SOAPNetwork(
                        server_ip_address1
                    )

                    # access
                    access_soap = Access.Access(
                            Protocols.SOAP,
                            AccessLevel.network,
                            (
                                server_soap_network1,
                            )
                        )

                    # append accesses to the server
                    map.append_accesses(
                        'machine' + str(machine_num),
                        'instance' + str(instance_num),
                        'server' + str(server_num),
                        (
                            access_direct,
                            access_soap
                        )
                    )

        server = map['machine1']['instance0']['server0']
        it = map.get_servers(server,ServerType.Coordinator)

        server,networks  = it.next()
        self.assertEquals(server,map['machine1']['instance0']['server1'])
        self.assertEquals(len(networks),2)
        self.assertEquals(
                networks[0].address.address,
                'server1:instance0@machine1'
            )
        self.assertEquals(
                networks[1].address.address,
                '192.168.0.2:8101'
            )

        server,networks  = it.next()
        self.assertEquals(server,map['machine1']['instance1']['server1'])
        self.assertEquals(len(networks),1)
        self.assertEquals(
                networks[0].address.address,
                '192.168.0.2:8111'
            )

        server,networks  = it.next()
        self.assertEquals(server,map['machine0']['instance0']['server1'])
        self.assertEquals(len(networks),1)
        self.assertEquals(
                networks[0].address.address,
                '192.168.0.1:8001'
            )

        server,networks  = it.next()
        self.assertEquals(len(networks),1)
        self.assertEquals(server,map['machine0']['instance1']['server1'])
        self.assertEquals(
                networks[0].address.address,
                '192.168.0.1:8011'
            )

        self.assertRaises(StopIteration,it.next)
Ejemplo n.º 12
0
    def test_accesses(self):
        # Create map, machine and instance
        map = CoordInfo.CoordinationMap()
        map.add_new_machine('machine')
        map.add_new_instance('machine','instance')
        # Create servers
        map.add_new_server(
                'machine',
                'instance',
                'server1',
                ServerType.Login,
                ()
            )
        map.add_new_server(
                'machine',
                'instance',
                'server2',
                ServerType.Login,
                ()
            )

        # Create accesses for server1

        # 1st: address
        server1_address = map['machine']['instance']['server1'].address

        # 2nd: network
        server1_direct_address = DirectAddress.from_coord_address(server1_address)
        server1_direct_network = DirectNetwork.DirectNetwork(server1_direct_address)

        # 3rd: access
        access1_direct = Access.Access(
                    Protocols.Direct,
                    AccessLevel.instance,
                    (server1_direct_network,)
                )

        # 1st: address
        server1_ip_address1 = SOAPAddress.Address(
                '192.168.0.1:8080@NETWORK1'
            )
        # 2nd: network
        server1_soap_network1 = SOAPNetwork.SOAPNetwork(
                server1_ip_address1
            )

        # 1st: address
        server1_ip_address2 = SOAPAddress.Address(
                '130.206.137.60:8080@NETWORK2'
            )

        # 2nd: network
        server1_soap_network2 = SOAPNetwork.SOAPNetwork(
                server1_ip_address2
            )

        # access (with two networks)
        access1_soap = Access.Access(
                    Protocols.SOAP,
                    AccessLevel.network,
                    (
                        server1_soap_network1,
                        server1_soap_network2
                    )
                )

        # append accesses to the server
        map.append_accesses('machine', 'instance', 'server1',
                (
                    access1_direct,
                    access1_soap
                )
            )

        # Same with the other server
        server2_address = map['machine']['instance']['server2'].address
        server2_direct_address = DirectAddress.from_coord_address(server2_address)
        server2_direct_network = DirectNetwork.DirectNetwork(server2_direct_address)


        access2_direct = Access.Access(
                    Protocols.Direct,
                    AccessLevel.instance,
                    (server2_direct_network,)
                )

        # 1st: address
        server2_ip_address1 = SOAPAddress.Address(
                '192.168.0.2:8080@NETWORK1'
            )
        # 2nd: network
        server2_soap_network1 = SOAPNetwork.SOAPNetwork(
                server2_ip_address1
            )

        # 1st: address
        server2_ip_address2 = SOAPAddress.Address(
                '130.206.137.61:8080@NETWORK3'
            )

        # 2nd: network
        server2_soap_network2 = SOAPNetwork.SOAPNetwork(
                server2_ip_address2
            )

        access2_soap = Access.Access(
                    Protocols.SOAP,
                    AccessLevel.network,
                    (
                        server2_soap_network1,
                        server2_soap_network2
                    )
                )

        map.append_accesses('machine', 'instance', 'server2',
                (
                    access2_direct,
                    access2_soap
                )
            )

        # Now, check results

        server1 = map[server1_address]
        server2 = map[server2_address]

        networks = server1.can_connect(server2)
        # There should be only 2 networks (130.206.137.61:8080@NETWORK3 is
        # at NETWORK3, which is different to 130.206.137.60)
        self.assertEquals(len(networks),2)
        # First one: the direct one
        self.assertEquals(networks[0].address.address,'server2:instance@machine')
        # Second one: the network one
        self.assertEquals(networks[1].address.address,'192.168.0.2:8080')

        # Let's try exceptions...

        # Machine does not exist
        self.assertRaises(
                CoordErrors.CoordMachineNotFound,
                map.add_new_instance,
                'machine_not_exists',
                'instanceX'
            )

        # Instance does not exist
        self.assertRaises(
                CoordErrors.CoordInstanceNotFound,
                map.add_new_server,
                'machine',
                'instance_not_exists',
                'server',
                ServerType.Login,
                ()
            )

        # Server does not exist
        self.assertRaises(
                CoordErrors.CoordServerNotFound,
                map.append_accesses,
                'machine',
                'instance',
                'server_not_exists',
                ()
            )

        # Invalid key
        self.assertRaises(
                CoordErrors.CoordInvalidKey,
                lambda : map[5])

        self.assertRaises(CoordErrors.CoordInvalidKey,
                lambda : map['machine'][5])

        self.assertRaises(CoordErrors.CoordInvalidKey,
                lambda : map['machine']['instance'][5])
Ejemplo n.º 13
0
    def gen_coordination_map(self, protocols):
        map = CoordInfo.CoordinationMap()

        map.add_new_machine('WL_MACHINE1')
        map.add_new_instance('WL_MACHINE1', 'WL_SERVER1')
        map.add_new_server('WL_MACHINE1', 'WL_SERVER1', 'login1',
                           ServerType.Login, ())
        map.add_new_server('WL_MACHINE1', 'WL_SERVER1', 'ups1',
                           ServerType.UserProcessing, ())
        map.add_new_server('WL_MACHINE1', 'WL_SERVER1', 'coordinator1',
                           ServerType.Coordinator, ())
        map.add_new_server('WL_MACHINE1', 'WL_SERVER1', 'laboratory1',
                           ServerType.Laboratory, ())
        map.add_new_server('WL_MACHINE1', 'WL_SERVER1', 'experiment1',
                           ServerType.Experiment, (),
                           ('ud-fpga@FPGA experiments', ))
        map.add_new_server('WL_MACHINE1', 'WL_SERVER1', 'experiment2',
                           ServerType.Experiment, (),
                           ('ud-pld@PLD experiments', ))

        if len(protocols) == 1 and protocols[0] == Protocols.Direct:
            # They all have Direct

            # 1st: address
            address1 = map['WL_MACHINE1']['WL_SERVER1']['login1'].address
            address2 = map['WL_MACHINE1']['WL_SERVER1']['ups1'].address
            address3 = map['WL_MACHINE1']['WL_SERVER1']['coordinator1'].address
            address5 = map['WL_MACHINE1']['WL_SERVER1']['laboratory1'].address
            address7 = map['WL_MACHINE1']['WL_SERVER1']['experiment1'].address
            address8 = map['WL_MACHINE1']['WL_SERVER1']['experiment2'].address

            # 2nd: network
            direct_network1 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address1))
            direct_network2 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address2))
            direct_network3 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address3))
            direct_network5 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address5))
            direct_network7 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address7))
            direct_network8 = DirectNetwork.DirectNetwork(
                DirectAddress.from_coord_address(address8))

            # 3rd: accesses
            access_direct1 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network1, ))
            access_direct2 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network2, ))
            access_direct3 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network3, ))
            access_direct5 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network5, ))
            access_direct7 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network7, ))
            access_direct8 = Access.Access(Protocols.Direct,
                                           AccessLevel.instance,
                                           (direct_network8, ))

            # 4th: appending accesses
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'login1',
                                (access_direct1, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'ups1',
                                (access_direct2, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'coordinator1',
                                (access_direct3, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'laboratory1',
                                (access_direct5, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'experiment1',
                                (access_direct7, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'experiment2',
                                (access_direct8, ))

        else:
            # They all have SOAP

            # 1st: address
            address1 = SOAPAddress.Address('127.0.0.1:10025@NETWORK')
            address2 = SOAPAddress.Address('127.0.0.1:10026@NETWORK')
            address3 = SOAPAddress.Address('127.0.0.1:10027@NETWORK')
            address5 = SOAPAddress.Address('127.0.0.1:10029@NETWORK')
            address7 = SOAPAddress.Address('127.0.0.1:10031@NETWORK')
            address8 = SOAPAddress.Address('127.0.0.1:10032@NETWORK')

            # 2nd: network
            soap_network1 = SOAPNetwork.SOAPNetwork(address1)
            soap_network2 = SOAPNetwork.SOAPNetwork(address2)
            soap_network3 = SOAPNetwork.SOAPNetwork(address3)
            soap_network5 = SOAPNetwork.SOAPNetwork(address5)
            soap_network7 = SOAPNetwork.SOAPNetwork(address7)
            soap_network8 = SOAPNetwork.SOAPNetwork(address8)

            # 3rd: accesses
            access_soap1 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network1, ))
            access_soap2 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network2, ))
            access_soap3 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network3, ))
            access_soap5 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network5, ))
            access_soap7 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network7, ))
            access_soap8 = Access.Access(Protocols.SOAP, AccessLevel.network,
                                         (soap_network8, ))

            # 4th: appending accesses
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'login1',
                                (access_soap1, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'ups1',
                                (access_soap2, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'coordinator1',
                                (access_soap3, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'laboratory1',
                                (access_soap5, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'experiment1',
                                (access_soap7, ))
            map.append_accesses('WL_MACHINE1', 'WL_SERVER1', 'experiment2',
                                (access_soap8, ))

        return map