#84 Allow specifying --installpkgs for lorax
Merged 8 years ago by ausil. Opened 8 years ago by lsedlar.
lsedlar/pungi include-product-image  into  master

file modified
+26 -2
@@ -86,6 +86,8 @@ 

          noupgrade = not self.compose.conf.get("buildinstall_upgrade_image", False)

          buildinstall_method = self.compose.conf["buildinstall_method"]

  

+         commands = []

+ 

          for arch in self.compose.get_arches():

              repo_baseurl = self.compose.paths.work.arch_repo(arch)

              output_dir = self.compose.paths.work.buildinstall_dir(arch)
@@ -93,11 +95,33 @@ 

              buildarch = get_valid_arches(arch)[0]

  

              if buildinstall_method == "lorax":

-                 cmd = lorax.get_lorax_cmd(product, version, release, repo_baseurl, output_dir, is_final=self.compose.supported, buildarch=buildarch, volid=volid, nomacboot=True, noupgrade=noupgrade)

+                 for variant in self.compose.get_variants(arch=arch, types=['variant']):

+                     commands.append(

+                         lorax.get_lorax_cmd(product,

+                                             version,

+                                             release,

+                                             repo_baseurl,

+                                             output_dir,

+                                             variant=variant.uid,

+                                             buildinstallpackages=variant.buildinstallpackages,

+                                             is_final=self.compose.supported,

+                                             buildarch=buildarch,

+                                             volid=volid,

+                                             nomacboot=True,

+                                             noupgrade=noupgrade))

              elif buildinstall_method == "buildinstall":

-                 cmd = lorax.get_buildinstall_cmd(product, version, release, repo_baseurl, output_dir, is_final=self.compose.supported, buildarch=buildarch, volid=volid)

+                 commands.append(lorax.get_buildinstall_cmd(product,

+                                                            version,

+                                                            release,

+                                                            repo_baseurl,

+                                                            output_dir,

+                                                            is_final=self.compose.supported,

+                                                            buildarch=buildarch,

+                                                            volid=volid))

              else:

                  raise ValueError("Unsupported buildinstall method: %s" % buildinstall_method)

+ 

+         for cmd in commands:

              self.pool.add(BuildinstallThread(self.pool))

              self.pool.queue_put((self.compose, arch, cmd))

  

file modified
+7 -2
@@ -21,7 +21,9 @@ 

  

  

  class LoraxWrapper(object):

-     def get_lorax_cmd(self, product, version, release, repo_baseurl, output_dir, variant=None, bugurl=None, nomacboot=False, noupgrade=False, is_final=False, buildarch=None, volid=None):

+     def get_lorax_cmd(self, product, version, release, repo_baseurl, output_dir,

+                       variant=None, bugurl=None, nomacboot=False, noupgrade=False,

+                       is_final=False, buildarch=None, volid=None, buildinstallpackages=None):

          cmd = ["lorax"]

          cmd.append("--product=%s" % product)

          cmd.append("--version=%s" % version)
@@ -36,7 +38,7 @@ 

              cmd.append("--variant=%s" % variant)

  

          if bugurl is not None:

-             cmd.append("--bugurl=%s" % variant)

+             cmd.append("--bugurl=%s" % bugurl)

  

          if nomacboot:

              cmd.append("--nomacboot")
@@ -53,6 +55,9 @@ 

          if volid:

              cmd.append("--volid=%s" % volid)

  

+         if buildinstallpackages:

+             cmd.extend(["--installpkgs=%s" % package for package in buildinstallpackages])

+ 

          output_dir = os.path.abspath(output_dir)

          cmd.append(output_dir)

  

file modified
+8 -1
@@ -70,6 +70,7 @@ 

              "arches": [str(i) for i in variant_node.xpath("arches/arch/text()")],

              "groups": [],

              "environments": [],

+             "buildinstallpackages": [],

          }

          if self.tree_arches:

              variant_dict["arches"] = [i for i in variant_dict["arches"] if i in self.tree_arches]
@@ -106,6 +107,10 @@ 

  

                  variant_dict["environments"].append(environment)

  

+         for buildinstallpackages_node in variant_node.xpath("buildinstallpackages"):

+             for package_node in buildinstallpackages_node.xpath("package"):

+                 variant_dict["buildinstallpackages"].append(package_node.text)

+ 

          variant = Variant(**variant_dict)

          if variant.type == "layered-product":

              release_node = variant_node.xpath("release")[0]
@@ -157,11 +162,12 @@ 

  

  

  class Variant(object):

-     def __init__(self, id, name, type, arches, groups, environments=None):

+     def __init__(self, id, name, type, arches, groups, environments=None, buildinstallpackages=None):

          if not id.isalnum():

              raise ValueError("Variant ID must contain only alphanumeric characters: %s" % id)

  

          environments = environments or []

+         buildinstallpackages = buildinstallpackages or []

  

          self.id = id

          self.name = name
@@ -169,6 +175,7 @@ 

          self.arches = sorted(copy.deepcopy(arches))

          self.groups = sorted(copy.deepcopy(groups), lambda x, y: cmp(x["name"], y["name"]))

          self.environments = sorted(copy.deepcopy(environments), lambda x, y: cmp(x["name"], y["name"]))

+         self.buildinstallpackages = sorted(buildinstallpackages)

          self.variants = {}

          self.parent = None

  

file modified
+4 -1
@@ -1,6 +1,6 @@ 

  <!ELEMENT variants (ref*,variant*)>

  

- <!ELEMENT variant (release?,arches,groups,environments*,variants*)?>

+ <!ELEMENT variant (release?,arches,groups,environments*,variants*,buildinstallpackages?)?>

  <!ATTLIST variant

      id ID #REQUIRED

      name CDATA #REQUIRED
@@ -40,3 +40,6 @@ 

  <!ATTLIST ref

      id IDREF #REQUIRED

  >

+ 

+ <!ELEMENT buildinstallpackages (package)+>

+ <!ELEMENT package (#PCDATA)>

@@ -0,0 +1,136 @@ 

+ #!/usr/bin/env python2

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

+ 

+ 

+ import unittest

+ import mock

+ 

+ import os

+ import sys

+ 

+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

+ 

+ from pungi.phases.buildinstall import BuildinstallPhase

+ 

+ 

+ class _DummyCompose(object):

+     def __init__(self, config):

+         self.conf = config

+         self.paths = mock.Mock(

+             compose=mock.Mock(

+                 topdir=mock.Mock(return_value='/a/b')

+             ),

+             work=mock.Mock(

+                 arch_repo=mock.Mock(return_value='file:///a/b/'),

+                 buildinstall_dir=mock.Mock(side_effect=lambda x: '/buildinstall_dir/' + x),

+             )

+         )

+         self._logger = mock.Mock()

+         self.log_debug = mock.Mock()

+         self.supported = True

+ 

+     def get_arches(self):

+         return ['x86_64', 'amd64']

+ 

+     def get_variants(self, arch, types):

+         variants = {

+             'x86_64': [mock.Mock(uid='Server', buildinstallpackages=['bash', 'vim'])],

+             'amd64': [mock.Mock(uid='Client', buildinstallpackages=[]),

+                       mock.Mock(uid='Server', buildinstallpackages=['bash', 'vim'])],

+         }

+         return variants.get(arch, [])

+ 

+ 

+ class TestImageChecksumPhase(unittest.TestCase):

+ 

+     def test_config_skip_unless_bootable(self):

+         compose = _DummyCompose({})

+         compose.just_phases = None

+         compose.skip_phases = []

+ 

+         phase = BuildinstallPhase(compose)

+ 

+         self.assertTrue(phase.skip())

+ 

+     def test_does_not_skip_on_bootable(self):

+         compose = _DummyCompose({'bootable': True})

+         compose.just_phases = None

+         compose.skip_phases = []

+ 

+         phase = BuildinstallPhase(compose)

+ 

+         self.assertFalse(phase.skip())

+ 

+     @mock.patch('pungi.phases.buildinstall.ThreadPool')

+     @mock.patch('pungi.phases.buildinstall.LoraxWrapper')

+     @mock.patch('pungi.phases.buildinstall.get_volid')

+     def test_starts_threads_for_each_cmd_with_lorax(self, get_volid, loraxCls, poolCls):

+         compose = _DummyCompose({

+             'bootable': True,

+             'release_name': 'Test',

+             'release_short': 't',

+             'release_version': '1',

+             'release_is_layered': False,

+             'buildinstall_method': 'lorax'

+         })

+ 

+         get_volid.return_value = 'vol_id'

+ 

+         phase = BuildinstallPhase(compose)

+ 

+         phase.run()

+ 

+         # Three items added for processing in total.

+         # Server.x86_64, Client.amd64, Server.x86_64

+         pool = poolCls.return_value

+         self.assertEqual(3, len(pool.queue_put.mock_calls))

+ 

+         # Obtained correct lorax commands.

+         lorax = loraxCls.return_value

+         lorax.get_lorax_cmd.assert_has_calls(

+             [mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/x86_64',

+                        buildarch='x86_64', is_final=True, nomacboot=True, noupgrade=True,

+                        volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim']),

+              mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/amd64',

+                        buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True,

+                        volid='vol_id', variant='Server', buildinstallpackages=['bash', 'vim']),

+              mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/amd64',

+                        buildarch='amd64', is_final=True, nomacboot=True, noupgrade=True,

+                        volid='vol_id', variant='Client', buildinstallpackages=[])],

+             any_order=True)

+ 

+     @mock.patch('pungi.phases.buildinstall.ThreadPool')

+     @mock.patch('pungi.phases.buildinstall.LoraxWrapper')

+     @mock.patch('pungi.phases.buildinstall.get_volid')

+     def test_starts_threads_for_each_cmd_with_buildinstall(self, get_volid, loraxCls, poolCls):

+         compose = _DummyCompose({

+             'bootable': True,

+             'release_name': 'Test',

+             'release_short': 't',

+             'release_version': '1',

+             'release_is_layered': False,

+             'buildinstall_method': 'buildinstall'

+         })

+ 

+         get_volid.return_value = 'vol_id'

+ 

+         phase = BuildinstallPhase(compose)

+ 

+         phase.run()

+ 

+         # Two items added for processing in total.

+         pool = poolCls.return_value

+         self.assertEqual(2, len(pool.queue_put.mock_calls))

+ 

+         # Obtained correct lorax commands.

+         lorax = loraxCls.return_value

+         lorax.get_buildinstall_cmd.assert_has_calls(

+             [mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/x86_64',

+                        buildarch='x86_64', is_final=True, volid='vol_id'),

+              mock.call('Test', '1', '1', 'file:///a/b/', '/buildinstall_dir/amd64',

+                        buildarch='amd64', is_final=True, volid='vol_id')],

+             any_order=True)

+ 

+ 

+ if __name__ == "__main__":

+     unittest.main()

@@ -0,0 +1,52 @@ 

+ #!/usr/bin/env python2

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

+ 

+ import unittest

+ 

+ import os

+ import sys

+ 

+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

+ 

+ from pungi.wrappers.lorax import LoraxWrapper

+ 

+ 

+ class LoraxWrapperTest(unittest.TestCase):

+ 

+     def setUp(self):

+         self.lorax = LoraxWrapper()

+ 

+     def test_get_command_with_minimal_arguments(self):

+         cmd = self.lorax.get_lorax_cmd("product", "version", "release",

+                                        "/mnt/repo_baseurl", "/mnt/output_dir")

+ 

+         self.assertEqual(cmd[0], 'lorax')

+         self.assertItemsEqual(cmd[1:],

+                               ['--product=product',

+                                '--version=version',

+                                '--release=release',

+                                '--source=file:///mnt/repo_baseurl',

+                                '/mnt/output_dir'])

+ 

+     def test_get_command_with_all_arguments(self):

+         cmd = self.lorax.get_lorax_cmd("product", "version", "release",

+                                        "/mnt/repo_baseurl", "/mnt/output_dir",

+                                        variant="Server", bugurl="http://example.com/",

+                                        nomacboot=True, noupgrade=True, is_final=True,

+                                        buildarch='x86_64', volid='VOLUME_ID',

+                                        buildinstallpackages=['bash', 'vim'])

+ 

+         self.assertEqual(cmd[0], 'lorax')

+         self.assertItemsEqual(cmd[1:],

+                               ['--product=product', '--version=version',

+                                '--release=release', '--variant=Server',

+                                '--source=file:///mnt/repo_baseurl',

+                                '--bugurl=http://example.com/',

+                                '--buildarch=x86_64', '--volid=VOLUME_ID',

+                                '--nomacboot', '--noupgrade', '--isfinal',

+                                '--installpkgs=bash', '--installpkgs=vim',

+                                '/mnt/output_dir'])

+ 

+ 

+ if __name__ == "__main__":

+     unittest.main()