def execute_boot_bisection_compared_to(doc_id, compare_to, db_options, fields=None): """Execute a bisect for one tree compared to another one. :param doc_id: The ID of the boot report we want compared. :type doc_id: string :param compare_to: The tree name to compare against. :type compare_to: string :param db_options: The options for the database connection. :type db_options: dictionary :param fields: A `fields` data structure with the fields to return or exclude. Default to None. :type fields: list or dict :return A numeric value for the result status and a list dictionaries. """ database = utils.db.get_db_connection(db_options) result = [] code = 200 obj_id = bson.objectid.ObjectId(doc_id) start_doc = utils.db.find_one2(database[models.BOOT_COLLECTION], obj_id, fields=BOOT_SEARCH_FIELDS) if start_doc and isinstance(start_doc, types.DictionaryType): start_doc_get = start_doc.get if start_doc_get(models.STATUS_KEY) == models.PASS_STATUS: code = 400 result = None else: # TODO: we need to know the baseline tree commit in order not to # search too much in the past. end_date, limit = bcommon.search_previous_bisect( database, {models.BOOT_ID_KEY: obj_id}, models.BISECT_BOOT_CREATED_KEY) board = start_doc_get(models.BOARD_KEY) job = start_doc_get(models.JOB_KEY) defconfig = start_doc_get(models.DEFCONFIG_KEY) defconfig_full = start_doc_get( models.DEFCONFIG_FULL_KEY) or defconfig created_on = start_doc_get(models.CREATED_KEY) arch = start_doc_get( models.ARCHITECTURE_KEY) or models.ARM_ARCHITECTURE_KEY lab_name = start_doc_get(models.LAB_NAME_KEY) bisect_doc = mbisect.BootBisectDocument(obj_id) bisect_doc.compare_to = compare_to bisect_doc.version = "1.0" bisect_doc.job = job bisect_doc.job_id = start_doc_get(models.JOB_ID_KEY, None) bisect_doc.build_id = start_doc_get(models.BUILD_ID_KEY, None) bisect_doc.boot_id = obj_id bisect_doc.created_on = datetime.datetime.now(tz=bson.tz_util.utc) bisect_doc.board = board bisect_doc.defconfig_full = defconfig_full bisect_doc.defconfig = defconfig bisect_doc.arch = arch if end_date: date_range = {"$lt": created_on, "$gte": end_date} else: date_range = {"$lt": created_on} spec = { models.LAB_NAME_KEY: lab_name, models.BOARD_KEY: board, models.DEFCONFIG_KEY: defconfig, models.DEFCONFIG_FULL_KEY: defconfig_full, models.JOB_KEY: compare_to, models.ARCHITECTURE_KEY: arch, models.GIT_BRANCH_KEY: start_doc_get(models.GIT_BRANCH_KEY), models.CREATED_KEY: date_range } prev_docs = utils.db.find(database[models.BOOT_COLLECTION], limit, 0, spec=spec, fields=BOOT_SEARCH_FIELDS, sort=BOOT_SORT) all_valid_docs = [] if prev_docs: # The function to apply to each boot document to find its # defconfig one and combine the values. func = bcommon.combine_defconfig_values all_valid_docs.extend( [func(doc, db_options) for doc in prev_docs]) bisect_doc.bisect_data = all_valid_docs bcommon.save_bisect_doc(database, bisect_doc, doc_id) bisect_doc = bcommon.update_doc_fields(bisect_doc, fields) result = [bisect_doc] else: code = 404 result = None return code, result
def execute_boot_bisection_compared_to( doc_id, compare_to, db_options, fields=None): """Execute a bisect for one tree compared to another one. :param doc_id: The ID of the boot report we want compared. :type doc_id: string :param compare_to: The tree name to compare against. :type compare_to: string :param db_options: The options for the database connection. :type db_options: dictionary :param fields: A `fields` data structure with the fields to return or exclude. Default to None. :type fields: list or dict :return A numeric value for the result status and a list dictionaries. """ database = utils.db.get_db_connection(db_options) result = [] code = 200 obj_id = bson.objectid.ObjectId(doc_id) start_doc = utils.db.find_one2( database[models.BOOT_COLLECTION], obj_id, fields=BOOT_SEARCH_FIELDS) if start_doc and isinstance(start_doc, types.DictionaryType): start_doc_get = start_doc.get if start_doc_get(models.STATUS_KEY) == models.PASS_STATUS: code = 400 result = None else: # TODO: we need to know the baseline tree commit in order not to # search too much in the past. end_date, limit = bcommon.search_previous_bisect( database, {models.BOOT_ID_KEY: obj_id}, models.BISECT_BOOT_CREATED_KEY ) board = start_doc_get(models.BOARD_KEY) job = start_doc_get(models.JOB_KEY) defconfig = start_doc_get(models.DEFCONFIG_KEY) defconfig_full = start_doc_get( models.DEFCONFIG_FULL_KEY) or defconfig created_on = start_doc_get(models.CREATED_KEY) arch = start_doc_get(models.ARCHITECTURE_KEY) lab_name = start_doc_get(models.LAB_NAME_KEY) bisect_doc = mbisect.BootBisectDocument(obj_id) bisect_doc.compare_to = compare_to bisect_doc.version = "1.0" bisect_doc.job = job bisect_doc.job_id = start_doc_get(models.JOB_ID_KEY, None) bisect_doc.build_id = start_doc_get(models.BUILD_ID_KEY, None) bisect_doc.boot_id = obj_id bisect_doc.created_on = datetime.datetime.now(tz=bson.tz_util.utc) bisect_doc.board = board bisect_doc.defconfig_full = defconfig_full bisect_doc.defconfig = defconfig bisect_doc.arch = arch if end_date: date_range = { "$lt": created_on, "$gte": end_date } else: date_range = {"$lt": created_on} spec = { models.LAB_NAME_KEY: lab_name, models.BOARD_KEY: board, models.DEFCONFIG_KEY: defconfig, models.DEFCONFIG_FULL_KEY: defconfig_full, models.JOB_KEY: compare_to, models.ARCHITECTURE_KEY: arch, models.GIT_BRANCH_KEY: start_doc_get(models.GIT_BRANCH_KEY), models.CREATED_KEY: date_range } prev_docs = utils.db.find( database[models.BOOT_COLLECTION], limit, 0, spec=spec, fields=BOOT_SEARCH_FIELDS, sort=BOOT_SORT) all_valid_docs = [] if prev_docs: # The function to apply to each boot document to find its # defconfig one and combine the values. func = bcommon.combine_defconfig_values all_valid_docs.extend( [ func(doc, db_options) for doc in prev_docs ] ) bisect_doc.bisect_data = all_valid_docs bcommon.save_bisect_doc(database, bisect_doc, doc_id) bisect_doc = bcommon.update_doc_fields(bisect_doc, fields) result = [bisect_doc] else: code = 404 result = None return code, result