diff --git a/module_build_service/manage.py b/module_build_service/manage.py index b69dac50..3faa77d1 100755 --- a/module_build_service/manage.py +++ b/module_build_service/manage.py @@ -110,9 +110,11 @@ def import_module(mmd_file): @manager.option('-s', '--set-stream', action='append', default=[], dest='default_streams') @manager.option('-r', '--platform-repo-file', action='append', default=[], dest='platform_repofiles') +@manager.option('-p', '--platform-id', action='store', default=None, + dest='platform_id') def build_module_locally(local_build_nsvs=None, yaml_file=None, srpms=None, stream=None, skiptests=False, default_streams=None, - offline=False, platform_repofiles=None): + offline=False, platform_repofiles=None, platform_id=None): """ Performs local module build using Mock """ if 'SERVER_NAME' not in app.config or not app.config['SERVER_NAME']: @@ -139,7 +141,7 @@ def build_module_locally(local_build_nsvs=None, yaml_file=None, srpms=None, db.create_all() if offline: - import_builds_from_local_dnf_repos() + import_builds_from_local_dnf_repos(platform_id) load_local_builds(local_build_nsvs) params = {} diff --git a/module_build_service/utils/general.py b/module_build_service/utils/general.py index ef01fc98..cbddb92a 100644 --- a/module_build_service/utils/general.py +++ b/module_build_service/utils/general.py @@ -485,12 +485,15 @@ def get_local_releasever(): return dnf_base.conf.releasever -def import_builds_from_local_dnf_repos(): +def import_builds_from_local_dnf_repos(platform_id=None): """ Imports the module builds from all available local repositories to MBS DB. This is used when building modules locally without any access to MBS infra. This method also generates and imports the base module according to /etc/os-release. + + :param str platform_id: The `name:stream` of a fake platform module to generate in this + method. When not set, the /etc/os-release is parsed to get the PLATFORM_ID. """ # Import DNF here to not force it as a hard MBS dependency. import dnf @@ -517,13 +520,13 @@ def import_builds_from_local_dnf_repos(): import_mmd(session, mmd) - # Parse the /etc/os-release to find out the local platform:stream. - platform_id = None - with open("/etc/os-release", "r") as fd: - for l in fd.readlines(): - if not l.startswith("PLATFORM_ID"): - continue - platform_id = l.split("=")[1].strip("\"' \n") + if not platform_id: + # Parse the /etc/os-release to find out the local platform:stream. + with open("/etc/os-release", "r") as fd: + for l in fd.readlines(): + if not l.startswith("PLATFORM_ID"): + continue + platform_id = l.split("=")[1].strip("\"' \n") if not platform_id: raise ValueError("Cannot get PLATFORM_ID from /etc/os-release.") diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index 620d7dea..4dfd61ad 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -1342,3 +1342,11 @@ class TestOfflineLocalBuilds: module_build = models.ModuleBuild.get_build_from_nsvc( db.session, "platform", "x", 1, "000000") assert module_build + + def test_import_builds_from_local_dnf_repos_platform_id(self): + with patch("dnf.Base"): + module_build_service.utils.import_builds_from_local_dnf_repos(platform_id="platform:y") + + module_build = models.ModuleBuild.get_build_from_nsvc( + db.session, "platform", "y", 1, "000000") + assert module_build