def post_buildlog(log_info: dict): """Store the given build log.""" adapter = BuildLogsStore() adapter.connect() document_id = adapter.store_document(log_info) return {"document_id": document_id}, 202
def _get_document(document_id: str, log: str): """Get the build log document from ceph and store it in required log path.""" adapter = BuildLogsStore() adapter.connect() document = adapter.retrieve_document(document_id) with open(log, "w") as f: f.write(document.get("build_log", {}).get("log")) return
def _store_build_log( build_log: typing.Dict[str, typing.Any], force: bool = False) -> typing.Tuple[str, typing.Optional[str]]: """Store the given build log, use cached entry if available.""" buildlog_analysis_id = None if not force: cache = BuildLogsAnalysesCacheStore() cache.connect() cached_document_id = _compute_digest_params(build_log) try: cache_record = cache.retrieve_document_record(cached_document_id) buildlog_analysis_id = cache_record.pop("analysis_id") except CacheMiss: pass adapter = BuildLogsStore() adapter.connect() document_id = adapter.store_document(build_log) return document_id, buildlog_analysis_id
def test_init_kwargs(self): """Test adapter initialization from explicit arguments supplied to constructor.""" adapter = BuildLogsStore(**_BUILDLOGS_INIT_KWARGS, **CEPH_INIT_KWARGS, **_BUILDLOGS_INIT_KWARGS_EXP) assert not adapter.is_connected() for key, value in _BUILDLOGS_INIT_KWARGS.items(): assert getattr(adapter, key) == value, ( f"Build log's adapter attribute {key!r} should have value {value!r} but " f"got {getattr(adapter, key)!r} instead") assert adapter.ceph is not None assert not adapter.ceph.is_connected() for key, value in CEPH_INIT_KWARGS.items(): assert getattr(adapter.ceph, key) == value, ( f"Ceph's adapter key {key!r} should have value {value!r} but " f"got {getattr(adapter.ceph, key)!r} instead") bucket_prefix = _BUILDLOGS_INIT_KWARGS_EXP["bucket_prefix"] assert adapter.prefix == f"{bucket_prefix}/{adapter.deployment_name}/buildlogs/" assert adapter.ceph.prefix == adapter.prefix
def _fixture_adapter(): """Retrieve an adapter to build logs.""" return BuildLogsStore()