#491 [pungi-make-ostree] New sub command 'liveimage'
Closed 7 years ago by ausil. Opened 7 years ago by qwan.

file modified
+2
@@ -38,6 +38,8 @@ 

  Requires:       git

  Requires:       python-jsonschema

  Requires:       libguestfs-tools-c

+ Requires:       ostree

+ Requires:       rpm-ostree >= 2016.11

  

  BuildArch:      noarch

  

file modified
+14 -2
@@ -18,6 +18,7 @@ 

  

  from .tree import Tree

  from .installer import Installer

+ from .liveimage import LiveImage

  

  

  def main(args=None):
@@ -63,7 +64,6 @@ 

      installerp.add_argument('--nomacboot', action='store_true', default=False)

      installerp.add_argument('--noupgrade', action='store_true', default=False)

      installerp.add_argument('--isfinal', action='store_true', default=False)

- 

      installerp.add_argument('--installpkgs', metavar='PACKAGE', action='append',

                              help='package glob to install before runtime-install.tmpl')

      installerp.add_argument('--add-template', metavar='FILE', action='append',
@@ -74,10 +74,22 @@ 

                              help='Additional template for architecture-specific image')

      installerp.add_argument('--add-arch-template-var', metavar='ADD_ARCH_TEMPLATE_VARS', action='append',

                              help='Set variable for architecture-specific image')

- 

      installerp.add_argument('--extra-config', metavar='FILE',

                              help='JSON file contains extra configurations')

  

+     liveimagep = subparser.add_parser("liveimage", help="Create OSTree live images")

+     liveimagep.set_defaults(_class=LiveImage, func='run')

+     liveimagep.add_argument('--ks', metavar='KICKSTART', required=True,

+                             help='Kickstart file defining the install (required)')

+     liveimagep.add_argument('--no-virt', action='store_true',

+                             help='Run anaconda directly on host instead of using qemu')

+     liveimagep.add_argument('--iso', metavar='ISO',

+                             help='Anaconda installation .iso path to use for qemu, required by virt install')

+     liveimagep.add_argument('--output', metavar='OUTPUT',

+                             help='Path to image output directory')

+     liveimagep.add_argument('--logdir', metavar='LOGDIR',

+                             help='where to log output')

+ 

      args = parser.parse_args(args)

      _class = args._class()

      _class.set_args(args)

@@ -0,0 +1,45 @@ 

+ # -*- coding: utf-8 -*-

+ 

+ 

+ # This program is free software; you can redistribute it and/or modify

+ # it under the terms of the GNU General Public License as published by

+ # the Free Software Foundation; version 2 of the License.

+ #

+ # This program is distributed in the hope that it will be useful,

+ # but WITHOUT ANY WARRANTY; without even the implied warranty of

+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

+ # GNU Library General Public License for more details.

+ #

+ # You should have received a copy of the GNU General Public License

+ # along with this program; if not, see <https://gnu.org/licenses/>.

+ 

+ 

+ import os

+ from kobo import shortcuts

+ 

+ from .base import OSTree

+ from .utils import make_log_file

+ from ..wrappers.lorax import LoraxWrapper

+ from ..util import makedirs

+ 

+ 

+ class LiveImage(OSTree):

+     def run(self):

+         self.ks = self.args.ks

+         self.no_virt = self.args.no_virt

+         self.iso = self.args.iso

+         self.output = self.args.output

+         self.logdir = self.args.logdir

+ 

+         if self.logdir and not os.path.exists(self.logdir):

+             makedirs(self.logdir)

+ 

+         lorax_wrapper = LoraxWrapper()

+         cmd = lorax_wrapper.get_lmc_ostree_live_cmd(self.ks,

+                                                     no_virt=self.no_virt,

+                                                     iso=self.iso,

+                                                     output_dir=self.output,

+                                                     logdir=self.logdir)

+ 

+         logfile = make_log_file(self.logdir, 'pungi-make-ostree-live-image')

+         shortcuts.run(cmd, show_cmd=True, stdout=True, logfile=logfile)

file modified
+22
@@ -114,3 +114,25 @@ 

              cmd.append(i)

  

          return cmd

+ 

+     def get_lmc_ostree_live_cmd(self, kickstart, no_virt=True, iso=None, output_dir=None, logdir=None):

+         cmd = ["livemedia-creator"]

+         cmd.append("--make-ostree-live")

+ 

+         cmd.extend(["--ks", kickstart])

+ 

+         if no_virt:

+             cmd.append("--no-virt")

+         else:

+             # virt install needs an install iso

+             if not iso:

+                 raise RuntimeError("iso is required for virt install")

+             cmd.extend(["--iso", iso])

+ 

+         if output_dir:

+             cmd.extend(["--resultdir", output_dir])

+ 

+         if logdir:

+             cmd.extend(["--logfile", os.path.join(logdir, 'lmc-make-ostree-live.log')])

+ 

+         return cmd

@@ -60,6 +60,42 @@ 

                                 '--logfile=/tmp/lorax.log',

                                 '/mnt/output_dir'])

  

+     def test_get_lmc_ostree_live_cmd_virt(self):

+         cmd = self.lorax.get_lmc_ostree_live_cmd('/path/to/ostree-pxe2live.ks',

+                                                  no_virt=False,

+                                                  iso='/path/to/install.iso',

+                                                  output_dir='/path/to/output',

+                                                  logdir='/path/to/logs')

+ 

+         self.assertEqual(cmd[0], 'livemedia-creator')

+         self.assertEqual(cmd[1:],

+                          ['--make-ostree-live',

+                           '--ks', '/path/to/ostree-pxe2live.ks',

+                           '--iso', '/path/to/install.iso',

+                           '--resultdir', '/path/to/output',

+                           '--logfile', '/path/to/logs/lmc-make-ostree-live.log'])

+ 

+     def test_get_lmc_ostree_live_cmd_virt_without_iso(self):

+         with self.assertRaises(RuntimeError) as ctx:

+             self.lorax.get_lmc_ostree_live_cmd('/path/to/ostree-pxe2live.ks',

+                                                no_virt=False,

+                                                iso=None)

+ 

+         self.assertIn('iso is required for virt install', str(ctx.exception))

+ 

+     def test_get_lmc_ostree_live_cmd_novirt(self):

+         cmd = self.lorax.get_lmc_ostree_live_cmd('/path/to/ostree-pxe2live.ks',

+                                                  no_virt=True,

+                                                  output_dir='/path/to/output',

+                                                  logdir='/path/to/logs')

+ 

+         self.assertEqual(cmd[0], 'livemedia-creator')

+         self.assertEqual(cmd[1:],

+                          ['--make-ostree-live',

+                           '--ks', '/path/to/ostree-pxe2live.ks',

+                           '--no-virt',

+                           '--resultdir', '/path/to/output',

+                           '--logfile', '/path/to/logs/lmc-make-ostree-live.log'])

  

  if __name__ == "__main__":

      unittest.main()

@@ -363,5 +363,70 @@ 

                                            '--rootfs-size=None',

                                            self.output])])

  

+ 

+ class OstreeLiveImageScriptTest(helpers.PungiTestCase):

+     def setUp(self):

+         super(OstreeLiveImageScriptTest, self).setUp()

+         self.ks = os.path.join(self.topdir, 'fedora-atomic-pxe-live.ks')

+         self.iso = os.path.join(self.topdir, 'install.iso')

+         self.output_dir = os.path.join(self.topdir, 'output')

+         self.logdir = os.path.join(self.topdir, 'logs')

+ 

+     @mock.patch('kobo.shortcuts.run')

+     def test_run_virt_install(self, run):

+         args = ['liveimage',

+                 '--ks=%s' % self.ks,

+                 '--iso=%s' % self.iso,

+                 '--output=%s' % self.output_dir,

+                 '--logdir=%s' % self.logdir]

+ 

+         ostree.main(args)

+ 

+         self.maxDiff = None

+         self.assertItemsEqual(run.mock_calls,

+                               [mock.call(['livemedia-creator',

+                                           '--make-ostree-live',

+                                           '--ks', self.ks,

+                                           '--iso', self.iso,

+                                           '--resultdir', self.output_dir,

+                                           '--logfile', os.path.join(self.logdir, 'lmc-make-ostree-live.log')],

+                                          logfile='%s/pungi-make-ostree-live-image.log' % self.logdir,

+                                          show_cmd=True,

+                                          stdout=True)])

+ 

+     @mock.patch('kobo.shortcuts.run')

+     def test_run_virt_install_without_iso(self, run):

+         args = ['liveimage',

+                 '--ks=%s' % self.ks,

+                 '--output=%s' % self.output_dir,

+                 '--logdir=%s' % self.logdir]

+ 

+         with self.assertRaises(RuntimeError) as ctx:

+             ostree.main(args)

+ 

+         self.assertIn('iso is required for virt install', str(ctx.exception))

+ 

+     @mock.patch('kobo.shortcuts.run')

+     def test_run_no_virt_install(self, run):

+         args = ['liveimage',

+                 '--ks=%s' % self.ks,

+                 '--no-virt',

+                 '--output=%s' % self.output_dir,

+                 '--logdir=%s' % self.logdir]

+ 

+         ostree.main(args)

+ 

+         self.maxDiff = None

+         self.assertItemsEqual(run.mock_calls,

+                               [mock.call(['livemedia-creator',

+                                           '--make-ostree-live',

+                                           '--ks', self.ks,

+                                           '--no-virt',

+                                           '--resultdir', self.output_dir,

+                                           '--logfile', os.path.join(self.logdir, 'lmc-make-ostree-live.log')],

+                                          logfile='%s/pungi-make-ostree-live-image.log' % self.logdir,

+                                          show_cmd=True,

+                                          stdout=True)])

+ 

  if __name__ == '__main__':

      unittest.main()

liveimage is added to support creating OSTree live images

Signed-off-by: Qixiang Wan qwan@redhat.com

Nak rpm-ostree-toolbox is not suitable for use and we should never do anything like this locally. For one we want things like this on multiple arches. We need to work out how to make the artifacts in runroot or develop a koji plugin for it.

rebased

7 years ago

Updated to use low level 'livemedia-creator' instead of 'rpm-ostree-toolbox', this PR adds a new sub command 'liveimage' to pungi-make-ostree. It doesn't have impact on the current phase chain. User can run 'pungi-make-ostree liveimage' locally just like 'pungi-make-ostree tree' and 'pungi-make-ostree installer'.

@ausil I agree with you on making the artifacts in runroot or with koji plugin when adding a new phase in the phase chain to build OSTree pxe2live image. Atomic & Fedora releng team were planing to work on the feature of shipping pxe2live and livemedia-creator plugin for koji, but de-prioritized that feature for a few reasons https://trello.com/c/I0Ycz10d/39-13-pxe-live-capability-pxe#comment-582c765c52ebab76dfe5b6c1 . So I just added this local build feature, and will work on the new phase of OSTree pxe2live once Atomic team finalize how would pxe2live images be shipped.

I will not allow anything that does not have proper logging, rpm-ostree-toolbox is not suitable for use in any part of making deliverables

Pull-Request has been closed by ausil

7 years ago

hi @ausil , rpm-ostree-toolbox is not used in the updated version, the low level tool 'livemedia-creator' is used instead. The main concern from your side of closing this PR is using 'rpm-ostree-toolbox', right?