From 030e69a7d7ccd62ed7a67e1f6cf6e9690c22fc71 Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Thu, 31 Oct 2024 14:50:31 +0100 Subject: [PATCH 1/2] cachi2: replace rubygems with bundler Rubygems pkg_manager is named bundler in cachi, name must be converted. STONEBLD-2919 Signed-off-by: Martin Basti --- atomic_reactor/utils/cachi2.py | 7 +++++++ tests/utils/test_cachi2.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/atomic_reactor/utils/cachi2.py b/atomic_reactor/utils/cachi2.py index cc6f2c540..d9e1ee444 100644 --- a/atomic_reactor/utils/cachi2.py +++ b/atomic_reactor/utils/cachi2.py @@ -28,6 +28,10 @@ def remote_source_to_cachi2(remote_source: Dict[str, Any]) -> Dict[str, Any]: * git-submodule """ + pkg_managers_map = { + "rubygems": "bundler" # renamed in cachi2 + } + removed_flags = {"include-git-dir", "remove-unsafe-symlinks"} removed_pkg_managers = {"git-submodule"} @@ -40,6 +44,9 @@ def remote_source_to_cachi2(remote_source: Dict[str, Any]) -> Dict[str, Any]: if pkg_manager in removed_pkg_managers: continue + # if pkg manager has different name in cachi2 update it + pkg_manager = pkg_managers_map.get(pkg_manager, pkg_manager) + packages = remote_source.get("packages", {}).get(pkg_manager, []) packages = packages or [{"path": "."}] for pkg in packages: diff --git a/tests/utils/test_cachi2.py b/tests/utils/test_cachi2.py index 363db0df8..25e0e99d6 100644 --- a/tests/utils/test_cachi2.py +++ b/tests/utils/test_cachi2.py @@ -22,6 +22,11 @@ {"flags": [], "packages": [{"path": ".", "type": "gomod"}]}, id="pkg_manager_plain", ), + pytest.param( + {"pkg_managers": ["rubygems"]}, + {"flags": [], "packages": [{"path": ".", "type": "bundler"}]}, + id="pkg_rubygems_to_bundler", + ), pytest.param( {"pkg_managers": ["gomod"], "packages": {"gomod": [{"path": "operator"}]}}, {"flags": [], "packages": [{"path": "operator", "type": "gomod"}]}, From f95ba9b50161fc52e449c04595f1e6be09a286e0 Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Thu, 31 Oct 2024 14:54:29 +0100 Subject: [PATCH 2/2] cachi2: support empty pkg_manager Empty package manager (not defined) should deafult to gomod, to keep compatibility in behavior with Cachito STONEBLD-2921 Signed-off-by: Martin Basti --- atomic_reactor/utils/cachi2.py | 7 ++++++- tests/utils/test_cachi2.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/atomic_reactor/utils/cachi2.py b/atomic_reactor/utils/cachi2.py index d9e1ee444..0191f3599 100644 --- a/atomic_reactor/utils/cachi2.py +++ b/atomic_reactor/utils/cachi2.py @@ -40,7 +40,12 @@ def remote_source_to_cachi2(remote_source: Dict[str, Any]) -> Dict[str, Any]: ) cachi2_packages = [] - for pkg_manager in remote_source["pkg_managers"]: + pkg_managers = remote_source.get("pkg_managers") + if pkg_managers is None: + # Cachito behavior, missing pkg_managers means to use gomod + pkg_managers = ["gomod"] + + for pkg_manager in pkg_managers: if pkg_manager in removed_pkg_managers: continue diff --git a/tests/utils/test_cachi2.py b/tests/utils/test_cachi2.py index 25e0e99d6..b8db18f30 100644 --- a/tests/utils/test_cachi2.py +++ b/tests/utils/test_cachi2.py @@ -27,6 +27,11 @@ {"flags": [], "packages": [{"path": ".", "type": "bundler"}]}, id="pkg_rubygems_to_bundler", ), + pytest.param( + {}, + {"flags": [], "packages": [{"path": ".", "type": "gomod"}]}, + id="pkg_manager_missing", + ), pytest.param( {"pkg_managers": ["gomod"], "packages": {"gomod": [{"path": "operator"}]}}, {"flags": [], "packages": [{"path": "operator", "type": "gomod"}]},