mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-14 02:29:44 +08:00
Allow the virtual streams of a base module to be queryable in the database and API
This commit is contained in:
@@ -27,7 +27,7 @@ import inspect
|
||||
import hashlib
|
||||
import time
|
||||
from datetime import datetime
|
||||
from six import text_type
|
||||
from six import text_type, string_types
|
||||
|
||||
from module_build_service import conf, log, models, Modulemd, glib
|
||||
from module_build_service.errors import (
|
||||
@@ -347,6 +347,20 @@ def import_mmd(session, mmd, check_buildrequires=True):
|
||||
except (ValueError, KeyError):
|
||||
disttag_marking = None
|
||||
|
||||
try:
|
||||
virtual_streams = mmd.get_xmd()["mbs"]["virtual_streams"]
|
||||
except (ValueError, KeyError):
|
||||
virtual_streams = []
|
||||
|
||||
# Verify that the virtual streams are the correct type
|
||||
if virtual_streams and (
|
||||
not isinstance(virtual_streams, list) or
|
||||
any(not isinstance(vs, string_types) for vs in virtual_streams)
|
||||
):
|
||||
msg = "The virtual streams must be a list of strings"
|
||||
log.error(msg)
|
||||
raise UnprocessableEntity(msg)
|
||||
|
||||
# If it is a base module, then make sure the value that will be used in the RPM disttags
|
||||
# doesn't contain a dash since a dash isn't allowed in the release field of the NVR
|
||||
if name in conf.base_module_names:
|
||||
@@ -426,6 +440,20 @@ def import_mmd(session, mmd, check_buildrequires=True):
|
||||
|
||||
session.add(build)
|
||||
session.commit()
|
||||
|
||||
for virtual_stream in virtual_streams:
|
||||
vs_obj = session.query(models.VirtualStream).filter_by(name=virtual_stream).first()
|
||||
if not vs_obj:
|
||||
vs_obj = models.VirtualStream(name=virtual_stream)
|
||||
session.add(vs_obj)
|
||||
session.commit()
|
||||
|
||||
if vs_obj not in build.virtual_streams:
|
||||
build.virtual_streams.append(vs_obj)
|
||||
session.add(build)
|
||||
|
||||
session.commit()
|
||||
|
||||
msg = "Module {} imported".format(nsvc)
|
||||
log.info(msg)
|
||||
msgs.append(msg)
|
||||
|
||||
@@ -242,29 +242,12 @@ def _get_base_module_mmds(mmd):
|
||||
# Get the list of compatible virtual streams.
|
||||
virtual_streams = xmd["mbs"]["virtual_streams"]
|
||||
|
||||
mmds = resolver.get_module_modulemds(name, stream, stream_version_lte=True)
|
||||
mmds = resolver.get_module_modulemds(
|
||||
name, stream, stream_version_lte=True, virtual_streams=virtual_streams)
|
||||
ret_chunk = []
|
||||
# Add the returned mmds to the `seen` set to avoid querying those individually if
|
||||
# they are part of the buildrequire streams for this base module
|
||||
for mmd_ in mmds:
|
||||
mmd_ns = ":".join([mmd_.get_name(), mmd_.get_stream()])
|
||||
xmd = mmd_.get_xmd()
|
||||
if "mbs" not in xmd.keys() or "virtual_streams" not in xmd["mbs"].keys():
|
||||
# This module does not contain any virtual stream, so it cannot
|
||||
# be compatible with our buildrequired module.
|
||||
continue
|
||||
|
||||
# Check if some virtual stream from buildrequired module exists in
|
||||
# this module. That would mean the modules are compatible.
|
||||
mmd_virtual_streams = xmd["mbs"]["virtual_streams"]
|
||||
for virtual_stream in virtual_streams:
|
||||
if virtual_stream in mmd_virtual_streams:
|
||||
break
|
||||
else:
|
||||
# No stream from `virtual_streams` exist in `mmd_virtual_streams`, so this
|
||||
# module is not compatible with our buildrequired module.
|
||||
continue
|
||||
|
||||
mmd_ns = ":".join([mmd_.get_name(), mmd_.get_stream()])
|
||||
# An extra precaution to ensure there are no duplicates in the event the sorting
|
||||
# above wasn't flawless
|
||||
|
||||
@@ -207,7 +207,8 @@ def filter_module_builds(flask_request):
|
||||
"""
|
||||
search_query = dict()
|
||||
special_columns = set((
|
||||
'time_submitted', 'time_modified', 'time_completed', 'state', 'stream_version_lte',))
|
||||
'time_submitted', 'time_modified', 'time_completed', 'state', 'stream_version_lte',
|
||||
'virtual_stream',))
|
||||
columns = models.ModuleBuild.__table__.columns.keys()
|
||||
for key in set(request.args.keys()) - special_columns:
|
||||
# Only filter on valid database columns but skip columns that are treated specially or
|
||||
@@ -283,6 +284,10 @@ def filter_module_builds(flask_request):
|
||||
elif context == 'before':
|
||||
query = query.filter(column <= item_datetime)
|
||||
|
||||
# Multiple virtual_streams can be supplied for "or" logic filtering
|
||||
virtual_streams = flask_request.args.getlist('virtual_stream')
|
||||
query = models.ModuleBuild._add_virtual_streams_filter(db.session, query, virtual_streams)
|
||||
|
||||
stream_version_lte = flask_request.args.get('stream_version_lte')
|
||||
if stream_version_lte is not None:
|
||||
invalid_error = ('An invalid value of stream_version_lte was provided. It must be an '
|
||||
|
||||
Reference in New Issue
Block a user