From c1b42e0c67b1050c00c922f882cc192dbc571edc Mon Sep 17 00:00:00 2001 From: Jay Greguske Date: Tue, 29 Jul 2014 21:33:49 -0400 Subject: [PATCH 3/3] add raw-xz option --- builder/kojid | 50 +++++++++++++++++++++++++++++++++++++++++++------- cli/koji | 2 +- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/builder/kojid b/builder/kojid index d3446b9..b23e9ce 100755 --- a/builder/kojid +++ b/builder/kojid @@ -2096,6 +2096,18 @@ class BuildBaseImageTask(BuildImageTask): spec_url, subtask, target_info, bld_info, repo_info['id']) + # make sure we only import the user-submitted kickstart file one + # time, otherwise we will have collisions. Remove it from exactly + # 1 results hash from the subtasks + if opts.has_key('kickstart'): + saw_ks = False + for arch in results.keys(): + ks = os.path.basename(opts.get('kickstart')) + if ks in results[arch]['files']: + if saw_ks: + results[arch]['files'].remove(ks) + saw_ks = True + self.logger.debug('Image Results for hub: %s' % results) if opts.get('scratch'): self.session.host.moveImageBuildToScratch(self.id, results) @@ -2728,7 +2740,7 @@ class OzImageTask(BaseTaskHandler): if self.opts.get('ksurl'): scm = SCM(self.opts['ksurl']) scm.assert_allowed(self.options.allowed_scms) - logfile = os.path.join(self.workdir, 'checkout.log') + logfile = os.path.join(self.workdir, 'checkout-%s.log' % self.arch) scmsrcdir = scm.checkout(self.workdir, self.session, self.getUploadDir(), logfile) kspath = os.path.join(scmsrcdir, os.path.basename(ksfile)) @@ -2989,7 +3001,7 @@ class BaseImageTask(OzImageTask): Some image formats require others to be processed first, which is why we have to do this. raw files in particular may not be kept. """ - supported = ('raw', 'vmdk', 'qcow', 'qcow2', 'vdi', 'rhevm-ova', 'vsphere-ova', 'docker') + supported = ('raw', 'raw-xz', 'vmdk', 'qcow', 'qcow2', 'vdi', 'rhevm-ova', 'vsphere-ova', 'docker') for f in formats: if f not in supported: raise koji.ApplianceError('Invalid format: %s' % f) @@ -3014,6 +3026,7 @@ class BaseImageTask(OzImageTask): of details for each image type we had to ask ImageFactory to build """ fcalls = {'raw': self._buildBase, + 'raw-xz': self._buildXZ, 'vmdk': self._buildConvert, 'vdi': self._buildConvert, 'qcow': self._buildConvert, @@ -3079,10 +3092,10 @@ class BaseImageTask(OzImageTask): """ if image.target_image: status = image.target_image.status - details = image.target_image.status_detail + details = image.target_image.status_detail['error'] else: status = image.base_image.status - details = image.base_image.status_detail + details = image.base_image.status_detail['error'] self.logger.debug('check image results: %s' % status) if status == 'FAILED': scrnshot = self.getScreenshot() @@ -3094,10 +3107,11 @@ class BaseImageTask(OzImageTask): if not self.session.checkUpload('', os.path.basename(self.ozlog)): self.tlog.removeHandler(self.fhandler) self.uploadFile(self.ozlog) + if 'No disk activity' in details: + details = 'Automated install failed or prompted for input. See the screenshot in the task results for more information.' raise koji.ApplianceError('Image status is %s: %s' % (status, details)) - def _buildBase(self, template, params, wait=True): """ Build a base image using ImageFactory. This is a "raw" image. @@ -3121,6 +3135,29 @@ class BaseImageTask(OzImageTask): self._checkImageState(base) return base + def _buildXZ(self, format): + """ + Use xz to compress a raw disk image. This is very straightforward. + + @args: + format - a string representing the image format, "raw-xz" + @returns: + a dict with some metadata about the image + """ + newimg = os.path.join(self.workdir, self.imgname + '.raw.xz') + rawimg = os.path.join(self.workdir, self.imgname + '.raw') + cmd = ['/bin/cp', self.base_img.base_image.data, rawimg] + conlog = os.path.join(self.workdir, + 'xz-cp-%s-%s.log' % (format, self.arch)) + log_output(self.session, cmd[0], cmd, conlog, self.getUploadDir(), + logerror=1) + cmd = ['/usr/bin/xz', '-z', rawimg] + conlog = os.path.join(self.workdir, + 'xz-%s-%s.log' % (format, self.arch)) + log_output(self.session, cmd[0], cmd, conlog, self.getUploadDir(), + logerror=1) + return {'image': newimg} + def _buildOVA(self, format): """ Build an OVA target image. This is a format supported by RHEV and @@ -3191,7 +3228,6 @@ class BaseImageTask(OzImageTask): @returns a dict with some metadata about the image """ - newimg = os.path.join(self.workdir, self.imgname + '.%s' % format) cmd = ['/usr/bin/qemu-img', 'convert', '-f', 'raw', '-O', format, self.base_img.base_image.data, newimg] @@ -3293,7 +3329,7 @@ class BaseImageTask(OzImageTask): # upload the results for format in (f for f in self.formats.keys() if self.formats[f]): newimg = images[format]['image'] - if 'ova' in format: + if 'ova' in format or format == 'raw-xz': newname = self.imgname + '.' + format.replace('-', '.') elif format == 'docker': newname = self.imgname + '.' + 'tar.gz' diff --git a/cli/koji b/cli/koji index 8722f01..9451963 100755 --- a/cli/koji +++ b/cli/koji @@ -5130,7 +5130,7 @@ def handle_spin_appliance(options, session, args): def handle_image_build(options, session, args): """Create a disk image given an install tree""" formats = ('vmdk', 'qcow', 'qcow2', 'vdi', 'rhevm-ova', 'vsphere-ova', - 'docker') + 'docker', 'raw-xz') usage = _("usage: %prog image-build [options] " + " [...]") usage += _("\n %prog image-build --config FILE") -- 2.0.4