From b05220e82c97018ba468ae5a6ca8feddf111b31c Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Aug 16 2018 14:42:43 +0000 Subject: Reserve last bodhi template on error Edited Bodhi template is reserved on error in case any input by packager is lost. The file is named `bodhi.template.last`. Resolves: rhbz#1467897 Signed-off-by: Chenxiong Qi --- diff --git a/fedpkg/cli.py b/fedpkg/cli.py index bc0d636..77a62c1 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -19,6 +19,7 @@ import re import json import pkg_resources import six +import shutil import textwrap import itertools @@ -707,7 +708,13 @@ targets to build the package for a particular stream. try: self.cmd.update(bodhi_config, template=bodhi_template_file) except Exception as e: - raise rpkgError('Could not generate update request: %s' % e) + # Reserve original edited bodhi template so that packager could + # have a chance to recover content on error for next try. + shutil.copyfile(bodhi_template_file, + '{0}.last'.format(bodhi_template_file)) + raise rpkgError('Could not generate update request: %s\n' + 'A copy of the filled in template is saved ' + 'as bodhi.template.last' % e) finally: os.unlink(bodhi_template_file) os.unlink('clog') diff --git a/test/test_cli.py b/test/test_cli.py index c452527..46fa309 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -132,6 +132,8 @@ class TestUpdate(CliTestCase): def tearDown(self): if os.path.exists('bodhi.template'): os.unlink('bodhi.template') + if os.path.exists('bodhi.template.last'): + os.unlink('bodhi.template.last') os.unlink(os.path.join(self.cloned_repo_path, 'clog')) self.user_patcher.stop() self.os_environ_patcher.stop() @@ -376,6 +378,17 @@ class TestUpdate(CliTestCase): 'update', '--bugs', '1000', '1001', '100l' ]) + def test_reserve_edited_template_on_error(self): + cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'update'] + cli = self.get_cli(cli_cmd) + + try: + self.assert_bodhi_update(cli, update_type='xxx') + except rpkgError: + pass + + self.assertTrue(os.path.exists('bodhi.template.last')) + @patch.object(BugzillaClient, 'client') class TestRequestRepo(CliTestCase):