def wait_for_task(cls, build_dict, task_id, results_dir): session = KojiHelper.create_session() task_dict = KojiHelper.watch_koji_tasks(session, [task_id]) rpms, logs = KojiHelper.download_task_results(session, list(task_dict), results_dir) exit_code = cls._verify_tasks(session, task_dict) if exit_code: raise BinaryPackageBuildError(exit_code=exit_code) return rpms, logs
def build_source_packages(self): try: builder = plugin_manager.srpm_build_tools.get_plugin(self.conf.srpm_buildtool) except NotImplementedError as e: raise RebaseHelperError('{}. Supported SRPM build tools are {}'.format( str(e), plugin_manager.srpm_build_tools.get_supported_tools())) for version in ['old', 'new']: koji_build_id = None results_dir = '{}-build'.format(os.path.join(self.results_dir, version)) spec = self.spec_file if version == 'old' else self.rebase_spec_file package_name = spec.get_package_name() package_version = spec.get_version() package_full_version = spec.get_full_version() logger.info('Building source package for %s version %s', package_name, package_full_version) if version == 'old' and self.conf.get_old_build_from_koji: koji_build_id, package_version, package_full_version = KojiHelper.get_old_build_info(package_name, package_version) build_dict = dict( name=package_name, version=package_version, srpm_buildtool=self.conf.srpm_buildtool, srpm_builder_options=self.conf.srpm_builder_options) try: if koji_build_id: session = KojiHelper.create_session() build_dict['srpm'], build_dict['logs'] = KojiHelper.download_build(session, koji_build_id, os.path.join( results_dir, 'SRPM' ), arches=['src']) else: build_dict.update(builder.build(spec, results_dir, **build_dict)) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) except RebaseHelperError: # pylint: disable=try-except-raise raise except SourcePackageBuildError as e: build_dict.update(builder.get_logs()) build_dict['source_package_build_error'] = str(e) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) if e.logfile: msg = 'Building {} SRPM packages failed; see {} for more information'.format(version, e.logfile) else: msg = 'Building {} SRPM packages failed; see logs in {} for more information'.format( version, os.path.join(results_dir, 'SRPM')) logger.error(msg) raise RebaseHelperError(msg, logfiles=builder.get_logs().get('logs')) except Exception: raise RebaseHelperError('Building package failed with unknown reason. ' 'Check all available log files.')
def build_source_packages(self): try: builder = srpm_build_helper.get_tool(self.conf.srpm_buildtool) except NotImplementedError as e: raise RebaseHelperError('{}. Supported SRPM build tools are {}'.format( six.text_type(e), srpm_build_helper.get_supported_tools())) for version in ['old', 'new']: koji_build_id = None results_dir = '{}-build'.format(os.path.join(self.results_dir, version)) spec = self.spec_file if version == 'old' else self.rebase_spec_file package_name = spec.get_package_name() package_version = spec.get_version() package_full_version = spec.get_full_version() logger.info('Building source package for %s version %s', package_name, package_full_version) if version == 'old' and self.conf.get_old_build_from_koji: koji_build_id, package_version, package_full_version = KojiHelper.get_old_build_info(package_name, package_version) build_dict = dict( name=package_name, version=package_version, srpm_buildtool=self.conf.srpm_buildtool, srpm_builder_options=self.conf.srpm_builder_options) try: if koji_build_id: session = KojiHelper.create_session() build_dict['srpm'], build_dict['logs'] = KojiHelper.download_build(session, koji_build_id, os.path.join( results_dir, 'SRPM' ), arches=['src']) else: build_dict.update(builder.build(spec, results_dir, **build_dict)) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) except RebaseHelperError: # pylint: disable=try-except-raise raise except SourcePackageBuildError as e: build_dict.update(builder.get_logs()) build_dict['source_package_build_error'] = six.text_type(e) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) if e.logfile: msg = 'Building {} SRPM packages failed; see {} for more information'.format(version, e.logfile) else: msg = 'Building {} SRPM packages failed; see logs in {} for more information'.format( version, os.path.join(results_dir, 'SRPM')) raise RebaseHelperError(msg, logfiles=builder.get_logs().get('logs')) except Exception: raise RebaseHelperError('Building package failed with unknown reason. ' 'Check all available log files.')
def get_detached_task(cls, task_id, results_dir): session = KojiHelper.create_session() rpms, logs = KojiHelper.download_task_results(session, [task_id], results_dir) task = session.getTaskInfo(task_id) exit_code = cls._verify_tasks(session, {task_id: task['state']}) if exit_code: raise BinaryPackageBuildError(exit_code=exit_code) if not rpms: raise RebaseHelperError('Koji tasks are not finished yet. Try again later.') return rpms, logs
def wait_for_task(cls, build_dict, task_id, results_dir): session = KojiHelper.create_session() task_dict = KojiHelper.watch_koji_tasks(session, [task_id]) rpms, logs = KojiHelper.download_task_results(session, list(task_dict), results_dir) exit_code = cls._verify_tasks(session, task_dict) if exit_code: raise BinaryPackageBuildError(logs=logs, logfile=get_mock_logfile_path( exit_code, results_dir)) return rpms, logs
def get_detached_task(cls, task_id, results_dir): session = KojiHelper.create_session() rpms, logs = KojiHelper.download_task_results(session, [task_id], results_dir) task = session.getTaskInfo(task_id) exit_code = cls._verify_tasks(session, {task_id: task['state']}) if exit_code: raise BinaryPackageBuildError(logs=logs, logfile=get_mock_logfile_path( exit_code, results_dir)) if not rpms: raise RebaseHelperError( 'Koji tasks are not finished yet. Try again later.') return rpms, logs
def _scratch_build(cls, srpm, **kwargs): session = KojiHelper.create_session(login=True) remote = KojiHelper.upload_srpm(session, srpm) task_id = session.build(remote, cls.target_tag, dict(scratch=True)) if kwargs['builds_nowait']: return None, None, task_id url = KojiHelper.get_task_url(session, task_id) logger.info('Koji task is here: %s\n', url) session.logout() task_dict = KojiHelper.watch_koji_tasks(session, [task_id]) path = os.path.dirname(srpm).replace('SRPM', 'RPM') rpms, logs = KojiHelper.download_task_results(session, list(task_dict), path) exit_code = cls._verify_tasks(session, task_dict) if exit_code: raise BinaryPackageBuildError(exit_code=exit_code) return rpms, logs, task_id
def _scratch_build(cls, results_dir, srpm, **kwargs): session = KojiHelper.create_session(login=True) remote = KojiHelper.upload_srpm(session, srpm) task_id = session.build(remote, cls.TARGET_TAG, dict(scratch=True)) if kwargs['builds_nowait']: return None, None, task_id url = KojiHelper.get_task_url(session, task_id) logger.info('Koji task is here: %s\n', url) session.logout() task_dict = KojiHelper.watch_koji_tasks(session, [task_id]) path = os.path.dirname(srpm).replace('SRPM', 'RPM') rpms, logs = KojiHelper.download_task_results(session, list(task_dict), path) exit_code = cls._verify_tasks(session, task_dict) if exit_code: raise BinaryPackageBuildError(logs=logs, logfile=get_mock_logfile_path( exit_code, results_dir)) return rpms, logs, task_id
def get_task_info(cls, build_dict): session = KojiHelper.create_session() url = KojiHelper.get_task_url(session, build_dict['koji_task_id']) return 'Scratch build for {} version is: {}'.format(build_dict['version'], url)
def build_binary_packages(self): """Function calls build class for building packages""" try: builder = build_helper.get_tool(self.conf.buildtool) except NotImplementedError as e: raise RebaseHelperError('{}. Supported build tools are {}'.format( six.text_type(e), build_helper.get_supported_tools())) for version in ['old', 'new']: results_dir = '{}-build'.format(os.path.join(self.results_dir, version)) spec = None task_id = None koji_build_id = None build_dict = {} if self.conf.build_tasks is None: spec = self.spec_file if version == 'old' else self.rebase_spec_file package_name = spec.get_package_name() package_version = spec.get_version() package_full_version = spec.get_full_version() if version == 'old' and self.conf.get_old_build_from_koji: koji_build_id, package_version, package_full_version = KojiHelper.get_old_build_info( package_name, package_version) build_dict = dict( name=package_name, version=package_version, builds_nowait=self.conf.builds_nowait, build_tasks=self.conf.build_tasks, builder_options=self.conf.builder_options, srpm=results_store.get_build(version).get('srpm'), srpm_logs=results_store.get_build(version).get('logs')) # prepare for building builder.prepare(spec, self.conf) logger.info('Building binary packages for %s version %s', package_name, package_full_version) else: task_id = self.conf.build_tasks[0] if version == 'old' else self.conf.build_tasks[1] try: if self.conf.build_tasks is None: if koji_build_id: session = KojiHelper.create_session() build_dict['rpm'], build_dict['logs'] = KojiHelper.download_build(session, koji_build_id, os.path.join( results_dir, 'RPM', ), arches=['noarch', 'x86_64']) else: build_dict.update(builder.build(spec, results_dir, **build_dict)) if builder.CREATES_TASKS and task_id and not koji_build_id: if not self.conf.builds_nowait: build_dict['rpm'], build_dict['logs'] = builder.wait_for_task(build_dict, task_id, results_dir) elif self.conf.build_tasks: build_dict['rpm'], build_dict['logs'] = builder.get_detached_task(task_id, results_dir) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) except RebaseHelperError: # pylint: disable=try-except-raise # Proper RebaseHelperError instance was created already. Re-raise it. raise except BinaryPackageBuildError as e: build_dict.update(builder.get_logs()) build_dict['binary_package_build_error'] = six.text_type(e) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) if e.logfile is None: msg = 'Building {} RPM packages failed; see logs in {} for more information'.format( version, os.path.join(results_dir, 'RPM') ) else: msg = 'Building {} RPM packages failed; see {} for more information'.format(version, e.logfile) logger.info(msg) raise RebaseHelperError(msg, logfiles=builder.get_logs().get('logs')) except Exception: raise RebaseHelperError('Building package failed with unknown reason. ' 'Check all available log files.') if self.conf.builds_nowait and not self.conf.build_tasks: if builder.CREATES_TASKS: self.print_task_info(builder)
def get_task_info(cls, build_dict): session = KojiHelper.create_session() url = KojiHelper.get_task_url(session, build_dict['koji_task_id']) return 'Scratch build for {} version is: {}'.format( build_dict['version'], url)
def build_binary_packages(self): """Function calls build class for building packages""" try: builder = plugin_manager.build_tools.get_plugin(self.conf.buildtool) except NotImplementedError as e: raise RebaseHelperError('{}. Supported build tools are {}'.format( str(e), plugin_manager.build_tools.get_supported_tools())) for version in ['old', 'new']: results_dir = '{}-build'.format(os.path.join(self.results_dir, version)) spec = None task_id = None koji_build_id = None build_dict = {} if self.conf.build_tasks is None: spec = self.spec_file if version == 'old' else self.rebase_spec_file package_name = spec.get_package_name() package_version = spec.get_version() package_full_version = spec.get_full_version() if version == 'old' and self.conf.get_old_build_from_koji: koji_build_id, package_version, package_full_version = KojiHelper.get_old_build_info( package_name, package_version) build_dict = dict( name=package_name, version=package_version, builds_nowait=self.conf.builds_nowait, build_tasks=self.conf.build_tasks, builder_options=self.conf.builder_options, srpm=results_store.get_build(version).get('srpm'), srpm_logs=results_store.get_build(version).get('logs')) # prepare for building builder.prepare(spec, self.conf) logger.info('Building binary packages for %s version %s', package_name, package_full_version) else: task_id = self.conf.build_tasks[0] if version == 'old' else self.conf.build_tasks[1] try: if self.conf.build_tasks is None: if koji_build_id: session = KojiHelper.create_session() build_dict['rpm'], build_dict['logs'] = KojiHelper.download_build(session, koji_build_id, os.path.join( results_dir, 'RPM', ), arches=['noarch', 'x86_64']) else: build_dict.update(builder.build(spec, results_dir, **build_dict)) if builder.CREATES_TASKS and task_id and not koji_build_id: if not self.conf.builds_nowait: build_dict['rpm'], build_dict['logs'] = builder.wait_for_task(build_dict, task_id, results_dir) elif self.conf.build_tasks: build_dict['rpm'], build_dict['logs'] = builder.get_detached_task(task_id, results_dir) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) except RebaseHelperError: # pylint: disable=try-except-raise # Proper RebaseHelperError instance was created already. Re-raise it. raise except BinaryPackageBuildError as e: build_dict.update(builder.get_logs()) build_dict['binary_package_build_error'] = str(e) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) if e.logfile is None: msg = 'Building {} RPM packages failed; see logs in {} for more information'.format( version, os.path.join(results_dir, 'RPM') ) else: msg = 'Building {} RPM packages failed; see {} for more information'.format(version, e.logfile) logger.error(msg) raise RebaseHelperError(msg, logfiles=builder.get_logs().get('logs')) except Exception: raise RebaseHelperError('Building package failed with unknown reason. ' 'Check all available log files.') if self.conf.builds_nowait and not self.conf.build_tasks: if builder.CREATES_TASKS: self.print_task_info(builder)
def build_source_packages(self): try: builder = plugin_manager.srpm_build_tools.get_plugin( self.conf.srpm_buildtool) except NotImplementedError as e: raise RebaseHelperError( '{}. Supported SRPM build tools are {}'.format( str(e), ', '.join(plugin_manager.srpm_build_tools. get_supported_plugins()))) from e for version in ['old', 'new']: koji_build_id = None results_dir = os.path.join(self.results_dir, '{}-build'.format(version), 'SRPM') spec = self.spec_file if version == 'old' else self.rebase_spec_file package_name = spec.header.name package_version = spec.header.version logger.info('Building source package for %s version %s', package_name, package_version) if version == 'old' and self.conf.get_old_build_from_koji: koji_build_id, ver = KojiHelper.get_old_build_info( package_name, package_version) if ver: package_version = ver build_dict = dict( name=package_name, version=package_version, srpm_buildtool=self.conf.srpm_buildtool, srpm_builder_options=self.conf.srpm_builder_options, app_kwargs=self.kwargs) try: os.makedirs(results_dir) if koji_build_id: session = KojiHelper.create_session() build_dict['srpm'], build_dict[ 'logs'] = KojiHelper.download_build(session, koji_build_id, results_dir, arches=['src']) else: build_dict.update( builder.build(spec, results_dir, **build_dict)) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) except RebaseHelperError: # pylint: disable=try-except-raise raise except SourcePackageBuildError as e: build_dict['logs'] = e.logs build_dict['source_package_build_error'] = str(e) build_dict = self._sanitize_build_dict(build_dict) results_store.set_build_data(version, build_dict) if e.logfile: msg = 'Building {} SRPM packages failed; see {} for more information'.format( version, e.logfile) else: msg = 'Building {} SRPM packages failed; see logs in {} for more information'.format( version, results_dir) raise RebaseHelperError(msg, logfiles=e.logs) from e except Exception as e: raise RebaseHelperError( 'Building package failed with unknown reason. ' 'Check all available log files.') from e