diff --git a/pungi/phases/ostree.py b/pungi/phases/ostree.py index 2abecf7f..42a0b8cc 100644 --- a/pungi/phases/ostree.py +++ b/pungi/phases/ostree.py @@ -100,7 +100,7 @@ class OSTreeThread(WorkerThread): '--treefile=%s' % os.path.join(config_repo, config['treefile']), ] - version = config.get('version', None) + version = util.version_generator(compose, config.get('version')) if version: cmd.append('--version=%s' % version) diff --git a/pungi/util.py b/pungi/util.py index de6effba..c44059f6 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -761,3 +761,12 @@ def get_repo_dicts(compose, repos, arch='$basearch'): repo_dict = get_repo_dict(compose, repo, arch=arch) repo_dicts.append(repo_dict) return repo_dicts + + +def version_generator(compose, gen): + """If ``gen`` is a known generator, create a value. Otherwise return + the argument value unchanged. + """ + if gen == '!OSTREE_VERSION_FROM_LABEL_DATE_TYPE_RESPIN': + return '%s.%s' % (compose.image_version, compose.image_release) + return gen diff --git a/tests/test_config.py b/tests/test_config.py index 769cb8d5..2d9af3f1 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -274,7 +274,8 @@ class OstreeConfigTestCase(ConfigTestCase): "treefile": "fedora-atomic-docker-host.json", "config_url": "https://git.fedorahosted.org/git/fedora-atomic.git", "repo": "Everything", - "ostree_repo": "/mnt/koji/compose/atomic/Rawhide/" + "ostree_repo": "/mnt/koji/compose/atomic/Rawhide/", + "version": '!OSTREE_VERSION_FROM_LABEL_DATE_TYPE_RESPIN', } }) ] diff --git a/tests/test_ostree_phase.py b/tests/test_ostree_phase.py index 15ebf395..33613533 100644 --- a/tests/test_ostree_phase.py +++ b/tests/test_ostree_phase.py @@ -296,6 +296,41 @@ class OSTreeThreadTest(helpers.PungiTestCase): [mock.call(koji.get_runroot_cmd.return_value, log_file=self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')]) + @mock.patch('pungi.wrappers.scm.get_dir_from_scm') + @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') + def test_run_with_generated_versioning_metadata(self, KojiWrapper, get_dir_from_scm): + self.cfg['version'] = '!OSTREE_VERSION_FROM_LABEL_DATE_TYPE_RESPIN' + + get_dir_from_scm.side_effect = self._dummy_config_repo + + koji = KojiWrapper.return_value + koji.run_runroot_cmd.side_effect = self._mock_runroot(0) + + t = ostree.OSTreeThread(self.pool) + + t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) + + self.assertEqual(get_dir_from_scm.call_args_list, + [mock.call({'scm': 'git', 'repo': 'https://git.fedorahosted.org/git/fedora-atomic.git', + 'branch': 'f24', 'dir': '.'}, + self.topdir + '/work/ostree-1/config_repo', logger=self.pool._logger)]) + self.assertEqual(koji.get_runroot_cmd.call_args_list, + [mock.call('rrt', 'x86_64', + ['pungi-make-ostree', + 'tree', + '--repo=%s' % self.repo, + '--log-dir=%s/logs/x86_64/Everything/ostree-1' % self.topdir, + '--treefile=%s/fedora-atomic-docker-host.json' % ( + self.topdir + '/work/ostree-1/config_repo'), + '--version=25.20151203.t.0', + '--extra-config=%s/work/ostree-1/extra_config.json' % self.topdir], + channel=None, mounts=[self.topdir, self.repo], + packages=['pungi', 'ostree', 'rpm-ostree'], + task_id=True, use_shell=True, new_chroot=True, weight=None)]) + self.assertEqual(koji.run_runroot_cmd.call_args_list, + [mock.call(koji.get_runroot_cmd.return_value, + log_file=self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')]) + @mock.patch('pungi.wrappers.scm.get_dir_from_scm') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') def test_write_extra_config_file(self, KojiWrapper, get_dir_from_scm):