#1447 Support change of the patch-iso temp dir
Merged 3 years ago by lsedlar. Opened 3 years ago by jkonecny.
jkonecny/pungi support-custom-tmp  into  master

@@ -34,6 +34,9 @@ 

          "--force-arch", help="Treat the ISO as bootable on given architecture"

      )

      parser.add_argument(

+         "--work-dir", help="Set custom working directory. Default: /tmp/", default=None

+     )

+     parser.add_argument(

          "target", metavar="TARGET_ISO", help="which file to write the result to"

      )

      parser.add_argument("source", metavar="SOURCE_ISO", help="source ISO to work with")

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

      log.info("Mounting %s", opts.source)

      target = os.path.abspath(opts.target)

  

-     with util.temp_dir(prefix="patch-iso-") as work_dir:

+     with util.temp_dir(prefix="patch-iso-", dir=opts.work_dir) as work_dir:

          with iso.mount(opts.source) as source_iso_dir:

              util.copy_all(source_iso_dir, work_dir)

  

file modified
+53
@@ -84,6 +84,7 @@ 

              target="test.iso",

              source="source.iso",

              force_arch=None,

+             work_dir=None,

              volume_id="FOOBAR",

              dirs=[],

          )
@@ -116,6 +117,55 @@ 

      @mock.patch("pungi_utils.patch_iso.util.copy_all")

      @mock.patch("pungi_utils.patch_iso.iso")

      @mock.patch("pungi_utils.patch_iso.sh")

+     def test_work_dir(self, sh, iso, copy_all):

+         iso.mount.return_value.__enter__.return_value = "mounted-iso-dir"

+ 

+         def _create_files(src, dest):

+             touch(os.path.join(dest, "dir", "file.txt"), "Hello")

+ 

+         copy_all.side_effect = _create_files

+ 

+         log = mock.Mock(name="logger")

+         opts = mock.Mock(

+             target="test.iso",

+             source="source.iso",

+             force_arch=None,

+             work_dir="/tmp/custom-workdir",

+             volume_id="FOOBAR",

+             dirs=[],

+         )

+         patch_iso.run(log, opts)

+ 

+         self.assertEqual(

+             iso.get_mkisofs_cmd.call_args_list,

+             [

+                 mock.call(

+                     os.path.abspath(opts.target),

+                     None,

+                     boot_args=None,

+                     exclude=["./lost+found"],

+                     graft_points=ANYTHING,

+                     input_charset=None,

+                     volid="FOOBAR",

+                 )

+             ],

+         )

+         self.assertEqual(iso.mount.call_args_list, [mock.call("source.iso")])

+         self.assertEqual(copy_all.mock_calls, [mock.call("mounted-iso-dir", ANYTHING)])

+         self.assertTrue(

+             copy_all.call_args.args[1].startswith("/tmp/custom-workdir/patch-iso-")

+         )

+         self.assertEqual(

+             sh.call_args_list,

+             [

+                 mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING),

+                 mock.call(log, iso.get_implantisomd5_cmd.return_value),

+             ],

+         )

+ 

+     @mock.patch("pungi_utils.patch_iso.util.copy_all")

+     @mock.patch("pungi_utils.patch_iso.iso")

+     @mock.patch("pungi_utils.patch_iso.sh")

      def test_detect_arch_discinfo(self, sh, iso, copy_all):

          iso.mount.return_value.__enter__.return_value = "mounted-iso-dir"

  
@@ -133,6 +183,7 @@ 

              target="test.iso",

              source="source.iso",

              force_arch=None,

+             work_dir=None,

              volume_id=None,

              dirs=[],

          )
@@ -182,6 +233,7 @@ 

              target="test.iso",

              source="source.iso",

              force_arch=None,

+             work_dir=None,

              volume_id=None,

              dirs=[],

          )
@@ -232,6 +284,7 @@ 

              target="test.iso",

              source="source.iso",

              force_arch="s390",

+             work_dir=None,

              volume_id="foobar",

              dirs=[],

          )

This is useful when running pungi-patch-iso on VM with low amount of memory but higher disk space. Without this option the operation will fail because /tmp is tmpfs filesystem.

This unused import seems to be the reason for failing Jenkins.

Ahh, my fault. I'll fixed that.

2 new commits added

  • Adapt tests to new patch-iso --work-dir parameter
  • Support change of the patch-iso temp dir
3 years ago

Looks good to me. Thanks for the patch!

Pull-Request has been merged by lsedlar

3 years ago