def intercept_library(self, content, mimetype): cookies = self.req.headers.getheader('cookie') sess_id = None reservation_id = None for cur_cookie in (cookies or '').split('; '): if cur_cookie.startswith("weblabsessionid="): sess_id = SessionId('.'.join( cur_cookie[len('weblabsessionid='):].split('.')[:-1])) if cur_cookie.startswith('weblab_reservation_id='): reservation_id = SessionId( cur_cookie[len('weblab_reservation_id='):].split('.')[0]) try: response = self.server.send_command(sess_id, Command("GIVE_ME_LIBRARY")) except: pass else: if response.commandstring is not None and response.commandstring != 'failed': return response.commandstring if reservation_id is None and sess_id is not None: try: reservation_id_str = self.server.get_reservation_id_by_session_id( sess_id) if reservation_id_str is not None: reservation_id = SessionId(reservation_id_str) except: traceback.print_exc() reservation_id = None if reservation_id is not None: try: response = self.server.send_command(reservation_id, Command("GIVE_ME_LIBRARY")) except: failed = True traceback.print_exc() else: failed = response.commandstring is None or response.commandstring == 'failed' else: print "Can not request library since reservation_id is None" failed = True if failed: return content else: return response.commandstring
def intercept_library(): session_id = request.cookies.get('weblabsessionid') if session_id and ';' in session_id: session_id = session_id.split(';', 1)[0] reservation_id = weblab_api.ctx.reservation_id if not reservation_id: reservation_id = request.cookies.get('weblab_reservation_id') if reservation_id: if ';' in reservation_id: reservation_id = reservation_id.split(';', 1)[0] weblab_api.ctx.reservation_id = reservation_id try: response = weblab_api.api.send_command(Command("GIVE_ME_LIBRARY")) except: pass else: if response.commandstring is not None: if response.commandstring == 'failed': return "" else: return response.commandstring if session_id is not None: try: reservation_id = weblab_api.api.get_reservation_id_by_session_id() if reservation_id is not None: weblab_api.ctx.reservation_id = reservation_id except: traceback.print_exc() if reservation_id is not None: try: response = weblab_api.api.send_command(Command("GIVE_ME_LIBRARY")) except: failed = True traceback.print_exc() else: failed = response.commandstring is None or response.commandstring == 'failed' else: print("Can not request library since reservation_id is None") failed = True if failed: return "" else: return response.commandstring
def _wait_reservation(self, reservation_id, expected_server_info, finish): max_timeout = 10 initial_time = time.time() reservation_status = self.consumer_client.get_reservation_status( reservation_id) while reservation_status.status in (Reservation.WAITING, Reservation.WAITING_CONFIRMATION): if time.time() - initial_time > max_timeout: self.fail("Waiting too long in the queue for %s" % expected_server_info) time.sleep(0.1) reservation_status = self.consumer_client.get_reservation_status( reservation_id) self.assertEquals(Reservation.CONFIRMED, reservation_status.status) experiment_reservation_id = reservation_status.remote_reservation_id if experiment_reservation_id.id == '': experiment_reservation_id = reservation_id client = WebLabDeustoClient(reservation_status.url) response = client.send_command(experiment_reservation_id, Command("server_info")) self.assertEquals(expected_server_info, response.get_command_string()) if finish: self.consumer_client.finished_experiment(reservation_id) return reservation_id
def retrieve_results(self): timestamp_before = self._utc_timestamp() translation = self._translator.on_finish(self._session['trans_session_id']) if translation is not None: timestamp_after = self._utc_timestamp() self._append_command(Command("on_finish"), timestamp_before, translation, timestamp_after) return self._session['commands'], self._session['files']
def send_command(command): """ send_command(command) send_command sends an abstract string <command> which will be unpacked by the experiment. """ reservation_processor = weblab_api.ctx.reservation_processor weblab_api.ctx.server_instance._check_reservation_not_expired_and_poll( reservation_processor ) return reservation_processor.send_command( Command(command['commandstring']) )
def send_file(self, reservation_id, file_content, file_info): serialized_reservation_id = {'id': reservation_id.id} response_command = self._core_call( 'send_file', reservation_id=serialized_reservation_id, file_content=file_content, file_info=file_info) return Command(response_command['commandstring'] if 'commandstring' in response_command and response_command['commandstring'] is not None else NullCommand())
def send_command(self, reservation_id, command): serialized_reservation_id = {'id': reservation_id.id} serialized_command = {'commandstring': command.commandstring} response_command = self._core_call( 'send_command', reservation_id=serialized_reservation_id, command=serialized_command) return Command(response_command['commandstring'] if 'commandstring' in response_command and response_command['commandstring'] is not None else NullCommand())
def send_async_command(command): """ send_async_command(session_id, command) send_async_command sends an abstract string <command> which will be unpacked by the experiment, and run asynchronously on its own thread. Its status may be checked through check_async_command_status. """ reservation_processor = weblab_api.ctx.reservation_processor weblab_api.ctx.server_instance._check_reservation_not_expired_and_poll( reservation_processor ) return reservation_processor.send_async_command( Command(command['commandstring']) )
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)
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
def _test_store_file(self, file_content): FILE_PATH = self._cfg_manager.get_value( 'proxy_store_students_programs_path') FILE_CONTENT = ExperimentUtil.serialize(file_content) fake_time.TIME_TO_RETURN = 1289548551.2617509 # 2010_11_12___07_55_51 proxy = self._create_proxy_session_handler(time_mock=fake_time) path, hash = proxy._store_file(Command(FILE_CONTENT), "student1", "my_session_id") self.assertEquals('2010_11_12___07_55_51_261_student1_my_session_id', path) self.assertTrue(os.path.exists('%s%s%s' % (FILE_PATH, os.sep, path))) self.assertEquals( '{sha}14b69e2393ace3feb980510e59dc8a1fc467575a', # sha of 'AAAHuuuuuuuuge file!' hash)
def _test_happy_path(self, translator_name): FILE_CONTENT = ExperimentUtil.serialize('Huuuuuuuuge file!') FILE_INFO = "My file's description" self._cfg_manager._set_value( ProxyServer.WEBLAB_PROXY_SERVER_DEFAULT_TRANSLATOR_NAME, translator_name) fake_time.TIME_TO_RETURN = 1289548551.2617509 # 2010_11_12___07_55_51 laboratory = self.mocker.mock() laboratory.send_command(self.LAB_SESS_ID, Command('Do this!')) self.mocker.result(Command('Done!')) laboratory.send_file(self.LAB_SESS_ID, Command(FILE_CONTENT), FILE_INFO) self.mocker.result(Command('File received!')) self.mocker.replay() proxy = self._create_proxy(laboratories=(laboratory, ), time_mock=fake_time) proxy.do_enable_access(self.RESERVATION_ID, "ud-fpga@FPGA experiments", "student1", self.LAB_COORD_ADDR, self.LAB_SESS_ID) command_response = proxy.send_command(self.RESERVATION_SESS_ID, Command('Do this!')) self.assertEquals(Command('Done!'), command_response) file_response = proxy.send_file(self.RESERVATION_SESS_ID, Command(FILE_CONTENT), FILE_INFO) self.assertEquals(Command('File received!'), file_response) proxy.do_disable_access(self.RESERVATION_ID) commands, files = proxy.do_retrieve_results(self.RESERVATION_ID) return commands, files
def do_before_send_file(self, session, file): session['log'] += "before_send_file " file_content = ExperimentUtil.deserialize(file.commandstring) return Command(ExperimentUtil.serialize("AAA%s" % file_content))
def do_before_send_command(self, session, command): session['log'] += "before_send_command " return Command("AAA%s" % command.commandstring)
def test_commands(self): self.retriever.start() try: usages = self.dbmanager.list_usages_per_user('student1') self.assertEquals(0, len(usages)) self.initial_store.put(self.entry1) wait_for(self.retriever) usages = self.dbmanager.list_usages_per_user('student1') self.assertEquals(1, len(usages)) entry_id1 = 58131 entry_id2 = 14214 entry_id3 = 84123 pre_command1 = TemporalInformationStore.CommandOrFileInformationEntry( RESERVATION1, True, True, entry_id1, Command(DATA_REQUEST1), self.initial_timestamp) post_command1 = TemporalInformationStore.CommandOrFileInformationEntry( RESERVATION1, False, True, entry_id1, Command(DATA1), self.initial_timestamp) pre_command2 = TemporalInformationStore.CommandOrFileInformationEntry( RESERVATION2, True, True, entry_id2, Command(DATA_REQUEST2), self.initial_timestamp) post_command2 = TemporalInformationStore.CommandOrFileInformationEntry( RESERVATION2, False, True, entry_id2, Command(DATA2), self.initial_timestamp) pre_command3 = TemporalInformationStore.CommandOrFileInformationEntry( RESERVATION3, True, True, entry_id3, Command(DATA_REQUEST3), self.initial_timestamp) post_command3 = TemporalInformationStore.CommandOrFileInformationEntry( RESERVATION3, False, True, entry_id3, Command(DATA3), self.initial_timestamp) # The reservation is stored, therefore this command will # also be stored self.commands_store.put(pre_command1) # This reservation has not been stored, therefore this command # will not be stored yet self.commands_store.put(pre_command2) # Neither this reservation or the pre_command3 have been stored, # therefore this command will not be stored self.commands_store.put(post_command3) wait_for(self.retriever) usages = self.dbmanager.list_usages_per_user('student1') self.assertEquals(1, len(usages)) full_usage1 = self.dbmanager.retrieve_usage( usages[0].experiment_use_id) self.assertEquals(DATA_REQUEST1, full_usage1.commands[-1].command.commandstring) self.assertEquals(None, full_usage1.commands[-1].response.commandstring) # So we add the post_command1, to avoid the "None" self.commands_store.put(post_command1) # And the pre_command3, to see if it is correctly enqueued self.commands_store.put(pre_command3) # And the entry 2, to let pre_command2 enter self.initial_store.put(self.entry2) wait_for(self.retriever) usages = self.dbmanager.list_usages_per_user('student1') self.assertEquals(2, len(usages)) full_usage1 = self.dbmanager.retrieve_usage( usages[0].experiment_use_id) self.assertEquals(DATA_REQUEST1, full_usage1.commands[-1].command.commandstring) self.assertEquals(DATA1, full_usage1.commands[-1].response.commandstring) full_usage2 = self.dbmanager.retrieve_usage( usages[1].experiment_use_id) self.assertEquals(DATA_REQUEST2, full_usage2.commands[-1].command.commandstring) self.assertEquals(None, full_usage2.commands[-1].response.commandstring) # So now we add the rest self.commands_store.put(post_command2) self.initial_store.put(self.entry3) wait_for(self.retriever) usages = self.dbmanager.list_usages_per_user('student1') self.assertEquals(3, len(usages)) full_usage1 = self.dbmanager.retrieve_usage( usages[0].experiment_use_id) self.assertEquals(DATA_REQUEST1, full_usage1.commands[-1].command.commandstring) self.assertEquals(DATA1, full_usage1.commands[-1].response.commandstring) full_usage2 = self.dbmanager.retrieve_usage( usages[1].experiment_use_id) self.assertEquals(DATA_REQUEST2, full_usage2.commands[-1].command.commandstring) self.assertEquals(DATA2, full_usage2.commands[-1].response.commandstring) full_usage3 = self.dbmanager.retrieve_usage( usages[2].experiment_use_id) self.assertEquals(DATA_REQUEST3, full_usage3.commands[-1].command.commandstring) self.assertEquals(DATA3, full_usage3.commands[-1].response.commandstring) finally: self.retriever.stop() self.retriever.join(1) self.assertFalse(self.retriever.isAlive())
def _store_two_reservations(self): # # Two users: student2, that started before "any" but finished after "any", and "any" then. Both use # the same experiment. # reservation_id1 = SessionId.SessionId(u'5') initial_usage1 = ExperimentUsage() initial_usage1.start_date = time.time() initial_usage1.end_date = time.time() initial_usage1.from_ip = u"130.206.138.16" initial_usage1.experiment_id = ExperimentId(u"ud-dummy",u"Dummy experiments") initial_usage1.coord_address = CoordAddress.CoordAddress(u"machine1",u"instance1",u"server1") #.translate_address("server1:instance1@machine1") initial_usage1.reservation_id = reservation_id1.id valid_file_path = os.path.relpath(os.sep.join(('test','__init__.py'))) file1 = FileSent( valid_file_path, u'{sha}12345', time.time()) file2 = FileSent( valid_file_path, u'{sha}123456', time.time(), Command(u'response'), time.time(), file_info = u'program') command1 = CommandSent( Command(u"your command1"), time.time()) command2 = CommandSent( Command(u"your command2"), time.time(), Command(u"your response2"), time.time()) initial_usage1.append_command(command1) initial_usage1.append_command(command2) initial_usage1.append_file(file1) initial_usage1.append_file(file2) reservation_id2 = SessionId.SessionId(u'6') initial_usage2 = ExperimentUsage() initial_usage2.start_date = time.time() initial_usage2.end_date = time.time() initial_usage2.from_ip = u"130.206.138.16" initial_usage2.experiment_id = ExperimentId(u"ud-dummy",u"Dummy experiments") initial_usage2.coord_address = CoordAddress.CoordAddress(u"machine1",u"instance1",u"server1") #.translate_address("server1:instance1@machine1") initial_usage2.reservation_id = reservation_id2.id file1 = FileSent( valid_file_path, u'{sha}12345', time.time()) file2 = FileSent( valid_file_path, u'{sha}123456', time.time(), Command(u'response'), time.time(), file_info = u'program') command1 = CommandSent( Command(u"your command1"), time.time()) command2 = CommandSent( Command(u"your command2"), time.time(), Command(u"your response2"), time.time()) initial_usage2.append_command(command1) initial_usage2.append_command(command2) initial_usage2.append_file(file1) initial_usage2.append_file(file2) self.ups._db_manager._gateway.store_experiment_usage('student1', initial_usage1) self.ups._db_manager._gateway.store_experiment_usage('student2', initial_usage2) return (reservation_id1, reservation_id2), (initial_usage1, initial_usage2)
while reservation.status in (Reservation.WAITING_CONFIRMATION or Reservation.WAITING): time.sleep(1) reservation = weblab.get_reservation_status( reservation.reservation_id ) print ".", sys.stdout.flush() if reservation.status != Reservation.CONFIRMED: raise Exception("Confirmed reservation expected for reservation_id (%r). Found status: %r" % (reservation.reservation_id, reservation.status)) print "[done]" sys.stdout.flush() print "Confirmed reservation, programming file..." sys.stdout.flush() reservation_id = reservation.reservation_id # # This code here is Robot dependent. Replace it with your code to check it. # response = weblab.send_command(reservation_id, Command("program:Interactive Demo")) if response == 'File sended & running': print "File programmed. Exiting." sys.stdout.flush() weblab.finished_experiment(reservation_id) print "Finished testing %s times" % N
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)
def do_after_send_file(self, session, response): session['log'] += "after_send_file " return Command("AAA%s" % response.commandstring)
def run(self): assertions = [] times = [] print "Starting process" reservation_id = None try: weblab = WebLabDeustoClient(self.url) session_id = weblab.login(self.username, self.password) reservation = weblab.reserve_experiment(session_id, ExperimentId("visir", "Visir experiments"), "{}", "{}") while reservation.status in (Reservation.WAITING_CONFIRMATION or Reservation.WAITING): time.sleep(1) reservation = weblab.get_reservation_status( reservation.reservation_id ) if reservation.status != Reservation.CONFIRMED: raise Exception("Confirmed reservation expected for reservation_id (%r). Found status: %r" % (reservation.reservation_id, reservation.status)) print "Confirmed reservation, starting..." reservation_id = reservation.reservation_id response = weblab.send_command(reservation_id, Command("GIVE_ME_SETUP_DATA")) cookie = json.loads(response.commandstring)['cookie'] login_response = weblab.send_command(reservation_id, Command(visir_commands.visir_login_request % cookie)) visir_sessionid = visir_commands.parse_login_response(login_response) for _ in xrange(self.executions): before = time.time() response = weblab.send_command(reservation_id, Command(visir_commands.visir_request_11k % visir_sessionid)) after = time.time() result = visir_commands.parse_command_response(response) assertions.append(AssertionResult(11000.0, 200, result)) times.append(after - before) before = time.time() response = weblab.send_command(reservation_id, Command(visir_commands.visir_request_rectifier % visir_sessionid)) after = time.time() # Don't know how to measure the response, but at least check that the response is a valid VISIR response result = visir_commands.parse_command_response(response, 'dmm_resolution') assertions.append(AssertionResult(3.5, 200, result)) times.append(after - before) before = time.time() response = weblab.send_command(reservation_id, Command(visir_commands.visir_request_900 % visir_sessionid)) after = time.time() result = visir_commands.parse_command_response(response) assertions.append(AssertionResult(900.0, 200, result)) times.append(after - before) before = time.time() response = weblab.send_command(reservation_id, Command(visir_commands.visir_request_1k % visir_sessionid)) after = time.time() result = visir_commands.parse_command_response(response) assertions.append(AssertionResult(1000.0, 200, result)) times.append(after - before) before = time.time() response = weblab.send_command(reservation_id, Command(visir_commands.visir_request_10k % visir_sessionid)) after = time.time() result = visir_commands.parse_command_response(response) assertions.append(AssertionResult(10000.0, 200, result)) times.append(after - before) weblab.finished_experiment(reservation_id) except Exception as exception: if reservation_id is not None: try: weblab.finished_experiment(reservation_id) loggedout = True except: loggedout = False else: loggedout = "no id provided" print "Finished with exception and logged out: %s" % loggedout traceback.print_exc() return TesterResult(True, assertions, exception, times) else: print "Finished without exception" return TesterResult(any(map(lambda assertion : assertion.failed, assertions)), assertions, None, times)
def do_on_finish(self, session): session['log'] += "do_on_finish " return Command(session['log'])
def run(self): assertions = [] times = [] print "Starting process" reservation_id = None try: weblab = WebLabDeustoClient(self.url) session_id = weblab.login(self.username, self.password) reservation = weblab.reserve_experiment( session_id, ExperimentId(VISIR_EXPERIMENT, "Visir experiments"), "{}", "{}") while reservation.status in (Reservation.WAITING_CONFIRMATION or Reservation.WAITING): time.sleep(1) reservation = weblab.get_reservation_status( reservation.reservation_id) if reservation.status != Reservation.CONFIRMED: raise Exception( "Confirmed reservation expected for reservation_id (%r). Found status: %r" % (reservation.reservation_id, reservation.status)) print "Confirmed reservation, starting..." reservation_id = reservation.reservation_id initial_config = reservation.initial_configuration cookie = json.loads(initial_config)['cookie'] login_response = weblab.send_command( reservation_id, Command(visir_commands.visir_login_request % cookie)) visir_sessionid = visir_commands.parse_login_response( login_response) iteration = 0 for _ in xrange(self.executions): before = time.time() response = weblab.send_command( reservation_id, Command(visir_commands.visir_request_11k % visir_sessionid)) after = time.time() result = visir_commands.parse_command_response(response) ar1 = AssertionResult(11000.0, 11000.0 * 0.2, result) if DEBUG and ar1.failed: print "[Failed at 1st]" + str(ar1) if not IGNORE_ASSERTIONS: assertions.append(ar1) times.append(after - before) # This command is currently commented out because it does not seem to be compatible with lxi_visir. # before = time.time() # response = weblab.send_command(reservation_id, Command(visir_commands.visir_request_rectifier % visir_sessionid)) # after = time.time() # # Don't know how to measure the response, but at least check that the response is a valid VISIR response # result = visir_commands.parse_command_response(response, 'dmm_resolution') # assertions.append(AssertionResult(3.5, 200, result)) # times.append(after - before) time.sleep(1) before = time.time() response = weblab.send_command( reservation_id, Command(visir_commands.visir_request_900 % visir_sessionid)) after = time.time() result = visir_commands.parse_command_response(response) ar3 = AssertionResult(900.0, 900.0 * 0.2, result) if DEBUG and ar3.failed: print "[Failed at 3rd]" + str(ar3) if not IGNORE_ASSERTIONS: assertions.append(ar3) times.append(after - before) time.sleep(1) before = time.time() response = weblab.send_command( reservation_id, Command(visir_commands.visir_request_1k % visir_sessionid)) after = time.time() result = visir_commands.parse_command_response(response) ar4 = AssertionResult(1000.0, 1000 * 0.2, result) if DEBUG and ar4.failed: print "[Failed at 4th]" + str(ar4) if not IGNORE_ASSERTIONS: assertions.append(ar4) times.append(after - before) time.sleep(1) before = time.time() response = weblab.send_command( reservation_id, Command(visir_commands.visir_request_10k % visir_sessionid)) after = time.time() result = visir_commands.parse_command_response(response) ar5 = AssertionResult(10000.0, 10000 * 0.2, result) if DEBUG and ar5.failed: print "[Failed at 5th]" + str(ar5) if not IGNORE_ASSERTIONS: assertions.append(ar5) times.append(after - before) iteration += 1 time.sleep(1) weblab.finished_experiment(reservation_id) except Exception as exception: if reservation_id is not None: try: weblab.finished_experiment(reservation_id) loggedout = True except: loggedout = False else: loggedout = "no id provided" print "Finished with exception and logged out: %s" % loggedout traceback.print_exc() return TesterResult(True, assertions, exception, times) else: print "Finished without exception" return TesterResult( any(map(lambda assertion: assertion.failed, assertions)), assertions, None, times)