diff --git a/src/pubtools/_pulp/tasks/copy_repo.py b/src/pubtools/_pulp/tasks/copy_repo.py index 4e9e7f5e..fadf175c 100644 --- a/src/pubtools/_pulp/tasks/copy_repo.py +++ b/src/pubtools/_pulp/tasks/copy_repo.py @@ -260,7 +260,13 @@ def repo_copy(copy_tasks, repo): tasks = list(chain.from_iterable(copy_tasks)) return RepoCopy(tasks=tasks, repo=repo) - for src_repo, dest_repo in sorted(repo_pairs): + def repo_pair_comparator(repo_pair): + # comapres the repo pairs of differnt types to sort them + # e.g. comapre FileRepository to YumRepository repo pair + src, dest = repo_pair + return (src.type, src.id, dest.id) + + for src_repo, dest_repo in sorted(repo_pairs, key=repo_pair_comparator): one_pair_copies = [] tasks_f = f_return() for item in criteria or [None]: diff --git a/tests/copy_repo/test_copy_repo.py b/tests/copy_repo/test_copy_repo.py index f3588d1a..2f336cd8 100644 --- a/tests/copy_repo/test_copy_repo.py +++ b/tests/copy_repo/test_copy_repo.py @@ -139,7 +139,7 @@ def test_copy_invalid_content_type(command_tester, fake_collector): assert not fake_collector.items -def test_copy_file_repo(command_tester, fake_collector): +def test_copy_repo(command_tester, fake_collector): """Copying a repo with file content succeeds.""" repoA = FileRepository( @@ -154,18 +154,47 @@ def test_copy_file_repo(command_tester, fake_collector): relative_url="another/publish/url", mutable_urls=["mutable1", "mutable2"], ) + repoC = YumRepository( + id="some-yumrepo", + eng_product_id=789, + relative_url="some/publish/url", + mutable_urls=["repomd.xml"], + ) + repoD = YumRepository( + id="another-yumrepo", + eng_product_id=890, + relative_url="another/publish/url", + mutable_urls=["repomd.xml"], + ) - files = [ + files1 = [ FileUnit(path="hello.txt", size=123, sha256sum="a" * 64), FileUnit(path="with/subdir.json", size=0, sha256sum="b" * 64), ] + files2 = [ + 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 FakeCopyRepo() as task_instance: fakepulp = task_instance.pulp_client_controller fakepulp.insert_repository(repoA) fakepulp.insert_repository(repoB) + fakepulp.insert_repository(repoC) + fakepulp.insert_repository(repoD) # Populate source repository. - fakepulp.insert_units(repoA, files) + fakepulp.insert_units(repoA, files1) + fakepulp.insert_units(repoC, files2) # It should run with expected output. command_tester.test( @@ -178,11 +207,22 @@ def test_copy_file_repo(command_tester, fake_collector): "--udcache-url", "https://ud.example.com/", "some-filerepo,another-filerepo", + "some-yumrepo,another-yumrepo", ], ) # It should record that it copied these push items: assert sorted(fake_collector.items, key=lambda pi: pi["filename"]) == [ + { + "build": None, + "checksums": {"sha256": "a" * 64}, + "dest": "another-yumrepo", + "filename": "bash-1.23-1.test8.x86_64.rpm", + "origin": "pulp", + "signing_key": None, + "src": None, + "state": "PUSHED", + }, { "state": "PUSHED", "origin": "pulp", @@ -193,6 +233,16 @@ def test_copy_file_repo(command_tester, fake_collector): "build": None, "signing_key": None, }, + { + "build": None, + "checksums": None, + "dest": "another-yumrepo", + "filename": "mymod:s1:123:a1c2:s390x", + "origin": "pulp", + "signing_key": None, + "src": None, + "state": "PUSHED", + }, { "state": "PUSHED", "origin": "pulp", @@ -208,13 +258,15 @@ def test_copy_file_repo(command_tester, fake_collector): # It should have published the copied Pulp repo assert [hist.repository.id for hist in fakepulp.publish_history] == [ "another-filerepo", + "another-yumrepo", ] # It should have flushed the copied UD object assert task_instance.udcache_client.flushed_repos == [ "another-filerepo", + "another-yumrepo", ] - assert task_instance.udcache_client.flushed_products == [456] + assert task_instance.udcache_client.flushed_products == [456, 890] def test_copy_file_skip_publish(command_tester): diff --git a/tests/logs/copy_repo/test_copy_repo/test_copy_file_repo.jsonl b/tests/logs/copy_repo/test_copy_repo/test_copy_repo.jsonl similarity index 100% rename from tests/logs/copy_repo/test_copy_repo/test_copy_file_repo.jsonl rename to tests/logs/copy_repo/test_copy_repo/test_copy_repo.jsonl diff --git a/tests/logs/copy_repo/test_copy_repo/test_copy_file_repo.txt b/tests/logs/copy_repo/test_copy_repo/test_copy_repo.txt similarity index 80% rename from tests/logs/copy_repo/test_copy_repo/test_copy_file_repo.txt rename to tests/logs/copy_repo/test_copy_repo/test_copy_repo.txt index 4d658b59..ae2620c2 100644 --- a/tests/logs/copy_repo/test_copy_repo/test_copy_file_repo.txt +++ b/tests/logs/copy_repo/test_copy_repo/test_copy_repo.txt @@ -2,6 +2,7 @@ [ INFO] Check repos: finished [ INFO] Copy content: started [ INFO] another-filerepo: copied 2 iso(s), tasks: e3e70682-c209-4cac-629f-6fbed82c07cd +[ INFO] another-yumrepo: copied 1 modulemd(s), 1 rpm(s), tasks: 82e2e662-f728-b4fa-4248-5e3a0a5d2f34 [ INFO] Copy content: finished [ INFO] Record push items: started [ INFO] Record push items: finished