From d8c579e4d03cf0a999a3d84b5d04ad73e315ae28 Mon Sep 17 00:00:00 2001 From: John Florian Date: Jul 18 2017 15:49:52 +0000 Subject: [PATCH 1/5] New - kojid.BuildRoot.relpath() This new method returns an absolute path within the chroot relative the BuildRoot's chroot. --- diff --git a/builder/kojid b/builder/kojid index f34bff6..dc76893 100755 --- a/builder/kojid +++ b/builder/kojid @@ -705,6 +705,21 @@ class BuildRoot(object): rpm_info['external_repo'] = erepo rpm_info['location'] = erepo['external_repo_id'] + def relpath(self, path): + """ + :param path: + A reference within the BuildRoot but as an absolute path from + without a chroot. + :return: + The equivalent absolute path from within a chroot of the BuildRoot. + """ + root = self.rootdir() + if os.path.commonprefix([root, path]) != root: + raise ValueError( + 'path %r is not within the BuildRoot at %r' % (path, root) + ) + return os.path.join('/', os.path.relpath(path, root)) + def resultdir(self): return "%s/%s/result" % (self.options.mockdir, self.name) From d431231fd87ac29d75ea62b729469a31cae2332a Mon Sep 17 00:00:00 2001 From: John Florian Date: Jul 18 2017 16:02:05 +0000 Subject: [PATCH 2/5] New - custom lorax templates for livemedia tasks This adds two new options (--lorax_url and --lorax_dir) to the Koji CLI so that it's now possible to use custom lorax templates for livemedia tasks. The custom templates must come from a supported, allowed SCM, which makes it trivial to inject the whole directory structure of template files that lorax expects. In addition to the CLI changes, kojid's LiveMediaTask handler recognizes these new options and acts accordingly by extending the livemedia-creator call via its --lorax-templates option. --- diff --git a/builder/kojid b/builder/kojid index dc76893..d1f77f2 100755 --- a/builder/kojid +++ b/builder/kojid @@ -3081,6 +3081,29 @@ class LiveMediaTask(ImageTask): # https://bugzilla.redhat.com/show_bug.cgi?id=1315541 bind_opts = {} + def fetch_lorax_templates_from_scm(self, build_root): + """ + Make a checkout of the lorax templates from SCM so that they may be + passed to livemedia-creator. Here we are operating outside the chroot + of the BuildRoot. The following options are essential: + - lorax_url points to the SCM containing the templates. + - lorax_dir provides a relative reference to the templates within + the checkout. + + :param build_root: + The BuildRoot instance to receive the checkout. + :return: + An absolute path (from within the chroot) to where livemedia-creator + can find the checked out templates. + """ + scm = SCM(self.opts['lorax_url']) + scm.assert_allowed(self.options.allowed_scms) + logfile = os.path.join(self.workdir, 'lorax-templates-checkout.log') + checkout_dir = scm.checkout(os.path.join(build_root.rootdir(), 'tmp'), + self.session, self.getUploadDir(), logfile) + return os.path.join(build_root.relpath(checkout_dir), + self.opts['lorax_dir']) + def genISOManifest(self, image, manifile): """ Using iso9660 from pycdio, get the file manifest of the given image, @@ -3194,6 +3217,10 @@ class LiveMediaTask(ImageTask): if arch == 'x86_64': cmd.append('--macboot') + if 'lorax_url' in self.opts: + templates_dir = self.fetch_lorax_templates_from_scm(broot) + cmd.extend(['--lorax-templates', templates_dir]) + # Run livemedia-creator rv = broot.mock(['--cwd', '/tmp', '--chroot', '--'] + cmd) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 2a6a367..23b9ffd 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -5219,6 +5219,13 @@ def handle_spin_livemedia(options, session, args): parser.add_option("--can-fail", action="store", dest="optional_arches", metavar="ARCH1,ARCH2,...", default="", help=_("List of archs which are not blocking for build (separated by commas.")) + parser.add_option('--lorax_dir', metavar='DIR', + help=_('The relative path to the lorax templates ' + 'directory within the checkout of "lorax_url".')) + parser.add_option('--lorax_url', metavar='URL', + help=_('The URL to the SCM containing any custom lorax ' + 'templates that are to be used to override the ' + 'default templates.')) (task_options, args) = parser.parse_args(args) # Make sure the target and kickstart is specified. @@ -5227,6 +5234,9 @@ def handle_spin_livemedia(options, session, args): " build target, an architecture, and a relative path to" + " a kickstart file.")) assert False # pragma: no cover + if task_options.lorax_url is not None and task_options.lorax_dir is None: + parser.error(_('The "--lorax_url" option requires that "--lorax_dir" ' + 'also be used.')) _build_image(options, task_options, session, args, 'livemedia') @@ -5608,6 +5618,7 @@ def _build_image(options, task_opts, session, args, img_type): 'format', 'install_tree_url', 'isoname', 'ksurl', 'ksversion', 'release', 'repo', 'scratch', 'skip_tag', 'specfile', 'title', 'vcpu', 'vmem', 'optional_arches', + 'lorax_dir', 'lorax_url', ] for opt in passthru_opts: val = getattr(task_opts, opt, None) From dc6a40d5d41a90b1e87a12d495805642ccc06584 Mon Sep 17 00:00:00 2001 From: John Florian Date: Jul 18 2017 16:02:05 +0000 Subject: [PATCH 3/5] Refactor - leverage koji.util.relpath() Per mikem's request: https://pagure.io/koji/pull-request/233#comment-22971 --- diff --git a/builder/kojid b/builder/kojid index d1f77f2..f80fd0c 100755 --- a/builder/kojid +++ b/builder/kojid @@ -718,7 +718,7 @@ class BuildRoot(object): raise ValueError( 'path %r is not within the BuildRoot at %r' % (path, root) ) - return os.path.join('/', os.path.relpath(path, root)) + return os.path.join('/', koji.util.relpath(path, root)) def resultdir(self): return "%s/%s/result" % (self.options.mockdir, self.name) From 1c1a8c889ce68c1bcf2c386f0ee5819038cd1186 Mon Sep 17 00:00:00 2001 From: John Florian Date: Jul 18 2017 16:02:05 +0000 Subject: [PATCH 4/5] Refactor - rename method BuildRoot.relpath for clarity The semantics of "relative" here are atypical of common expectations. While the method does return a "related" path, it's still absolute. Hopefully this new name is less confusing. --- diff --git a/builder/kojid b/builder/kojid index f80fd0c..9d710a9 100755 --- a/builder/kojid +++ b/builder/kojid @@ -705,7 +705,7 @@ class BuildRoot(object): rpm_info['external_repo'] = erepo rpm_info['location'] = erepo['external_repo_id'] - def relpath(self, path): + def path_without_to_within(self, path): """ :param path: A reference within the BuildRoot but as an absolute path from @@ -3101,7 +3101,7 @@ class LiveMediaTask(ImageTask): logfile = os.path.join(self.workdir, 'lorax-templates-checkout.log') checkout_dir = scm.checkout(os.path.join(build_root.rootdir(), 'tmp'), self.session, self.getUploadDir(), logfile) - return os.path.join(build_root.relpath(checkout_dir), + return os.path.join(build_root.path_without_to_within(checkout_dir), self.opts['lorax_dir']) def genISOManifest(self, image, manifile): From 748001dbe9cdc1e2f884df6e0a61af59be69a35b Mon Sep 17 00:00:00 2001 From: John Florian Date: Jul 18 2017 16:02:05 +0000 Subject: [PATCH 5/5] Change - docstrings for PEP257 compliance Neither of these methods started with a one-line summary. --- diff --git a/builder/kojid b/builder/kojid index 9d710a9..3fb7e28 100755 --- a/builder/kojid +++ b/builder/kojid @@ -707,6 +707,12 @@ class BuildRoot(object): def path_without_to_within(self, path): """ + Convert an absolute path from without the BuildRoot to one within. + + For example, if the BuildRoot is located at '/tmp/my/build/root', + calling path_without_to_within('/tmp/my/build/root/foo/bar') would + return '/foo/bar'). + :param path: A reference within the BuildRoot but as an absolute path from without a chroot. @@ -3083,9 +3089,11 @@ class LiveMediaTask(ImageTask): def fetch_lorax_templates_from_scm(self, build_root): """ - Make a checkout of the lorax templates from SCM so that they may be - passed to livemedia-creator. Here we are operating outside the chroot - of the BuildRoot. The following options are essential: + Checkout the lorax templates from SCM for use by livemedia-creator. + + This will make a checkout of the lorax templates from SCM so that they + may be passed to livemedia-creator. Here we are operating outside the + chroot of the BuildRoot. The following options are essential: - lorax_url points to the SCM containing the templates. - lorax_dir provides a relative reference to the templates within the checkout.