def get_image_output(self, arch): """ Create the output for the image This is the Koji Content Generator metadata, along with the 'docker save' output to upload. For metadata-only builds, an empty file is used instead of the output of 'docker save'. :param arch: str, architecture for this output :return: tuple, (metadata dict, Output instance) """ image_id = self.workflow.builder.image_id saved_image = self.workflow.exported_image_sequence[-1].get('path') ext = saved_image.split('.', 1)[1] name_fmt = 'docker-image-{id}.{arch}.{ext}' image_name = name_fmt.format(id=image_id, arch=arch, ext=ext) if self.metadata_only: metadata = self.get_output_metadata(os.path.devnull, image_name) output = Output(file=None, metadata=metadata) else: metadata = self.get_output_metadata(saved_image, image_name) output = Output(file=open(saved_image), metadata=metadata) return metadata, output
def get_image_output(self, arch): """ Create the output for the image This is the Koji Content Generator metadata, along with the 'docker save' output to upload. For metadata-only builds, an empty file is used instead of the output of 'docker save'. :param arch: str, architecture for this output :return: tuple, (metadata dict, Output instance) """ saved_image = self.workflow.exported_image_sequence[-1].get('path') image_name = get_image_upload_filename(self.workflow.exported_image_sequence[-1], self.workflow.builder.image_id, arch) if self.metadata_only: metadata = self.get_output_metadata(os.path.devnull, image_name) output = Output(file=None, metadata=metadata) else: metadata = self.get_output_metadata(saved_image, image_name) output = Output(file=open(saved_image), metadata=metadata) return metadata, output
def get_logs(self): """ Build the logs entry for the metadata 'output' section :return: list, Output instances """ output = [] # Collect logs from server try: logs = self.osbs.get_build_logs(self.build_id) except OsbsException as ex: self.log.error("unable to get build logs: %r", ex) else: # Deleted once closed logfile = NamedTemporaryFile(prefix=self.build_id, suffix=".log", mode='wb') try: logfile.write(logs) except (TypeError, UnicodeEncodeError): # Older osbs-client versions returned Unicode objects logfile.write(logs.encode('utf-8')) logfile.flush() metadata = self.get_output_metadata(logfile.name, "openshift-final.log") output.append(Output(file=logfile, metadata=metadata)) docker_logs = NamedTemporaryFile(prefix="docker-%s" % self.build_id, suffix=".log", mode='wb') docker_logs.write("\n".join(self.workflow.build_result.logs).encode('utf-8')) docker_logs.flush() output.append(Output(file=docker_logs, metadata=self.get_output_metadata(docker_logs.name, "build.log"))) return output
def get_logs(self): """ Build list of log files :return: list, of log files """ logs = None output = [] # Collect logs from server try: logs = self.osbs.get_orchestrator_build_logs(self.build_id) except OsbsException as ex: self.log.error("unable to get build logs: %r", ex) return output except TypeError: # Older osbs-client has no get_orchestrator_build_logs self.log.error( "OSBS client does not support get_orchestrator_build_logs") return output platform_logs = {} for entry in logs: platform = entry.platform if platform not in platform_logs: filename = 'orchestrator' if platform is None else platform platform_logs[platform] = NamedTemporaryFile( prefix="%s-%s" % (self.build_id, filename), suffix=".log", mode='wb') platform_logs[platform].write((entry.line + '\n').encode('utf-8')) for platform, logfile in platform_logs.items(): logfile.flush() filename = 'orchestrator' if platform is None else platform metadata = self.get_output_metadata(logfile.name, "%s.log" % filename) output.append(Output(file=logfile, metadata=metadata)) return output
def add_log_type(output): logfile, metadata = output metadata.update({'type': 'log', 'arch': 'noarch'}) return Output(file=logfile, metadata=metadata)
def add_buildroot_id(output): logfile, metadata = output metadata.update({'buildroot_id': buildroot_id}) return Output(file=logfile, metadata=metadata)