Ejemplo n.º 1
0
    def test_get_experiment_uses_by_id_notfound(self):
        reservations, usages = self._store_two_reservations()

        reservation1 = self._reserve_experiment()
        reservation2 = self._reserve_experiment()

        db_sess_id = ValidDatabaseSessionId('student1', "student")

        sess_id, _ = self.ups._reserve_session(db_sess_id)
        with wlcontext(self.ups, session_id=sess_id):
            experiment_results = core_api.get_experiment_uses_by_id(
                (reservations[0], reservation1, reservation2))

            self.assertEquals(3, len(experiment_results))

            # reservation_id1 is for student1, so it returns a real object (with a real experiment_use_id)
            self.assertTrue(experiment_results[0].is_finished())
            experiment_results[0].experiment_use.experiment_use_id = None
            self.assertEquals(
                FinishedReservationResult(usages[0].load_files('.')),
                experiment_results[0])

            # reservation_id2 is for student2, and the session is for student1, so it returns None
            self.assertTrue(experiment_results[1].is_alive())
            self.assertTrue(experiment_results[2].is_alive())
Ejemplo n.º 2
0
    def _process_use(self, use, reservation_id):
        """Given a reservation_id not present in the usage db, check if it is still running or waiting, or it did never enter the system"""
        if use is not None:
            if use == self._db_manager.forbidden_access:
                return ForbiddenReservationResult()
            if use.end_date is None:
                log.log(
                    UserProcessor, log.level.Debug,
                    "Reservation %s is running since end_time is None" %
                    reservation_id)
                return RunningReservationResult()
            storage_path = self._cfg_manager.get_value(
                'core_store_students_programs_path')
            use.load_files(storage_path)
            return FinishedReservationResult(use)

        try:
            # We don't actually care about the result. The question is: has it expired or is it running?
            status = self._coordinator.get_reservation_status(
                reservation_id.id)
            if status.status in WebLabSchedulingStatus.NOT_USED_YET_EXPERIMENT_STATUS:
                return WaitingReservationResult()
            else:
                log.log(
                    UserProcessor, log.level.Debug,
                    "Reservation %s is running due to status %r" %
                    (reservation_id, status))
                return RunningReservationResult()
        except coord_exc.ExpiredSessionError, ese:
            log.log(
                UserProcessor, log.level.Debug,
                "Reservation %s is cancelled due to expired session: %s" %
                (reservation_id, ese))
            return CancelledReservationResult()
Ejemplo n.º 3
0
    def test_get_experiment_use_by_id_found(self):
        reservations, usages = self._store_two_reservations()

        db_sess_id = DatabaseSession.ValidDatabaseSessionId('student1', "student")

        sess_id, _ = self.ups.do_reserve_session(db_sess_id)
        finished_result = self.ups.get_experiment_use_by_id(sess_id, reservations[0])

        self.assertTrue( finished_result.is_finished() )

        # reservation_id1 is for student1, so it returns a real object (with a real experiment_use_id)
        finished_result.experiment_use.experiment_use_id = None
        self.assertEquals(FinishedReservationResult(usages[0].load_files('.')), finished_result)
Ejemplo n.º 4
0
    def test_get_experiment_uses_by_id_found(self):
        reservations, usages = self._store_two_reservations()

        db_sess_id = DatabaseSession.ValidDatabaseSessionId('student1', "student")

        sess_id, _ = self.ups.do_reserve_session(db_sess_id)
        experiment_results = self.ups.get_experiment_uses_by_id(sess_id, reservations)
        
        self.assertEquals(2, len(experiment_results))

        self.assertTrue( experiment_results[0].is_finished() )
        # reservation_id1 is for student1, so it returns a real object (with a real experiment_use_id)
        experiment_results[0].experiment_use.experiment_use_id = None
        self.assertEquals(FinishedReservationResult(usages[0].load_files('.')), experiment_results[0])

        # reservation_id2 is for student2, and the session is for student1, so it is forbidden
        self.assertTrue(experiment_results[1].is_forbidden())
Ejemplo n.º 5
0
    def test_get_experiment_uses_by_id(self):
        port = 15131
        self.configurationManager._set_value(self.rfs.FACADE_JSON_PORT, port)
        self.rfs.start()
        try:
            client = WebLabDeustoClient("http://localhost:%s/weblab/" % port)

            expected_sess_id = SessionId.SessionId("whatever")
            expected_usage = ExperimentUsage(10, time.time(), time.time(), '127.0.0.1', ExperimentId("exp","cat"), 'reser1', CoordAddress('machine','instance','server'))

            command_sent = CommandSent(Command.Command("request"), time.time(), Command.Command("response"), time.time())
            expected_usage.append_command(command_sent)

            loaded_file_sent = LoadedFileSent('content-of-the-file', time.time(), Command.Command("response"), time.time(), 'program')
            expected_usage.append_file(loaded_file_sent)

            expected_finished_result  = FinishedReservationResult(expected_usage)
            expected_alive_result     = RunningReservationResult()
            expected_cancelled_result = CancelledReservationResult()

            self.mock_server.return_values['get_experiment_uses_by_id'] = (expected_finished_result, expected_alive_result, expected_cancelled_result)

            expected_reservations = (SessionId.SessionId('reservation'), SessionId.SessionId('reservation2'), SessionId.SessionId('reservation3') )

            results = client.get_experiment_uses_by_id(expected_sess_id, expected_reservations)

            self.assertEquals( expected_sess_id.id, self.mock_server.arguments['get_experiment_uses_by_id'][0])
            self.assertEquals( expected_reservations, tuple(self.mock_server.arguments['get_experiment_uses_by_id'][1]))


            self.assertEquals(3, len(results))
            self.assertEquals(expected_finished_result.status,  results[0].status)
            self.assertEquals(expected_alive_result.status,     results[1].status)
            self.assertEquals(expected_cancelled_result.status, results[2].status)

            self.assertEquals(expected_usage, results[0].experiment_use)

        finally:
            self.rfs.stop()
Ejemplo n.º 6
0
    def test_return_get_experiment_uses_by_id(self):
        expected_sess_id = SessionId.SessionId("whatever")

        expected_usage = ExperimentUsage(10, time.time(),
                                         time.time(), '127.0.0.1',
                                         ExperimentId("exp", "cat"))

        command_sent = CommandSent(Command.Command("request"), time.time(),
                                   Command.Command("response"), time.time())
        expected_usage.append_command(command_sent)

        loaded_file_sent = LoadedFileSent('content-of-the-file', time.time(),
                                          Command.Command("response"),
                                          time.time(), 'program')
        expected_usage.append_file(loaded_file_sent)

        expected_finished_result = FinishedReservationResult(expected_usage)
        expected_alive_result = WaitingReservationResult()
        expected_cancelled_result = CancelledReservationResult()

        self.mock_ups.return_values['get_experiment_uses_by_id'] = (
            expected_finished_result, expected_alive_result,
            expected_cancelled_result)

        results = self.rfm.get_experiment_uses_by_id(
            expected_sess_id, (SessionId.SessionId('reservation'),
                               SessionId.SessionId('reservation2'),
                               SessionId.SessionId('reservation3')))

        self.assertEquals(3, len(results))
        self.assertEquals(expected_finished_result.status, results[0].status)
        self.assertEquals(expected_alive_result.status, results[1].status)
        self.assertEquals(expected_cancelled_result.status, results[2].status)

        self.assertEquals(expected_usage,
                          expected_finished_result.experiment_use)
Ejemplo n.º 7
0
    def _parse_experiment_result(self, experiment_result):
        if experiment_result['status'] == ReservationResult.ALIVE:
            if experiment_result['running']:
                return RunningReservationResult()
            else:
                return WaitingReservationResult()
        elif experiment_result['status'] == ReservationResult.CANCELLED:
            return CancelledReservationResult()
        elif experiment_result['status'] == ReservationResult.FORBIDDEN:
            return ForbiddenReservationResult()

        experiment_use = experiment_result['experiment_use']

        experiment_id = ExperimentId(
            experiment_use['experiment_id']['exp_name'],
            experiment_use['experiment_id']['cat_name'])

        addr = experiment_use['coord_address']
        if 'machine_id' in addr:
            coord_address = CoordAddress(addr['machine_id'],
                                         addr['instance_id'],
                                         addr['server_id'])
        else:
            coord_address = CoordAddress(addr['host'], addr['process'],
                                         addr['component'])

        use = ExperimentUsage(experiment_use['experiment_use_id'],
                              experiment_use['start_date'],
                              experiment_use['end_date'],
                              experiment_use['from_ip'], experiment_id,
                              experiment_use['reservation_id'], coord_address,
                              experiment_use['request_info'])
        for sent_file in experiment_use['sent_files']:
            response = Command(
                sent_file['response']['commandstring']
            ) if 'commandstring' in sent_file['response'] and sent_file[
                'response'] is not None else NullCommand
            if sent_file['file_info'] == {}:
                file_info = None
            else:
                file_info = sent_file['file_info']
            unserialized_sent_file = LoadedFileSent(
                sent_file['file_content'], sent_file['timestamp_before'],
                response, sent_file['timestamp_after'], file_info)
            use.append_file(unserialized_sent_file)

        for command in experiment_use['commands']:
            request = Command(
                command['command']['commandstring']
            ) if 'commandstring' in command['command'] and command[
                'command'] is not None else NullCommand
            response_command = command['response'][
                'commandstring'] if 'commandstring' in command[
                    'response'] and command['response'] is not None else None
            if response_command is None or response_command == {}:
                response = NullCommand()
            else:
                response = Command(response_command)

            if command['timestamp_after'] is None or command[
                    'timestamp_after'] == {}:
                timestamp_after = None
            else:
                timestamp_after = command['timestamp_after']
            unserialized_command = CommandSent(request,
                                               command['timestamp_before'],
                                               response, timestamp_after)
            use.append_command(unserialized_command)
        return FinishedReservationResult(use)