Пример #1
0
    def test_remove_destination(self):
        """Removing a destination should remove it from the router store and
        the list of destinations on the router."""
        router_config = self.create_router_config()
        router = Router(self.api, router_config)

        destination_config = self.create_destination_config()
        destination = router.add_destination(destination_config)

        yield router.save()

        self.assertIn(destination.id, router.destinations)
        self.assertIn(
            destination.id,
            (yield self.api.router_store.get_router_destination_list(
                router.id))
        )

        yield destination.delete()

        self.assertNotIn(destination.id, router.destinations)
        self.assertNotIn(
            destination.id,
            (yield self.api.router_store.get_router_destination_list(
                router.id))
        )
Пример #2
0
    def test_validate_router_config_existing_router(self):
        """
        If an existing router is already listening to the specified channel,
        then a config error should be raised
        """
        channel = yield self.create_channel(self.api.service,
                                            self.redis,
                                            properties={
                                                'type': 'telnet',
                                                'config': {
                                                    'twisted_endpoint':
                                                    'tcp:0',
                                                },
                                            })

        config = self.create_router_config(config={
            'test': 'pass',
            'channel': channel.id
        })
        router = Router(self.api, config)
        yield router.save()
        router.start(self.api.service)

        with self.assertRaises(InvalidRouterConfig) as e:
            yield FromAddressRouter.validate_router_config(
                self.api, {'channel': channel.id})

        self.assertEqual(
            e.exception.message,
            "Router {} is already routing channel {}".format(
                router.id, channel.id))
Пример #3
0
    def test_delete_router(self):
        """Removes the router config from the store"""
        config = self.create_router_config()
        router = Router(self.api, config)
        yield router.save()
        self.assertEqual((yield self.api.router_store.get_router_list()),
                         [router.router_config['id']])

        yield router.delete()
        self.assertEqual((yield self.api.router_store.get_router_list()), [])
Пример #4
0
    def test_delete_router(self):
        """Removes the router config from the store"""
        config = self.create_router_config()
        router = Router(self.api, config)
        yield router.save()
        self.assertEqual(
            (yield self.api.router_store.get_router_list()),
            [router.router_config['id']])

        yield router.delete()
        self.assertEqual((yield self.api.router_store.get_router_list()), [])
Пример #5
0
 def create_router(self, request, body):
     """Create a new router"""
     router = Router(self, body)
     yield router.validate_config()
     router.start(self.service)
     yield router.save()
     returnValue(response(
         request,
         'router created',
         (yield router.status()),
         code=http.CREATED
     ))
Пример #6
0
    def test_from_id(self):
        """from_id should be able to restore a router, given just the id"""
        config = self.create_router_config()
        router = Router(self.api, config)
        yield router.save()
        router.start(self.api.service)

        restored_router = yield Router.from_id(self.api,
                                               router.router_config['id'])

        self.assertEqual(router.router_config, restored_router.router_config)
        self.assertEqual(router.router_worker, restored_router.router_worker)
Пример #7
0
    def test_from_id(self):
        """from_id should be able to restore a router, given just the id"""
        config = self.create_router_config()
        router = Router(self.api, config)
        yield router.save()
        router.start(self.api.service)

        restored_router = yield Router.from_id(
            self.api, router.router_config['id'])

        self.assertEqual(router.router_config, restored_router.router_config)
        self.assertEqual(router.router_worker, restored_router.router_worker)
Пример #8
0
    def test_start_all(self):
        """start_all should start all of the stored routers"""
        config = self.create_router_config()
        router = Router(self.api, config)
        yield router.save()

        yield Router.start_all_routers(self.api)

        router_worker = self.service.namedServices[router.id]
        self.assertEqual(router_worker.parent, self.service)
        router_worker_config = config['config']
        for k, v in router_worker_config.items():
            self.assertEqual(router_worker.config[k], v)
Пример #9
0
    def test_start_all(self):
        """start_all should start all of the stored routers"""
        config = self.create_router_config()
        router = Router(self.api, config)
        yield router.save()

        yield Router.start_all_routers(self.api)

        router_worker = self.service.namedServices[router.id]
        self.assertEqual(router_worker.parent, self.service)
        router_worker_config = config['config']
        for k, v in router_worker_config.items():
            self.assertEqual(router_worker.config[k], v)
Пример #10
0
    def test_destinations_restored_on_router_from_id(self):
        """Creating a router object from id should also restore the
        destinations for that router"""
        router_config = self.create_router_config()
        router = Router(self.api, router_config)
        router.start(self.api.service)
        destination_config = self.create_destination_config()
        destination = router.add_destination(destination_config)
        yield router.save()

        restored_router = yield Router.from_id(self.api, router.id)
        self.assertEqual(router.destinations.keys(),
                         restored_router.destinations.keys())
        self.assertEqual(
            router.destinations[destination.id].destination_config,
            restored_router.destinations[destination.id].destination_config)
Пример #11
0
    def test_destinations_restored_on_router_from_id(self):
        """Creating a router object from id should also restore the
        destinations for that router"""
        router_config = self.create_router_config()
        router = Router(self.api, router_config)
        router.start(self.api.service)
        destination_config = self.create_destination_config()
        destination = router.add_destination(destination_config)
        yield router.save()

        restored_router = yield Router.from_id(self.api, router.id)
        self.assertEqual(
            router.destinations.keys(), restored_router.destinations.keys())
        self.assertEqual(
            router.destinations[destination.id].destination_config,
            restored_router.destinations[destination.id].destination_config)
Пример #12
0
    def test_save(self):
        """save should save the configuration of the router and all the
        destinations into the router store"""
        config = self.create_router_config()
        router = Router(self.api, config)
        dest_config = self.create_destination_config()
        destination = router.add_destination(dest_config)

        self.assertEqual((yield self.api.router_store.get_router_list()), [])
        self.assertEqual(
            (yield self.api.router_store.get_router_destination_list(
                router.id)), [])
        yield router.save()
        self.assertEqual((yield self.api.router_store.get_router_list()),
                         [router.id])
        self.assertEqual(
            (yield self.api.router_store.get_router_destination_list(
                router.id)), [destination.id])
Пример #13
0
    def test_save(self):
        """save should save the configuration of the router and all the
        destinations into the router store"""
        config = self.create_router_config()
        router = Router(self.api, config)
        dest_config = self.create_destination_config()
        destination = router.add_destination(dest_config)

        self.assertEqual((yield self.api.router_store.get_router_list()), [])
        self.assertEqual(
            (yield self.api.router_store.get_router_destination_list(
                router.id)), [])
        yield router.save()
        self.assertEqual(
            (yield self.api.router_store.get_router_list()), [router.id])
        self.assertEqual(
            (yield self.api.router_store.get_router_destination_list(
                router.id)), [destination.id])
Пример #14
0
    def test_remove_destination(self):
        """Removing a destination should remove it from the router store and
        the list of destinations on the router."""
        router_config = self.create_router_config()
        router = Router(self.api, router_config)

        destination_config = self.create_destination_config()
        destination = router.add_destination(destination_config)

        yield router.save()

        self.assertIn(destination.id, router.destinations)
        self.assertIn(destination.id,
                      (yield self.api.router_store.get_router_destination_list(
                          router.id)))

        yield destination.delete()

        self.assertNotIn(destination.id, router.destinations)
        self.assertNotIn(
            destination.id,
            (yield self.api.router_store.get_router_destination_list(
                router.id)))