#271 Reserve last bodhi template on error
Merged 5 years ago by cqi. Opened 5 years ago by cqi.

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

  import json

  import pkg_resources

  import six

+ import shutil

  import textwrap

  import itertools

  
@@ -707,7 +708,13 @@ 

              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')

file modified
+13
@@ -132,6 +132,8 @@ 

      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 @@ 

                  '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):

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 cqi@redhat.com

Fixes #157

Looks good. Maybe it would be nice to add information to the error message that a copy of the template is saved? Otherwise people might miss it and later wonder what that file is doing there.
Something like Could not generate update request: %s\nA copy of the filled in template is saved as bodhi.template.last might be helpful.

No other comment from me.

rebased onto c90e352e1dca6a7fa8ce5cbdbb91a811c4bcb673

5 years ago

rebased onto b05220e

5 years ago

Pull-Request has been merged by cqi

5 years ago