94 Commits

Author SHA1 Message Date
Chenxiong Qi
f24cd4222f Make db_session singleton
Please note that this patch does not change the use of database session
in MBS. So, in the frontend, the database session is still managed by
Flask-SQLAlchemy, that is the db.session. And the backend, running event
handlers, has its own database session created from SQLAclehmy session
API directly.

This patch aims to reduce the number of scoped_session created when call
original function make_db_session. For technical detailed information,
please refer to SQLAlchemy documentation Contextual/Thread-local
Sessions.

As a result, a global scoped_session is accessible from the
code running inside backend, both the event handlers and functions
called from handlers. The library code shared by frontend and backend,
like resolvers, has no change.

Similarly, db.session is only used to recreate database for every test.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-11-07 11:06:40 +08:00
Valerij Maljulin
689d949a48 buildonly support
This fixes #1307

Signed-off-by: Valerij Maljulin <vmaljuli@redhat.com>
2019-10-03 16:20:04 +02:00
mprahl
8c6cfb702d Use small license headers in the Python files
This also removes the outdated comments around authorship of each
file. If there is still interest in this information, one can just
look at the git history.
2019-10-03 08:47:24 -04:00
mprahl
f60b292c9c Use double quotes instead of single quotes to match the style guide 2019-10-02 07:42:20 -04:00
Jan Kaluza
fc39df9487 Store the build_context without base modules in a database.
For KojiResolver, we need to be able to find out the module to reuse
components from based only on the non-base-module buildrequires. The
base module buildrequirement will be defined by the Koji tag inheritance.

For this, we need to store build_context computed without the base
modules.
2019-10-02 07:16:55 +02:00
Mike McLean
bbb1d4bb5b Use utc date for compare and correct operator 2019-09-18 20:21:14 +00:00
Mike McLean
fafff9f5d0 use date comparison rather than datetime 2019-09-18 20:21:14 +00:00
Chenxiong Qi
c36bd7ebac Name component builds by states
This patch attemps to make code shorter and easier to read by naming
component builds for different states.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-09-16 15:29:21 +08:00
Chenxiong Qi
c54c3a288b Do not ignore building components to reset state when submit an existing module build
koji.BUILD_STATE["BUILDING"] equals to 0. So, checking if
component.state is None explicitly to avoid ignoring the components
which are in building state.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-09-11 09:55:10 +08:00
mprahl
f3db9a0ac2 Fix a typo in an error message 2019-08-22 17:15:55 -04:00
Jan Kaluža
13a18d1d5a Merge #1384 Add "scratch_build_only_branches" configuration options. 2019-08-21 11:18:34 +00:00
Jan Kaluza
80fca557af Do not check Greenwave gating status for scratch builds.
Scratch builds cannot be gated. They stay in the `done` state forever.
Therefore it is useless to query Greenwave for its status in the Poller.
2019-08-21 13:17:04 +02:00
Chenxiong Qi
dbced8668b Do not compare with a empty list
An empty list [] is evaluated as a false value. So, it is not necessary
to compare like "if some_var == []:".

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-08-15 17:48:33 +08:00
Jan Kaluza
796a367457 Add "scratch_build_only_branches" configuration options.
The goal here is to define certain branches from which only scratch
module builds can be submitted. The main use case is for "private-*"
branches which can be created and maintained by anyone, but there
must not be production-ready module build created from them.

This commit adds new `scratch_build_only_branches` config option
to define the list of regexes to match such branches.
2019-08-15 10:49:03 +02:00
mprahl
a6bf9f88dd Allow components to be reused from module builds even if the buildrequires commit hashes changed for the changed-and-after rebuild strategy
This behavior was not documented, and it was confusing to users since module builds
in a stream should always have a compatible API.
2019-08-05 09:23:44 -04:00
Chenxiong Qi
0d6a26b71e Make fetch_mmd public
fetch_mmd was imported at other places like in views.py for
ImportModuleAPI. So, make it public.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-07-19 09:29:05 +08:00
Chenxiong Qi
f5717e3469 Fix incorrect error message and method call on ComponentRpm
When resubmitting a module build, if some component is found out that
its attributes have changed, MBS will raise an error to stop the work to
recording components. The problem is original code tells a module build
exists in database already rather than a component build, meanwhile
get_module_name() call on an ComponentRpm object is also incorrect.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-07-18 22:09:45 +08:00
Chenxiong Qi
3878affa41 Separate use of database sessions
This patch separates the use of database session in different MBS components
and do not mix them together.

In general, MBS components could be separated as the REST API (implemented
based on Flask) and non-REST API including the backend build workflow
(implemented as a fedmsg consumer on top of fedmsg-hub and running
independently) and library shared by them. As a result, there are two kind of
database session used in MBS, one is created and managed by Flask-SQLAlchemy,
and another one is created from SQLAclhemy Session API directly. The goal of
this patch is to make ensure session object is used properly in the right
place.

All the changes follow these rules:

* REST API related code uses the session object db.session created and
  managed by Flask-SQLAlchemy.
* Non-REST API related code uses the session object created with SQLAlchemy
  Session API. Function make_db_session does that.
* Shared code does not created a new session object as much as possible.
  Instead, it accepts an argument db_session.

The first two rules are applicable to tests as well.

Major changes:

* Switch tests back to run with a file-based SQLite database.
* make_session is renamed to make_db_session and SQLAlchemy connection pool
  options are applied for PostgreSQL backend.
* Frontend Flask related code uses db.session
* Shared code by REST API and backend build workflow accepts SQLAlchemy session
  object as an argument. For example, resolver class is constructed with a
  database session, and some functions accepts an argument for database session.
* Build workflow related code use session object returned from make_db_session
  and ensure db.session is not used.
* Only tests for views use db.session, and other tests use db_session fixture
  to access database.
* All argument name session, that is for database access, are renamed to
  db_session.
* Functions model_tests_init_data, reuse_component_init_data and
  reuse_shared_userspace_init_data, which creates fixture data for
  tests, are converted into pytest fixtures from original function
  called inside setup_method or a test method. The reason of this
  conversion is to use fixture ``db_session`` rather than create a
  new one. That would also benefit the whole test suite to reduce the
  number of SQLAlchemy session objects.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-07-18 21:26:50 +08:00
mprahl
1bcb40d4d0 Allow specifying a specific module build to reuse components from
This resolves #1296.
2019-07-16 11:40:59 +00:00
Merlin Mathesius
9f269c39e1 Older versions of kobo.rpmlib.get_header_field() return bytes, newer versions
return str. Decode as necessary.

Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>
2019-06-27 10:44:58 -05:00
Jan Kaluza
bf0bcaff57 Take the list of arches for -build Koji tag from buildrequired modules.
Currently, we are using just `conf.arches` and `conf.base_module_arches`
to define the list of arches for which the RPMs in a submitted module are
built. This is not enough, because RCM needs to generate modules based
on the base modules which should use different arches.

This commit changes the MBS to take the list of arches from the buildrequired
module build. It checks the buildrequires for "privileged" module or base
module and if it finds such module, it queries the Koji to find out the list
of arches to set for the module.

The "privileged" module is a module which can override base module arches
or disttag. Previously, these modules have been defined by
`allowed_disttag_marking_module_names` config option. In this commit,
this has been renamed to `allowed_privileged_module_names`.

The list of arches are stored per module build in new table represented
by ModuleArch class and are m:n mapped to ModuleBuild.
2019-06-07 13:16:31 +02:00
mprahl
dd5667665d Query the Red Hat Product Pages to see if this is a Z stream build when configured
In certain use-cases, a module's buildrequires may remain the same
in the modulemd, but a different support stream of the buildrequired
base module should be used. For example, since RHEL 8.0.0 is GA, any
modules that buildrequire platform:el8.0.0 should buildrequire
platform:el8.0.0z instead.
2019-05-21 08:55:52 -04:00
mprahl
00ea4e3bca Breakout some of the functionality in _handle_base_module_virtual_stream_br so it can be reused for a future feature 2019-05-21 08:55:52 -04:00
mprahl
2208021470 Fix the Python 3 unit tests 2019-05-13 13:40:37 -04:00
mprahl
d0f03daf61 Raise a ValidationError when buildonly or buildafter are set
This can be reverted when #1216 is implemented.
2019-05-13 13:40:37 -04:00
mprahl
14098cea08 Migrate to libmodulemd v2
This also moves the methods load_mmd and load_mmd_file to
module_build_service.utils.general.

This also removes some MSE unit tests with a mix of positive and
negative streams since this is not supported in libmodulemd v2. The
user will be presented with a syntax error if they try to submit
such a modulemd file.
2019-05-13 13:40:37 -04:00
mprahl
37e4c718d9 Simplify format_mmd since scm.commit is always set or returns an exception 2019-05-06 15:13:24 +00:00
mprahl
02f00d93c1 Add debug log statements so that SCM problems are easier to debug in the future 2019-05-06 15:13:23 +00:00
mprahl
6c8d48280d Use load_mmd_file instead of load_mmd where possible 2019-04-26 08:00:54 -04:00
mprahl
66c3f82160 Format the coding style across the codebase using "black" and manual tweaks
The main benefit of this commit is that the use of double quotes
is now consistent.
2019-04-26 00:32:13 -04:00
mprahl
7b8947f660 Allow buildrequring a virtual stream of a base module 2019-04-25 13:15:27 -04:00
Chenxiong Qi
1146bb3043 Reuse function load_mmd
GenericResolver.extract_modulemd is not removed, but deprecated. Call of it
will result in a deprecation message printed. Any new code should call
load_mmd.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-04-25 17:05:43 +08:00
Chenxiong Qi
7c993f9165 Handle streams in base module stream
A base module's stream (the platform for RHEL) could have Z-stream suffix, e.g.
el8.0.0.z, this patch handles this Z-stream suffix and other potential streams
by returning the stream version as a float with configured suffix value. For
example, el8.1.0.z would be parsed as 080100.1. Note that, the 0.1 is totally
configured in config and it actually could be any value according to concrete
cases in practice.

Config STREAM_SUFFIXES is enabled in TestConfiguration so that tests depending
on the return value from ModuleBuild.get_stream_version are covered.

Part fixture of test TestMMDResolver.test_solve_virtual_streams is updated by
adding Z-stream suffix to platform:el8.2.0 in order to ensure this patch does
not break the MMD resolver.

Addresses FACTORY-4307

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-04-23 11:21:46 +08:00
mprahl
9512a49631 Allow whitelisted buildrequires with xmd.mbs.disttag_marking set to influnece the disttag 2019-04-04 09:12:27 -04:00
mprahl
e2b2da7708 Move the module name validation to validate_mmd 2019-04-04 09:12:27 -04:00
mprahl
1570db8a7e Don't allow a user to set the xmd.mbs field in their modulemd 2019-04-04 09:12:27 -04:00
Merlin Mathesius
06e903c3c1 Fixes and test improvements based on review feedback.
Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>
2019-04-03 18:15:59 +00:00
Merlin Mathesius
cd76a1dca5 Update scratch context uniqueness suffix character from '.' to '_'.
Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>
2019-04-03 18:15:59 +00:00
Merlin Mathesius
663b7fc4d0 Allow resubmitting the same NSV for scratch module builds.
Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>
2019-04-03 18:15:59 +00:00
mprahl
a8a8913bbc Add the ability to override a buildrequired module stream based on a module's branch
This moves the functionality that was in rpkg to MBS. See the following
PRs for more context:
https://pagure.io/rpkg/pull-request/390
https://pagure.io/rpkg/pull-request/420
2019-03-19 16:45:00 -04:00
mprahl
998084b441 Don't default the module name to "unnamed" on a direct modulemd submission
The module name should either be set in the modulemd file or provided
by the `module_name` parameter.
2019-03-19 08:31:33 -04:00
mprahl
275e7e4509 Remove the concept of required and optional parameters
Since the required parameters vary based on if the modulemd
comes from SCM or a direct submission, the concept of optional
parameters doesn't really apply.
2019-03-19 08:02:39 -04:00
mprahl
3d3da4def1 Fix RHBZ#1686473 2019-03-18 13:30:04 -04:00
mprahl
b570948484 Don't allow building modules with the same name as a base module (e.g. platform)
A user managed to build a module called "platform", which stopped dependency
resolution from working. This should stop that from happening again.
2019-03-12 14:58:28 -04:00
Merlin Mathesius
152419f376 Module scratch build fixups per PR review feedback:
- Keep scratch module builds in the 'done' state.
- Make koji tagging for scratch modules unique so the same
  commit can be resubmitted.
- Use alternate prefix for scratch module build components so they can
  be identified later.
- Prevent scratch build components from being reused.
- Assorted code and comment cleanup.

Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>
2019-03-01 10:27:04 -06:00
Merlin Mathesius
a43d684859 Updates to handle including custom SRPMs for scratch module builds.
Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>
2019-03-01 10:27:04 -06:00
mprahl
d5f9c5872f Return an exception to the user if no dependency combination is determined 2019-02-27 14:08:15 +00:00
Valerij Maljulin
f6a4befefe Change exception information for errors when parsing modulemd file.
This fixes #1149

Signed-off-by: Valerij Maljulin <vmaljuli@redhat.com>
2019-02-26 14:09:57 +01:00
Jan Kaluza
efaaea66e0 Update the ModuleBuild.time_modified in case the format_mmd takes long time.
In case there is lot of components in a module build or there are some
networking issues and we need to retry the "git clone" commands, the
`format_mmd` method can take long time.

If it takes more than 10 minutes, the poller can produce fake event,
because it seems the module build is stuck. This is wrong, because
it would lead to another unexpected init handler call.

In this commit, the `format_mmd` updates the `ModuleBuild.time_modified`
method regularly to prevent poller from sending the unexpected fake
init message.
2019-02-15 15:20:34 +01:00
Jan Kaluza
40f23b65e4 Fix the handling of modulemd files with unicode characters.
This commit introduces new to_text_type helper method and calls it
for return value of all mmd.dumps() calls. That way, we always
end up with proper unicode string represntation on both python
major versions.

This commit also adds unicode character to description of all
the yaml files we use in the tests so we can be sure MBS can
handle unicode characters properly.

This might be temporary fix, depending on the result of discussion
at https://github.com/fedora-modularity/libmodulemd/issues/184.
2019-02-14 13:42:47 +00:00