Beispiel #1
0
    def test_worker_registers_and_deregisters(self):
        pid = random.randint(1, 512)
        self.patch(os, "getpid").return_value = pid
        (
            master,
            connected,
            disconnected,
        ) = self.make_IPCMasterService_with_wrap()
        yield master.startService()
        worker = IPCWorkerService(reactor, socket_path=self.ipc_path)
        yield worker.startService()

        yield connected.get(timeout=2)
        self.assertIn(pid, master.connections)

        def getProcessFromDB():
            region = RegionController.objects.get_running_controller()
            return RegionControllerProcess.objects.get(region=region, pid=pid)

        process = yield deferToDatabase(getProcessFromDB)
        self.assertEquals(process.id, master.connections[pid]["process_id"])

        worker_procId = yield worker.processId.get(timeout=2)
        self.assertEquals(process.id, worker_procId)

        yield worker.stopService()

        yield disconnected.get(timeout=2)
        self.assertEquals({}, master.connections)

        process = yield deferToDatabase(reload_object, process)
        self.assertIsNone(process)

        yield master.stopService()
Beispiel #2
0
    def test_worker_registers_and_unregister_rpc_connection(self):
        yield deferToDatabase(load_builtin_scripts)
        pid = random.randint(1, 512)
        self.patch(os, "getpid").return_value = pid
        (
            master,
            connected,
            disconnected,
        ) = self.make_IPCMasterService_with_wrap()
        rpc_started = self.wrap_async_method(master, "registerWorkerRPC")
        yield master.startService()

        worker = IPCWorkerService(reactor, socket_path=self.ipc_path)
        rpc = RegionService(worker)
        yield worker.startService()
        yield rpc.startService()

        yield connected.get(timeout=2)
        yield rpc_started.get(timeout=2)

        rackd = yield deferToDatabase(factory.make_RackController)
        connid = str(uuid.uuid4())
        address = factory.make_ipv4_address()
        port = random.randint(1000, 5000)
        yield worker.rpcRegisterConnection(connid, rackd.system_id, address,
                                           port)

        def getConnection():
            region = RegionController.objects.get_running_controller()
            process = RegionControllerProcess.objects.get(region=region,
                                                          pid=pid)
            endpoint = RegionControllerProcessEndpoint.objects.get(
                process=process, address=address, port=port)
            return RegionRackRPCConnection.objects.filter(
                endpoint=endpoint, rack_controller=rackd).first()

        connection = yield deferToDatabase(getConnection)
        self.assertIsNotNone(connection)
        self.assertEqual(
            {connid: (rackd.system_id, address, port)},
            master.connections[pid]["rpc"]["connections"],
        )

        yield worker.rpcUnregisterConnection(connid)
        connection = yield deferToDatabase(getConnection)
        self.assertIsNone(connection)

        yield rpc.stopService()
        yield worker.stopService()
        yield disconnected.get(timeout=2)
        yield master.stopService()
Beispiel #3
0
    def test_master_calls_killWorker_on_deregister(self):
        pid = random.randint(1, 512)
        self.patch(os, "getpid").return_value = pid
        workers = MagicMock()
        master, connected, disconnected = self.make_IPCMasterService_with_wrap(
            workers=workers)
        yield master.startService()
        worker = IPCWorkerService(reactor, socket_path=self.ipc_path)
        yield worker.startService()

        yield connected.get(timeout=2)
        yield worker.stopService()
        yield disconnected.get(timeout=2)
        yield master.stopService()

        self.assertThat(workers.killWorker, MockCalledOnceWith(pid))
Beispiel #4
0
    def test_worker_registers_and_deregisters(self):
        pid = random.randint(1, 512)
        self.patch(os, 'getpid').return_value = pid
        master, connected, disconnected = self.make_IPCMasterService()
        yield master.startService()
        worker = IPCWorkerService(reactor, socket_path=self.ipc_path)
        yield worker.startService()

        yield connected.get(timeout=2)
        self.assertIn(pid, master.connections)

        yield worker.stopService()

        yield disconnected.get(timeout=2)
        self.assertEquals({}, master.connections)

        yield master.stopService()
Beispiel #5
0
    def test_worker_registers_rpc_endpoints(self):
        yield deferToDatabase(load_builtin_scripts)
        pid = random.randint(1, 512)
        self.patch(os, "getpid").return_value = pid
        (
            master,
            connected,
            disconnected,
        ) = self.make_IPCMasterService_with_wrap()
        rpc_started = self.wrap_async_method(master, "registerWorkerRPC")
        yield master.startService()

        worker = IPCWorkerService(reactor, socket_path=self.ipc_path)
        rpc = RegionService(worker)
        yield worker.startService()
        yield rpc.startService()

        yield connected.get(timeout=2)
        yield rpc_started.get(timeout=2)

        def getEndpoints():
            region = RegionController.objects.get_running_controller()
            process = RegionControllerProcess.objects.get(region=region,
                                                          pid=pid)
            return set([(endpoint.address, endpoint.port) for endpoint in (
                RegionControllerProcessEndpoint.objects.filter(
                    process=process))])

        endpoints = yield deferToDatabase(getEndpoints)
        self.assertEqual(
            master._getListenAddresses(master.connections[pid]["rpc"]["port"]),
            endpoints,
        )

        yield rpc.stopService()
        yield worker.stopService()
        yield disconnected.get(timeout=2)
        yield master.stopService()