mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-01 18:01:40 +08:00
Allow passing --platform-id (-p) to build_module_locally.
Currently, the PLATFORM_ID is parsed from the `/etc/os-release`. This is good default value, but sometimes you want to build module locally against the different platform stream. For example building on platform:f29 against the platform:f30 modules. In that case, we need to be able to override the host PLATFORM_ID and set it manually chosen value.
This commit is contained in:
@@ -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 = {}
|
||||
|
||||
@@ -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.")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user