748 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
Jan Kaluža
84398834e4 Merge #1481 Search for default modules built also against compatible base modules. 2019-11-05 07:41:42 +00:00
Jan Kaluza
96ca7fd00b Search for default modules built also against compatible base modules. 2019-11-05 07:03:40 +01:00
mprahl
f95b665904 Use RuntimeError instead of ValueError when the retrieval of default modules fails
This will result in the error actually being in the state reason
of the failed module build instead of "An unknown error occurred
while validating the modulemd".
2019-11-01 14:49:10 -04:00
mprahl
ef0ab348bc Remove commented out code in test_utils.py 2019-10-30 15:29:45 -04:00
Chenxiong Qi
d1026c0df7 Do not drop realm from user's kerberos principal name
Save the realm and just keep the variable there for any further possible
use.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-10-25 13:46:54 +08:00
Hunor Csomortáni
0066c79dae Bootstrap integration tests
This is the first step to have some tests, that we could run against an
MBS instance, to check that it's functionally correct. Ultimately, these
will replace the test scripts (`contrib/test-*`).

This doesn't really do anything yet, but I would like to make sure that
everyone is on the same page regarding how this will be set up.

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
2019-10-24 10:16:16 +02:00
Mike McLean
107df94776 fix unit test 2019-10-18 09:44:45 -04:00
Mike McLean
dbcb0f30d1 drop unnecessary parentheses 2019-10-18 09:44:45 -04:00
Mike McLean
5e854f503d adjust unit test 2019-10-18 09:44:45 -04:00
Mike McLean
8a83a17c53 update devel case assertion 2019-10-18 09:44:45 -04:00
Chenxiong Qi
9fd3731ff7 Remove KerberosAuthenticate and get kerberos username from REMOTE_USER
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-10-17 10:20:59 +08:00
Jan Kaluza
eeb65c97da KojiResolver: Filter module builds based on the real stream name.
Query Koji for the real stream name of each module and keep only those matching
requested `stream`.

This needs to be done, because MBS stores the stream name in the "version" field in Koji,
but the "version" field cannot contain "-" character. Therefore MBS replaces all "-"
with "_". This makes it impossible to reconstruct the original stream name from the
"version" field.

We therefore need to ask for real original stream name here and filter out modules based
on this real stream name.
2019-10-14 14:13:34 +02:00
Matt Prahl
74bf638cdc Merge #1458 Only use default modules that were built with the same base module 2019-10-09 12:44:52 +00:00
Jan Kaluža
514e4c115a Merge #1457 Make reuse_shared_userspace_init_data faster 2019-10-09 05:24:00 +00:00
mprahl
27f4d71392 Only use default modules that were built with the same base module 2019-10-08 11:38:39 -04:00
Chenxiong Qi
800f606b83 Make reuse_shared_userspace_init_data faster
* A significant performance improvement is to avoid repeating call of
  mmd.get_xmd() in a looping.
* Function is refactored to avoid call of mmd_to_str twice for a module
  build.
* Test using this fixture already has a setup_method to clean database,
  so no need to call clean_database again.
* Calculate build context directly without calculating other contexts
  together.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-10-08 11:30:50 +08:00
Jan Kaluza
339c1ef98d Add KojiResolver to config.SUPPORTED_RESOLVERS. 2019-10-07 12:52:13 +02:00
Jan Kaluza
5ffdeb4649 Fallback to DBResolver in KojiResolver.get_compatible_base_module_modulemds.
In case KojiResolver is not enabled for the base module, fallback to
DBResolver in `KojiResolver.get_compatible_base_module_modulemds`.
2019-10-04 15:22:35 +02:00
Jan Kaluža
9e38493112 Merge #1452 Support KojiResolver in MBSResolver. 2019-10-04 06:45:39 +00:00
Jan Kaluza
72d2c3daf4 Support KojiResolver in MBSResolver.
If KojiResolver is enabled for buildrequired base module and
MBSResolver is used, then `MBSResolver.get_buildrequired_modulemds`
will use KojiResolver to get the list of buildrequired module builds.

Otherwise it uses the current behavior.

To implement this, the `KojiResolver.get_buildrequired_modules` was
split into two methods:

- `get_buildrequired_koji_builds` returns buildrequired Koji builds.
- `get_buildrequired_modules` calls `get_buildrequired_koji_builds`
  and finds the corresponding ModuleBuilds in MBS DB.
2019-10-04 07:43:11 +02:00
Valerij Maljulin
2c0291987f Raise Unathorized exception instead of general one whenever OIDC auth fails
This fixes #1147
2019-10-03 17:02:33 +02: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
Jan Kaluža
6e34e50c18 Merge #1451 Add support for KojiResolver in component reuse code. 2019-10-03 13:16:00 +00:00
Jan Kaluza
486dc39898 Add support for KojiResolver in component reuse code.
In this commit, when component reuse code finds out that the base module uses
KojiResolver, it uses the `KojiResolver.get_buildrequired_modules` method
to find out possible modules to reuse and limits the original query just
by the IDs of these modules.

In order to do that, this commit splits the original
`KojiResolver.get_buildrequired_modulemds` into two methods:

- The `get_buildrequired_modules` returning the ModuleBuilds.
- The `get_buildrequired_modulemds` calling the `get_buildrequired_modules`
  and returning modulemd metadata.
2019-10-03 15:14:29 +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
Matt Prahl
df295516e3 Merge #1449 Use double quotes instead of single quotes to match the style guide 2019-10-02 13:57:36 +00:00
mprahl
f60b292c9c Use double quotes instead of single quotes to match the style guide 2019-10-02 07:42:20 -04:00
mprahl
164f592c1d Make the DNF minrate setting configurable when loading repos 2019-10-02 07:37:12 -04:00
Matt Prahl
2796b9e6a1 Merge #1448 Load the DNF repos in parallel 2019-10-02 11:33:21 +00: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
mprahl
8d76977434 Load the DNF repos in parallel
In production, loading each repo can be quite slow. This approach
loads the repos in parallel.
2019-10-01 15:29:00 -04:00
Matt Prahl
d4b7a019c7 Merge #1444 Return an empty list in KojiResolver.get_compatible_base_module_modulemds. 2019-09-30 15:12:31 +00:00
Jan Kaluza
a28df5edb7 Return an empty list in KojiResolver.get_compatible_base_module_modulemds.
For KojiResolver, this method returns always an empty list. The compatible modules are
defined by the Koji tag inheritance, so there is no need to find out the compatible
base modules on MBS side.

This makes `mse.get_base_module_mmds` to ignore virtual streams and just use
the input base module as the only module without finding the compatible
base modules.
2019-09-30 09:04:21 +02:00
Jan Kaluža
f6c2a88cc0 Merge #1435 Add initial code for KojiResolver class. 2019-09-30 06:25:55 +00:00
Jan Kaluza
a7540452cd Add initial code for KojiResolver class.
This commit:

- Adds KojiResolver class and KojiResolver tests.
- Changes the GenericResolver and its subclasses to pass base_module_mmds
  instead of base_module_nsvc to get_buildrequired_modulemds. This is needed,
  because KojiResolver needs to access XMD section of base module.
- Implements KojiResolver.get_buildrequired_modulemds to ask Koji for list of
  modules tagged in the Koji tag and return their modulemds.
2019-09-30 07:56:07 +02:00
Jan Kaluza
1385a1dea3 default_modules: Convert arch to canon_arch.
Convert arch to canon_arch. This handles cases where Koji "i686" arch is mapped to
"i386" when generating RPM repository.
2019-09-23 13:18:38 +02:00
mprahl
749f186524 Add conflicts in module-build-macros for NEVRAs found in handle_collisions_with_base_module_rpms
PR #1331 made the assumption that the Ursa Major ursine RPMs were at
xmd["mbs"]["ursine_rpms"], but they are actually at
xmd["mbs"]["buildrequires"]["platform"]["ursine_rpms"]. This commit
handles the ursine RPMs generated by handle_collisions_with_base_module_rpms
separately since the base module the RPMs came from are not tracked in
that function.
2019-09-19 13:31:10 +00:00
Mike McLean
e2939c80a1 use patch.object 2019-09-18 17:22:59 -04:00
Mike McLean
e1cf07c038 extend unit test 2019-09-18 20:21:14 +00:00
mprahl
235d4cd457 Fix the test_handle_collisions_with_base_module_rpms unit test 2019-09-18 12:04:18 -04:00
Chenxiong Qi
3fb079f23d Add more tests for mbs-manager command build_module_locally
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-09-18 13:42:42 +00:00
Chenxiong Qi
e3f91dd8a8 Add missing keyword assert to test
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-09-18 16:49:21 +08:00
mprahl
1a05d59a4d Use double quotes instead of single quotes 2019-09-17 13:11:22 -04:00
Chenxiong Qi
065abe3c45 Fix DetachedInstanceError in command module_build_locally
Update test test_build_module_locally_set_stream accordingly by not
mocking database session object in order to test against the real
SQLAlchemy Session scope.

Resolves: RHBZ#1752075

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-09-17 23:09:14 +08:00
mprahl
d2e7c0cf90 Don't check for compatibile modules during component reuse if allow_only_compatible_base_modules is false
Addresses #1409
2019-09-13 13:06:35 +00:00
Jan Kaluza
52e88ba3ff Handle the conflicts between base module modular Koji tags everytime.
Currently, we generate `Conflicts` for ursine RPMs conflicting with
modular RPMs only when Ursa Prime is used for the base module. This
commit changes it, so these Conflicts are generated everytime.

The reason is that modular RPMs should always be preferred in the
buildroot over the ursine RPMs no matter what is their NVR. So far,
this has been guarded on Koji side by using external repos, but
we need to move away from external repo or at least use "bare"
merge mode which basically means we won't get this feature for free
from Koji.

The reason why we need to move away from external repos or use "bare"
merge mode is that without this, the Koji removes RPMs sharing the same
name but different version/release from the buildroot and only keeps
the latest one. This is an issue in situation when you need two
versions of single RPM in a buildroot comming from two modules.
2019-09-12 11:08:57 +02:00
mprahl
00e78494d9 Refactor handling of default buildroot modules (Ursa Prime)
This removes support for default_modules_url in the Platform XMD and
gets the list of default name:stream combinations to include in the buildroot
from https://pagure.io/releng/fedora-module-defaults.

Addresses #1402
2019-09-11 12:20:35 -04:00
Jan Kaluža
457b16daff Merge #1395 Reuse the latest module build found. 2019-08-30 05:48:25 +00:00
Jan Kaluza
00ad20dfcd Reuse the latest module build found.
Before this commit, the base modules used in the `get_reusable_module` have
not been sorted and therefore when `get_reusable_module` tried to find out
the reusable module built against some base module, it could find a module
built against some old version of base module.

This could lead to situation when MBS tried to reuse components from quite
old module despite the fact that newer module build existed.

This commit fixes this by sorting the base modules by stream_version,
so MBS always tries to get the reusable module built against the latest
base module.
2019-08-29 15:35:21 +02:00