2016-05-03 14:31:20 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
2016-05-25 11:39:02 +00:00
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
2016-05-03 14:31:20 +00:00
|
|
|
|
2016-06-06 08:29:40 +00:00
|
|
|
import mock
|
2016-05-03 14:31:20 +00:00
|
|
|
import os
|
2019-10-04 12:45:03 +00:00
|
|
|
import six
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
import pungi.phases.test as test_phase
|
2017-07-27 09:59:03 +00:00
|
|
|
from tests.helpers import DummyCompose, PungiTestCase, touch, mk_boom
|
2016-05-03 14:31:20 +00:00
|
|
|
|
2019-08-13 12:15:35 +00:00
|
|
|
try:
|
2020-02-06 02:21:54 +00:00
|
|
|
import dnf # noqa: F401
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2019-08-13 12:15:35 +00:00
|
|
|
HAS_DNF = True
|
|
|
|
except ImportError:
|
|
|
|
HAS_DNF = False
|
|
|
|
|
|
|
|
try:
|
2020-02-06 02:21:54 +00:00
|
|
|
import yum # noqa: F401
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2019-08-13 12:15:35 +00:00
|
|
|
HAS_YUM = True
|
|
|
|
except ImportError:
|
|
|
|
HAS_YUM = False
|
|
|
|
|
2016-05-03 14:31:20 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
PAD = b"\0" * 100
|
|
|
|
UNBOOTABLE_ISO = (b"\0" * 0x8001) + b"CD001" + PAD
|
|
|
|
ISO_WITH_MBR = (b"\0" * 0x1FE) + b"\x55\xAA" + (b"\0" * 0x7E01) + b"CD001" + PAD
|
|
|
|
ISO_WITH_GPT = (b"\0" * 0x200) + b"EFI PART" + (b"\0" * 0x7DF9) + b"CD001" + PAD
|
|
|
|
ISO_WITH_MBR_AND_GPT = (
|
|
|
|
(b"\0" * 0x1FE) + b"\x55\xAAEFI PART" + (b"\0" * 0x7DF9) + b"CD001" + PAD
|
|
|
|
)
|
|
|
|
ISO_WITH_TORITO = (
|
|
|
|
(b"\0" * 0x8001)
|
|
|
|
+ b"CD001"
|
|
|
|
+ (b"\0" * 0x7FA)
|
|
|
|
+ b"\0CD001\1EL TORITO SPECIFICATION"
|
|
|
|
+ PAD
|
|
|
|
)
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestCheckImageSanity(PungiTestCase):
|
|
|
|
def test_missing_file_reports_error(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
|
|
|
|
|
|
|
with self.assertRaises(IOError):
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
|
|
|
def test_missing_file_doesnt_report_if_failable(self):
|
2016-06-24 07:44:40 +00:00
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.deliverable = "iso"
|
2016-06-24 07:44:40 +00:00
|
|
|
compose.image.can_fail = True
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Failable deliverable must not raise")
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
def test_correct_iso_does_not_raise(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2016-05-03 14:31:20 +00:00
|
|
|
compose.image.bootable = False
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(self.topdir, "compose", compose.image.path), UNBOOTABLE_ISO)
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Correct unbootable image must not raise")
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
def test_incorrect_iso_raises(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2016-05-03 14:31:20 +00:00
|
|
|
compose.image.bootable = False
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(self.topdir, "compose", compose.image.path), "Hey there")
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn("does not look like an ISO file", str(ctx.exception))
|
2016-05-03 14:31:20 +00:00
|
|
|
|
2016-08-10 11:02:56 +00:00
|
|
|
def test_bootable_iso_without_mbr_or_gpt_raises_on_x86_64(self):
|
2016-05-03 14:31:20 +00:00
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.arch = "x86_64"
|
|
|
|
compose.image.format = "iso"
|
2016-05-03 14:31:20 +00:00
|
|
|
compose.image.bootable = True
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(self.topdir, "compose", compose.image.path), UNBOOTABLE_ISO)
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn(
|
|
|
|
"is supposed to be bootable, but does not have MBR nor GPT",
|
|
|
|
str(ctx.exception),
|
|
|
|
)
|
2016-05-03 14:31:20 +00:00
|
|
|
|
2016-08-10 11:02:56 +00:00
|
|
|
def test_bootable_iso_without_mbr_or_gpt_doesnt_raise_on_arm(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.arch = "armhfp"
|
|
|
|
compose.image.format = "iso"
|
2016-08-10 11:02:56 +00:00
|
|
|
compose.image.bootable = True
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(self.topdir, "compose", compose.image.path), UNBOOTABLE_ISO)
|
2016-08-10 11:02:56 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Failable deliverable must not raise")
|
2016-08-10 11:02:56 +00:00
|
|
|
|
2016-05-03 14:31:20 +00:00
|
|
|
def test_failable_bootable_iso_without_mbr_gpt_doesnt_raise(self):
|
2016-06-24 07:44:40 +00:00
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2016-05-03 14:31:20 +00:00
|
|
|
compose.image.bootable = True
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.deliverable = "iso"
|
2016-06-24 07:44:40 +00:00
|
|
|
compose.image.can_fail = True
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(self.topdir, "compose", compose.image.path), UNBOOTABLE_ISO)
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Failable deliverable must not raise")
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
def test_bootable_iso_with_mbr_does_not_raise(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2016-05-03 14:31:20 +00:00
|
|
|
compose.image.bootable = True
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(self.topdir, "compose", compose.image.path), ISO_WITH_MBR)
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Bootable image with MBR must not raise")
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
def test_bootable_iso_with_gpt_does_not_raise(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2016-05-03 14:31:20 +00:00
|
|
|
compose.image.bootable = True
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(self.topdir, "compose", compose.image.path), ISO_WITH_GPT)
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Bootable image with GPT must not raise")
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
def test_bootable_iso_with_mbr_and_gpt_does_not_raise(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2016-05-03 14:31:20 +00:00
|
|
|
compose.image.bootable = True
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(
|
|
|
|
os.path.join(self.topdir, "compose", compose.image.path),
|
|
|
|
ISO_WITH_MBR_AND_GPT,
|
|
|
|
)
|
2016-05-03 14:31:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Bootable image with MBR and GPT must not raise")
|
2016-05-03 14:31:20 +00:00
|
|
|
|
2016-07-22 11:58:29 +00:00
|
|
|
def test_bootable_iso_with_el_torito_does_not_raise(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2016-07-22 11:58:29 +00:00
|
|
|
compose.image.bootable = True
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(os.path.join(self.topdir, "compose", compose.image.path), ISO_WITH_TORITO)
|
2016-07-22 11:58:29 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Bootable image with El Torito must not raise")
|
2016-07-22 11:58:29 +00:00
|
|
|
|
2016-06-06 08:29:40 +00:00
|
|
|
def test_checks_with_optional_variant(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.variants["Server"].variants = {
|
|
|
|
"optional": mock.Mock(
|
|
|
|
uid="Server-optional",
|
|
|
|
arches=["x86_64"],
|
|
|
|
type="optional",
|
|
|
|
is_empty=False,
|
|
|
|
)
|
2016-06-06 08:29:40 +00:00
|
|
|
}
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2016-06-06 08:29:40 +00:00
|
|
|
compose.image.bootable = True
|
2020-01-22 10:02:22 +00:00
|
|
|
touch(
|
|
|
|
os.path.join(self.topdir, "compose", compose.image.path),
|
|
|
|
ISO_WITH_MBR_AND_GPT,
|
|
|
|
)
|
2016-06-06 08:29:40 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
image = mock.Mock(
|
|
|
|
path="Server/i386/optional/iso/image.iso", format="iso", bootable=False
|
|
|
|
)
|
|
|
|
compose.im.images["Server-optional"] = {"i386": [image]}
|
2016-06-06 08:29:40 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
test_phase.check_image_sanity(compose)
|
2017-01-26 08:44:45 +00:00
|
|
|
except Exception:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.fail("Checking optional variant must not raise")
|
2016-06-06 08:29:40 +00:00
|
|
|
|
2019-02-12 11:09:08 +00:00
|
|
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
|
|
|
def test_too_big_iso(self):
|
|
|
|
compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 10})]})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2019-02-12 11:09:08 +00:00
|
|
|
compose.image.bootable = False
|
|
|
|
compose.image.size = 20
|
|
|
|
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
|
|
|
warnings = [call[0][0] for call in compose.log_warning.call_args_list]
|
|
|
|
self.assertIn(
|
|
|
|
"ISO Client/i386/iso/image.iso is too big. Expected max 10B, got 20B",
|
|
|
|
warnings,
|
|
|
|
)
|
|
|
|
|
2019-07-15 07:25:26 +00:00
|
|
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
|
|
|
def test_too_big_iso_strict(self):
|
|
|
|
compose = DummyCompose(
|
|
|
|
self.topdir,
|
|
|
|
{
|
|
|
|
"createiso_max_size": [(".*", {"*": 10})],
|
|
|
|
"createiso_max_size_is_strict": [(".*", {"*": True})],
|
|
|
|
},
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2019-07-15 07:25:26 +00:00
|
|
|
compose.image.bootable = False
|
|
|
|
compose.image.size = 20
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
str(ctx.exception),
|
|
|
|
"ISO Client/i386/iso/image.iso is too big. Expected max 10B, got 20B",
|
|
|
|
)
|
|
|
|
|
2019-07-16 06:22:28 +00:00
|
|
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
|
|
|
def test_too_big_iso_not_strict(self):
|
|
|
|
compose = DummyCompose(
|
|
|
|
self.topdir,
|
|
|
|
{
|
|
|
|
"createiso_max_size": [(".*", {"*": 10})],
|
|
|
|
"createiso_max_size_is_strict": [(".*", {"*": False})],
|
|
|
|
},
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2019-07-16 06:22:28 +00:00
|
|
|
compose.image.bootable = False
|
|
|
|
compose.image.size = 20
|
|
|
|
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
|
|
|
warnings = [call[0][0] for call in compose.log_warning.call_args_list]
|
|
|
|
self.assertIn(
|
|
|
|
"ISO Client/i386/iso/image.iso is too big. Expected max 10B, got 20B",
|
|
|
|
warnings,
|
|
|
|
)
|
|
|
|
|
2019-02-12 11:09:08 +00:00
|
|
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
|
|
|
def test_too_big_unified(self):
|
|
|
|
compose = DummyCompose(self.topdir, {})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2019-02-12 11:09:08 +00:00
|
|
|
compose.image.bootable = False
|
|
|
|
compose.image.size = 20
|
|
|
|
compose.image.unified = True
|
|
|
|
setattr(compose.image, "_max_size", 10)
|
|
|
|
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
|
|
|
warnings = [call[0][0] for call in compose.log_warning.call_args_list]
|
|
|
|
self.assertIn(
|
|
|
|
"ISO Client/i386/iso/image.iso is too big. Expected max 10B, got 20B",
|
|
|
|
warnings,
|
|
|
|
)
|
|
|
|
|
2019-07-15 07:25:26 +00:00
|
|
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
|
|
|
def test_too_big_unified_strict(self):
|
|
|
|
compose = DummyCompose(
|
2020-01-22 10:02:22 +00:00
|
|
|
self.topdir, {"createiso_max_size_is_strict": [(".*", {"*": True})]},
|
2019-07-15 07:25:26 +00:00
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2019-07-15 07:25:26 +00:00
|
|
|
compose.image.bootable = False
|
|
|
|
compose.image.size = 20
|
|
|
|
compose.image.unified = True
|
|
|
|
setattr(compose.image, "_max_size", 10)
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
str(ctx.exception),
|
|
|
|
"ISO Client/i386/iso/image.iso is too big. Expected max 10B, got 20B",
|
|
|
|
)
|
|
|
|
|
2019-02-12 11:09:08 +00:00
|
|
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
|
|
|
def test_fits_in_limit(self):
|
|
|
|
compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 20})]})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "iso"
|
2019-02-12 11:09:08 +00:00
|
|
|
compose.image.bootable = False
|
|
|
|
compose.image.size = 5
|
|
|
|
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
|
|
|
self.assertEqual(compose.log_warning.call_args_list, [])
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.test.check_sanity", new=mock.Mock())
|
|
|
|
def test_non_iso(self):
|
|
|
|
compose = DummyCompose(self.topdir, {"createiso_max_size": [(".*", {"*": 10})]})
|
2020-01-22 10:02:22 +00:00
|
|
|
compose.image.format = "qcow2"
|
2019-02-12 11:09:08 +00:00
|
|
|
compose.image.bootable = False
|
|
|
|
compose.image.size = 20
|
|
|
|
|
|
|
|
test_phase.check_image_sanity(compose)
|
|
|
|
|
|
|
|
self.assertEqual(compose.log_warning.call_args_list, [])
|
|
|
|
|
2016-05-03 14:31:20 +00:00
|
|
|
|
2017-01-26 08:44:45 +00:00
|
|
|
class TestRepoclosure(PungiTestCase):
|
2017-07-27 09:59:03 +00:00
|
|
|
def setUp(self):
|
|
|
|
super(TestRepoclosure, self).setUp()
|
|
|
|
self.maxDiff = None
|
|
|
|
|
2019-08-05 07:44:38 +00:00
|
|
|
def _get_repo(self, compose_id, variant, arch, path=None):
|
2020-01-22 10:02:22 +00:00
|
|
|
path = path or arch + "/os"
|
2017-01-26 08:44:45 +00:00
|
|
|
return {
|
2020-01-22 10:02:22 +00:00
|
|
|
"%s-repoclosure-%s.%s" % (compose_id, variant, arch): self.topdir
|
|
|
|
+ "/compose/%s/%s" % (variant, path)
|
2017-01-26 08:44:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd")
|
|
|
|
@mock.patch("pungi.phases.test.run")
|
2017-07-27 09:59:03 +00:00
|
|
|
def test_repoclosure_skip_if_disabled(self, mock_run, mock_grc):
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = DummyCompose(
|
|
|
|
self.topdir, {"repoclosure_strictness": [("^.*$", {"*": "off"})]}
|
|
|
|
)
|
2017-07-27 09:59:03 +00:00
|
|
|
test_phase.run_repoclosure(compose)
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
self.assertEqual(mock_grc.call_args_list, [])
|
2017-07-27 09:59:03 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@unittest.skipUnless(HAS_YUM, "YUM is not available")
|
|
|
|
@mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd")
|
|
|
|
@mock.patch("pungi.phases.test.run")
|
2017-01-26 08:19:12 +00:00
|
|
|
def test_repoclosure_default_backend(self, mock_run, mock_grc):
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("six.PY2", new=True):
|
2017-12-04 11:30:18 +00:00
|
|
|
compose = DummyCompose(self.topdir, {})
|
|
|
|
|
2017-01-26 08:44:45 +00:00
|
|
|
test_phase.run_repoclosure(compose)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2017-01-26 08:44:45 +00:00
|
|
|
mock_grc.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
backend="yum",
|
|
|
|
arch=["amd64", "x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Everything", "amd64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="yum",
|
|
|
|
arch=["amd64", "x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Client", "amd64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="yum",
|
|
|
|
arch=["amd64", "x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Server", "amd64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="yum",
|
|
|
|
arch=["x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Server", "x86_64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="yum",
|
|
|
|
arch=["x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Everything", "x86_64"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
@unittest.skipUnless(HAS_DNF, "DNF is not available")
|
|
|
|
@mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd")
|
|
|
|
@mock.patch("pungi.phases.test.run")
|
2017-01-26 08:19:12 +00:00
|
|
|
def test_repoclosure_dnf_backend(self, mock_run, mock_grc):
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = DummyCompose(self.topdir, {"repoclosure_backend": "dnf"})
|
2017-01-26 08:19:12 +00:00
|
|
|
test_phase.run_repoclosure(compose)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2017-01-26 08:19:12 +00:00
|
|
|
mock_grc.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
backend="dnf",
|
|
|
|
arch=["amd64", "x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Everything", "amd64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="dnf",
|
|
|
|
arch=["amd64", "x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Client", "amd64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="dnf",
|
|
|
|
arch=["amd64", "x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Server", "amd64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="dnf",
|
|
|
|
arch=["x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Server", "x86_64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="dnf",
|
|
|
|
arch=["x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Everything", "x86_64"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2017-01-26 08:44:45 +00:00
|
|
|
|
2018-10-22 12:14:53 +00:00
|
|
|
@mock.patch("glob.glob")
|
2019-12-02 09:06:25 +00:00
|
|
|
@mock.patch("pungi.wrappers.repoclosure.extract_from_fus_logs")
|
2018-10-22 12:14:53 +00:00
|
|
|
@mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd")
|
|
|
|
@mock.patch("pungi.phases.test.run")
|
|
|
|
def test_repoclosure_hybrid_variant(self, mock_run, mock_grc, effl, glob):
|
|
|
|
compose = DummyCompose(
|
|
|
|
self.topdir, {"repoclosure_backend": "dnf", "gather_method": "hybrid"}
|
|
|
|
)
|
|
|
|
f = mock.Mock()
|
|
|
|
glob.return_value = [f]
|
|
|
|
|
|
|
|
def _log(a, v):
|
|
|
|
return compose.paths.log.log_file(a, "repoclosure-%s" % compose.variants[v])
|
|
|
|
|
|
|
|
test_phase.run_repoclosure(compose)
|
|
|
|
|
|
|
|
self.assertEqual(mock_grc.call_args_list, [])
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2018-10-22 12:14:53 +00:00
|
|
|
effl.call_args_list,
|
|
|
|
[
|
2019-12-02 09:06:25 +00:00
|
|
|
mock.call([f], _log("amd64", "Everything")),
|
|
|
|
mock.call([f], _log("amd64", "Client")),
|
|
|
|
mock.call([f], _log("amd64", "Server")),
|
|
|
|
mock.call([f], _log("x86_64", "Server")),
|
|
|
|
mock.call([f], _log("x86_64", "Everything")),
|
2020-01-22 10:02:22 +00:00
|
|
|
],
|
2018-10-22 12:14:53 +00:00
|
|
|
)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd")
|
|
|
|
@mock.patch("pungi.phases.test.run")
|
2017-07-27 09:59:03 +00:00
|
|
|
def test_repoclosure_report_error(self, mock_run, mock_grc):
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = DummyCompose(
|
|
|
|
self.topdir, {"repoclosure_strictness": [("^.*$", {"*": "fatal"})]}
|
|
|
|
)
|
2017-07-27 09:59:03 +00:00
|
|
|
mock_run.side_effect = mk_boom(cls=RuntimeError)
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
|
|
test_phase.run_repoclosure(compose)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@unittest.skipUnless(HAS_DNF, "DNF is not available")
|
|
|
|
@mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd")
|
|
|
|
@mock.patch("pungi.phases.test.run")
|
|
|
|
def test_repoclosure_overwrite_options_creates_correct_commands(
|
|
|
|
self, mock_run, mock_grc
|
|
|
|
):
|
|
|
|
compose = DummyCompose(
|
|
|
|
self.topdir,
|
|
|
|
{
|
|
|
|
"repoclosure_backend": "dnf",
|
|
|
|
"repoclosure_strictness": [
|
|
|
|
("^.*$", {"*": "off"}),
|
|
|
|
("^Server$", {"*": "fatal"}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
)
|
2017-07-27 09:59:03 +00:00
|
|
|
test_phase.run_repoclosure(compose)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2017-07-27 09:59:03 +00:00
|
|
|
mock_grc.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
backend="dnf",
|
|
|
|
arch=["amd64", "x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Server", "amd64"),
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
backend="dnf",
|
|
|
|
arch=["x86_64", "noarch"],
|
|
|
|
lookaside={},
|
|
|
|
repos=self._get_repo(compose.compose_id, "Server", "x86_64"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
@mock.patch("pungi.phases.test._delete_repoclosure_cache_dirs")
|
|
|
|
@mock.patch("pungi.wrappers.repoclosure.get_repoclosure_cmd")
|
|
|
|
@mock.patch("pungi.phases.test.run")
|
2019-08-23 02:23:44 +00:00
|
|
|
def test_repoclosure_uses_correct_behaviour(self, mock_run, mock_grc, mock_del):
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = DummyCompose(
|
|
|
|
self.topdir,
|
|
|
|
{
|
|
|
|
"repoclosure_backend": "dnf",
|
|
|
|
"repoclosure_strictness": [
|
|
|
|
("^.*$", {"*": "off"}),
|
|
|
|
("^Server$", {"*": "fatal"}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
)
|
2017-07-27 09:59:03 +00:00
|
|
|
mock_run.side_effect = mk_boom(cls=RuntimeError)
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
|
|
test_phase.run_repoclosure(compose)
|