#381 Automatically generate missing image version
Merged 8 years ago by ausil. Opened 8 years ago by lsedlar.

file modified
+5 -2
@@ -810,14 +810,17 @@ 

   * ``live_media_target``

   * ``image_build_target``

  

- Version is specified by these options.

+ .. _auto_version:

+ 

+ Version is specified by these options. If no version is set, a default value

+ will be provided based on product version. If label is used (and is not

+ ``RC``), the milestone will be appended to the version with an underscore.

  

   * ``global_version`` -- global fallback setting

   * ``live_media_version``

   * ``image_build_version``

   * ``live_images_version``

  

- 

  .. _auto_release:

  

  Release is specified by these options. If set explicitly to ``None``, a value

file modified
+14
@@ -355,3 +355,17 @@ 

  

          return '%s%s.%s' % (self.compose_date, self.ci_base.compose.type_suffix,

                              self.compose_respin)

+ 

+     @property

+     def image_version(self):

+         """Generate a value to pass to Koji as image version.

+ 

+         The value is based on release version. If compose has a label, the

+         milestone from it is appended to the version (unless it is RC).

+         """

+         version = self.ci_base.release.version

+         if self.compose_label and not self.compose_label.startswith('RC-'):

+             milestone, release = self.compose_label.split('-')

+             return '%s_%s' % (version, milestone)

+ 

+         return version

file modified
+7
@@ -106,6 +106,13 @@ 

                  '%s_%s' % (self.name, opt), self.compose.conf.get(

                      'global_%s' % opt)))

  

+     def get_version(self, cfg):

+         """

+         Get version from configuration hierarchy or fall back to release

+         version.

+         """

+         return self.get_config(cfg, 'version') or self.compose.image_version

+ 

      def get_release(self, cfg):

          """

          If release is set explicitly to None, replace it with date and respin.

file modified
+1 -1
@@ -134,7 +134,7 @@ 

                  if release:

                      image_conf['image-build']['release'] = release

  

-                 image_conf['image-build']['version'] = self.get_config(image_conf['image-build'], 'version')

+                 image_conf['image-build']['version'] = self.get_version(image_conf['image-build'])

                  image_conf['image-build']['target'] = self.get_config(image_conf['image-build'], 'target')

  

                  # transform format into right 'format' for image-build

file modified
+1 -1
@@ -140,7 +140,7 @@ 

  

                      cmd = {

                          "name": data.get('name'),

-                         "version": self.get_config(data, 'version'),

+                         "version": self.get_version(data),

                          "release": self.get_release(data),

                          "dest_dir": dest_dir,

                          "build_arch": arch,

@@ -115,7 +115,7 @@ 

                      'title': image_conf.get('title'),

                      'repo': self._get_repos(image_conf, variant),

                      'install_tree': self._get_install_tree(image_conf, variant),

-                     'version': self.get_config(image_conf, 'version'),

+                     'version': self.get_version(image_conf),

                      'failable_arches': image_conf.get('failable', []),

                  }

                  self.pool.add(LiveMediaThread(self.pool))

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

          self.compose_label = None

          self.compose_label_major_version = None

          self.image_release = '20151203.t.0'

+         self.image_version = '25'

          self.ci_base = mock.Mock(

              release_id='Test-1.0',

              release=mock.Mock(

file modified
+44 -2
@@ -127,12 +127,12 @@ 

          ci.return_value.compose.respin = 2

          ci.return_value.compose.date = '20160107'

          ci.return_value.compose.type = 'production'

-         ci.return_value.compose.type_suffix = '.n'

+         ci.return_value.compose.type_suffix = ''

          ci.return_value.compose.label = None

  

          compose = Compose(conf, self.tmp_dir)

  

-         self.assertEqual(compose.image_release, '20160107.n.2')

+         self.assertEqual(compose.image_release, '20160107.2')

  

      @mock.patch('pungi.compose.ComposeInfo')

      def test_image_release_from_label(self, ci):
@@ -148,6 +148,48 @@ 

          self.assertEqual(compose.image_release, '1.2')

  

      @mock.patch('pungi.compose.ComposeInfo')

+     def test_image_version_without_label(self, ci):

+         conf = {}

+         ci.return_value.compose.respin = 2

+         ci.return_value.compose.date = '20160107'

+         ci.return_value.compose.type = 'nightly'

+         ci.return_value.compose.type_suffix = '.n'

+         ci.return_value.compose.label = None

+         ci.return_value.release.version = '25'

+ 

+         compose = Compose(conf, self.tmp_dir)

+ 

+         self.assertEqual(compose.image_version, '25')

+ 

+     @mock.patch('pungi.compose.ComposeInfo')

+     def test_image_version_with_label(self, ci):

+         conf = {}

+         ci.return_value.compose.respin = 2

+         ci.return_value.compose.date = '20160107'

+         ci.return_value.compose.type = 'nightly'

+         ci.return_value.compose.type_suffix = '.n'

+         ci.return_value.compose.label = 'Alpha-1.2'

+         ci.return_value.release.version = '25'

+ 

+         compose = Compose(conf, self.tmp_dir)

+ 

+         self.assertEqual(compose.image_version, '25_Alpha')

+ 

+     @mock.patch('pungi.compose.ComposeInfo')

+     def test_image_version_with_label_rc(self, ci):

+         conf = {}

+         ci.return_value.compose.respin = 2

+         ci.return_value.compose.date = '20160107'

+         ci.return_value.compose.type = 'nightly'

+         ci.return_value.compose.type_suffix = '.n'

+         ci.return_value.compose.label = 'RC-1.2'

+         ci.return_value.release.version = '25'

+ 

+         compose = Compose(conf, self.tmp_dir)

+ 

+         self.assertEqual(compose.image_version, '25')

+ 

+     @mock.patch('pungi.compose.ComposeInfo')

      def test_get_variant_arches_without_filter(self, ci):

          conf = ConfigWrapper(

              variants_file={'scm': 'file',

@@ -164,6 +164,65 @@ 

                                [mock.call((compose, server_args))])

  

      @mock.patch('pungi.phases.image_build.ThreadPool')

+     def test_image_build_phase_missing_version(self, ThreadPool):

+         compose = DummyCompose(self.topdir, {

+             'image_build_ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',

+             'image_build_release': None,

+             'image_build_target': 'f24',

+             'image_build': {

+                 '^Server$': [

+                     {

+                         'image-build': {

+                             'format': [('docker', 'tar.xz')],

+                             'name': 'Fedora-Docker-Base',

+                             'kickstart': "fedora-docker-base.ks",

+                             'distro': 'Fedora-20',

+                             'disk_size': 3

+                         }

+                     }

+                 ]

+             },

+             'koji_profile': 'koji',

+         })

+ 

+         phase = ImageBuildPhase(compose)

+ 

+         phase.run()

+         self.maxDiff = None

+ 

+         # assert at least one thread was started

+         self.assertTrue(phase.pool.add.called)

+         server_args = {

+             "format": [('docker', 'tar.xz')],

+             "image_conf": {

+                 'image-build': {

+                     'install_tree': self.topdir + '/compose/Server/$arch/os',

+                     'kickstart': 'fedora-docker-base.ks',

+                     'format': 'docker',

+                     'repo': self.topdir + '/compose/Server/$arch/os',

+                     'variant': compose.variants['Server'],

+                     'target': 'f24',

+                     'disk_size': 3,

+                     'name': 'Fedora-Docker-Base',

+                     'arches': 'amd64,x86_64',

+                     'version': '25',

+                     'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',

+                     'distro': 'Fedora-20',

+                     'release': '20151203.t.0',

+                 }

+             },

+             "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg',

+             "image_dir": self.topdir + '/compose/Server/%(arch)s/images',

+             "relative_image_dir": 'Server/%(arch)s/images',

+             "link_type": 'hardlink-or-copy',

+             "scratch": False,

+             "failable_arches": [],

+         }

+         self.maxDiff = None

+         self.assertItemsEqual(phase.pool.queue_put.mock_calls,

+                               [mock.call((compose, server_args))])

+ 

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

      def test_image_build_filter_all_variants(self, ThreadPool):

          compose = DummyCompose(self.topdir, {

              'image_build': {

@@ -50,7 +50,7 @@ 

                                             'label': '',

                                             'name': None,

                                             'filename': 'image-name',

-                                            'version': None,

+                                            'version': '25',

                                             'specfile': None,

                                             'sign': False,

                                             'type': 'live',
@@ -99,7 +99,7 @@ 

                                             'label': '',

                                             'name': None,

                                             'filename': 'image-name',

-                                            'version': None,

+                                            'version': '25',

                                             'specfile': None,

                                             'sign': False,

                                             'type': 'live',
@@ -145,7 +145,7 @@ 

                                             'label': '',

                                             'name': None,

                                             'filename': None,

-                                            'version': None,

+                                            'version': '25',

                                             'specfile': None,

                                             'sign': False,

                                             'type': 'live',
@@ -193,7 +193,7 @@ 

                                             'label': '',

                                             'name': None,

                                             'filename': 'image-name',

-                                            'version': None,

+                                            'version': '25',

                                             'specfile': None,

                                             'sign': False,

                                             'type': 'live',
@@ -214,7 +214,7 @@ 

                                             'label': '',

                                             'name': None,

                                             'filename': 'image-name',

-                                            'version': None,

+                                            'version': '25',

                                             'specfile': None,

                                             'sign': False,

                                             'type': 'live',
@@ -263,7 +263,7 @@ 

                                             'label': '',

                                             'name': None,

                                             'filename': 'image-name',

-                                            'version': None,

+                                            'version': '25',

                                             'specfile': None,

                                             'sign': False,

                                             'type': 'appliance',
@@ -417,7 +417,7 @@ 

                                             'label': '',

                                             'name': None,

                                             'filename': 'image-name',

-                                            'version': None,

+                                            'version': '25',

                                             'specfile': None,

                                             'sign': False,

                                             'type': 'live',

file modified
+1 -2
@@ -339,7 +339,6 @@ 

                          'arches': ['x86_64'],

                          'ksversion': '24',

                          'release': None,

-                         'version': 'Rawhide',

                          'install_tree_from': 'Everything',

                          'subvariant': 'Something',

                          'failable': ['*'],
@@ -372,7 +371,7 @@ 

                                           'target': 'f24',

                                           'title': 'Custom Title',

                                           'install_tree': self.topdir + '/compose/Everything/$basearch/os',

-                                          'version': 'Rawhide',

+                                          'version': '25',

                                           'subvariant': 'Something',

                                           'failable_arches': ['*'],

                                       }))])

If the configuration does not specify version for images or live media,
Pungi will create a default value based on release_version. If label
is used for the compose, the milestone from it will be appended to the
version (unless it's RC).

This change is backwards compatible: nothing changes when version is set
in configuration. If the version was missing before, building the
artifacts would fail. With this patch, default values will be supplied.

Pull-Request has been merged by ausil

8 years ago