예제 #1
0
    def setUp(self):
        # Create a random bus
        self.tmp_queue = TemporaryQueue(__class__.__name__)
        self.tmp_queue.open()
        self.addCleanup(self.tmp_queue.close)

        self.notification_bus = self.tmp_queue.create_tobus()
        self.notification_bus.open()
        self.addCleanup(self.notification_bus.close)

        # ================================
        # Global state to manipulate
        # ================================

        global otdb_predecessors
        otdb_predecessors = {
            1: [2, 3, 4],
            2: [3],
            3: [],
            4: [],
        }

        global otdb_status
        otdb_status = {
            1:
            "scheduled",  # cannot start, since predecessor 2 hasn't finished
            2: "scheduled",  # can start, since predecessor 3 has finished
            3: "finished",
            4: "scheduled",  # can start, because no predecessors
        }

        # Setup mock otdb service
        service = RPCService(
            service_name=DEFAULT_OTDB_SERVICENAME,
            handler_type=MockOTDBService,
            handler_kwargs={"notification_bus": self.notification_bus})
        service.start_listening()
        self.addCleanup(service.stop_listening)

        # ================================
        # Setup mock ra service
        #
        # Note that RA IDs are the same as
        # OTDB IDs + 1000 in this test.
        # ================================

        service = RPCService(service_name=DEFAULT_RAS_SERVICENAME,
                             handler_type=MockRAService,
                             handler_kwargs={
                                 "predecessors": otdb_predecessors,
                                 "status": otdb_status
                             })
        service.start_listening()
        self.addCleanup(service.stop_listening)
예제 #2
0
    def setUp(self):
        self.temp_exchange = TemporaryExchange(__class__.__name__)
        self.temp_exchange.open()
        self.addCleanup(self.temp_exchange.close)

        self.notification_bus = self.temp_exchange.create_tobus()
        self.notification_bus.open()
        self.addCleanup(self.notification_bus.close)

        # Patch SLURM
        class MockSlurm(object):
            def __init__(self):
                self.scheduled_jobs = {}

            def submit(self, job_name, *args, **kwargs):
                logger.info("Schedule SLURM job '%s': %s, %s", job_name, args,
                            kwargs)

                self.scheduled_jobs[job_name] = (args, kwargs)

                # Return fake job ID
                return "42"

            def isQueuedOrRunning(self, otdb_id):
                return str(otdb_id) in self.scheduled_jobs

        self.mock_slurm = MockSlurm()
        patcher = patch('lofar.mac.PipelineControl.Slurm')
        patcher.start().return_value = self.mock_slurm
        self.addCleanup(patcher.stop)

        # Catch functions to prevent running executables
        patcher = patch('lofar.mac.PipelineControl.Parset.dockerImage')
        patcher.start().return_value = "lofar-pipeline:trunk"
        self.addCleanup(patcher.stop)

        # ================================
        # Global state to manipulate
        # ================================

        global otdb_predecessors
        otdb_predecessors = {
            1: [2, 3, 4],
            2: [3],
            3: [],
            4: [],
        }

        global otdb_status
        otdb_status = {
            1: "prescheduled",
            2: "prescheduled",
            3: "prescheduled",
            4: "prescheduled",
        }

        service = RPCService(
            service_name=DEFAULT_OTDB_SERVICENAME,
            exchange=self.temp_exchange.address,
            handler_type=MockOTDBService,
            handler_kwargs={"notification_bus": self.notification_bus})
        service.start_listening()
        self.addCleanup(service.stop_listening)

        # ================================
        # Setup mock ra service
        # ================================

        service = RPCService(service_name=DEFAULT_RAS_SERVICENAME,
                             exchange=self.temp_exchange.address,
                             handler_type=MockRAService,
                             handler_kwargs={
                                 "predecessors": otdb_predecessors,
                                 "status": otdb_status
                             })
        service.start_listening()
        self.addCleanup(service.stop_listening)