def test_bisect_base_properties(self): bisect_doc = modbs.BootBisectDocument("foo") bisect_doc.id = "bar" bisect_doc.created_on = "now" bisect_doc.job = "fooz" bisect_doc.bisect_data = [1, 2, 3] bisect_doc.good_commit = "1" bisect_doc.good_commit_date = "now" bisect_doc.good_commit_url = "url" bisect_doc.bad_commit = "2" bisect_doc.bad_commit_date = "now" bisect_doc.bad_commit_url = "url" bisect_doc.found_summary = "1234abcd foo: bar" bisect_doc.verified = "pass" bisect_doc.log = "https://storage.org/log.txt" self.assertEqual(bisect_doc.id, "bar") self.assertEqual(bisect_doc.created_on, "now") self.assertEqual(bisect_doc.job, "fooz") self.assertEqual(bisect_doc.bisect_data, [1, 2, 3]) self.assertEqual(bisect_doc.good_commit, "1") self.assertEqual(bisect_doc.good_commit_date, "now") self.assertEqual(bisect_doc.good_commit_url, "url") self.assertEqual(bisect_doc.bad_commit, "2") self.assertEqual(bisect_doc.bad_commit_date, "now") self.assertEqual(bisect_doc.bad_commit_url, "url") self.assertEqual(bisect_doc.found_summary, "1234abcd foo: bar") self.assertEqual(bisect_doc.verified, "pass") self.assertEqual(bisect_doc.log, "https://storage.org/log.txt")
def test_bisect_boot_to_dict(self): bisect_doc = modbs.BootBisectDocument("foo") bisect_doc.id = "bar" bisect_doc.board = "baz" bisect_doc.version = "1.0" bisect_doc.boot_id = "boot-id" bisect_doc.build_id = "build-id" bisect_doc.job_id = "job-id" expected = { "_id": "bar", "board": "baz", "created_on": None, "job": None, "bisect_data": [], "compare_to": None, "good_commit": None, "good_commit_date": None, "good_commit_url": None, "bad_commit": None, "bad_commit_date": None, "bad_commit_url": None, "version": "1.0", "boot_id": "boot-id", "build_id": "build-id", "job_id": "job-id", "type": "boot", "arch": None, "defconfig": None, "defconfig_full": None } self.assertDictEqual(expected, bisect_doc.to_dict())
def create_boot_bisect(good, bad, db_options): """Create a boot bisection document or find existing matching one :param good: Passing boot data :type good: dict :param bad: Failing boot data :type bad: dict :param db_options: The options for the database connection. :type db_options: dictionary :return The BootBisectDocument instance. """ database = utils.db.get_db_connection(db_options) good_commit, bad_commit = (b[models.GIT_COMMIT_KEY] for b in (good, bad)) spec = { x: bad[x] for x in [ models.LAB_NAME_KEY, models.DEVICE_TYPE_KEY, models.ARCHITECTURE_KEY, models.DEFCONFIG_FULL_KEY, ] } spec.update({ models.BISECT_GOOD_COMMIT_KEY: good_commit, models.BISECT_BAD_COMMIT_KEY: bad_commit, }) doc = utils.db.find_one2(database[models.BISECT_COLLECTION], spec) if doc: return doc bad_boot_id = bson.objectid.ObjectId(bad["_id"]) doc = mbisect.BootBisectDocument(bad_boot_id) doc.boot_id = bad_boot_id doc.version = "1.0" doc.job = bad[models.JOB_KEY] doc.job_id = bad[models.JOB_ID_KEY] doc.created_on = datetime.datetime.now(tz=bson.tz_util.utc) doc.bisect_data = [bad, good] doc.good_commit = good_commit doc.good_commit_url = good[models.GIT_URL_KEY] doc.good_commit_date = good[models.CREATED_KEY] doc.bad_commit = bad_commit doc.bad_commit_url = bad[models.GIT_URL_KEY] doc.bad_commit_date = bad[models.CREATED_KEY] doc.kernel = bad[models.KERNEL_KEY] doc.git_branch = bad[models.GIT_BRANCH_KEY] doc.git_url = bad[models.GIT_URL_KEY] doc.arch = bad[models.ARCHITECTURE_KEY] doc.defconfig = bad[models.DEFCONFIG_KEY] doc.defconfig_full = bad[models.DEFCONFIG_FULL_KEY] doc.compiler = bad[models.COMPILER_KEY] doc.compiler_version = bad[models.COMPILER_VERSION_KEY] doc.build_environment = bad[models.BUILD_ENVIRONMENT_KEY] doc.build_id = bad[models.BUILD_ID_KEY] doc.lab_name = bad[models.LAB_NAME_KEY] doc.device_type = bad[models.DEVICE_TYPE_KEY] bcommon.save_bisect_doc(database, doc, bad_boot_id) return doc.to_dict()
def test_bisect_boot_to_dict(self): bisect_doc = modbs.BootBisectDocument("foo") bisect_doc.id = "bar" bisect_doc.board = "baz" bisect_doc.version = "1.0" bisect_doc.boot_id = "boot-id" bisect_doc.build_id = "build-id" bisect_doc.job_id = "job-id" bisect_doc.git_url = "https://somewhere.com/blah.git" bisect_doc.git_branch = "master" bisect_doc.kernel = "v123.456" bisect_doc.log = "https://storage.org/log.txt" bisect_doc.device_type = "qemu" bisect_doc.lab_name = "secret-lab" expected = { "_id": "bar", "board": "baz", "created_on": None, "job": None, "bisect_data": [], "compare_to": None, "good_commit": None, "good_commit_date": None, "good_commit_url": None, "good_summary": None, "bad_commit": None, "bad_commit_date": None, "bad_commit_url": None, "bad_summary": None, "version": "1.0", "boot_id": "boot-id", "build_id": "build-id", "job_id": "job-id", "type": "boot", "compiler": None, "compiler_version": None, "build_environment": None, "lab_name": "secret-lab", "arch": None, "device_type": "qemu", "defconfig": None, "defconfig_full": None, "git_url": "https://somewhere.com/blah.git", "git_branch": "master", "kernel": "v123.456", "log": "https://storage.org/log.txt", "found_summary": None, "checks": {}, } self.assertDictEqual(expected, bisect_doc.to_dict())
def test_bisect_base_properties(self): bisect_doc = modbs.BootBisectDocument("foo") bisect_doc.id = "bar" bisect_doc.created_on = "now" bisect_doc.job = "fooz" bisect_doc.bisect_data = [1, 2, 3] bisect_doc.good_commit = "1" bisect_doc.good_commit_date = "now" bisect_doc.good_commit_url = "url" bisect_doc.bad_commit = "2" bisect_doc.bad_commit_date = "now" bisect_doc.bad_commit_url = "url" self.assertEqual(bisect_doc.id, "bar") self.assertEqual(bisect_doc.created_on, "now") self.assertEqual(bisect_doc.job, "fooz") self.assertEqual(bisect_doc.bisect_data, [1, 2, 3]) self.assertEqual(bisect_doc.good_commit, "1") self.assertEqual(bisect_doc.good_commit_date, "now") self.assertEqual(bisect_doc.good_commit_url, "url") self.assertEqual(bisect_doc.bad_commit, "2") self.assertEqual(bisect_doc.bad_commit_date, "now") self.assertEqual(bisect_doc.bad_commit_url, "url")
def _find_boot_bisect_data(obj_id, start_doc, database, db_options): """Execute the real bisect logic. This is where the BisectDocument is created and returned. :param obj_id: The `bson.objectid.ObjectId` of the starting point. :type obj_id: bson.objectid.ObjectId :param start_doc: The starting document. :type start_doc: dictionary :param database: The connection to the database. :param db_options: The options for the database connection. :type db_options: dictionary :return A BisectDocument instance. """ start_doc_get = start_doc.get 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.boot_id = obj_id 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.created_on = datetime.datetime.now(tz=bson.tz_util.utc) bisect_doc.board = board bisect_doc.arch = arch bisect_doc.defconfig = defconfig bisect_doc.defconfig_full = defconfig_full spec = { models.LAB_NAME_KEY: lab_name, models.BOARD_KEY: board, models.DEFCONFIG_KEY: defconfig, models.DEFCONFIG_FULL_KEY: defconfig_full, models.JOB_KEY: start_doc_get(models.JOB_KEY), models.ARCHITECTURE_KEY: arch, models.CREATED_KEY: { "$lt": created_on }, models.GIT_BRANCH_KEY: start_doc_get(models.GIT_BRANCH_KEY) } # The function to apply to each boot document to find its build # one and combine the values. func = bcommon.combine_defconfig_values bad_doc = func(start_doc, db_options) bad_doc_get = bad_doc.get bisect_doc.bad_commit_date = bad_doc_get( models.BISECT_DEFCONFIG_CREATED_KEY) bisect_doc.bad_commit = bad_doc_get(models.GIT_COMMIT_KEY) bisect_doc.bad_commit_url = bad_doc_get(models.GIT_URL_KEY) all_valid_docs = [bad_doc] # Search through all the previous boot reports, until one that # passed is found, and combine them with their build document. all_prev_docs = utils.db.find(database[models.BOOT_COLLECTION], 0, 0, spec=spec, fields=BOOT_SEARCH_FIELDS, sort=BOOT_SORT) if all_prev_docs: all_valid_docs.extend([ func(doc, db_options) for doc in bcommon.get_docs_until_pass(all_prev_docs) ]) # The last doc should be the good one, in case it is, add the # values to the bisect_doc. good_doc = all_valid_docs[-1] if (good_doc[models.BISECT_BOOT_STATUS_KEY] == models.PASS_STATUS): good_doc_get = good_doc.get bisect_doc.good_commit = good_doc_get(models.GIT_COMMIT_KEY) bisect_doc.good_commit_url = good_doc_get(models.GIT_URL_KEY) bisect_doc.good_commit_date = good_doc_get( models.BISECT_DEFCONFIG_CREATED_KEY) # Store everything in the bisect_data list of the bisect_doc. bisect_doc.bisect_data = all_valid_docs return bisect_doc
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 test_bisect_boot_document_collection(self): bisect_doc = modbs.BootBisectDocument("foo") self.assertEqual(bisect_doc.collection, "bisect")
def test_boot_bisect_document(self): bisect_doc = modbs.BootBisectDocument("bar") self.assertIsInstance(bisect_doc, modbs.BisectDocument) self.assertIsInstance(bisect_doc, modb.BaseDocument)
def test_bisect_boot_properties(self): bisect_doc = modbs.BootBisectDocument("foo") bisect_doc.board = "bar" self.assertEqual(bisect_doc.board, "bar")