From d53734c142edf6c0dbda8bd085e0967d799cd9c2 Mon Sep 17 00:00:00 2001 From: Brian Herring Date: Wed, 20 Mar 2019 13:27:34 -0400 Subject: [PATCH] Updating CopyModulesTestCase to include latest dependency test Documentation added from #4371 highlighted that using the `--recursive` option, the latest RPM dependencies should be copied to he B repo. Ticket #4543 updates tests with the inclusion of logic from #4371. Additional cases where `walrus-0.71` RPM is already on B included. Through multiple permutations of `module_defaults` and `modulemd` with `override_config`, copying the walrus module will copy the correct streams of the walrus module and dependent RPMs from A to B. See: - https://pulp.plan.io/issues/4371 - https://pulp.plan.io/issues/4543 closes #4364 --- pulp_2_tests/constants.py | 1 + .../tests/rpm/api_v2/test_modularity.py | 231 +++++++++++++----- 2 files changed, 171 insertions(+), 61 deletions(-) diff --git a/pulp_2_tests/constants.py b/pulp_2_tests/constants.py index 6d544fe..2653717 100644 --- a/pulp_2_tests/constants.py +++ b/pulp_2_tests/constants.py @@ -181,6 +181,7 @@ 'new_stream': '5.21', 'rpm_count': 4, 'total_available_units': 5, + 'module_defaults': 3, }) """The name and the stream of the package listed in `modules.yaml`_. diff --git a/pulp_2_tests/tests/rpm/api_v2/test_modularity.py b/pulp_2_tests/tests/rpm/api_v2/test_modularity.py index be18fec..4751f45 100644 --- a/pulp_2_tests/tests/rpm/api_v2/test_modularity.py +++ b/pulp_2_tests/tests/rpm/api_v2/test_modularity.py @@ -24,6 +24,7 @@ RPM_UNSIGNED_FEED_URL, RPM_WITH_MODULES_FEED_URL, RPM_WITH_MODULES_SHA1_FEED_URL, + RPM_WITH_OLD_VERSION_URL, ) from pulp_2_tests.tests.rpm.api_v2.utils import ( gen_distributor, @@ -36,17 +37,6 @@ gen_yum_config_file, os_support_modularity, ) -from pulp_2_tests.tests.rpm.utils import set_up_module - - -def setUpModule(): # pylint:disable=invalid-name - """Possibly skip the tests in this module. - - Skip tests if `Pulp #4405 `_ affects us. - """ - set_up_module() - if check_issue_4405(config.get_config()): - raise unittest.SkipTest('https://pulp.plan.io/issues/4405') class ManageModularContentTestCase(unittest.TestCase): @@ -156,32 +146,171 @@ def remove_module_from_repo(self, repo, criteria): return self.client.get(repo['_href'], params={'details': True}) -class CopyModulesTestCase(unittest.TestCase): - """Test copy of modules, and its artifacts. +class CopyModularDefaultsTestCase(unittest.TestCase): + """Test ``recursive`` and ``recursive_conservative`` flags during copy. - This test targets the following issue: + This test targets the following issues: - `Pulp Smash #1122 `_ + * `Pulp Smash #1122 `_ + * `Pulp #4543 `_ + + Recursive or conservative copy of ``modulemd_defaults`` + should always only copy: + + * 3 modules: ``duck``, ``kangaroo``, ``walrus`` + + Exercise the use of ``recursive and ``recursive_conservative``. """ @classmethod def setUpClass(cls): """Create class wide variables.""" cls.cfg = config.get_config() - if cls.cfg.pulp_version < Version('2.17'): - raise unittest.SkipTest('This test requires Pulp 2.17 or newer.') + if cls.cfg.pulp_version < Version('2.19'): + raise unittest.SkipTest('This test requires Pulp 2.19 or newer.') + if check_issue_4405(cls.cfg): + raise unittest.SkipTest('https://pulp.plan.io/issues/4405') cls.client = api.Client(cls.cfg, api.json_handler) - def test_copy_modulemd_recur(self): - """Test copy of modulemd in RPM repository in recursive mode.""" + def test_copy_modulemd_defaults(self): + """Test copy of modulemd_defaults in RPM repository.""" + repo = self.copy_units(False, False) + self.check_module_total_units(repo) + + def test_copy_modulemd_defaults_recursive(self): + """Test copy of modulemd_defaults in RPM repository.""" + repo = self.copy_units(True, False) + self.check_module_total_units(repo) + + def test_copy_modulemd_defaults_conservative(self): + """Test copy of modulemd_defaults in RPM repository.""" + repo = self.copy_units(False, True) + self.check_module_total_units(repo) + + def test_copy_modulemd_defaults_recursive_conservative(self): + """Test copy of modulemd_defaults in RPM repository.""" + repo = self.copy_units(True, True) + self.check_module_total_units(repo) + + def check_module_total_units(self, repo): + """Test copy of modulemd_defaults in RPM repository.""" + self.assertEqual( + repo['content_unit_counts']['modulemd_defaults'], + MODULE_FIXTURES_PACKAGE_STREAM['module_defaults'], + repo['content_unit_counts'] + ) + self.assertEqual( + repo['total_repository_units'], + MODULE_FIXTURES_PACKAGE_STREAM['module_defaults'], + repo['total_repository_units'] + ) + self.assertNotIn('rpm', repo['content_unit_counts']) + + def copy_units(self, recursive, recursive_conservative, old_dependency=False): + """Create two repositories and copy content between them.""" criteria = { - 'filters': {'unit': { - 'name': MODULE_FIXTURES_PACKAGE_STREAM['name'], - 'stream': MODULE_FIXTURES_PACKAGE_STREAM['stream'] - }}, - 'type_ids': ['modulemd'], + 'filters': {}, + 'type_ids': ['modulemd_defaults'], } - repo = self.copy_units(True, criteria) + repos = [] + body = gen_repo( + importer_config={'feed': RPM_WITH_MODULES_FEED_URL}, + distributors=[gen_distributor()] + ) + repos.append(self.client.post(REPOSITORY_PATH, body)) + self.addCleanup(self.client.delete, repos[0]['_href']) + sync_repo(self.cfg, repos[0]) + repos.append(self.client.post(REPOSITORY_PATH, gen_repo())) + self.addCleanup(self.client.delete, repos[1]['_href']) + # Add `old_dependency` for OLD RPM on B + if old_dependency: + rpm = utils.http_get(RPM_WITH_OLD_VERSION_URL) + upload_import_unit( + self.cfg, + rpm, + {'unit_type_id': 'rpm'}, repos[1] + ) + units = search_units(self.cfg, repos[1], {'type_ids': ['rpm']}) + self.assertEqual(len(units), 1, units) + + self.client.post(urljoin(repos[1]['_href'], 'actions/associate/'), { + 'source_repo_id': repos[0]['id'], + 'override_config': { + 'recursive': recursive, + 'recursive_conservative': recursive_conservative, + }, + 'criteria': criteria + }) + return self.client.get(repos[1]['_href'], params={'details': True}) + + +class CopyModulesTestCase(unittest.TestCase): + """Test copy of modules, and its artifacts. + + This test targets the following issues: + + * `Pulp Smash #1122 `_ + * `Pulp #4543 `_ + + Modules and RPM packages used in this test case are the + following. + + Modules:: + + [walrus-0.71] + └── walrus-0.71 + [walrus-5.21] + └── walrus-5.21 + + Dependent RPMs of the provided RPM from ``walrus-0.71``:: + + walrus-0.71 + └── whale + ├── shark + └── stork + + The RPM ``walrus-5.21`` has no dependencies. + + Exercise the use of ``recursive`` and ``recursive_conservative``. + """ + + @classmethod + def setUpClass(cls): + """Create class wide variables.""" + cls.cfg = config.get_config() + if cls.cfg.pulp_version < Version('2.19'): + raise unittest.SkipTest('This test requires Pulp 2.19 or newer.') + if check_issue_4405(cls.cfg): + raise unittest.SkipTest('https://pulp.plan.io/issues/4405') + cls.client = api.Client(cls.cfg, api.json_handler) + + def test_copy_modulemd_recursive_nonconservative(self): + """Test modular copy using override_config and old RPMs.""" + repo = self.copy_units(True, False) + self.check_module_rpm_total_units(repo) + + def test_copy_modulemd_recursive_nonconservative_dependency(self): + """Test modular copy using override_config and old RPMs.""" + repo = self.copy_units(True, False, True) + self.check_module_rpm_total_units(repo) + + def test_copy_modulemd_recursive_conservative(self): + """Test modular copy using override_config and old RPMs.""" + repo = self.copy_units(True, True) + self.check_module_rpm_total_units(repo) + + def test_copy_modulemd_nonrecursive_conservative_dependency(self): + """Test modular copy using override_config and old RPMs.""" + repo = self.copy_units(False, True, True) + self.check_module_rpm_total_units(repo) + + def test_copy_modulemd_recursive_conservative_depenency(self): + """Test modular copy using override_config and old RPMs.""" + repo = self.copy_units(True, True, True) + self.check_module_rpm_total_units(repo) + + def check_module_rpm_total_units(self, repo): + """Test copy of modulemd in RPM repository.""" self.assertEqual(repo['content_unit_counts']['modulemd'], 1) self.assertEqual( repo['content_unit_counts']['rpm'], @@ -194,8 +323,8 @@ def test_copy_modulemd_recur(self): repo['total_repository_units'] ) - def test_copy_modulemd_non_recur(self): - """Test copy of modulemd in RPM repository in non recursive mode.""" + def copy_units(self, recursive, recursive_conservative, old_dependency=False): + """Create two repositories and copy content between them.""" criteria = { 'filters': {'unit': { 'name': MODULE_FIXTURES_PACKAGE_STREAM['name'], @@ -203,39 +332,6 @@ def test_copy_modulemd_non_recur(self): }}, 'type_ids': ['modulemd'], } - repo = self.copy_units(False, criteria) - self.assertEqual( - repo['content_unit_counts']['modulemd'], - 1, - repo['content_unit_counts']['modulemd'] - ) - self.assertEqual( - repo['total_repository_units'], - 1, - repo['total_repository_units'] - ) - self.assertNotIn('rpm', repo['content_unit_counts']) - - def test_copy_modulemd_defaults(self): - """Test copy of modulemd_defaults in RPM repository.""" - criteria = { - 'filters': {}, - 'type_ids': ['modulemd_defaults'], - } - repo = self.copy_units(True, criteria) - self.assertEqual( - repo['content_unit_counts']['modulemd_defaults'], - 3, - repo['content_unit_counts']) - self.assertEqual( - repo['total_repository_units'], - 3, - repo['total_repository_units'] - ) - self.assertNotIn('rpm', repo['content_unit_counts']) - - def copy_units(self, recursive, criteria): - """Create two repositories and copy content between them.""" repos = [] body = gen_repo( importer_config={'feed': RPM_WITH_MODULES_FEED_URL}, @@ -246,10 +342,23 @@ def copy_units(self, recursive, criteria): sync_repo(self.cfg, repos[0]) repos.append(self.client.post(REPOSITORY_PATH, gen_repo())) self.addCleanup(self.client.delete, repos[1]['_href']) + # Add `old_dependency` for OLD RPM on B + if old_dependency: + rpm = utils.http_get(RPM_WITH_OLD_VERSION_URL) + upload_import_unit( + self.cfg, + rpm, + {'unit_type_id': 'rpm'}, repos[1] + ) + units = search_units(self.cfg, repos[1], {'type_ids': ['rpm']}) + self.assertEqual(len(units), 1, units) self.client.post(urljoin(repos[1]['_href'], 'actions/associate/'), { 'source_repo_id': repos[0]['id'], - 'override_config': {'recursive': recursive}, + 'override_config': { + 'recursive': recursive, + 'recursive_conservative': recursive_conservative, + }, 'criteria': criteria }) return self.client.get(repos[1]['_href'], params={'details': True})