lorax: [PATCH] Add --add-template{,-var}

Brian C. Lane bcl at redhat.com
Mon May 12 15:24:25 UTC 2014


On Sun, May 11, 2014 at 09:35:56PM +0000, Colin Walters wrote:
> [ Also attached is the template I used to make an rpm-ostree installer ]
> 
> What I need is to make something like the traditional DVD which also
> includes packages. At present this is apparently handled by the
> entirely separate pungi tool.
> 
> At the moment for me, it's the least bad option to modify lorax to
> inject data from an external source than to create a new tool, or
> attempt to also modify pungi to do this.
> 
> This would also allow pungi's DVD creation to eventually be a set of
> external templates for Lorax.
> ---
> src/pylorax/__init__.py | 9 +++++++--
> src/pylorax/treebuilder.py | 18 ++++++++++++++++--
> src/sbin/lorax | 8 ++++++++
> 3 files changed, 31 insertions(+), 4 deletions(-)
> 
> diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py
> index 7d94783..8c1d631 100644
> --- a/src/pylorax/__init__.py
> +++ b/src/pylorax/__init__.py
> @@ -151,7 +151,10 @@ class Lorax(BaseLoraxClass):
> 
>     def run(self, ybo, product, version, release, variant="",
> bugurl="",
>             isfinal=False, workdir=None, outputdir=None,
> buildarch=None, volid=None,
> - domacboot=True, doupgrade=True, remove_temp=False, size=2):
> + domacboot=True, doupgrade=True, remove_temp=False,
> + add_templates=[],
> + add_template_vars=[],
> + size=2):

Your email client seems to be mangling the patches, or maybe you're
using tabs? For patches of this size I need to be able to git am them,
or pick them from a remote repo.

I also like to see new options added to the end, not inserted in the
middle, and Vratislav's comments about setting them to None and checking
them is correct.


> 
>         assert self._configured
> 
> @@ -249,7 +252,9 @@ class Lorax(BaseLoraxClass):
>         templatedir = self.conf.get("lorax", "sharedir")
>         # NOTE: rb.root = ybo.conf.installroot (== self.inroot)
>         rb = RuntimeBuilder(product=self.product, arch=self.arch,
> - yum=ybo, templatedir=templatedir)
> + yum=ybo, templatedir=templatedir,
> + add_templates=add_templates,
> + add_template_vars=add_template_vars)
> 
>         logger.info("installing runtime packages")
>         rb.yum.conf.skip_broken = self.conf.getboolean("yum",
> "skipbroken")
> diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py
> index 1b71604..771fdcd 100644
> --- a/src/pylorax/treebuilder.py
> +++ b/src/pylorax/treebuilder.py
> @@ -67,7 +67,9 @@ def generate_module_info(moddir, outfile=None):
> 
> class RuntimeBuilder(object):
>     '''Builds the anaconda runtime image.'''
> - def __init__(self, product, arch, yum, templatedir=None):
> + def __init__(self, product, arch, yum, templatedir=None,
> + add_templates=[],
> + add_template_vars=[]):
>         root = yum.conf.installroot
>         # use a copy of product so we can modify it locally
>         product = product.copy()
> @@ -77,6 +79,8 @@ class RuntimeBuilder(object):
>         self.yum = yum
>         self._runner = LoraxTemplateRunner(inroot=root, outroot=root,
>                                            yum=yum,
> templatedir=templatedir)
> + self.add_templates = add_templates
> + self.add_template_vars = add_template_vars
>         self._runner.defaults = self.vars
> 
>     def _install_branding(self):
> @@ -104,6 +108,15 @@ class RuntimeBuilder(object):
>         '''Install packages and do initial setup with
> runtime-install.tmpl'''
>         self._install_branding()
>         self._runner.run("runtime-install.tmpl")
> + addvars = {}
> + for kv in self.add_template_vars:
> + vals = kv.split('=', 1)
> + if len(vals) <= 1:
> + raise ValueError("Template variables must be of the form key=value")

This validation should be done earlier so that you don't have to wait to
find out the stuff you passed is wrong. At least in Lorax.run() if not
also when the args are parsed in the lorax script.

> + (k,v) = vals
> + addvars[k] = v
> + for tmpl in self.add_templates:
> + self._runner.run(tmpl, **addvars)
> 
>     def writepkglists(self, pkglistdir):
>         '''debugging data: write out lists of package contents'''
> @@ -161,7 +174,8 @@ class RuntimeBuilder(object):
>         # Reset selinux context on new rootfs
>         with imgutils.LoopDev( joinpaths(workdir,
> "LiveOS/rootfs.img") ) as loopdev:
>             with imgutils.Mount(loopdev) as mnt:
> - cmd = [ "setfiles", "-e", "/proc", "-e", "/sys", "-e", "/dev",
> "/etc/selinux/targeted/contexts/files/file_contexts", "/"]
> + cmd = [ "setfiles", "-e", "/proc", "-e", "/sys", "-e", "/dev",
> "-e", "/install",
> + "/etc/selinux/targeted/contexts/files/file_contexts", "/"]
>                 runcmd(cmd, root=mnt)
> 
>         # squash the live rootfs and clean up workdir
> diff --git a/src/sbin/lorax b/src/sbin/lorax
> index 4a9cde5..bfb90a5 100755
> --- a/src/sbin/lorax
> +++ b/src/sbin/lorax
> @@ -134,6 +134,12 @@ def main(args):
>             help="Path to logfile")
>     optional.add_option("--tmp", default="/var/tmp",
>             help="Top level temporary directory" )
> + optional.add_option("--add-template", dest="add_templates",
> + action="append", help="Additional template to execute",
> + default=[])
> + optional.add_option("--add-template-var", dest="add_template_vars",
> + action="append", help="Set variable for additional templates",
> + default=[])
> 
>     # add the option groups to the parser
>     parser.add_option_group(required)
> @@ -193,6 +199,8 @@ def main(args):
>               opts.variant, opts.bugurl, opts.isfinal,
>               workdir=tempdir, outputdir=outputdir,
> buildarch=opts.buildarch,
>               volid=opts.volid, domacboot=opts.domacboot,
> doupgrade=opts.doupgrade,
> + add_templates=opts.add_templates,
> + add_template_vars=opts.add_template_vars,
>               remove_temp=True)
> 
> 
> -- 
> 1.8.3.1
> 
> 
> 

> ## Lorax template to embed ostree repo into installer
> 
> <%page args="root, ostree_repo, ostree_ref"/>
> 
> mkdir install/ostree
> 
> runcmd ostree --repo=${root}/install/ostree init --mode=archive-z2
> runcmd ostree --repo=${root}/install/ostree pull-local --disable-fsync ${ostree_repo} ${ostree_ref}
> 
> append usr/share/anaconda/interactive-defaults.ks "bootloader --timeout=3 --extlinux\n"
> append usr/share/anaconda/interactive-defaults.ks "ostreesetup --nogpg --osname=rhel-atomic-host --remote=installmedia --url=file:///install/ostree --ref=${ostree_ref}\n"
> 

> From 33bc0796af3dfcf8da19a18c3a9f29de88a33b36 Mon Sep 17 00:00:00 2001
> From: Colin Walters <walters at verbum.org>
> Date: Thu, 1 May 2014 21:34:54 -0400
> Subject: [PATCH] Add --add-template{,-var}
> 
> What I need is to make something like the traditional DVD which also
> includes packages.  At present this is apparently handled by the
> entirely separate pungi tool.
> 
> At the moment for me, it's the least bad option to modify lorax to
> inject data from an external source than to create a new tool, or
> attempt to also modify pungi to do this.
> 
> This would also allow pungi's DVD creation to eventually be a set of
> external templates for Lorax.
> ---
>  src/pylorax/__init__.py    |  9 +++++++--
>  src/pylorax/treebuilder.py | 18 ++++++++++++++++--
>  src/sbin/lorax             |  8 ++++++++
>  3 files changed, 31 insertions(+), 4 deletions(-)
> 
> diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py
> index 7d94783..8c1d631 100644
> --- a/src/pylorax/__init__.py
> +++ b/src/pylorax/__init__.py
> @@ -151,7 +151,10 @@ class Lorax(BaseLoraxClass):
>  
>      def run(self, ybo, product, version, release, variant="", bugurl="",
>              isfinal=False, workdir=None, outputdir=None, buildarch=None, volid=None,
> -            domacboot=True, doupgrade=True, remove_temp=False, size=2):
> +            domacboot=True, doupgrade=True, remove_temp=False,
> +            add_templates=[],
> +            add_template_vars=[],
> +            size=2):


Odd. I see now there are 2 copies of the patch.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)


More information about the anaconda-patches mailing list