#1772 rpmbuild: properly cleanup mock bootstrap
Merged 3 years ago by praiskup. Opened 3 years ago by praiskup.
Unknown source clean-bootstrap  into  main

@@ -39,6 +39,7 @@

              "group" if self.copr_username.startswith("@") else "user",

              self.copr_username,

          )

+         self.uniqueext = get_mock_uniqueext()

  

      def run(self):

          open(self.logfile, 'w').close() # truncate logfile
@@ -87,7 +88,7 @@

              "--spec", spec,

              "--sources", sources,

              "--resultdir", resultdir,

-             "--uniqueext", get_mock_uniqueext(),

+             "--uniqueext", self.uniqueext,

              "-r", self.mock_config_file]

  

          for with_opt in self.with_opts:
@@ -113,6 +114,7 @@

          """ Do a best effort Mock cleanup. """

          cmd = MOCK_CALL + [

              "-r", self.mock_config_file,

+             "--uniqueext", self.uniqueext,

              "--scrub", "bootstrap",

              "--scrub", "chroot",

              "--scrub", "root-cache",
@@ -162,7 +164,7 @@

          cmd = MOCK_CALL + [

                 "--rebuild", srpm,

                 "--resultdir", resultdir,

-                "--uniqueext", get_mock_uniqueext(),

+                "--uniqueext", self.uniqueext,

                 "-r", self.mock_config_file]

  

          for with_opt in self.with_opts:

file modified
+10 -2
@@ -180,12 +180,14 @@

          call = f_mock_calls[1]

          assert call[0][0] == self.mock_rpm_call

  

+     @mock.patch("copr_rpmbuild.builders.mock.subprocess.call")

      @mock.patch("copr_rpmbuild.builders.mock.MockBuilder.prepare_configs")

      @mock.patch("copr_rpmbuild.builders.mock.get_mock_uniqueext")

      @mock.patch("copr_rpmbuild.builders.mock.GentlyTimeoutedPopen")

-     def test_produce_rpm(self, popen_mock, get_mock_uniqueext_mock, prep_configs):

+     def test_produce_rpm(self, popen_mock, get_mock_uniqueext_mock,

+                          prep_configs, sp_call):

+         get_mock_uniqueext_mock.side_effect = ['2', 'not_called_twice']

          builder = MockBuilder(self.task, self.sourcedir, self.resultdir, self.config)

-         get_mock_uniqueext_mock.return_value = '2'

          process = mock.MagicMock(returncode=0)

          popen_mock.return_value = process

          builder.produce_rpm("/path/to/pkg.src.rpm", "/path/to/results")
@@ -196,6 +198,12 @@

                        '-r', builder.mock_config_file]

          popen_mock.assert_called_with(assert_cmd, stdin=subprocess.PIPE,

                                        timeout=21600)

+         builder.mock_clean()

+         sp_call.assert_called_with(

+             ['unbuffer', 'mock', '-r', builder.mock_config_file,

+              '--uniqueext', '2', '--scrub', 'bootstrap', '--scrub', 'chroot',

+              '--scrub', 'root-cache', '--quiet'])

+         assert get_mock_uniqueext_mock.call_count == 1

  

      @mock.patch('{0}.open'.format(builtins), new_callable=mock.mock_open())

      def test_touch_success_file(self, mock_open):

We forgot to specify uniqueext, so the unique bootstrap directory stayed
mounted.

Fixes: #1697

Build succeeded.

Can you please add assert get_mock_uniqueext_mock.call_count == 1 or some alternative somewhere to this test?

A minor thing in a test but otherwise +1

rebased onto edd5ef1d5b86c62e634876218e908f8e60a2bd41

3 years ago

Can you please add assert get_mock_uniqueext_mock.call_count == 1 or some alternative somewhere to this test?

Done.

Build succeeded.

rebased onto 376df1b

3 years ago

Pull-Request has been merged by praiskup

3 years ago

Build succeeded.