def test_doc_to_dict(self): doc = merrl.ErrorLogDocument("job_id", "1.1") doc.arch = "arm" doc.created_on = "today" doc.defconfig = "defconfig" doc.defconfig_full = "defconfig_full" doc.build_id = "build-id" doc.errors = ["error1"] doc.errors_count = 1 doc.job = "job" doc.kernel = "kernel" doc.mismatches = ["mismatch1"] doc.mismatches_count = 1 doc.status = "FAIL" doc.warnings = ["warning1"] doc.warnings_count = 1 doc.file_server_url = "foo" doc.file_server_resource = "bar" doc.compiler = "gcc" doc.compiler_version = "gcc version" doc.compiler_version_ext = "gcc version ext" doc.compiler_version_full = "gcc version full" doc.git_branch = "branch" doc.build_environment = "build_environment" expected = { "arch": "arm", "created_on": "today", "defconfig": "defconfig", "defconfig_full": "defconfig_full", "build_id": "build-id", "errors": ["error1"], "errors_count": 1, "job": "job", "job_id": "job_id", "kernel": "kernel", "mismatches": ["mismatch1"], "mismatches_count": 1, "status": "FAIL", "version": "1.1", "warnings": ["warning1"], "warnings_count": 1, "file_server_url": "foo", "file_server_resource": "bar", "compiler": "gcc", "compiler_version": "gcc version", "compiler_version_ext": "gcc version ext", "compiler_version_full": "gcc version full", "git_branch": "branch", "build_environment": "build_environment" } self.assertDictEqual(expected, doc.to_dict()) doc.id = "id" expected["_id"] = "id" self.assertDictEqual(expected, doc.to_dict())
def test_doc_wrong_lists(self): doc = merrl.ErrorLogDocument("job_id", "1.1") self.assertRaises(TypeError, setattr, doc, "errors", {}) self.assertRaises(TypeError, setattr, doc, "errors", "") self.assertRaises(TypeError, setattr, doc, "errors", 0) self.assertRaises(TypeError, setattr, doc, "errors", ()) self.assertRaises(TypeError, setattr, doc, "warnings", {}) self.assertRaises(TypeError, setattr, doc, "warnings", "") self.assertRaises(TypeError, setattr, doc, "warnings", 0) self.assertRaises(TypeError, setattr, doc, "warnings", ()) self.assertRaises(TypeError, setattr, doc, "mismatches", {}) self.assertRaises(TypeError, setattr, doc, "mismatches", "") self.assertRaises(TypeError, setattr, doc, "mismatches", 0) self.assertRaises(TypeError, setattr, doc, "mismatches", ())
def test_doc_valid_instance(self): doc = merrl.ErrorLogDocument("job_id", "1.1") self.assertIsInstance(doc, modb.BaseDocument) self.assertIsInstance(doc, merrl.ErrorLogDocument)
def test_doc_collection(self): doc = merrl.ErrorLogDocument("job_id", "1.1") self.assertEqual("error_logs", doc.collection)
def save_defconfig_errors(build_doc, job_id, error_lines, warning_lines, mismatch_lines, db_options): """Save the build errors found. Save in the database the extracted lines from the build log. :param job_id: The ID of the job. :type job_id: str :param job: The name of the job. :type job: str :param kernel: The name of the kernel. :type kernel: str :param defconfig: The defconfig value. :type defconfig: str :param defconfig_full: The full defconfig value. :type defconfig_full: str :param arch: The architecture type. :type arch: str :param build_status: The status of the build. :type build_status: str :param error_lines: The extracted error lines. :type error_lines: list :param warning_lines: The extracted warning lines. :type warning_lines: list :param mismatch_lines: The extracted mismatch lines. :type mismatch_lines: list :param db_options: The database connection options. :type db_options: dictionary :return 201 if saving has success, 500 otherwise. """ build_id = None database = utils.db.get_db_connection(db_options) if not build_doc.id: spec = { models.ARCHITECTURE_KEY: build_doc.arch, models.DEFCONFIG_FULL_KEY: build_doc.defconfig_full, models.DEFCONFIG_KEY: build_doc.defconfig, models.GIT_BRANCH_KEY: build_doc.git_branch, models.JOB_KEY: build_doc.job, models.KERNEL_KEY: build_doc.kernel } if job_id: spec[models.JOB_ID_KEY] = job_id doc = utils.db.find_one2(database[models.BUILD_COLLECTION], spec, fields=[models.ID_KEY]) if doc: build_id = doc[models.ID_KEY] else: utils.LOG.warn("No build ID found for %s-%s-%s (%s)", build_doc.job, build_doc.kernel, build_doc.defconfig_full, build_doc.arch) else: build_id = build_doc.id if build_id: prev_spec = {models.BUILD_ID_KEY: build_id} else: prev_spec = { models.ARCHITECTURE_KEY: build_doc.arch, models.DEFCONFIG_FULL_KEY: build_doc.defconfig_full, models.DEFCONFIG_KEY: build_doc.defconfig, models.GIT_BRANCH_KEY: build_doc.git_branch, models.JOB_KEY: build_doc.job, models.KERNEL_KEY: build_doc.kernel, models.STATUS_KEY: build_doc.status } prev_doc = utils.db.find_one2(database[models.ERROR_LOGS_COLLECTION], prev_spec, fields=[models.ID_KEY]) err_doc = merrl.ErrorLogDocument(job_id, "1.1") err_doc.arch = build_doc.arch err_doc.created_on = datetime.datetime.now(tz=bson.tz_util.utc) err_doc.defconfig = build_doc.defconfig err_doc.defconfig_full = build_doc.defconfig_full err_doc.build_id = build_id err_doc.errors = error_lines err_doc.errors_count = len(error_lines) err_doc.git_branch = build_doc.git_branch err_doc.job = build_doc.job err_doc.kernel = build_doc.kernel err_doc.mismatch_lines = len(mismatch_lines) err_doc.mismatches = mismatch_lines err_doc.status = build_doc.status err_doc.warnings = warning_lines err_doc.warnings_count = len(warning_lines) err_doc.file_server_resource = build_doc.file_server_resource err_doc.file_server_url = build_doc.file_server_url err_doc.compiler = build_doc.compiler err_doc.compiler_version = build_doc.compiler_version err_doc.compiler_version_ext = build_doc.compiler_version_ext err_doc.compiler_version_full = build_doc.compiler_version_full manipulate = True if prev_doc: manipulate = False err_doc.id = prev_doc[models.ID_KEY] ret_val, _ = utils.db.save(database, err_doc, manipulate=manipulate) return ret_val