2016-05-12 11:41:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2024-01-26 07:38:32 +00:00
|
|
|
try:
|
|
|
|
from unittest import mock
|
|
|
|
except ImportError:
|
|
|
|
import mock
|
2016-05-12 11:41:53 +00:00
|
|
|
import os
|
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
from productmd.extra_files import ExtraFiles
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
import six
|
|
|
|
|
2016-05-12 11:41:53 +00:00
|
|
|
from pungi.phases import extra_files
|
|
|
|
from tests import helpers
|
|
|
|
|
|
|
|
|
|
|
|
class TestExtraFilePhase(helpers.PungiTestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.extra_files.copy_extra_files")
|
2016-05-12 11:50:34 +00:00
|
|
|
def test_skips_unless_has_config(self, copy_extra_files):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
compose.just_phases = None
|
|
|
|
compose.skip_phases = []
|
|
|
|
phase = extra_files.ExtraFilesPhase(compose, mock.Mock())
|
|
|
|
self.assertTrue(phase.skip())
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.extra_files.copy_extra_files")
|
2016-05-12 11:41:53 +00:00
|
|
|
def test_runs_copy_files_for_each_variant(self, copy_extra_files):
|
|
|
|
cfg = mock.Mock()
|
|
|
|
pkgset_phase = mock.Mock()
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = helpers.DummyCompose(
|
|
|
|
self.topdir, {"extra_files": [("^.+$", {"x86_64": [cfg]})]}
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
phase = extra_files.ExtraFilesPhase(compose, pkgset_phase)
|
|
|
|
phase.run()
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2016-05-12 11:41:53 +00:00
|
|
|
copy_extra_files.call_args_list,
|
2019-11-01 08:10:34 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
compose,
|
|
|
|
[cfg],
|
|
|
|
"x86_64",
|
|
|
|
compose.variants["Server"],
|
|
|
|
pkgset_phase.package_sets,
|
|
|
|
phase.metadata,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
compose,
|
|
|
|
[cfg],
|
|
|
|
"x86_64",
|
|
|
|
compose.variants["Everything"],
|
|
|
|
pkgset_phase.package_sets,
|
|
|
|
phase.metadata,
|
|
|
|
),
|
|
|
|
],
|
2016-05-12 11:41:53 +00:00
|
|
|
)
|
2019-11-01 08:10:34 +00:00
|
|
|
self.assertTrue(isinstance(phase.metadata, ExtraFiles))
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestCopyFiles(helpers.PungiTestCase):
|
2019-11-01 08:10:34 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(TestCopyFiles, self).setUp()
|
|
|
|
self.metadata = ExtraFiles()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
self.variant = self.compose.variants["Server"]
|
|
|
|
|
2016-05-12 11:41:53 +00:00
|
|
|
def test_copy_local_file(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
tgt = os.path.join(self.topdir, "file")
|
2016-05-12 11:41:53 +00:00
|
|
|
helpers.touch(tgt)
|
2020-01-22 10:02:22 +00:00
|
|
|
cfg = {"scm": "file", "file": tgt, "repo": None}
|
2016-05-12 12:19:14 +00:00
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
extra_files.copy_extra_files(
|
|
|
|
self.compose, [cfg], "x86_64", self.variant, mock.Mock(), self.metadata
|
|
|
|
)
|
2016-05-12 12:19:14 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(
|
|
|
|
os.path.join(self.topdir, "compose", "Server", "x86_64", "os", "file")
|
|
|
|
)
|
|
|
|
)
|
2016-05-12 12:19:14 +00:00
|
|
|
|
|
|
|
def test_copy_multiple_sources(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
tgt1 = os.path.join(self.topdir, "file")
|
|
|
|
tgt2 = os.path.join(self.topdir, "gpl")
|
2016-05-12 12:19:14 +00:00
|
|
|
helpers.touch(tgt1)
|
|
|
|
helpers.touch(tgt2)
|
2020-01-22 10:02:22 +00:00
|
|
|
cfg1 = {"scm": "file", "file": tgt1, "repo": None}
|
|
|
|
cfg2 = {"scm": "file", "file": tgt2, "repo": None, "target": "license"}
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
extra_files.copy_extra_files(
|
|
|
|
self.compose,
|
|
|
|
[cfg1, cfg2],
|
|
|
|
"x86_64",
|
|
|
|
self.variant,
|
|
|
|
mock.Mock(),
|
2020-01-22 10:02:22 +00:00
|
|
|
self.metadata,
|
2019-11-01 08:10:34 +00:00
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(
|
|
|
|
os.path.join(self.topdir, "compose", "Server", "x86_64", "os", "file")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(
|
|
|
|
os.path.join(
|
|
|
|
self.topdir, "compose", "Server", "x86_64", "os", "license", "gpl"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
def test_copy_local_dir(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
helpers.touch(os.path.join(self.topdir, "src", "file"))
|
|
|
|
helpers.touch(os.path.join(self.topdir, "src", "another"))
|
|
|
|
cfg = {
|
|
|
|
"scm": "file",
|
|
|
|
"dir": os.path.join(self.topdir, "src"),
|
|
|
|
"repo": None,
|
|
|
|
"target": "subdir",
|
|
|
|
}
|
2019-11-01 08:10:34 +00:00
|
|
|
extra_files.copy_extra_files(
|
|
|
|
self.compose, [cfg], "x86_64", self.variant, mock.Mock(), self.metadata
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(
|
|
|
|
os.path.join(
|
|
|
|
self.topdir, "compose", "Server", "x86_64", "os", "subdir", "file"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(
|
|
|
|
os.path.join(
|
|
|
|
self.topdir,
|
|
|
|
"compose",
|
|
|
|
"Server",
|
|
|
|
"x86_64",
|
|
|
|
"os",
|
|
|
|
"subdir",
|
|
|
|
"another",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.extra_files.get_file_from_scm")
|
|
|
|
@mock.patch("pungi.phases.extra_files.get_dir_from_scm")
|
2016-05-12 11:41:53 +00:00
|
|
|
def test_copy_from_external_rpm(self, get_dir_from_scm, get_file_from_scm):
|
2020-01-22 10:02:22 +00:00
|
|
|
cfg = {
|
|
|
|
"scm": "rpm",
|
|
|
|
"file": "file.txt",
|
|
|
|
"repo": "http://example.com/package.rpm",
|
|
|
|
}
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
get_file_from_scm.side_effect = self.fake_get_file
|
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
extra_files.copy_extra_files(
|
|
|
|
self.compose, [cfg], "x86_64", self.variant, mock.Mock(), self.metadata
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(get_file_from_scm.call_args_list), 1)
|
|
|
|
self.assertEqual(get_dir_from_scm.call_args_list, [])
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
self.scm_dict,
|
|
|
|
{
|
|
|
|
"scm": "rpm",
|
|
|
|
"file": "file.txt",
|
|
|
|
"repo": "http://example.com/package.rpm",
|
|
|
|
},
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(
|
|
|
|
os.path.join(
|
|
|
|
self.topdir, "compose", "Server", "x86_64", "os", "file.txt"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.phases.extra_files.get_file_from_scm")
|
|
|
|
@mock.patch("pungi.phases.extra_files.get_dir_from_scm")
|
2016-05-12 11:41:53 +00:00
|
|
|
def test_copy_from_rpm_in_compose(self, get_dir_from_scm, get_file_from_scm):
|
2020-01-22 10:02:22 +00:00
|
|
|
cfg = {"scm": "rpm", "file": "file.txt", "repo": "%(variant_uid)s-data*"}
|
2016-05-12 11:41:53 +00:00
|
|
|
server_po, client_po, src_po = mock.Mock(), mock.Mock(), mock.Mock()
|
2020-01-22 10:02:22 +00:00
|
|
|
server_po.configure_mock(
|
|
|
|
name="Server-data-1.1-1.fc24.x86_64.rpm",
|
|
|
|
file_path="/server/location",
|
|
|
|
arch="x86_64",
|
|
|
|
)
|
|
|
|
client_po.configure_mock(
|
|
|
|
name="Client-data-1.1-1.fc24.x86_64.rpm",
|
|
|
|
file_path="/client/location",
|
|
|
|
arch="x86_64",
|
|
|
|
)
|
|
|
|
src_po.configure_mock(
|
|
|
|
name="extra-data-1.1-1.fc24.src.rpm", file_path="/src/location", arch="src"
|
|
|
|
)
|
2019-07-25 08:15:14 +00:00
|
|
|
package_sets = [
|
|
|
|
{
|
|
|
|
"x86_64": {
|
|
|
|
server_po.name: server_po,
|
|
|
|
client_po.name: client_po,
|
|
|
|
src_po.name: src_po,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
get_file_from_scm.side_effect = self.fake_get_file
|
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
extra_files.copy_extra_files(
|
|
|
|
self.compose, [cfg], "x86_64", self.variant, package_sets, self.metadata
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(get_file_from_scm.call_args_list), 1)
|
|
|
|
self.assertEqual(get_dir_from_scm.call_args_list, [])
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
self.scm_dict,
|
|
|
|
{"scm": "rpm", "file": "file.txt", "repo": ["/server/location"]},
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(
|
|
|
|
os.path.join(
|
|
|
|
self.topdir, "compose", "Server", "x86_64", "os", "file.txt"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2019-10-07 10:26:22 +00:00
|
|
|
def fake_get_file(self, scm_dict, dest, compose):
|
2016-05-12 11:41:53 +00:00
|
|
|
self.scm_dict = scm_dict
|
2020-01-22 10:02:22 +00:00
|
|
|
helpers.touch(os.path.join(dest, scm_dict["file"]))
|
|
|
|
return [scm_dict["file"]]
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.extra_files.get_file_from_scm")
|
|
|
|
@mock.patch("pungi.phases.extra_files.get_dir_from_scm")
|
|
|
|
def test_copy_from_non_existing_rpm_in_compose(
|
|
|
|
self, get_dir_from_scm, get_file_from_scm
|
|
|
|
):
|
|
|
|
cfg = {"scm": "rpm", "file": "file.txt", "repo": "bad-%(variant_uid_lower)s*"}
|
2019-07-25 08:15:14 +00:00
|
|
|
package_sets = [{"x86_64": {}}]
|
2016-11-10 08:38:50 +00:00
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
extra_files.copy_extra_files(
|
2019-11-01 08:10:34 +00:00
|
|
|
self.compose, [cfg], "x86_64", self.variant, package_sets, self.metadata
|
|
|
|
)
|
2016-11-10 08:38:50 +00:00
|
|
|
|
2020-07-28 01:23:53 +00:00
|
|
|
self.assertRegex(str(ctx.exception), r"No.*package.*matching bad-server\*.*")
|
2016-11-10 08:38:50 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(get_file_from_scm.call_args_list), 0)
|
|
|
|
self.assertEqual(get_dir_from_scm.call_args_list, [])
|