2017-02-20 09:35:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mock
|
|
|
|
import os
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2017-02-20 09:35:34 +00:00
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from tests.helpers import boom, touch, copy_fixture
|
|
|
|
from pungi_utils import patch_iso
|
|
|
|
|
|
|
|
|
|
|
|
class TestUnifiedIsos(unittest.TestCase):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetLoraxDir(unittest.TestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("kobo.shortcuts.run")
|
2017-02-20 09:35:34 +00:00
|
|
|
def test_success(self, mock_run):
|
2020-01-22 10:02:22 +00:00
|
|
|
mock_run.return_value = (0, "hello")
|
|
|
|
self.assertEqual(patch_iso.get_lorax_dir(None), "hello")
|
2017-02-20 09:35:34 +00:00
|
|
|
self.assertEqual(1, len(mock_run.call_args_list))
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("kobo.shortcuts.run")
|
2017-02-20 09:35:34 +00:00
|
|
|
def test_crash(self, mock_run):
|
|
|
|
mock_run.side_effect = boom
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(patch_iso.get_lorax_dir("hello"), "hello")
|
2017-02-20 09:35:34 +00:00
|
|
|
self.assertEqual(1, len(mock_run.call_args_list))
|
|
|
|
|
|
|
|
|
|
|
|
class TestSh(unittest.TestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("kobo.shortcuts.run")
|
2017-02-20 09:35:34 +00:00
|
|
|
def test_cmd(self, mock_run):
|
2020-01-22 10:02:22 +00:00
|
|
|
mock_run.return_value = (0, "ok")
|
2017-02-20 09:35:34 +00:00
|
|
|
log = mock.Mock()
|
2020-01-22 10:02:22 +00:00
|
|
|
patch_iso.sh(log, ["ls"], foo="bar")
|
|
|
|
self.assertEqual(
|
|
|
|
mock_run.call_args_list,
|
|
|
|
[mock.call(["ls"], foo="bar", universal_newlines=True)],
|
|
|
|
)
|
|
|
|
self.assertEqual(log.info.call_args_list, [mock.call("Running: %s", "ls")])
|
|
|
|
self.assertEqual(log.debug.call_args_list, [mock.call("%s", "ok")])
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestAsBool(unittest.TestCase):
|
|
|
|
def test_true(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertTrue(patch_iso.as_bool("true"))
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
def test_false(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertFalse(patch_iso.as_bool("false"))
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
def test_anything_else(self):
|
|
|
|
obj = mock.Mock()
|
|
|
|
self.assertIs(patch_iso.as_bool(obj), obj)
|
|
|
|
|
|
|
|
|
|
|
|
class EqualsAny(object):
|
|
|
|
def __eq__(self, another):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def __repr__(self):
|
2022-08-10 06:31:02 +00:00
|
|
|
return "ANYTHING"
|
2017-02-20 09:35:34 +00:00
|
|
|
|
2019-05-31 07:31:01 +00:00
|
|
|
|
2017-02-20 09:35:34 +00:00
|
|
|
ANYTHING = EqualsAny()
|
|
|
|
|
|
|
|
|
|
|
|
class TestPatchingIso(unittest.TestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi_utils.patch_iso.util.copy_all")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.iso")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.sh")
|
2017-02-20 09:35:34 +00:00
|
|
|
def test_whole(self, sh, iso, copy_all):
|
2020-01-22 10:02:22 +00:00
|
|
|
iso.mount.return_value.__enter__.return_value = "mounted-iso-dir"
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
def _create_files(src, dest):
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(dest, "dir", "file.txt"), "Hello")
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
copy_all.side_effect = _create_files
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
log = mock.Mock(name="logger")
|
2017-02-20 09:35:34 +00:00
|
|
|
opts = mock.Mock(
|
2020-01-22 10:02:22 +00:00
|
|
|
target="test.iso",
|
|
|
|
source="source.iso",
|
2017-02-20 09:35:34 +00:00
|
|
|
force_arch=None,
|
2020-09-15 13:47:25 +00:00
|
|
|
work_dir=None,
|
2020-01-22 10:02:22 +00:00
|
|
|
volume_id="FOOBAR",
|
|
|
|
dirs=[],
|
2017-02-20 09:35:34 +00:00
|
|
|
)
|
|
|
|
patch_iso.run(log, opts)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
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)])
|
2017-02-20 09:35:34 +00:00
|
|
|
self.assertEqual(
|
|
|
|
sh.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING),
|
|
|
|
mock.call(log, iso.get_implantisomd5_cmd.return_value),
|
|
|
|
],
|
|
|
|
)
|
2017-02-20 09:35:34 +00:00
|
|
|
|
2020-09-15 13:47:25 +00:00
|
|
|
@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(
|
2020-09-25 10:38:13 +00:00
|
|
|
copy_all.call_args[0][1].startswith("/tmp/custom-workdir/patch-iso-")
|
2020-09-15 13:47:25 +00:00
|
|
|
)
|
|
|
|
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),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi_utils.patch_iso.util.copy_all")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.iso")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.sh")
|
2017-02-20 09:35:34 +00:00
|
|
|
def test_detect_arch_discinfo(self, sh, iso, copy_all):
|
2020-01-22 10:02:22 +00:00
|
|
|
iso.mount.return_value.__enter__.return_value = "mounted-iso-dir"
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
def _create_files(src, dest):
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(dest, "dir", "file.txt"), "Hello")
|
|
|
|
touch(
|
|
|
|
os.path.join(dest, ".discinfo"),
|
|
|
|
"1487578537.111417\nDummy Product 1.0\nppc64\n1",
|
|
|
|
)
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
copy_all.side_effect = _create_files
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
log = mock.Mock(name="logger")
|
2017-02-20 09:35:34 +00:00
|
|
|
opts = mock.Mock(
|
2020-01-22 10:02:22 +00:00
|
|
|
target="test.iso",
|
|
|
|
source="source.iso",
|
2017-02-20 09:35:34 +00:00
|
|
|
force_arch=None,
|
2020-09-15 13:47:25 +00:00
|
|
|
work_dir=None,
|
2019-04-12 13:09:53 +00:00
|
|
|
volume_id=None,
|
2020-01-22 10:02:22 +00:00
|
|
|
dirs=[],
|
2017-02-20 09:35:34 +00:00
|
|
|
)
|
|
|
|
patch_iso.run(log, opts)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(iso.mount.call_args_list, [mock.call("source.iso")])
|
|
|
|
self.assertEqual(
|
|
|
|
iso.get_mkisofs_cmd.call_args_list,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
os.path.abspath(opts.target),
|
|
|
|
None,
|
|
|
|
boot_args=iso.get_boot_options.return_value,
|
|
|
|
exclude=["./lost+found"],
|
|
|
|
graft_points=ANYTHING,
|
|
|
|
input_charset=None,
|
|
|
|
volid=iso.get_volume_id.return_value,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertEqual(copy_all.mock_calls, [mock.call("mounted-iso-dir", ANYTHING)])
|
2017-02-20 09:35:34 +00:00
|
|
|
self.assertEqual(
|
|
|
|
sh.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING),
|
|
|
|
mock.call(log, iso.get_implantisomd5_cmd.return_value),
|
|
|
|
],
|
|
|
|
)
|
2017-02-20 09:35:34 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi_utils.patch_iso.util.copy_all")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.iso")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.sh")
|
2017-02-20 09:35:34 +00:00
|
|
|
def test_run_isohybrid(self, sh, iso, copy_all):
|
2020-01-22 10:02:22 +00:00
|
|
|
iso.mount.return_value.__enter__.return_value = "mounted-iso-dir"
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
def _create_files(src, dest):
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(dest, "dir", "file.txt"), "Hello")
|
2017-02-20 09:35:34 +00:00
|
|
|
copy_fixture(
|
2020-01-22 10:02:22 +00:00
|
|
|
"DP-1.0-20161013.t.4/compose/Server/x86_64/os/.treeinfo",
|
|
|
|
os.path.join(dest, ".treeinfo"),
|
2017-02-20 09:35:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
copy_all.side_effect = _create_files
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
log = mock.Mock(name="logger")
|
2017-02-20 09:35:34 +00:00
|
|
|
opts = mock.Mock(
|
2020-01-22 10:02:22 +00:00
|
|
|
target="test.iso",
|
|
|
|
source="source.iso",
|
2017-02-20 09:35:34 +00:00
|
|
|
force_arch=None,
|
2020-09-15 13:47:25 +00:00
|
|
|
work_dir=None,
|
2019-04-12 13:09:53 +00:00
|
|
|
volume_id=None,
|
2020-01-22 10:02:22 +00:00
|
|
|
dirs=[],
|
2017-02-20 09:35:34 +00:00
|
|
|
)
|
|
|
|
patch_iso.run(log, opts)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(iso.mount.call_args_list, [mock.call("source.iso")])
|
|
|
|
self.assertEqual(
|
|
|
|
iso.get_mkisofs_cmd.call_args_list,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
os.path.abspath(opts.target),
|
|
|
|
None,
|
|
|
|
boot_args=iso.get_boot_options.return_value,
|
|
|
|
exclude=["./lost+found"],
|
|
|
|
graft_points=ANYTHING,
|
|
|
|
input_charset="utf-8",
|
|
|
|
volid=iso.get_volume_id.return_value,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertEqual(copy_all.mock_calls, [mock.call("mounted-iso-dir", ANYTHING)])
|
2017-02-20 09:35:34 +00:00
|
|
|
self.assertEqual(
|
|
|
|
sh.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING),
|
|
|
|
mock.call(log, iso.get_isohybrid_cmd.return_value),
|
|
|
|
mock.call(log, iso.get_implantisomd5_cmd.return_value),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
@mock.patch("pungi_utils.patch_iso.tweak_configs")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.util.copy_all")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.iso")
|
|
|
|
@mock.patch("pungi_utils.patch_iso.sh")
|
2017-02-20 09:35:34 +00:00
|
|
|
def test_add_ks_cfg(self, sh, iso, copy_all, tweak_configs):
|
2020-01-22 10:02:22 +00:00
|
|
|
iso.mount.return_value.__enter__.return_value = "mounted-iso-dir"
|
2017-02-20 09:35:34 +00:00
|
|
|
iso.get_graft_points.return_value = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"ks.cfg": "path/to/ks.cfg",
|
2017-02-20 09:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _create_files(src, dest):
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(dest, "dir", "file.txt"), "Hello")
|
2017-02-20 09:35:34 +00:00
|
|
|
|
|
|
|
copy_all.side_effect = _create_files
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
log = mock.Mock(name="logger")
|
2017-02-20 09:35:34 +00:00
|
|
|
opts = mock.Mock(
|
2020-01-22 10:02:22 +00:00
|
|
|
target="test.iso",
|
|
|
|
source="source.iso",
|
|
|
|
force_arch="s390",
|
2020-09-15 13:47:25 +00:00
|
|
|
work_dir=None,
|
2020-01-22 10:02:22 +00:00
|
|
|
volume_id="foobar",
|
2019-04-12 13:09:53 +00:00
|
|
|
dirs=[],
|
2017-02-20 09:35:34 +00:00
|
|
|
)
|
|
|
|
patch_iso.run(log, opts)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(iso.mount.call_args_list, [mock.call("source.iso")])
|
|
|
|
self.assertEqual(
|
|
|
|
iso.get_mkisofs_cmd.call_args_list,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
os.path.abspath(opts.target),
|
|
|
|
None,
|
|
|
|
boot_args=iso.get_boot_options.return_value,
|
|
|
|
exclude=["./lost+found"],
|
|
|
|
graft_points=ANYTHING,
|
|
|
|
input_charset="utf-8",
|
|
|
|
volid="foobar",
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
tweak_configs.call_args_list,
|
|
|
|
[mock.call(ANYTHING, "foobar", "path/to/ks.cfg", logger=log)],
|
|
|
|
)
|
|
|
|
self.assertEqual(copy_all.mock_calls, [mock.call("mounted-iso-dir", ANYTHING)])
|
2017-02-20 09:35:34 +00:00
|
|
|
self.assertEqual(
|
|
|
|
sh.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(log, iso.get_mkisofs_cmd.return_value, workdir=ANYTHING),
|
|
|
|
mock.call(log, iso.get_implantisomd5_cmd.return_value),
|
|
|
|
],
|
|
|
|
)
|