#420 Fixes for ostree installer
Merged 8 years ago by ausil. Opened 8 years ago by lsedlar.
lsedlar/pungi ostree-inst-filename  into  master

file modified
+1
@@ -246,6 +246,7 @@ 

       * ``boot`` -- for ``boot.iso`` images created in  *buildinstall* phase

       * ``live`` -- for images created by *live_images* phase

       * ``dvd`` -- for images created by *createiso* phase

+      * ``ostree`` -- for ostree installer images

  

      Default values are the same as the keys.

  

@@ -10,6 +10,7 @@ 

  from .base import ConfigGuardedPhase

  from .. import util

  from ..paths import translate_path

+ from ..util import get_volid

  from ..wrappers import kojiwrapper, iso, lorax, scm

  

  
@@ -50,10 +51,11 @@ 

  

          self.template_dir = os.path.join(compose.paths.work.topdir(arch), variant.uid, 'lorax_templates')

          self._clone_templates(config.get('template_repo'), config.get('template_branch'))

+         disc_type = compose.conf['disc_types'].get('ostree', 'ostree')

  

-         self._run_ostree_cmd(compose, variant, arch, config, source_repo, output_dir)

+         volid = get_volid(compose, arch, variant, disc_type=disc_type)

+         self._run_ostree_cmd(compose, variant, arch, config, source_repo, output_dir, volid)

  

-         disc_type = compose.conf['disc_types'].get('dvd', 'dvd')

          filename = compose.get_image_name(arch, variant, disc_type=disc_type)

          self._copy_image(compose, variant, arch, filename, output_dir)

          self._add_to_manifest(compose, variant, arch, filename)
@@ -135,7 +137,7 @@ 

              templates.append(template)

          return templates

  

-     def _run_ostree_cmd(self, compose, variant, arch, config, source_repo, output_dir):

+     def _run_ostree_cmd(self, compose, variant, arch, config, source_repo, output_dir, volid):

          lorax_wrapper = lorax.LoraxWrapper()

          cmd = lorax_wrapper.get_lorax_cmd(

              compose.conf['release_name'],
@@ -145,6 +147,7 @@ 

              output_dir=output_dir,

              variant=variant.uid,

              nomacboot=True,

+             volid=volid,

              buildinstallpackages=config.get('installpkgs'),

              add_template=self._get_templates(config, 'add_template'),

              add_arch_template=self._get_templates(config, 'add_arch_template'),

@@ -45,6 +45,16 @@ 

  

  class OstreeThreadTest(helpers.PungiTestCase):

  

+     def setUp(self):

+         super(OstreeThreadTest, self).setUp()

+         self.compose = helpers.DummyCompose(self.topdir, {

+             'release_name': 'Fedora',

+             'release_version': 'Rawhide',

+             'koji_profile': 'koji',

+             'runroot_tag': 'rrt',

+             'image_volid_formats': ['{release_short}-{variant}-{arch}'],

+         })

+ 

      def assertImageAdded(self, compose, ImageCls, IsoWrapper):

          image = ImageCls.return_value

          self.assertEqual(image.path, 'Everything/x86_64/iso/image-name')
@@ -60,6 +70,43 @@ 

          self.assertEqual(compose.im.add.mock_calls,

                           [mock.call('Everything', 'x86_64', image)])

  

+     def assertRunrootCall(self, koji, source, release, isfinal=False, extra=[]):

+         final = ['--isfinal'] if isfinal else []

+         self.assertEqual(koji.get_runroot_cmd.call_args_list,

+                          [mock.call('rrt', 'x86_64',

+                                     ['lorax',

+                                      '--product=Fedora',

+                                      '--version=Rawhide',

+                                      '--release=%s' % release,

+                                      '--source=%s' % source,

+                                      '--variant=Everything',

+                                      '--nomacboot'] +

+                                     final +

+                                     ['--volid=test-Everything-x86_64'] +

+                                     extra +

+                                     [self.topdir + '/work/x86_64/Everything/ostree_installer'],

+                                     channel=None, mounts=[self.topdir],

+                                     packages=['pungi', 'lorax', 'ostree'],

+                                     task_id=True, use_shell=True)])

+         self.assertEqual(koji.run_runroot_cmd.call_args_list,

+                          [mock.call(koji.get_runroot_cmd.return_value,

+                                     log_file=self.topdir + '/logs/x86_64/ostree_installer/runroot.log')])

+ 

+     def assertIsoLinked(self, link, get_file_size, get_mtime, final_iso_path):

+         self.assertEqual(link.call_args_list,

+                          [mock.call(self.topdir + '/work/x86_64/Everything/ostree_installer/images/boot.iso',

+                                     final_iso_path)])

+         self.assertEqual(get_file_size.call_args_list, [mock.call(final_iso_path)])

+         self.assertEqual(get_mtime.call_args_list, [mock.call(final_iso_path)])

+ 

+     def assertAllCopied(self, run):

+         self.assertEqual(self.compose.get_image_name.call_args_list,

+                          [mock.call('x86_64', self.compose.variants['Everything'], disc_type='ostree')])

+         self.assertTrue(os.path.isdir(self.topdir + '/work/x86_64/Everything/'))

+         self.assertFalse(os.path.isdir(self.topdir + '/work/x86_64/Everything/ostree_installer'))

+         self.assertEqual(run.call_args_list,

+                          [mock.call('cp -av {0}/work/x86_64/Everything/ostree_installer/* {0}/compose/Everything/x86_64/os/'.format(self.topdir))])

+ 

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

      @mock.patch('productmd.images.Image')

      @mock.patch('pungi.util.get_mtime')
@@ -69,13 +116,7 @@ 

      @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')

      def test_run(self, KojiWrapper, link, IsoWrapper,

                   get_file_size, get_mtime, ImageCls, run):

-         compose = helpers.DummyCompose(self.topdir, {

-             'release_name': 'Fedora',

-             'release_version': 'Rawhide',

-             'koji_profile': 'koji',

-             'runroot_tag': 'rrt',

-         })

-         compose.supported = False

+         self.compose.supported = False

          pool = mock.Mock()

          cfg = {

              'source_repo_from': 'Everything',
@@ -93,36 +134,14 @@ 

  

          t = ostree.OstreeInstallerThread(pool)

  

-         t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)

+         t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)

  

-         self.assertEqual(koji.get_runroot_cmd.call_args_list,

-                          [mock.call('rrt', 'x86_64',

-                                     ['lorax',

-                                      '--product=Fedora',

-                                      '--version=Rawhide',

-                                      '--release=20160321.n.0',

-                                      '--source=file://%s/compose/Everything/x86_64/os' % self.topdir,

-                                      '--variant=Everything',

-                                      '--nomacboot',

-                                      self.topdir + '/work/x86_64/Everything/ostree_installer'],

-                                     channel=None, mounts=[self.topdir],

-                                     packages=['pungi', 'lorax', 'ostree'],

-                                     task_id=True, use_shell=True)])

-         self.assertEqual(koji.run_runroot_cmd.call_args_list,

-                          [mock.call(koji.get_runroot_cmd.return_value,

-                                     log_file=self.topdir + '/logs/x86_64/ostree_installer/runroot.log')])

-         self.assertEqual(link.call_args_list,

-                          [mock.call(self.topdir + '/work/x86_64/Everything/ostree_installer/images/boot.iso',

-                                     final_iso_path)])

-         self.assertEqual(get_file_size.call_args_list, [mock.call(final_iso_path)])

-         self.assertEqual(get_mtime.call_args_list, [mock.call(final_iso_path)])

-         self.assertImageAdded(compose, ImageCls, IsoWrapper)

-         self.assertEqual(compose.get_image_name.call_args_list,

-                          [mock.call('x86_64', compose.variants['Everything'], disc_type='dvd')])

-         self.assertTrue(os.path.isdir(self.topdir + '/work/x86_64/Everything/'))

-         self.assertFalse(os.path.isdir(self.topdir + '/work/x86_64/Everything/ostree_installer'))

-         self.assertEqual(run.call_args_list,

-                          [mock.call('cp -av {0}/work/x86_64/Everything/ostree_installer/* {0}/compose/Everything/x86_64/os/'.format(self.topdir))])

+         self.assertRunrootCall(koji,

+                                'file://%s/compose/Everything/x86_64/os' % self.topdir,

+                                cfg['release'])

+         self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)

+         self.assertImageAdded(self.compose, ImageCls, IsoWrapper)

+         self.assertAllCopied(run)

  

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

      @mock.patch('productmd.images.Image')
@@ -133,12 +152,6 @@ 

      @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')

      def test_run_external_source(self, KojiWrapper, link, IsoWrapper,

                                   get_file_size, get_mtime, ImageCls, run):

-         compose = helpers.DummyCompose(self.topdir, {

-             'release_name': 'Fedora',

-             'release_version': 'Rawhide',

-             'koji_profile': 'koji',

-             'runroot_tag': 'rrt',

-         })

          pool = mock.Mock()

          cfg = {

              'source_repo_from': 'http://example.com/repo/$arch/',
@@ -156,37 +169,12 @@ 

  

          t = ostree.OstreeInstallerThread(pool)

  

-         t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)

+         t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)

  

-         self.assertEqual(koji.get_runroot_cmd.call_args_list,

-                          [mock.call('rrt', 'x86_64',

-                                     ['lorax',

-                                      '--product=Fedora',

-                                      '--version=Rawhide',

-                                      '--release=20160321.n.0',

-                                      '--source=http://example.com/repo/x86_64/',

-                                      '--variant=Everything',

-                                      '--nomacboot',

-                                      '--isfinal',

-                                      self.topdir + '/work/x86_64/Everything/ostree_installer'],

-                                     channel=None, mounts=[self.topdir],

-                                     packages=['pungi', 'lorax', 'ostree'],

-                                     task_id=True, use_shell=True)])

-         self.assertEqual(koji.run_runroot_cmd.call_args_list,

-                          [mock.call(koji.get_runroot_cmd.return_value,

-                                     log_file=self.topdir + '/logs/x86_64/ostree_installer/runroot.log')])

-         self.assertEqual(link.call_args_list,

-                          [mock.call(self.topdir + '/work/x86_64/Everything/ostree_installer/images/boot.iso',

-                                     final_iso_path)])

-         self.assertEqual(get_file_size.call_args_list, [mock.call(final_iso_path)])

-         self.assertEqual(get_mtime.call_args_list, [mock.call(final_iso_path)])

-         self.assertImageAdded(compose, ImageCls, IsoWrapper)

-         self.assertEqual(compose.get_image_name.call_args_list,

-                          [mock.call('x86_64', compose.variants['Everything'], disc_type='dvd')])

-         self.assertTrue(os.path.isdir(self.topdir + '/work/x86_64/Everything/'))

-         self.assertFalse(os.path.isdir(self.topdir + '/work/x86_64/Everything/ostree_installer'))

-         self.assertEqual(run.call_args_list,

-                          [mock.call('cp -av {0}/work/x86_64/Everything/ostree_installer/* {0}/compose/Everything/x86_64/os/'.format(self.topdir))])

+         self.assertRunrootCall(koji, 'http://example.com/repo/x86_64/', cfg['release'], isfinal=True)

+         self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)

+         self.assertImageAdded(self.compose, ImageCls, IsoWrapper)

+         self.assertAllCopied(run)

  

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

      @mock.patch('productmd.images.Image')
@@ -198,12 +186,6 @@ 

      def test_fail_with_relative_template_path_but_no_repo(self, KojiWrapper, link,

                                                            IsoWrapper, get_file_size,

                                                            get_mtime, ImageCls, run):

-         compose = helpers.DummyCompose(self.topdir, {

-             'release_name': 'Fedora',

-             'release_version': 'Rawhide',

-             'koji_profile': 'koji',

-             'runroot_tag': 'rrt',

-         })

          pool = mock.Mock()

          cfg = {

              'source_repo_from': 'Everything',
@@ -222,7 +204,7 @@ 

          t = ostree.OstreeInstallerThread(pool)

  

          with self.assertRaises(RuntimeError) as ctx:

-             t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)

+             t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)

  

          self.assertIn('template_repo', str(ctx.exception))

  
@@ -237,12 +219,6 @@ 

      def test_run_clone_templates(self, KojiWrapper, link, IsoWrapper,

                                   get_file_size, get_mtime, ImageCls, run,

                                   get_dir_from_scm):

-         compose = helpers.DummyCompose(self.topdir, {

-             'release_name': 'Fedora',

-             'release_version': 'Rawhide',

-             'koji_profile': 'koji',

-             'runroot_tag': 'rrt',

-         })

          pool = mock.Mock()

          cfg = {

              'source_repo_from': 'Everything',
@@ -265,43 +241,21 @@ 

  

          t = ostree.OstreeInstallerThread(pool)

  

-         t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)

+         t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)

  

          self.assertEqual(get_dir_from_scm.call_args_list,

                           [mock.call({'scm': 'git', 'repo': 'git://example.com/templates.git',

                                       'branch': 'f24', 'dir': '.'},

                                      templ_dir, logger=pool._logger)])

-         self.assertEqual(koji.get_runroot_cmd.call_args_list,

-                          [mock.call('rrt', 'x86_64',

-                                     ['lorax',

-                                      '--product=Fedora',

-                                      '--version=Rawhide',

-                                      '--release=20160321.n.0',

-                                      '--source=file://%s/compose/Everything/x86_64/os' % self.topdir,

-                                      '--variant=Everything',

-                                      '--nomacboot',

-                                      '--isfinal',

-                                      '--add-template=%s/some_file.txt' % templ_dir,

-                                      '--add-arch-template=%s/other_file.txt' % templ_dir,

-                                      self.topdir + '/work/x86_64/Everything/ostree_installer'],

-                                     channel=None, mounts=[self.topdir],

-                                     packages=['pungi', 'lorax', 'ostree'],

-                                     task_id=True, use_shell=True)])

-         self.assertEqual(koji.run_runroot_cmd.call_args_list,

-                          [mock.call(koji.get_runroot_cmd.return_value,

-                                     log_file=self.topdir + '/logs/x86_64/ostree_installer/runroot.log')])

-         self.assertEqual(link.call_args_list,

-                          [mock.call(self.topdir + '/work/x86_64/Everything/ostree_installer/images/boot.iso',

-                                     final_iso_path)])

-         self.assertEqual(get_file_size.call_args_list, [mock.call(final_iso_path)])

-         self.assertEqual(get_mtime.call_args_list, [mock.call(final_iso_path)])

-         self.assertImageAdded(compose, ImageCls, IsoWrapper)

-         self.assertEqual(compose.get_image_name.call_args_list,

-                          [mock.call('x86_64', compose.variants['Everything'], disc_type='dvd')])

-         self.assertTrue(os.path.isdir(self.topdir + '/work/x86_64/Everything/'))

-         self.assertFalse(os.path.isdir(self.topdir + '/work/x86_64/Everything/ostree_installer'))

-         self.assertEqual(run.call_args_list,

-                          [mock.call('cp -av {0}/work/x86_64/Everything/ostree_installer/* {0}/compose/Everything/x86_64/os/'.format(self.topdir))])

+         self.assertRunrootCall(koji,

+                                'file://%s/compose/Everything/x86_64/os' % self.topdir,

+                                cfg['release'],

+                                isfinal=True,

+                                extra=['--add-template=%s/some_file.txt' % templ_dir,

+                                       '--add-arch-template=%s/other_file.txt' % templ_dir])

+         self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)

+         self.assertImageAdded(self.compose, ImageCls, IsoWrapper)

+         self.assertAllCopied(run)

  

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

      @mock.patch('productmd.images.Image')
@@ -312,12 +266,6 @@ 

      @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')

      def test_run_with_implicit_release(self, KojiWrapper, link, IsoWrapper,

                                         get_file_size, get_mtime, ImageCls, run):

-         compose = helpers.DummyCompose(self.topdir, {

-             'release_name': 'Fedora',

-             'release_version': 'Rawhide',

-             'koji_profile': 'koji',

-             'runroot_tag': 'rrt',

-         })

          pool = mock.Mock()

          cfg = {

              'source_repo_from': 'Everything',
@@ -347,41 +295,25 @@ 

  

          t = ostree.OstreeInstallerThread(pool)

  

-         t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)

- 

-         self.assertEqual(

-             koji.get_runroot_cmd.call_args_list,

-             [mock.call('rrt', 'x86_64',

-                        ['lorax',

-                         '--product=Fedora',

-                         '--version=Rawhide', '--release=20151203.t.0',

-                         '--source=file://%s/compose/Everything/x86_64/os' % self.topdir,

-                         '--variant=Everything',

-                         '--nomacboot',

-                         '--isfinal',

-                         '--installpkgs=fedora-productimg-atomic',

-                         '--add-template=/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl',

-                         '--add-arch-template=/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl',

-                         '--add-template-var=ostree_osname=fedora-atomic',

-                         '--add-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host',

-                         '--add-arch-template-var=ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/',

-                         '--add-arch-template-var=ostree_osname=fedora-atomic',

-                         '--add-arch-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host',

-                         self.topdir + '/work/x86_64/Everything/ostree_installer'],

-                        channel=None, mounts=[self.topdir],

-                        packages=['pungi', 'lorax', 'ostree'],

-                        task_id=True, use_shell=True)])

-         self.assertEqual(koji.run_runroot_cmd.call_args_list,

-                          [mock.call(koji.get_runroot_cmd.return_value,

-                                     log_file=self.topdir + '/logs/x86_64/ostree_installer/runroot.log')])

-         self.assertEqual(link.call_args_list,

-                          [mock.call(self.topdir + '/work/x86_64/Everything/ostree_installer/images/boot.iso',

-                                     final_iso_path)])

-         self.assertEqual(get_file_size.call_args_list, [mock.call(final_iso_path)])

-         self.assertEqual(get_mtime.call_args_list, [mock.call(final_iso_path)])

-         self.assertImageAdded(compose, ImageCls, IsoWrapper)

-         self.assertEqual(compose.get_image_name.call_args_list,

-                          [mock.call('x86_64', compose.variants['Everything'], disc_type='dvd')])

+         t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)

+ 

+         self.assertRunrootCall(

+             koji,

+             'file://%s/compose/Everything/x86_64/os' % self.topdir,

+             '20151203.t.0',

+             isfinal=True,

+             extra=['--installpkgs=fedora-productimg-atomic',

+                    '--add-template=/spin-kickstarts/atomic-installer/lorax-configure-repo.tmpl',

+                    '--add-arch-template=/spin-kickstarts/atomic-installer/lorax-embed-repo.tmpl',

+                    '--add-template-var=ostree_osname=fedora-atomic',

+                    '--add-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host',

+                    '--add-arch-template-var=ostree_repo=https://kojipkgs.fedoraproject.org/compose/atomic/Rawhide/',

+                    '--add-arch-template-var=ostree_osname=fedora-atomic',

+                    '--add-arch-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host']

+         )

+         self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path)

+         self.assertImageAdded(self.compose, ImageCls, IsoWrapper)

+         self.assertAllCopied(run)

  

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

      @mock.patch('productmd.images.Image')
@@ -392,12 +324,6 @@ 

      @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')

      def test_fail_crash(self, KojiWrapper, link, IsoWrapper, get_file_size,

                          get_mtime, ImageCls, run):

-         compose = helpers.DummyCompose(self.topdir, {

-             'release_name': 'Fedora',

-             'release_version': 'Rawhide',

-             'koji_profile': 'koji',

-             'runroot_tag': 'rrt',

-         })

          pool = mock.Mock()

          cfg = {

              'source_repo_from': 'Everything',
@@ -409,8 +335,8 @@ 

  

          t = ostree.OstreeInstallerThread(pool)

  

-         t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)

-         compose.log_info.assert_has_calls([

+         t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)

+         self.compose.log_info.assert_has_calls([

              mock.call('[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway.'),

              mock.call('BOOM')

          ])
@@ -424,12 +350,6 @@ 

      @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')

      def test_fail_runroot_fail(self, KojiWrapper, link, IsoWrapper,

                                 get_file_size, get_mtime, ImageCls, run):

-         compose = helpers.DummyCompose(self.topdir, {

-             'release_name': 'Fedora',

-             'release_version': 'Rawhide',

-             'koji_profile': 'koji',

-             'runroot_tag': 'rrt',

-         })

          pool = mock.Mock()

          cfg = {

              'source_repo_from': 'Everything',
@@ -445,8 +365,8 @@ 

  

          t = ostree.OstreeInstallerThread(pool)

  

-         t.process((compose, compose.variants['Everything'], 'x86_64', cfg), 1)

-         compose.log_info.assert_has_calls([

+         t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)

+         self.compose.log_info.assert_has_calls([

              mock.call('[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway.'),

              mock.call('Runroot task failed: 1234. See %s/logs/x86_64/ostree_installer/runroot.log for more details.'

                        % self.topdir)

  • Instead of overloading the dvd value, use new value ostree that can be overridden by a config change.
  • Volume ID is generated according to format template from config (instead of not being specified at all).
  • Tests are cleaned up a bit.

2 new commits added

  • ostree-installer: Reduce duplication in tests
  • ostree-installer: Generate correct volume ID
8 years ago

Pull-Request has been merged by ausil

8 years ago

Didn't test it, but eyeball review LGTM.