mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-02 10:20:31 +08:00
Add 'mbs-manager import_module'.
This commit is contained in:
@@ -34,7 +34,7 @@ from module_build_service import app, conf, db, create_app
|
||||
from module_build_service import models
|
||||
from module_build_service.utils import (
|
||||
submit_module_build_from_yaml,
|
||||
load_local_builds,
|
||||
load_local_builds, load_mmd, import_mmd
|
||||
)
|
||||
import module_build_service.messaging
|
||||
import module_build_service.scheduler.consumer
|
||||
@@ -90,6 +90,15 @@ def cleardb():
|
||||
models.ComponentBuild.query.delete()
|
||||
|
||||
|
||||
@console_script_help
|
||||
@manager.command
|
||||
def import_module(mmd_file):
|
||||
""" Imports the module from mmd_file
|
||||
"""
|
||||
mmd = load_mmd(mmd_file, is_file=True)
|
||||
import_mmd(db.session, mmd)
|
||||
|
||||
|
||||
@manager.option('--stream', action='store', dest="stream")
|
||||
@manager.option('--file', action='store', dest="yaml_file")
|
||||
@manager.option('--skiptests', action='store_true', dest="skiptests")
|
||||
|
||||
@@ -1796,3 +1796,60 @@ def cors_header(allow='*'):
|
||||
return rv
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
|
||||
def import_mmd(session, mmd):
|
||||
"""
|
||||
Imports new module build defined by `mmd` to MBS database using `session`.
|
||||
If it already exists, it is updated.
|
||||
|
||||
The ModuleBuild.koji_tag is set according to xmd['mbs]['koji_tag'].
|
||||
The ModuleBuild.state is set to "ready".
|
||||
The ModuleBuild.rebuild_strategy is set to "all".
|
||||
The ModuleBuild.owner is set to "mbs_import".
|
||||
|
||||
TODO: The "context" is not stored directly in database. We only store
|
||||
build_context and runtime_context and compute context, but when importing
|
||||
the module, we have no idea what build_context or runtime_context is - we only
|
||||
know the resulting "context", but there is no way to store it into do DB.
|
||||
By now, we just ignore mmd.get_context() and use default 00000000 context instead.
|
||||
"""
|
||||
mmd.set_context("00000000")
|
||||
name = mmd.get_name()
|
||||
stream = mmd.get_stream()
|
||||
version = str(mmd.get_version())
|
||||
context = mmd.get_context()
|
||||
|
||||
# NSVC is used for logging purpose later.
|
||||
nsvc = ":".join([name, stream, version, context])
|
||||
|
||||
# Get the koji_tag.
|
||||
xmd = mmd.get_xmd()
|
||||
if "mbs" in xmd.keys() and "koji_tag" in xmd["mbs"].keys():
|
||||
koji_tag = xmd["mbs"]["koji_tag"]
|
||||
else:
|
||||
log.warn("'koji_tag' is not set in xmd['mbs'] for module %s", nsvc)
|
||||
koji_tag = ""
|
||||
|
||||
# Get the ModuleBuild from DB.
|
||||
build = models.ModuleBuild.get_build_from_nsvc(
|
||||
session, name, stream, version, context)
|
||||
if build:
|
||||
log.info("Updating existing module build %s.", nsvc)
|
||||
else:
|
||||
build = models.ModuleBuild()
|
||||
|
||||
build.name = name
|
||||
build.stream = stream
|
||||
build.version = version
|
||||
build.koji_tag = koji_tag
|
||||
build.state = models.BUILD_STATES['ready']
|
||||
build.modulemd = mmd.dumps()
|
||||
build.owner = "mbs_import"
|
||||
build.rebuild_strategy = 'all'
|
||||
build.time_submitted = datetime.utcnow()
|
||||
build.time_modified = datetime.utcnow()
|
||||
build.time_completed = datetime.utcnow()
|
||||
session.add(build)
|
||||
session.commit()
|
||||
log.info("Module %s imported", nsvc)
|
||||
|
||||
@@ -30,7 +30,7 @@ from traceback import extract_stack
|
||||
import koji
|
||||
import module_build_service
|
||||
from module_build_service import db
|
||||
from module_build_service.utils import get_rpm_release
|
||||
from module_build_service.utils import get_rpm_release, import_mmd, load_mmd
|
||||
from module_build_service.config import init_config
|
||||
from module_build_service.models import ModuleBuild, ComponentBuild, make_session, BUILD_STATES
|
||||
from module_build_service import glib, Modulemd
|
||||
@@ -89,21 +89,8 @@ def clean_database(add_platform_module=True):
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
if add_platform_module:
|
||||
platform = ModuleBuild()
|
||||
platform.name = 'platform'
|
||||
platform.stream = 'f28'
|
||||
platform.version = '3'
|
||||
platform.koji_tag = 'module-f28-build'
|
||||
platform.state = BUILD_STATES['ready']
|
||||
with open(os.path.join(base_dir, 'staged_data', 'platform.yaml')) as f:
|
||||
platform.modulemd = f.read()
|
||||
platform.rebuild_strategy = 'all'
|
||||
platform.owner = 'releng'
|
||||
platform.time_submitted = datetime.utcnow()
|
||||
platform.time_modified = datetime.utcnow()
|
||||
platform.time_completed = datetime.utcnow()
|
||||
db.session.add(platform)
|
||||
db.session.commit()
|
||||
mmd = load_mmd(os.path.join(base_dir, 'staged_data', 'platform.yaml'), True)
|
||||
import_mmd(db.session, mmd)
|
||||
|
||||
|
||||
def init_data(data_size=10, contexts=False):
|
||||
|
||||
@@ -23,3 +23,4 @@ data:
|
||||
commit: virtual
|
||||
requires: {}
|
||||
mse: true
|
||||
koji_tag: module-f28-build
|
||||
|
||||
@@ -127,7 +127,7 @@ class TestRepoDone:
|
||||
db.session.commit()
|
||||
module_build_service.scheduler.handlers.repos.done(
|
||||
config=conf, session=db.session, msg=msg)
|
||||
mock_log_info.assert_called_once_with(
|
||||
mock_log_info.assert_called_with(
|
||||
'Ignoring repo regen, because not all components are tagged.')
|
||||
module_build = module_build_service.models.ModuleBuild.query.get(2)
|
||||
# Make sure the module build didn't transition since all the components weren't tagged
|
||||
|
||||
Reference in New Issue
Block a user