diff --git a/atomic_reactor/utils/cachi2.py b/atomic_reactor/utils/cachi2.py index cc6f2c540..0191f3599 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"} @@ -36,10 +40,18 @@ 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 + # 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..b8db18f30 100644 --- a/tests/utils/test_cachi2.py +++ b/tests/utils/test_cachi2.py @@ -22,6 +22,16 @@ {"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( + {}, + {"flags": [], "packages": [{"path": ".", "type": "gomod"}]}, + id="pkg_manager_missing", + ), pytest.param( {"pkg_managers": ["gomod"], "packages": {"gomod": [{"path": "operator"}]}}, {"flags": [], "packages": [{"path": "operator", "type": "gomod"}]},