def afterTest(self, test): """ After each testcase, upload logs to the S3 bucket. """ s3_bucket = S3LoggingBucket() guid = str(uuid.uuid4().hex) path = "%s/%s" % (self.options.log_path, test.test.id()) uploaded_files = [] for logfile in os.listdir(path): logfile_name = "%s/%s/%s" % (guid, test.test.id(), logfile.split(path)[-1]) s3_bucket.upload_file(logfile_name, "%s/%s" % (path, logfile)) uploaded_files.append(logfile_name) s3_bucket.save_uploaded_file_names(uploaded_files) index_file = s3_bucket.upload_index_file(test.id(), guid) print "Log files uploaded: %s" % index_file logging.error("Log files uploaded: %s" % index_file) # If the database plugin is running, attach a link to the logs index database row if hasattr(test.test, "testcase_guid"): from test_framework.core.testcase_manager \ import TestcaseDataPayload, TestcaseManager self.testcase_manager = TestcaseManager(self.options.database_env) data_payload = TestcaseDataPayload() data_payload.guid = test.test.testcase_guid data_payload.logURL = index_file self.testcase_manager.update_testcase_log_url(data_payload)
def startTest(self, test): """at the start of the test, set the test case details""" data_payload = TestcaseDataPayload() self.testcase_guid = test.testcase_guid data_payload.guid = self.testcase_guid data_payload.execution_guid = self.execution_guid if hasattr(test, "browser"): data_payload.browser = test.browser else: data_payload.browser = "N/A" data_payload.sauceJobID = test.sauce_job_id data_payload.testcaseAddress = test.id() data_payload.application = \ ApplicationManager.generate_application_string(test) data_payload.state = constants.State.NOTRUN data_payload.startTime = int(time.time() * 1000) self.testcase_manager.insert_testcase_data(data_payload) self.case_start_time = int(time.time() * 1000) #more accurate #make the testcase and execution guids available to other plugins test.execution_guid = self.execution_guid
def startTest(self, test): """at the start of the test, set the test case details""" data_payload = TestcaseDataPayload() self.testcase_guid = str(uuid.uuid4()) data_payload.guid = self.testcase_guid data_payload.execution_guid = self.execution_guid if hasattr(test, "browser"): data_payload.browser = test.browser else: data_payload.browser = "N/A" data_payload.testcaseAddress = test.id() application = ApplicationManager.generate_application_string(test) data_payload.env = application.split('.')[0] data_payload.start_time = application.split('.')[1] data_payload.state = constants.State.NOTRUN self.testcase_manager.insert_testcase_data(data_payload) self.case_start_time = int(time.time() * 1000) # Make the testcase guid available to other plugins test.testcase_guid = self.testcase_guid
def __insert_test_result(self, state, test, err=None): data_payload = TestcaseDataPayload() data_payload.runtime = int(time.time() * 1000) - self.case_start_time data_payload.guid = self.testcase_guid data_payload.execution_guid = self.execution_guid data_payload.state = state if err is not None: data_payload.message = err[1].__str__().split('-------------------- >> begin captured logging << --------------------', 1)[0] self.testcase_manager.update_testcase_data(data_payload)
def test_insert_test_case_data(self): payload = TestcaseDataPayload() payload.guid = "antestcaseguid" payload.testcaseAddress = self.id() payload.application = "python unittest" payload.execution_guid = "executionmachine" payload.runtime = 55 payload.state = "Massachusetts" payload.browser = "SeaMonkey" self.manager.insert_testcase_data(payload) query = """SELECT * FROM testcaseRunData WHERE guid = %(guid)s""" results = DatabaseManager('qa').\ fetchone_query_and_close(query, {"guid":'antestcaseguid'}) self.assertTrue(results[0] == 'antestcaseguid') self.assertTrue(results[1] == self.id()) self.assertTrue(results[2] == "python unittest") self.assertTrue(results[3] == "executionmachine") self.assertTrue(results[4] == 55) self.assertTrue(results[5] == 'Massachusetts') self.assertTrue(results[6] == 'SeaMonkey')
def afterTest(self, test): """after each testcase, upload its logs to the location specified""" index_file = None if constants.LogUploader.USE_S3: from test_framework.core.s3_manager import S3LoggingBucket s3_bucket = S3LoggingBucket() guid = str(uuid.uuid4().hex) path = "%s/%s" % (self.options.log_path, test.test.id()) uploaded_files = [] for logfile in os.listdir(path): logfile_name = "%s/%s/%s" % (guid, test.test.id(), logfile.split(path)[-1]) s3_bucket.upload_file(logfile_name, "%s/%s" % (path, logfile)) uploaded_files.append(logfile_name) s3_bucket.save_uploaded_file_names(uploaded_files) index_file = s3_bucket.upload_index_file(test.id(), guid) print "Log files uploaded: %s" % index_file logging.error("Log files uploaded: %s" % index_file) if constants.LogUploader.USE_LOCAL: import shutil guid = test.test.execution_guid path = "%s/%s" % (self.options.log_path, test.test.id()) # only move logs if they actually exist log_files = os.listdir(path) if log_files: dest_path = "%s/%s" % (constants.LogUploader.DESTINATION_PATH, guid) if not os.path.exists(dest_path): os.mkdir(dest_path) dest_path = "%s/%s/" % (dest_path, test.test.id()) shutil.copytree(path, dest_path) log_files.sort() index_str = [] for logfile in log_files: index_str.append('<a href="%s">%s</a>' % (logfile, logfile)) # also add a link to the Sauce job if there was one sauce_id = test.test.sauce_job_id if sauce_id is not None: token = hmac.new("%s:%s" % (constants.Sauce.USER, constants.Sauce.ACCESS_KEY), sauce_id, md5).hexdigest() sauce_url = "https://saucelabs.com/jobs/%s?auth=%s" % (sauce_id, token) index_str.append('<a href="%s">Sauce Job Results</a>' % sauce_url) index = open(dest_path + 'index.html', 'w') index.write("<br>".join(index_str)) file_name = "%s/%s/index.html" % (guid, test.test.id()) index_file = "%s%s" % (constants.LogUploader.BASE_URL, file_name) print "Log files copied: %s" % index_file logging.error("Log files copied: %s" % index_file) if index_file: #if the database plugin is running, attach a link to the logs index #to the database row if hasattr(test.test, "testcase_guid"): from test_framework.core.testcase_manager \ import TestcaseDataPayload, TestcaseManager self.testcase_manager = TestcaseManager(self.options.database_env) data_payload = TestcaseDataPayload() data_payload.guid = test.test.testcase_guid data_payload.logURL = index_file self.testcase_manager.update_testcase_log_url(data_payload)