def test_state_checkers(self): build_response = BuildResponse({ 'status': { 'phase': 'Complete' } }) build_response.status = 'complete' assert build_response.is_finished() assert build_response.is_succeeded() assert not build_response.is_failed() assert not build_response.is_cancelled() assert not build_response.is_running() assert not build_response.is_pending() assert not build_response.is_in_progress() build_response.status = 'failed' assert build_response.is_failed() assert build_response.is_finished() assert not build_response.is_succeeded() assert not build_response.is_cancelled() assert not build_response.is_running() assert not build_response.is_pending() assert not build_response.is_in_progress() build_response.status = 'cancelled' assert build_response.is_cancelled() assert build_response.is_failed() assert build_response.is_finished() assert not build_response.is_succeeded() assert not build_response.is_running() assert not build_response.is_pending() assert not build_response.is_in_progress() build_response.status = 'running' assert build_response.is_running() assert build_response.is_in_progress() assert not build_response.is_cancelled() assert not build_response.is_failed() assert not build_response.is_finished() assert not build_response.is_succeeded() assert not build_response.is_pending() build_response.status = 'pending' assert build_response.is_pending() assert build_response.is_in_progress() assert not build_response.is_running() assert not build_response.is_cancelled() assert not build_response.is_failed() assert not build_response.is_finished() assert not build_response.is_succeeded()
def test_state_checkers(self): build_response = BuildResponse({ 'status': { 'phase': 'Complete' } }) build_response.status = 'complete' assert build_response.is_finished() assert build_response.is_succeeded() assert not build_response.is_failed() assert not build_response.is_cancelled() assert not build_response.is_running() assert not build_response.is_pending() assert not build_response.is_in_progress() build_response.status = 'failed' assert build_response.is_failed() assert build_response.is_finished() assert not build_response.is_succeeded() assert not build_response.is_cancelled() assert not build_response.is_running() assert not build_response.is_pending() assert not build_response.is_in_progress() build_response.status = 'cancelled' assert build_response.is_cancelled() assert build_response.is_failed() assert build_response.is_finished() assert not build_response.is_succeeded() assert not build_response.is_running() assert not build_response.is_pending() assert not build_response.is_in_progress() build_response.status = 'running' assert build_response.is_running() assert build_response.is_in_progress() assert not build_response.is_cancelled() assert not build_response.is_failed() assert not build_response.is_finished() assert not build_response.is_succeeded() assert not build_response.is_pending() build_response.status = 'pending' assert build_response.is_pending() assert build_response.is_in_progress() assert not build_response.is_running() assert not build_response.is_cancelled() assert not build_response.is_failed() assert not build_response.is_finished() assert not build_response.is_succeeded()
def get_build_logs(self, build_id, follow=False, namespace=DEFAULT_NAMESPACE): if follow: return self.os.logs(build_id, follow, namespace=namespace) try: build = self.os.get_build(build_id, namespace=namespace) except OsbsResponseException as ex: if ex.status_code != 404: raise else: build_response = BuildResponse(build) logs = None if build_response.is_finished(): metadata = build_response.json.get("metadata", {}) md = metadata.get("annotations", metadata.get("labels", {})) logs = md.get("logs", None) if logs: return logs return self.os.logs(build_id, follow=False, namespace=namespace)
def get_docker_build_logs(self, build_id, decode_logs=True, build_json=None): """ get logs provided by "docker build" :param build_id: str :param decode_logs: bool, docker by default output logs in simple json structure: { "stream": "line" } if this arg is set to True, it decodes logs to human readable form :param build_json: dict, to save one get-build query :return: str """ if not build_json: build = self.os.get_build(build_id) build_response = BuildResponse(build.json()) else: build_response = BuildResponse(build_json) if build_response.is_finished(): logs = build_response.get_logs(decode_logs=decode_logs) return logs logger.warning("build haven't finished yet")
def get_docker_build_logs(self, build_id, decode_logs=True, build_json=None): """ get logs provided by "docker build" :param build_id: str :param decode_logs: bool, docker by default output logs in simple json structure: { "stream": "line" } if this arg is set to True, it decodes logs to human readable form :param build_json: dict, to save one get-build query :return: str """ if not build_json: build = self.os.get_build(build_id) build_response = BuildResponse(build.json()) else: build_response = BuildResponse(build_json) if build_response.is_finished(): logs = build_response.get_logs(decode_logs=decode_logs) return logs logger.warning("build haven't finished yet")