def test_search_moludemds(pulp): """Test convenient method for searching modulemds""" repo = YumRepository(id="test_repo_1", ) repo.__dict__["_client"] = pulp.client unit_1 = ModulemdUnit( name="test", stream="10", version=100, context="abcdef", arch="x86_64", ) unit_2 = ModulemdUnit( name="test", stream="20", version=100, context="abcdef", arch="x86_64", ) pulp.insert_repository(repo) pulp.insert_units(repo, [unit_1, unit_2]) matcher = Matcher(None, None) criteria = matcher._create_or_criteria(["name", "stream"], [("test", "10")]) # let Future return result result = matcher.search_modulemds(criteria, [repo]).result() # there should be be only one unit in the result set according to criteria assert len(result) == 1 assert result.pop().nsvca == "test:10:100:abcdef:x86_64"
def test_search_content_by_unit_type(populated_repo): """search_content on unit_type returns only units of that type""" crit = Criteria.with_unit_type(ModulemdUnit) units = list(populated_repo.search_content(crit)) assert sorted(units) == [ ModulemdUnit( unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613", name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64", repository_memberships=["repo1"], ), ModulemdUnit( unit_id="e6f4590b-9a16-4106-cf6a-659eb4862b21", name="module2", stream="s2", version=1234, context="a1b2", arch="x86_64", repository_memberships=["repo1"], ), ]
def populated_repo(controller): units = [ RpmUnit(name="bash", version="4.0", release="1", arch="x86_64"), RpmUnit(content_type_id="srpm", name="bash", version="4.0", release="1", arch="src"), RpmUnit( name="glibc", version="5.0", release="1", arch="x86_64", sourcerpm="glibc-5.0-1.el5_11.1.src.rpm", ), ModulemdUnit(name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64"), ModulemdUnit(name="module2", stream="s2", version=1234, context="a1b2", arch="x86_64"), ErratumUnit(id="RHBA-1234:56", summary="The best advisory"), ] repo = YumRepository(id="repo1") controller.insert_repository(repo) controller.insert_units(repo, units) return controller.client.get_repository(repo.id).result()
def test_keep_n_latest_modules(): """Test keeping only the latest version of modulemd""" unit_1 = UbiUnit( ModulemdUnit(name="test", stream="10", version=100, context="abcd", arch="x86_64"), None, ) unit_2 = UbiUnit( ModulemdUnit(name="test", stream="10", version=101, context="abcd", arch="x86_64"), None, ) matcher = ModularMatcher(None, None) modules = [unit_1, unit_2] matcher._keep_n_latest_modules(modules) # there should only one modulemd assert len(modules) == 1 # with the highest number of version assert modules.pop().version == 101
def test_can_remove_content(): """repo.remove() succeeds and removes expected units inserted via controller.""" controller = FakeController() client = controller.client rpm_units = [ RpmUnit(name="bash", version="4.0", release="1", arch="x86_64"), RpmUnit(name="glibc", version="5.0", release="1", arch="x86_64"), ] modulemd_units = [ ModulemdUnit( name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64" ), ModulemdUnit( name="module1", stream="s1", version=1235, context="a1b2", arch="x86_64" ), ] units = rpm_units + modulemd_units repo = YumRepository(id="repo1") controller.insert_repository(repo) controller.insert_units(repo, units) remove_rpms = client.get_repository("repo1").remove_content(type_ids=["rpm"]) assert len(remove_rpms) == 1 task = remove_rpms[0] # It should have completed successfully assert task.completed assert task.succeeded # It should have removed (only) RPM units assert sorted(task.units) == sorted(rpm_units) # Now if we ask to remove same content again... remove_rpms = client.get_repository("repo1").remove_content(type_ids=["rpm"]) assert len(remove_rpms) == 1 task = remove_rpms[0] # It should have completed successfully, but no RPMs to remove assert task.completed assert task.succeeded assert not task.units # It should still be possible to remove other content remove_all = client.get_repository("repo1").remove_content() assert len(remove_all) == 1 task = remove_all[0] # It should have completed successfully, and removed the modulemds assert task.completed assert task.succeeded assert sorted(task.units) == sorted(modulemd_units)
def test_get_modular_rpms_criteria(ubi_config): """Test creation of criteria for rpms query""" matcher = ModularMatcher(None, ubi_config.modules) unit = UbiUnit( ModulemdUnit( name="test", stream="10", version=100, context="abcd", arch="x86_64", artifacts=[ "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.src", "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.x86_64", ], ), None, ) matcher.modules = f_proxy(f_return(set([unit]))) criteria = matcher._get_modular_rpms_criteria() # there should be 1 criterium created - srpm is skipped assert len(criteria) == 1 # it should be instance of Criteria for crit in criteria: assert isinstance(crit, Criteria)
def test_modular_rpms_filenames_per_profiles_missing_profile(ubi_config): """Test getting filename from module artifacts, request for non-existing profile in modulemd""" matcher = ModularMatcher(None, ubi_config.modules) unit = UbiUnit( ModulemdUnit( name="fake_name", stream="fake_stream", version=100, context="abcd", arch="x86_64", artifacts=[ "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.src", "perl-7:0.99.24-441.module+el8.3.0+6718+7f269185.x86_64", "bash-7:10.5-el6.x86_64", "bash-devel-7:0.99.24-441.module+el8.3.0+6718+7f269185.x86_64", ], profiles={"another": ["bash"]}, ), None, ) modules = f_proxy(f_return(set([unit]))) filenames = matcher._modular_rpms_filenames(modules) # all non-src pkgs are in result # this result is driven by ubi_config that force to use only profile called "test" # but we don't have this profile in the testing modulemd, so we take all non-src artifacts assert len(filenames) == 3 assert filenames == set([ "bash-10.5-el6.x86_64.rpm", "bash-devel-0.99.24-441.module+el8.3.0+6718+7f269185.x86_64.rpm", "perl-0.99.24-441.module+el8.3.0+6718+7f269185.x86_64.rpm", ])
def test_modular_rpms_filenames_per_profiles(ubi_config): """Test getting filename from module artifacts, limited by profiles""" matcher = ModularMatcher(None, ubi_config.modules) unit = UbiUnit( ModulemdUnit( name="fake_name", stream="fake_stream", version=100, context="abcd", arch="x86_64", artifacts=[ "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.src", "perl-7:0.99.24-441.module+el8.3.0+6718+7f269185.x86_64", "bash-7:10.5-el6.x86_64", "bash-devel-7:0.99.24-441.module+el8.3.0+6718+7f269185.x86_64", ], profiles={ "test": ["perl", "bash"], "another": ["bash"] }, ), None, ) modules = f_proxy(f_return(set([unit]))) filenames = matcher._modular_rpms_filenames(modules) # only pkgs from test profile perl+bash should be in result # this result is driven also by ubi_config that force to use only profile called "test" assert len(filenames) == 2 assert filenames == set([ "bash-10.5-el6.x86_64.rpm", "perl-0.99.24-441.module+el8.3.0+6718+7f269185.x86_64.rpm", ])
def test_modular_rpms_filenames(ubi_config): """Test getting filename from module artifacts, srpms are skipped.""" matcher = ModularMatcher(None, ubi_config.modules) unit = UbiUnit( ModulemdUnit( name="test", stream="10", version=100, context="abcd", arch="x86_64", artifacts=[ "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.src", "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.x86_64", ], ), None, ) modules = f_proxy(f_return(set([unit]))) filenames = matcher._modular_rpms_filenames(modules) # there should be only 1 filename because srpms are skipped assert len(filenames) == 1 assert (filenames.pop() == "perl-version-0.99.24-441.module+el8.3.0+6718+7f269185.x86_64.rpm")
def test_search_content_mixed_fields(populated_repo): """search_content crossing multiple fields and types returns matching units""" crit = Criteria.and_( Criteria.with_field_in("content_type_id", ["rpm", "modulemd"]), Criteria.with_field_in("name", ["bash", "module1"]), ) units = list(populated_repo.search_content(crit)) # Note: sorting different types not natively supported, hence sorting by repr assert sorted(units, key=repr) == [ ModulemdUnit( unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613", name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64", repository_memberships=["repo1"], ), RpmUnit( unit_id="e3e70682-c209-4cac-629f-6fbed82c07cd", name="bash", version="4.0", release="1", arch="x86_64", repository_memberships=["repo1"], ), ]
def test_keep_n_latest_modules_different_context(): """Test keeping only the latest version of modulemds with the different context""" unit_1 = UbiUnit( ModulemdUnit(name="test", stream="10", version=100, context="abcd", arch="x86_64"), None, ) unit_2 = UbiUnit( ModulemdUnit(name="test", stream="10", version=100, context="xyz", arch="x86_64"), None, ) unit_3 = UbiUnit( ModulemdUnit(name="test", stream="10", version=99, context="xyz", arch="x86_64"), None, ) matcher = ModularMatcher(None, None) modules = [unit_1, unit_2, unit_3] matcher._keep_n_latest_modules(modules) expected_contexts = ["abcd", "xyz"] # both of modulemd should be in result assert len(modules) == 2 actual_contexts = [] versions = set() for module in modules: actual_contexts.append(module.context) versions.add(module.version) # the should have different contexts assert sorted(actual_contexts) == expected_contexts # but only modules with the highest version are kept assert len(versions) == 1 assert versions.pop() == 100
def test_get_pkgs_from_all_modules(pulp): """tests getting pkgs filenames from all available modulemd units""" repo = YumRepository(id="test_repo_1", ) repo.__dict__["_client"] = pulp.client unit_1 = ModulemdUnit( name="test", stream="10", version=100, context="abcdef", arch="x86_64", artifacts=[ "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.src", "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.x86_64", ], ) unit_2 = ModulemdUnit( name="test", stream="20", version=100, context="abcdef", arch="x86_64", artifacts=[ "perl-version-7:1.99.24-441.module+el8.4.0+9911+7f269185.src", "perl-version-7:1.99.24-441.module+el8.4.0+9911+7f269185.x86_64", ], ) pulp.insert_repository(repo) pulp.insert_units(repo, [unit_1, unit_2]) repos_set = RepoSet(rpm=[repo], debug=[], source=[]) matcher = RpmMatcher(repos_set, None) modular_filenames = matcher._get_pkgs_from_all_modules().result() # there are 4 filenames according from 2 modulemd units expected_filenames = set([ "perl-version-0.99.24-441.module+el8.3.0+6718+7f269185.src.rpm", "perl-version-0.99.24-441.module+el8.3.0+6718+7f269185.x86_64.rpm", "perl-version-1.99.24-441.module+el8.4.0+9911+7f269185.src.rpm", "perl-version-1.99.24-441.module+el8.4.0+9911+7f269185.x86_64.rpm", ]) assert len(modular_filenames) == 4 assert modular_filenames == expected_filenames
def test_modulemd_nsvca(): unit = ModulemdUnit( name="fake_name", stream="fake_stream", version=1234, context="fake_context", arch="fake_arch", ) expected_nsvca = "fake_name:fake_stream:1234:fake_context:fake_arch" assert unit.nsvca == expected_nsvca
def test_get_modulemd_output_set(): """Test creation of modulemd output set for ubipop""" unit_1 = UbiUnit( ModulemdUnit(name="test", stream="10", version=100, context="abcd", arch="x86_64"), None, ) unit_2 = UbiUnit( ModulemdUnit(name="test", stream="10", version=101, context="xyz", arch="x86_64"), None, ) unit_3 = UbiUnit( ModulemdUnit(name="test", stream="20", version=100, context="xyz", arch="x86_64"), None, ) matcher = ModularMatcher(None, None) output_set = matcher._get_modulemd_output_set([unit_1, unit_2, unit_3]) assert isinstance(output_set, list) # In output_set, we should have only the latest version of modulemds # of the same name and stream assert sorted(output_set, key=attrgetter("_unit")) == [unit_2, unit_3]
def test_get_modulemd_defaults_criteria(): """Test proper creation of criteria for modulemd_defaults query""" matcher = ModularMatcher(None, None) unit = UbiUnit( ModulemdUnit(name="test", stream="10", version=100, context="abcd", arch="x86_64"), None, ) matcher.modules = [unit] criteria = matcher._get_modulemd_defaults_criteria() # there should be 1 criterium created based on modules list of Matcher obj. assert len(criteria) == 1 # it should be instance of Criteria for crit in criteria: assert isinstance(crit, Criteria)
def test_modulemd_artifacts_filenames(): unit = ModulemdUnit( name="fake", stream="fake", version=1234, context="fake", arch="fake", artifacts=[ "perl-utils-0:5.30.1-452.module+el8.4.0+8990+01326e37.noarch", "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.src", "perl-version-7:0.99.24-441.module+el8.3.0+6718+7f269185.x86_64", ], ) filenames = unit.artifacts_filenames # expected filenames should have the epoch stripped and added '.rpm' extension expected_filenames = [ "perl-utils-5.30.1-452.module+el8.4.0+8990+01326e37.noarch.rpm", "perl-version-0.99.24-441.module+el8.3.0+6718+7f269185.src.rpm", "perl-version-0.99.24-441.module+el8.3.0+6718+7f269185.x86_64.rpm", ] assert sorted(filenames) == sorted(expected_filenames)
def get_test_values(): default_unit = ModulemdDefaultsUnit( unit_id="md_unit_id", name="md_unit_name", repo_id="md_unit_repo", profiles={"1.0": ["default"]}, ) md_unit = ModulemdUnit( unit_id="unit_id", name="name", stream="1.0", version=1, context="context", arch="x86_64", profiles={ "default": { "description": "Default description", "rpms": ["rpm"], }, }, ) return default_unit, md_unit
def test_get_current_content(mock_ubipop_runner, pulp, skip_debug_repo): """Tests getting current content from ubi repos, using Fake Client from pubtools-pulplib""" rpm_repo = YumRepository( id="rpm_repo", ) rpm_repo.__dict__["_client"] = pulp.client debug_repo = YumRepository( id="debug_repo", ) debug_repo.__dict__["_client"] = pulp.client source_repo = YumRepository( id="source_repo", ) source_repo.__dict__["_client"] = pulp.client binary_rpm = RpmUnit(name="test", version="1.0", release="1", arch="x86_64") modulemd = ModulemdUnit( name="test_module_md", stream="fake-stream", version=1, context="fake-context", arch="x86_64", ) modulemd_defaults = ModulemdDefaultsUnit( name="test_modulemd_defaults", stream="rhel", repo_id="rpm_repo" ) debug_rpm = RpmUnit( name="test-debuginfo", version="1.0", release="1", arch="x86_64" ) source_rpm = RpmUnit( name="test-srpm", version="1.0", release="1", arch="src", content_type_id="srpm" ) pulp.insert_repository(rpm_repo) pulp.insert_units(rpm_repo, [binary_rpm, modulemd, modulemd_defaults]) if not skip_debug_repo: pulp.insert_repository(debug_repo) pulp.insert_units(debug_repo, [debug_rpm]) pulp.insert_repository(source_repo) pulp.insert_units(source_repo, [source_rpm]) if skip_debug_repo: debug_repo = f_return(None) else: debug_repo = f_proxy(f_return(debug_repo)) # overwrite out_repos with the testing ones mock_ubipop_runner.repos.out_repos = RepoSet( f_proxy(f_return(rpm_repo)), f_proxy(f_return(source_repo)), debug_repo ) content = mock_ubipop_runner._get_current_content() binary_rpms = list(content.binary_rpms) assert len(binary_rpms) == 1 assert binary_rpms[0].name == "test" modules = list(content.modules) assert len(modules) == 1 assert modules[0].name == "test_module_md" modulemd_defaults = list(content.modulemd_defaults) assert len(modulemd_defaults) == 1 assert modulemd_defaults[0].name == "test_modulemd_defaults" debug_rpms = list(content.debug_rpms) if skip_debug_repo: assert len(debug_rpms) == 0 else: assert len(debug_rpms) == 1 assert debug_rpms[0].name == "test-debuginfo" source_rpms = list(content.source_rpms) assert len(source_rpms) == 1 assert source_rpms[0].name == "test-srpm"
def test_copy_no_criteria(fast_poller, requests_mocker, client): """Copy succeeds when given no criteria""" src = Repository(id="src-repo") dest = Repository(id="dest-repo") src.__dict__["_client"] = client dest.__dict__["_client"] = client requests_mocker.post( "https://pulp.example.com/pulp/api/v2/repositories/dest-repo/actions/associate/", [{"json": {"spawned_tasks": [{"task_id": "task1"}, {"task_id": "task2"}]}}], ) requests_mocker.post( "https://pulp.example.com/pulp/api/v2/tasks/search/", [ { "json": [ { "task_id": "task1", "state": "finished", "result": { "units_successful": [ { "type_id": "modulemd", "unit_key": { "name": "module", "stream": "s1", "version": 1234, "context": "a1b2c3", "arch": "s390x", }, } ] }, }, {"task_id": "task2", "state": "skipped"}, ] } ], ) # Copy should succeed, and return the tasks with units parsed. assert sorted(client.copy_content(src, dest), key=lambda t: t.id) == [ Task( id="task1", completed=True, succeeded=True, units=[ ModulemdUnit( name="module", stream="s1", version=1234, context="a1b2c3", arch="s390x", content_type_id="modulemd", ) ], units_data=[ { "type_id": "modulemd", "unit_key": { "name": "module", "stream": "s1", "version": 1234, "context": "a1b2c3", "arch": "s390x", }, } ], ), Task(id="task2", completed=True, succeeded=True), ] hist = requests_mocker.request_history # First request should have been the associate. assert ( hist[0].url == "https://pulp.example.com/pulp/api/v2/repositories/dest-repo/actions/associate/" ) # It should have posted for the given source repo, with empty criteria. assert hist[0].json() == {"criteria": {}, "source_repo_id": "src-repo"}
def test_can_upload_units(use_file_object, data_path): """repo.upload_modules() succeeds with fake client and populates units.""" modules_path = os.path.join(data_path, "sample-modules.yaml") controller = FakeController() controller.insert_repository(YumRepository(id="repo1")) client = controller.client repo1 = client.get_repository("repo1").result() to_upload = modules_path if use_file_object: to_upload = open(to_upload, "rb") upload_f = repo1.upload_modules(to_upload) # Upload should complete successfully. tasks = upload_f.result() # At least one task. assert tasks # Every task should have succeeded. for t in tasks: assert t.succeeded # If I now search for content in that repo, or content across all repos... units_in_repo = sorted(repo1.search_content().result(), key=repr) units_all = sorted(client.search_content().result(), key=repr) # They should be equal assert units_all == units_in_repo # And they should be this assert units_in_repo == [ ModulemdDefaultsUnit( unit_id="e3e70682-c209-4cac-629f-6fbed82c07cd", name="ant", repo_id="repo1", # Note, this tests that 1.10 does not get coerced to 1.1, # as happened in some tools previously. stream="1.10", profiles={"1.10": ["default"]}, content_type_id="modulemd_defaults", repository_memberships=["repo1"], ), ModulemdDefaultsUnit( unit_id="d4713d60-c8a7-0639-eb11-67b367a9c378", name="dwm", repo_id="repo1", stream=None, profiles={ "6.0": ["default"], "6.1": ["default"], "6.2": ["default"], "latest": ["default"], }, content_type_id="modulemd_defaults", repository_memberships=["repo1"], ), ModulemdUnit( unit_id="82e2e662-f728-b4fa-4248-5e3a0a5d2f34", name="avocado-vt", stream="82lts", version=3420210902113311, context="035be0ad", arch="x86_64", content_type_id="modulemd", repository_memberships=["repo1"], artifacts=[ "avocado-vt-0:82.0-3.module_f34+12808+b491ffc8.src", "python3-avocado-vt-0:82.0-3.module_f34+12808+b491ffc8.noarch", ], profiles={ "default": { "description": "Common profile installing the avocado-vt plugin.", "rpms": ["python3-avocado-vt"], } }, dependencies=[ModulemdDependency(name="avocado", stream="82lts")], ), ModulemdUnit( unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613", name="dwm", stream="6.0", version=3420210201213909, context="058368ca", arch="x86_64", content_type_id="modulemd", repository_memberships=["repo1"], artifacts=[ "dwm-0:6.0-1.module_f34+11150+aec78cf8.src", "dwm-0:6.0-1.module_f34+11150+aec78cf8.x86_64", "dwm-debuginfo-0:6.0-1.module_f34+11150+aec78cf8.x86_64", "dwm-debugsource-0:6.0-1.module_f34+11150+aec78cf8.x86_64", "dwm-user-0:6.0-1.module_f34+11150+aec78cf8.x86_64", ], profiles={ "default": { "description": "The minimal, distribution-compiled dwm binary.", "rpms": ["dwm"], }, "user": { "description": "Includes distribution-compiled dwm as well as a helper script to apply user patches and configuration, dwm-user.", "rpms": ["dwm", "dwm-user"], }, }, dependencies=[], ), ]
def test_clear_repo_multiple_content_types(command_tester, fake_collector, monkeypatch): """Test clearing a Yum repo given multiple content type values.""" repo = YumRepository(id="some-yumrepo", relative_url="some/publish/url", mutable_urls=["repomd.xml"]) files = [ RpmUnit( name="bash", version="1.23", release="1.test8", arch="x86_64", sha256sum="a" * 64, md5sum="b" * 32, signing_key="aabbcc", ), ModulemdUnit(name="mymod", stream="s1", version=123, context="a1c2", arch="s390x"), ] with FakeClearRepo() as task_instance: task_instance.pulp_client_controller.insert_repository(repo) task_instance.pulp_client_controller.insert_units(repo, files) # It should run with expected output. command_tester.test( task_instance.main, [ "test-clear-repo", "--pulp-url", "https://pulp.example.com/", "--content-type", "rpm", "--content-type", "modulemd", "--content-type", "iso", "some-yumrepo", ], ) # test the new ClearRepo argument handling for --content-type # produces the expected output assert task_instance.args.content_type == ["rpm", "modulemd", "iso"] # It should record that it removed these push items: assert sorted(fake_collector.items, key=lambda pi: pi["filename"]) == [ { "state": "DELETED", "origin": "pulp", "src": None, "dest": None, "filename": "bash-1.23-1.test8.x86_64.rpm", "checksums": { "sha256": "a" * 64 }, "signing_key": None, "build": None, }, { "state": "DELETED", "origin": "pulp", "src": None, "dest": None, "filename": "mymod:s1:123:a1c2:s390x", "checksums": None, "signing_key": None, "build": None, }, ]
def test_remove_filtered_content(): """repo.remove_content() succeeds and removes expected units inserted via controller.""" controller = FakeController() client = controller.client rpm_units = [ RpmUnit(name="bash", version="4.0", release="1", arch="x86_64"), RpmUnit(name="glibc", version="5.0", release="1", arch="x86_64"), ] modulemd_units = [ ModulemdUnit(name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64"), ModulemdUnit(name="module1", stream="s1", version=1235, context="a1b2", arch="x86_64"), ] units = rpm_units + modulemd_units repo = YumRepository(id="repo1") controller.insert_repository(repo) controller.insert_units(repo, units) criteria = Criteria.and_(Criteria.with_unit_type(RpmUnit), Criteria.with_field("name", "bash")) remove_rpms = client.get_repository("repo1").remove_content( criteria=criteria) assert len(remove_rpms) == 1 task = remove_rpms[0] # It should have completed successfully assert task.completed assert task.succeeded # It should have removed the specific rpm assert len(task.units) == 1 assert task.units[0] == sorted(rpm_units)[0] # Try removing a module with incorrect type_ids criteria = Criteria.and_(Criteria.with_unit_type(RpmUnit), Criteria.with_field("name", "module1")) remove_rpms = client.get_repository("repo1").remove_content( criteria=criteria) assert len(remove_rpms) == 1 task = remove_rpms[0] # It should have completed successfully assert task.completed assert task.succeeded # Nothing's removed as criteria isn't fulfilled assert len(task.units) == 0 # Removing module with correct type_ids criteria = Criteria.and_(Criteria.with_unit_type(ModulemdUnit), Criteria.with_field("name", "module1")) remove_rpms = client.get_repository("repo1").remove_content( criteria=criteria) assert len(remove_rpms) == 1 task = remove_rpms[0] # It should have completed successfully assert task.completed assert task.succeeded # It should have removed both the modules as they # match the criteria assert len(task.units) == 2 assert sorted(task.units) == sorted(modulemd_units)
def test_copy_content_all(controller): """copy_content with no criteria copies all units from a repo""" src = YumRepository(id="src-repo") dest = YumRepository(id="dest-repo") other = YumRepository(id="other-repo") controller.insert_repository(src) controller.insert_repository(dest) controller.insert_repository(other) # Set up that both 'src' and 'other' contain some units. # The units in 'other' are there to ensure that copying only # happens from the given source repo and not other repos unexpectedly. src_units = [ ErratumUnit(id="RHSA-1111:22", summary="Fixes bad things"), ModulemdUnit( name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64", repository_memberships=["repoA", "repoB"], ), RpmUnit( name="bash", version="4.0", release="1", arch="x86_64", # Note: the next two fields aren't part of the unit key on RPM units. # We put these here specifically to verify they'll be filtered out # on the copy response (as a real Pulp server does). filename="bash-4.0-1.x86_64.rpm", signing_key="a1b2c3", ), ] controller.insert_units(src, src_units) controller.insert_units( other, [ RpmUnit( name="glibc", version="5.0", release="1", arch="x86_64", sourcerpm="glibc-5.0-1.el5_11.1.src.rpm", ) ], ) client = controller.client # Repos are initially detached, re-fetch them via client src = client.get_repository(src.id).result() dest = client.get_repository(dest.id).result() # It should succeed copy_tasks = list(client.copy_content(src, dest)) # Gather all units apparently copied units = sum([t.units for t in copy_tasks], []) # It should copy just the units we expect, from src. # Note that these are incomplete views of the units, as (just like real pulp) # the fake will only return fields present in the unit_key after a copy. assert sorted(units, key=repr) == [ ErratumUnit(id="RHSA-1111:22"), ModulemdUnit(name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64"), RpmUnit(name="bash", version="4.0", release="1", arch="x86_64", epoch="0"), ] # The copy should also impact subsequent content searches. dest_units = list(dest.search_content()) # The units we get from the search are not *precisely* the same as src_units, # because repository_memberships has been updated. assert sorted(dest_units, key=repr) == [ ErratumUnit( unit_id="e3e70682-c209-4cac-629f-6fbed82c07cd", id="RHSA-1111:22", summary="Fixes bad things", content_type_id="erratum", repository_memberships=["src-repo", "dest-repo"], ), ModulemdUnit( unit_id="82e2e662-f728-b4fa-4248-5e3a0a5d2f34", name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64", content_type_id="modulemd", repository_memberships=["src-repo", "dest-repo", "repoA", "repoB"], ), RpmUnit( unit_id="d4713d60-c8a7-0639-eb11-67b367a9c378", name="bash", version="4.0", release="1", arch="x86_64", epoch="0", signing_key="a1b2c3", filename="bash-4.0-1.x86_64.rpm", content_type_id="rpm", repository_memberships=["src-repo", "dest-repo"], ), ]
def test_delete_rpms(command_tester, fake_collector, monkeypatch): """Deleting RPMs from repos succeeds""" repo1 = YumRepository( id="some-yumrepo", relative_url="some/publish/url", mutable_urls=["repomd.xml"] ) repo2 = YumRepository( id="other-yumrepo", relative_url="other/publish/url", mutable_urls=["repomd.xml"], ) files1 = [ RpmUnit( name="bash", version="1.23", release="1.test8", arch="x86_64", filename="bash-1.23-1.test8_x86_64.rpm", sha256sum="a" * 64, md5sum="b" * 32, signing_key="aabbcc", unit_id="file1_rpm1", ), RpmUnit( name="dash", version="2.25", release="1.test8", arch="x86_64", filename="dash-2.25-1.test8_x86_64.rpm", sha256sum="a" * 64, md5sum="b" * 32, signing_key="aabbcc", unit_id="file1_rpm2", ), ModulemdUnit( name="mymod", stream="s1", version=123, context="a1c2", arch="s390x", unit_id="file1_mod1", ), ] files2 = [ RpmUnit( name="crash", version="3.30", release="1.test8", arch="s390x", filename="crash-3.30-1.test8_s390x.rpm", sha256sum="a" * 64, md5sum="b" * 32, signing_key="aabbcc", unit_id="file2_rpm1", ) ] files3 = [ RpmUnit( name="rash", version="1.30", release="1.test8", arch="noarch", filename="rash-1.30-1.test8_noarch.rpm", sha256sum="a" * 64, md5sum="b" * 32, signing_key="aabbcc", unit_id="file3_rpm1", ) ] undeleted = [ RpmUnit( name="exist", version="1.34", release="1.test8", arch="noarch", filename="exist-1.34-1.test8_noarch.rpm", sha256sum="a" * 64, md5sum="b" * 32, signing_key="aabbcc", unit_id="undeleted_rpm1", ) ] files1.extend(files3) files1.extend(undeleted) files2.extend(files3) with FakeDeletePackages() as task_instance: task_instance.pulp_client_controller.insert_repository(repo1) task_instance.pulp_client_controller.insert_repository(repo2) task_instance.pulp_client_controller.insert_units(repo1, files1) task_instance.pulp_client_controller.insert_units(repo2, files2) # Let's try setting the cache flush root via env. monkeypatch.setenv("FASTPURGE_ROOT_URL", "https://cdn.example2.com/") # It should run with expected output. command_tester.test( task_instance.main, [ "test-delete", "--pulp-url", "https://pulp.example.com/", "--fastpurge-host", "fakehost-xxx.example.net", "--fastpurge-client-secret", "abcdef", "--fastpurge-client-token", "efg", "--fastpurge-access-token", "tok", "--repo", "some-yumrepo,other-yumrepo", "--repo", "some-other-repo", "--file", "bash-1.23-1.test8_x86_64.rpm", "--file", "dash-2.25-1.test8_x86_64.rpm,crash-3.30-1.test8_s390x.rpm", "--file", "trash-1.0-1.test8_noarch.rpm,rash-1.30-1.test8_noarch.rpm", "--signing-key", "aabbcc", ], ) # It should record that it removed these push items: assert sorted(fake_collector.items, key=lambda pi: pi["filename"]) == [ { "origin": "pulp", "src": None, "dest": "some-yumrepo", "signing_key": None, "filename": "bash-1.23-1.test8.x86_64.rpm", "state": "DELETED", "build": None, "checksums": {"sha256": "a" * 64}, }, { "origin": "pulp", "src": None, "dest": "other-yumrepo", "signing_key": None, "filename": "crash-3.30-1.test8.s390x.rpm", "state": "DELETED", "build": None, "checksums": {"sha256": "a" * 64}, }, { "origin": "pulp", "src": None, "dest": "some-yumrepo", "signing_key": None, "filename": "dash-2.25-1.test8.x86_64.rpm", "state": "DELETED", "build": None, "checksums": {"sha256": "a" * 64}, }, { "origin": "pulp", "src": None, "dest": "other-yumrepo", "signing_key": None, "filename": "rash-1.30-1.test8.noarch.rpm", "state": "DELETED", "build": None, "checksums": {"sha256": "a" * 64}, }, { "origin": "pulp", "src": None, "dest": "some-yumrepo", "signing_key": None, "filename": "rash-1.30-1.test8.noarch.rpm", "state": "DELETED", "build": None, "checksums": {"sha256": "a" * 64}, }, ] # verify whether files were deleted on Pulp client = task_instance.pulp_client # get the repo where the files were deleted repos = sorted( list( client.search_repository( Criteria.with_id(["some-yumrepo", "other-yumrepo"]) ).result() ), key=lambda r: r.id, ) assert len(repos) == 2 r2, r1 = repos assert r1.id == repo1.id assert r2.id == repo2.id # criteria with the unit_ids # critera1 for files1 in repo1 unit_ids = [] for f in files1: unit_ids.append(f.unit_id) criteria1 = Criteria.with_field("unit_id", Matcher.in_(unit_ids)) # critera2 for files2 in repo2 unit_ids = [] for f in files2: unit_ids.append(f.unit_id) criteria2 = Criteria.with_field("unit_id", Matcher.in_(unit_ids)) # files are not in the repo1 except undeleted rpm and module result1 = sorted( list(r1.search_content(criteria1).result()), key=lambda v: v.unit_id ) assert len(result1) == 2 # modulemd in files1 assert result1[0].unit_id == files1[2].unit_id # undeleted file assert result1[1].unit_id == undeleted[0].unit_id # files are not in repo2 result2 = list(r2.search_content(criteria1).result()) assert len(result2) == 0 # All the files exist on Pulp files_search = list( client.search_content(Criteria.or_(criteria1, criteria2)).result() ) assert len(files_search) == 6
def test_delete_modules(command_tester, fake_collector, monkeypatch): """Deleting modules and it's artifacts from repos succeeds""" repo = YumRepository( id="some-yumrepo", relative_url="some/publish/url", mutable_urls=["repomd.xml"] ) files = [ RpmUnit( name="bash", version="1.23", release="1.test8", arch="x86_64", filename="bash-1.23-1.test8_x86_64.rpm", sha256sum="a" * 64, md5sum="b" * 32, signing_key="aabbcc", provides=[], requires=[], unit_id="rpm1", ), RpmUnit( name="dash", version="1.23", release="1.test8", arch="x86_64", filename="dash-1.23-1.test8_x86_64.rpm", sha256sum="a" * 64, md5sum="b" * 32, signing_key="aabbcc", provides=[], requires=[], unit_id="rpm2", ), ModulemdUnit( name="mymod", stream="s1", version=123, context="a1c2", arch="s390x", artifacts=["bash-0:1.23-1.test8_x86_64", "dash-0:1.23-1.test8_x86_64"], unit_id="module1", ), ] with FakeDeletePackages() as task_instance: task_instance.pulp_client_controller.insert_repository(repo) task_instance.pulp_client_controller.insert_units(repo, files) # Let's try setting the cache flush root via env. monkeypatch.setenv("FASTPURGE_ROOT_URL", "https://cdn.example2.com/") # It should run with expected output. command_tester.test( task_instance.main, [ "test-delete", "--pulp-url", "https://pulp.example.com/", "--fastpurge-host", "fakehost-xxx.example.net", "--fastpurge-client-secret", "abcdef", "--fastpurge-client-token", "efg", "--fastpurge-access-token", "tok", "--repo", "some-yumrepo", "--file", "mymod:s1:123:a1c2:s390x", "--signing-key", "aabbcc", ], ) assert sorted(fake_collector.items, key=lambda pi: pi["filename"]) == [ { "origin": "pulp", "src": None, "state": "DELETED", "build": None, "dest": "some-yumrepo", "checksums": {"sha256": "a" * 64}, "signing_key": None, "filename": "bash-1.23-1.test8.x86_64.rpm", }, { "origin": "pulp", "src": None, "state": "DELETED", "build": None, "dest": "some-yumrepo", "checksums": {"sha256": "a" * 64}, "signing_key": None, "filename": "dash-1.23-1.test8.x86_64.rpm", }, { "origin": "pulp", "src": None, "state": "DELETED", "build": None, "dest": "some-yumrepo", "checksums": None, "signing_key": None, "filename": "mymod:s1:123:a1c2:s390x", }, ] # verify whether files were deleted on Pulp client = task_instance.pulp_client # get the repo where the files were deleted repos = list( client.search_repository(Criteria.with_id("some-yumrepo")).result() ) assert len(repos) == 1 repo = repos[0] # criteria with the unit_ids unit_ids = [] for f in files: unit_ids.append(f.unit_id) criteria = Criteria.with_field("unit_id", Matcher.in_(unit_ids)) # deleted files are not in the repo files = list(repo.search_content(criteria).result()) assert len(files) == 0 # same files exist on Pulp as orphans files_search = list(client.search_content(criteria).result()) assert len(files_search) == 3
def populated_units(controller): units1 = [ RpmUnit( name="bash", version="4.0", release="1", arch="x86_64", repository_memberships=["repo1"], ), RpmUnit( content_type_id="srpm", name="bash", version="4.0", release="1", arch="src", repository_memberships=["repo1"], ), RpmUnit( name="glibc", version="5.0", release="1", arch="x86_64", repository_memberships=["repo1"], ), ModulemdUnit( name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64", repository_memberships=["repo1"], ), ModulemdUnit( name="module2", stream="s2", version=1234, context="a1b2", arch="x86_64", repository_memberships=["repo1"], ), ModulemdDefaultsUnit( name="module1", repo_id="repo1", repository_memberships=["repo1"] ), ] units2 = [ RpmUnit( name="glic", version="2.3.4", release="1", arch="x86_64", repository_memberships=["repo2"], ), RpmUnit( content_type_id="srpm", name="gnu-efi", version="3.0c", release="1", arch="src", repository_memberships=["repo2"], ), ] repo1 = YumRepository(id="repo1") repo2 = YumRepository(id="repo2") controller.insert_repository(repo1) controller.insert_units(repo1, units1) controller.insert_units(repo2, units2)