def setUp(self):
        # Clean the global registry of servers
        GLOBAL_REGISTRY.clear()

        CONSUMER_CONFIG_PATH = self.FEDERATED_DEPLOYMENTS + '/consumer/'
        PROVIDER1_CONFIG_PATH = self.FEDERATED_DEPLOYMENTS + '/provider1/'
        PROVIDER2_CONFIG_PATH = self.FEDERATED_DEPLOYMENTS + '/provider2/'

        self.consumer_handler = load_dir(CONSUMER_CONFIG_PATH).load_process(
            'consumer_machine', 'main_instance')
        self.provider1_handler = load_dir(PROVIDER1_CONFIG_PATH).load_process(
            'provider1_machine', 'main_instance')
        self.provider2_handler = load_dir(PROVIDER2_CONFIG_PATH).load_process(
            'provider2_machine', 'main_instance')

        self.consumer_client = WebLabDeustoClient(
            "http://127.0.0.1:%s/weblab/" % 18345)

        self.provider1_client = WebLabDeustoClient(
            "http://127.0.0.1:%s/weblab/" % 28345)

        self.provider2_client = WebLabDeustoClient(
            "http://127.0.0.1:%s/weblab/" % 38345)

        # dummy1: deployed in consumer, provider1, provider2
        self.dummy1 = ExperimentId("dummy1", "Dummy experiments")
        # dummy2: deployed in consumer
        self.dummy2 = ExperimentId("dummy2", "Dummy experiments")
        # dummy3: deployed in provider1 as "dummy3_with_other_name"
        self.dummy3 = ExperimentId("dummy3", "Dummy experiments")
        # dummy4: deployed in provider2
        self.dummy4 = ExperimentId("dummy4", "Dummy experiments")
Esempio n. 2
0
    def test_reserve_experiment(self):
        db_sess_id = DatabaseSession.ValidDatabaseSessionId('student2', "student")
        sess_id, _ = self.ups.do_reserve_session(db_sess_id)

        exp_id = ExperimentId('this does not experiment','this neither')

        self.assertRaises(
            coreExc.UnknownExperimentIdError,
            self.ups.reserve_experiment,
            sess_id, exp_id, "{}", "{}", ClientAddress.ClientAddress("127.0.0.1")
        )

        exp_id = ExperimentId('ud-dummy','Dummy experiments')

        lab_sess_id = SessionId.SessionId("lab_session_id")
        self.lab_mock.reserve_experiment(exp_id, "{}")
        self.mocker.result(lab_sess_id)
        self.mocker.count(0, 1)
        self.lab_mock.resolve_experiment_address(lab_sess_id)
        self.mocker.result(CoordAddress.CoordAddress.translate_address('foo:bar@machine'))
        self.mocker.count(0, 1)
        self.mocker.replay()

        reservation = self.ups.reserve_experiment(
            sess_id, exp_id, "{}", "{}",
            ClientAddress.ClientAddress("127.0.0.1")
        )

        self.assertTrue( isinstance(reservation,Reservation.Reservation))

        self.ups.logout(sess_id)
    def test_reserve_experiment_not_found(self):
        self.coordinator._clean()

        self.assertRaises(coreExc.NoAvailableExperimentFoundError,
                          self.processor.reserve_experiment,
                          ExperimentId('ud-dummy', 'Dummy experiments'), "{}",
                          "{}", "127.0.0.1", 'uuid')
 def test_reserve_experiment_waiting_confirmation(self):
     status = self.processor.reserve_experiment(
         ExperimentId('ud-dummy', 'Dummy experiments'), "{}", "{}",
         "127.0.0.1", 'uuid')
     self.assertTrue(
         isinstance(status,
                    WebLabSchedulingStatus.WaitingConfirmationQueueStatus))
    def test_list_sessions(self):
        exp_id1 = ExperimentId("exp1","cat1")
        exp_id2 = ExperimentId("exp2","cat1")

        sessions = self.reservations_manager.list_sessions(exp_id1)
        self.assertEquals(0, len(sessions))

        reservation1 = self.reservations_manager.create(exp_id1, "{}", REQUEST_INFO)
        reservation2 = self.reservations_manager.create(exp_id1, "{}", REQUEST_INFO)

        self.reservations_manager.create(exp_id2, "{}", REQUEST_INFO)

        sessions = self.reservations_manager.list_sessions(exp_id1)
        self.assertEquals(2, len(sessions))
        self.assertTrue(reservation1 in sessions)
        self.assertTrue(reservation2 in sessions)
Esempio n. 6
0
    def test_get_reservation_info(self):
        db_sess_id = DatabaseSession.ValidDatabaseSessionId('student2', "student")
        sess_id, _ = self.ups.do_reserve_session(db_sess_id)

        exp_id = ExperimentId('ud-dummy','Dummy experiments')

        lab_sess_id = SessionId.SessionId("lab_session_id")
        self.lab_mock.reserve_experiment(exp_id, "{}")
        self.mocker.result(lab_sess_id)
        self.mocker.count(0, 1)
        self.lab_mock.resolve_experiment_address(lab_sess_id)
        self.mocker.result(CoordAddress.CoordAddress.translate_address('foo:bar@machine'))
        self.mocker.count(0, 1)
        self.mocker.replay()

        reservation = self.ups.reserve_experiment(
            sess_id, exp_id, "{}", "{}",
            ClientAddress.ClientAddress("127.0.0.1")
        )

        reservation_info = self.ups.get_reservation_info(reservation.reservation_id)
        self.assertEquals('ud-dummy', reservation_info.exp_name)
        self.assertEquals('Dummy experiments', reservation_info.cat_name)

        self.ups.logout(sess_id)
Esempio n. 7
0
    def test_confirm_experiment(self):
        lab_session_id = SessionId.SessionId("samplesession_id")

        mock_laboratory = self.mocker.mock()
        mock_laboratory.reserve_experiment(ExperimentInstanceId('inst1','exp1','cat1'), '"sample initial data"', mocker.ANY)
        self.mocker.result((lab_session_id, None, 'server:inst@mach'))

        self.mock_locator.real_mock = self.mocker.mock()
        self.mock_locator.real_mock.get_server_from_coordaddress(
                self.coord_address,
                coord_addr(self.lab_address),
                ServerType.Laboratory,
                'all'
        )
        self.mocker.result((mock_laboratory,))
        self.mocker.count(min=1,max=None)

        self.mocker.replay()
        status, reservation1_id = self.coordinator.reserve_experiment(ExperimentId('exp1','cat1'), 30, 5, True, 'sample initial data', DEFAULT_REQUEST_INFO, {})
        now = datetime.datetime.fromtimestamp(int(time.time())) # Remove milliseconds as MySQL do
        self.coordinator.confirmer._confirm_handler.join()
        self.assertEquals( None, self.confirmer._confirm_handler.raised_exc )

        status = self.coordinator.get_reservation_status(reservation1_id)
        expected_status =  WSS.LocalReservedStatus(reservation1_id, CoordAddress.CoordAddress.translate_address(self.lab_address), lab_session_id, 30, '{}', now, now, True, 30, 'http://www.weblab.deusto.es/weblab/client/adfas')

        self.assertTrue(hasattr(status, 'timestamp_before'),  "Unexpected status. Expected\n %s\n, but the obtained does not have timestamp_before:\n %s\n" % (status, expected_status))
        self.assertTrue(status.timestamp_before >= now and status.timestamp_before <= now + datetime.timedelta(seconds=10),
                        "Unexpected status due to timestamp_before: %s; expected something like %s" % (status, expected_status))
        self.assertTrue(status.timestamp_after  >= now and status.timestamp_after  <= now + datetime.timedelta(seconds=10),
                        "Unexpected status due to timestamp_after: %s; expected something like %s" % (status, expected_status))

        status.timestamp_before = now
        status.timestamp_after = now
        self.assertEquals( expected_status, status )
Esempio n. 8
0
def process_Submit(self):
    lab_server_id, experiment_specification, _, _ = serializer.parse_submit_request(
        request.data)
    ilab_request = {'operation': 'submit', 'payload': experiment_specification}
    reservation_status = weblab_api.api.reserve_experiment(
        ExperimentId(lab_server_id, 'iLab experiments'),
        json.dumps(ilab_request), '{}')
    weblab_api.ctx.other_cookies = {
        'weblab_reservation_id': reservation_status.reservation_id.id
    }

    return """<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SubmitResponse xmlns="http://ilab.mit.edu">
<SubmitResult>
<vReport>
<accepted>true</accepted>
<errorMessage />
<estRuntime>8</estRuntime>
</vReport>
<experimentID>61</experimentID>
<minTimeToLive>0</minTimeToLive>
<wait>
<effectiveQueueLength>%s</effectiveQueueLength>
<estWait>5</estWait>
</wait>
</SubmitResult>
</SubmitResponse>
</soap:Body>
</soap:Envelope>""" % reservation_status.position
Esempio n. 9
0
    def test_get_experiment_status__one_reservation(self):
        category   = "Dummy experiments"
        experiment = "ud-dummy"

        status, reservation_id = self.coordinator.reserve_experiment(ExperimentId(experiment, category), 30, 5, True, '{}', {}, {})

        result   = methods.get_experiment_status.call(category, experiment)
        self.assertEquals({reservation_id : status}, result)
    def test_list_sessions_not_existing(self):
        exp_id = ExperimentId("exp.that.doesnt.exist","cat1")

        self.assertRaises(
            CoordExc.ExperimentNotFoundError,
            self.reservations_manager.list_sessions,
            exp_id
        )
    def test_reserve_experiment_repeated_uuid(self):
        uuid = self.cfg_manager.get_doc_value(
            configuration_doc.CORE_UNIVERSAL_IDENTIFIER)

        status = self.processor.reserve_experiment(
            ExperimentId('ud-dummy', 'Dummy experiments'), "{}",
            '{ "%s" : [["%s","server x"]]}' %
            (UserProcessor.SERVER_UUIDS, uuid), "127.0.0.1", uuid)
        self.assertEquals('replicated', status)
Esempio n. 12
0
    def test_get_reservation_id_one_user(self):
        category   = "Dummy experiments"
        experiment = "ud-dummy"

        db_sess_id = DatabaseSession.ValidDatabaseSessionId('student2', "student")
        sess_id, _ = self.ups.do_reserve_session(db_sess_id)
        self.ups.reserve_experiment(sess_id, ExperimentId( experiment, category ), "{}", "{}", ClientAddress.ClientAddress( "127.0.0.1" ))

        reservation_id = methods.get_reservation_id.call(sess_id.id)
        self.assertNotEquals(None, reservation_id)
Esempio n. 13
0
    def test_reserve_experiment_repeated_uuid(self):
        uuid = self.cfg_manager.get_value(
            WEBLAB_CORE_SERVER_UNIVERSAL_IDENTIFIER)

        status = self.processor.reserve_experiment(
            ExperimentId('ud-dummy', 'Dummy experiments'), "{}",
            '{ "%s" : [["%s","server x"]]}' %
            (UserProcessor.SERVER_UUIDS, uuid),
            ClientAddress.ClientAddress("127.0.0.1"), uuid)
        self.assertEquals('replicated', status)
Esempio n. 14
0
    def test_get_resource_types_by_experiment_id_error(self):
        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        self.assertRaises(
            CoordExc.ExperimentNotFoundError,
            self.resources_manager.get_resource_types_by_experiment_id,
            ExperimentId("foo", "bar"))
    def test_get_reservation_id_one_user(self):
        category   = "Dummy experiments"
        experiment = "ud-dummy"

        db_sess_id = ValidDatabaseSessionId('student2', "student")
        sess_id, _ = self.ups._reserve_session(db_sess_id)
        with wlcontext(self.ups, session_id = sess_id):
            core_api.reserve_experiment(ExperimentId( experiment, category ), "{}", "{}")

        reservation_id = methods.get_reservation_id.call(sess_id.id)
        self.assertNotEquals(None, reservation_id)
Esempio n. 16
0
    def test_get_resource_types_by_experiment_id(self):
        exp_id = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id,
            Resource("type", "instance"))

        exp_type_id = ExperimentId("ud-pld", "PLD Experiments")
        resource_types = self.resources_manager.get_resource_types_by_experiment_id(
            exp_type_id)
        self.assertEquals(1, len(resource_types))
        self.assertTrue(u"type" in resource_types)
    def create_reservation_processor(self, faking_response=False):
        if faking_response:
            self._fake_simple_lab_response()

        status = self.user_processor.reserve_experiment(
            ExperimentId('ud-dummy', 'Dummy experiments'), "{}", "{}",
            ClientAddress.ClientAddress("127.0.0.1"), 'uuid')
        self.reservation_processor = ReservationProcessor(
            self.cfg_manager,
            SessionId.SessionId(status.reservation_id.split(';')[0]), {
                'session_polling':
                (time.time(), ReservationProcessor.EXPIRATION_TIME_NOT_SET),
                'latest_timestamp':
                0,
                'experiment_id':
                ExperimentId('ud-dummy', 'Dummy experiments'),
                'creator_session_id':
                '',
                'reservation_id':
                SessionId.SessionId(status.reservation_id.split(';')[0]),
            }, self.coordinator, self.locator, self.commands_store)
Esempio n. 18
0
def process_GetLabConfiguration(self):
    lab_server_id = serializer.parse_get_lab_configuration_request(
        request.data)
    ilab_request = {
        'operation': 'get_lab_configuration',
    }
    # TODO: client address
    reservation_status = weblab_api.api.reserve_experiment(
        ExperimentId(lab_server_id, 'iLab experiments'),
        json.dumps(ilab_request), '{}')
    lab_configuration = reservation_status.initial_data
    return serializer.generate_lab_configuration_response(lab_configuration)
    def setUp(self):

        cfg_manager = ConfigurationManager.ConfigurationManager()
        cfg_manager.append_module(configuration)
        self.dbmanager = DatabaseGateway(cfg_manager)
        self.dbmanager._delete_all_uses()
        session = self.dbmanager.Session()
        try:
            student1 = self.dbmanager._get_user(session, 'student1')
        finally:
            session.close()

        self.initial_store = TemporalInformationStore.InitialTemporalInformationStore(
        )
        self.finished_store = TemporalInformationStore.FinishTemporalInformationStore(
        )
        self.commands_store = TemporalInformationStore.CommandsTemporalInformationStore(
        )
        self.completed_store = TemporalInformationStore.CompletedInformationStore(
        )

        self.retriever = TemporalInformationRetriever.TemporalInformationRetriever(
            cfg_manager, self.initial_store, self.finished_store,
            self.commands_store, self.completed_store, self.dbmanager)
        self.retriever.timeout = 0.001  # Be quicker instead of waiting for half a second

        self.initial_time = self.end_time = datetime.datetime.now()
        self.initial_timestamp = self.end_timestamp = time.time()

        request_info = {
            'username': '******',
            'role': 'student',
            'permission_scope': 'user',
            'permission_id': student1.id
        }
        exp_id = ExperimentId('ud-dummy', 'Dummy Experiments')

        self.entry1 = TemporalInformationStore.InitialInformationEntry(
            RESERVATION1, exp_id, coord_addr('ser:inst@mach'), DATA1,
            self.initial_time, self.end_time, request_info.copy(),
            DATA_REQUEST1)
        self.entry2 = TemporalInformationStore.InitialInformationEntry(
            RESERVATION2, exp_id, coord_addr('ser:inst@mach'), DATA2,
            self.initial_time, self.end_time, request_info.copy(),
            DATA_REQUEST2)
        self.entry3 = TemporalInformationStore.InitialInformationEntry(
            RESERVATION3, exp_id, coord_addr('ser:inst@mach'), DATA3,
            self.initial_time, self.end_time, request_info.copy(),
            DATA_REQUEST3)
        self.entry4 = TemporalInformationStore.InitialInformationEntry(
            RESERVATION4, exp_id, coord_addr('ser:inst@mach'), DATA4,
            self.initial_time, self.end_time, request_info.copy(),
            DATA_REQUEST3)
Esempio n. 20
0
    def do_full_experiment_use(self, user_number):
        """
        Uses the configured experiment trying to resemble the way a human would do it.
        This method will block for a while.
        :return:
        """
        client = self.clients[user_number]
        sessionid = client.login(self.user, self.password)
        if not sessionid:
            raise Exception("Wrong login")

        # Reserve the flash dummy experiment.
        experiment_id = ExperimentId(self.exp_name, self.cat_name)
        waiting = client.reserve_experiment(sessionid, experiment_id, "{}",
                                            "{}", None)
        # print "Reserve response: %r" % waiting

        reservation_id = waiting.reservation_id

        initial_time = time.time()

        while (time.time() - initial_time) < self.max_time:
            status = client.get_reservation_status(reservation_id)

            if type(status) is WaitingReservation:
                time.sleep(0.1)
            elif type(status) is ConfirmedReservation:
                break
            elif type(status) is WaitingConfirmationReservation:
                time.sleep(0.1)

        if (time.time() - initial_time) >= self.max_time:
            raise Exception(
                "Max time (%s seconds) achieved and still waiting..." %
                self.max_time)

        self.users_in += 1

        # Send some commands.

        for i in range(20):
            # What's commandstring actually for??
            cmd = Command("foo")
            result = client.send_command(reservation_id, cmd)
            if not result.commandstring.startswith("Received command"):
                raise Exception("Unrecognized command response")
            # print "Command result: %r" % result
            time.sleep(0.1)

        self.users_in -= 1

        result = client.logout(sessionid)
Esempio n. 21
0
 def process_GetLabConfiguration(self):
     lab_server_id = self.serializer.parse_get_lab_configuration_request(
         self.payload)
     request = {
         'operation': 'get_lab_configuration',
     }
     # TODO: client address
     reservation_status = self.server.reserve_experiment(
         self.sess_id, ExperimentId(lab_server_id, 'iLab experiments'),
         json.dumps(request), '{}', ClientAddress.ClientAddress(''))
     lab_configuration = reservation_status.initial_data
     return self.serializer.generate_lab_configuration_response(
         lab_configuration)
Esempio n. 22
0
    def test_reject_experiment_voodoo_gen_raises_exception(self):
        self.mock_locator[coord_addr(self.lab_address)]
        self.mocker.throw(Exception("Unhandled exception"))

        self.mocker.replay()
        status, reservation1_id = self.coordinator.reserve_experiment(
            ExperimentId('exp1', 'cat1'), 30, 5, True, 'sample initial data',
            DEFAULT_REQUEST_INFO, {})
        self.coordinator.confirmer._confirm_handler.join()
        self.assertEquals(None, self.confirmer._confirm_handler.raised_exc)

        status = self.coordinator.get_reservation_status(reservation1_id)
        expected_status = WSS.WaitingInstancesQueueStatus(reservation1_id, 0)
        self.assertEquals(expected_status, status)
Esempio n. 23
0
    def test_list_experiments(self):
        exp_id1 = ExperimentInstanceId("exp1", "ud-pld", "PLD Experiments")
        resource_instance1 = Resource("type1", "instance1")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id1, resource_instance1)

        exp_id2 = ExperimentInstanceId("exp2", "ud-pld", "PLD Experiments")
        resource_instance2 = Resource("type2", "instance1")
        self.resources_manager.add_experiment_instance_id(
            "laboratory1:WL_SERVER1@WL_MACHINE1", exp_id2, resource_instance2)

        resources = self.resources_manager.list_experiments()
        self.assertEquals(1, len(resources))
        self.assertTrue(ExperimentId('ud-pld', 'PLD Experiments') in resources)
Esempio n. 24
0
def do_full_experiment_use():
    """
    Uses the configured experiment trying to resemble the way a human would do it.
    This method will block for a while.
    :return:
    """
    wc = WebLabDeustoClient(config.WEBLAB_BASE_URL)
    sessionid = wc.login(config.LOGIN, config.PASSWORD)
    if not sessionid: raise Exception("Wrong login")

    # Reserve the flash dummy experiment.
    experiment_id = ExperimentId(config.EXP_NAME, config.EXP_CATEGORY)
    waiting = wc.reserve_experiment(sessionid, experiment_id, "{}", "{}", None)
    # print "Reserve response: %r" % waiting

    reservation_id = waiting.reservation_id

    while True:
        status = wc.get_reservation_status(reservation_id)
        # print "Reservation status: %r" % status

        if type(status) is WaitingReservation:
            time.sleep(0.5)
        elif type(status) is ConfirmedReservation:
            break
        elif type(status) is WaitingConfirmationReservation:
            time.sleep(0.5)
        else:
            print "Unknown reservation status."

    print "Experiment reserved."

    global users_in
    users_in += 1

    # Send some commands.

    for i in range(config.COMMANDS_PER_USER):
        # What's commandstring actually for??
        cmd = Command(config.COMMAND)
        result = wc.send_command(reservation_id, cmd)
        if not result.commandstring.startswith("Received command"):
            raise Exception("Unrecognized command response")
        # print "Command result: %r" % result
        time.sleep(config.TIME_BETWEEN_COMMANDS)

    users_in -= 1

    result = wc.logout(sessionid)
    print "Logout result: %r" % result
Esempio n. 25
0
def reserve_experiment(experiment_id=None,
                       client_initial_data=None,
                       consumer_data=None):
    server = weblab_api.ctx.server_instance
    client_address = weblab_api.ctx.client_address
    # core_server_universal_id should be copied
    experiment_id = ExperimentId(experiment_id['exp_name'],
                                 experiment_id['cat_name'])
    status = weblab_api.ctx.user_processor.reserve_experiment(
        experiment_id, client_initial_data, consumer_data, client_address,
        server.core_server_universal_id)

    if status == 'replicated':
        return Reservation.NullReservation()

    reservation_id = status.reservation_id.split(';')[0]
    reservation_session_id = SessionId(reservation_id)

    server._alive_users_collection.add_user(reservation_session_id)

    session_id = server._reservations_session_manager.create_session(
        reservation_id)

    initial_session = {
        'session_polling':
        (time.time(), ReservationProcessor.EXPIRATION_TIME_NOT_SET),
        'latest_timestamp':
        0,
        'experiment_id':
        experiment_id,
        'creator_session_id':
        weblab_api.ctx.
        user_session['session_id'],  # Useful for monitor; should not be used
        'reservation_id':
        reservation_session_id,
        'federated':
        False,
    }
    reservation_processor = server._load_reservation(initial_session)
    reservation_processor.update_latest_timestamp()

    if status.status == WebLabSchedulingStatus.WebLabSchedulingStatus.RESERVED_LOCAL:
        reservation_processor.process_reserved_status(status)

    if status.status == WebLabSchedulingStatus.WebLabSchedulingStatus.RESERVED_REMOTE:
        reservation_processor.process_reserved_remote_status(status)

    server._reservations_session_manager.modify_session(
        session_id, initial_session)
    return Reservation.Reservation.translate_reservation(status)
Esempio n. 26
0
    def test_update_command(self):
        student1 = self.gateway._get_user(self.session, 'student1')

        RESERVATION_ID1 = 'my_reservation_id1'

        usage1 = ExperimentUsage()
        usage1.start_date = time.time()
        usage1.end_date = time.time()
        usage1.from_ip = "130.206.138.16"
        usage1.experiment_id = ExperimentId("ud-dummy", "Dummy experiments")
        usage1.coord_address = CoordAddress("machine1", "instance1", "server1")
        usage1.reservation_id = RESERVATION_ID1
        usage1.request_info = {
            'facebook': False,
            'permission_scope': 'user',
            'permission_id': student1.id
        }

        self.gateway.store_experiment_usage(student1.login, usage1)

        usages = self.gateway.list_usages_per_user(student1.login)
        self.assertEquals(1, len(usages))

        full_usage = self.gateway.retrieve_usage(usages[0].experiment_use_id)

        self.assertEquals(0, len(full_usage.commands))

        command1 = CommandSent(Command.Command("your command"), time.time())
        command_id = self.gateway.append_command(RESERVATION_ID1, command1)

        full_usage = self.gateway.retrieve_usage(usages[0].experiment_use_id)

        self.assertEquals("your command",
                          full_usage.commands[0].command.commandstring)
        self.assertEquals(Command.NullCommand(),
                          full_usage.commands[0].response)

        self.gateway.update_command(command_id,
                                    Command.Command("the response"),
                                    time.time())

        full_usage = self.gateway.retrieve_usage(usages[0].experiment_use_id)
        self.assertEquals("your command",
                          full_usage.commands[0].command.commandstring)
        self.assertEquals("the response",
                          full_usage.commands[0].response.commandstring)
Esempio n. 27
0
def create_usage(gateway, reservation_id = 'my_reservation_id'):
        session = gateway.Session()
        student1 = gateway._get_user(session, 'student1')

        initial_usage = ExperimentUsage()
        initial_usage.start_date    = time.time()
        initial_usage.end_date      = time.time()
        initial_usage.from_ip       = "130.206.138.16"
        initial_usage.experiment_id = ExperimentId("ud-dummy","Dummy experiments")
        initial_usage.coord_address = CoordAddress.CoordAddress("machine1","instance1","server1") #.translate_address("server1:instance1@machine1")
        initial_usage.reservation_id = reservation_id

        file1 = FileSent(
                    'path/to/file1',
                    '{sha}12345',
                    time.time()
            )

        file2 = FileSent(
                    'path/to/file2',
                    '{sha}123456',
                    time.time(),
                    Command.Command('response'),
                    time.time(),
                    file_info = 'program'
            )

        command1 = CommandSent(
                    Command.Command("your command1"),
                    time.time()
            )

        command2 = CommandSent(
                    Command.Command("your command2"),
                    time.time(),
                    Command.Command("your response2"),
                    time.time()
            )

        initial_usage.append_command(command1)
        initial_usage.append_command(command2)
        initial_usage.append_file(file1)
        initial_usage.append_file(file2)
        initial_usage.request_info = {'facebook' : False}
        gateway.store_experiment_usage(student1.login, initial_usage)
        return student1, initial_usage, command1, command2, file1, file2
Esempio n. 28
0
    def _reserve_experiment(self):
        db_sess_id = ValidDatabaseSessionId('student1', "student")
        sess_id, _ = self.ups._reserve_session(db_sess_id)
        with wlcontext(self.ups, session_id=sess_id):
            exp_id = ExperimentId('ud-dummy', 'Dummy experiments')

            lab_sess_id = SessionId.SessionId("lab_session_id")
            self.lab_mock.reserve_experiment(exp_id, "{}")
            self.mocker.result(lab_sess_id)
            self.mocker.count(0, 1)
            self.lab_mock.resolve_experiment_address(lab_sess_id)
            self.mocker.result(CoordAddress.translate('foo:bar@machine'))
            self.mocker.count(0, 1)
            self.mocker.replay()

            reservation = core_api.reserve_experiment(exp_id, "{}", "{}")
            return reservation.reservation_id
Esempio n. 29
0
    def test_kickout_from_coordinator(self):
        category   = "Dummy experiments"
        experiment = "ud-dummy"

        db_sess_id = DatabaseSession.ValidDatabaseSessionId('student2', "student")
        sess_id, _ = self.ups.do_reserve_session(db_sess_id)
        status = self.ups.reserve_experiment(sess_id, ExperimentId( experiment, category ), "{}", "{}", ClientAddress.ClientAddress( "127.0.0.1" ))

        reservation_session_id = status.reservation_id

        status = self.ups.get_reservation_status(reservation_session_id)
        self.assertNotEquals( None, status )

        reservation_id = methods.get_reservation_id.call(sess_id.id)
        methods.kickout_from_coordinator.call(reservation_id)

        self.assertRaises( core_exc.NoCurrentReservationError, self.ups.get_reservation_status, reservation_session_id )
Esempio n. 30
0
    def _reserve_experiment(self):
        db_sess_id = DatabaseSession.ValidDatabaseSessionId('student1', "student")
        sess_id, _ = self.ups.do_reserve_session(db_sess_id)

        exp_id = ExperimentId('ud-dummy','Dummy experiments')

        lab_sess_id = SessionId.SessionId("lab_session_id")
        self.lab_mock.reserve_experiment(exp_id, "{}")
        self.mocker.result(lab_sess_id)
        self.mocker.count(0, 1)
        self.lab_mock.resolve_experiment_address(lab_sess_id)
        self.mocker.result(CoordAddress.CoordAddress.translate_address('foo:bar@machine'))
        self.mocker.count(0, 1)
        self.mocker.replay()

        reservation = self.ups.reserve_experiment(
            sess_id, exp_id, "{}", "{}",
            ClientAddress.ClientAddress("127.0.0.1"))
        return reservation.reservation_id