129 Commits

Author SHA1 Message Date
Owen W. Taylor
debfd8a5c5 Combine mock stderr and stdout logs
Mock doesn't normally log anything to stdout - so it's confusing to mention
separate logs in the messages. Combine the two output streams together.
(This is what koji does as well.)
2023-03-20 10:55:28 -04:00
Owen W. Taylor
35086174ba Pass koji_tag to get_built_rpms_in_module_build()
For local builds, required modules are not necessarily in the local
database, so the method of looking up the build to find the koji tag
doesn't work reliably. However, the caller has the koji_tag - so just
pass it in.
2023-03-15 17:53:38 +00:00
Brendan Reilly
d4c213d678 Resolve issues reported by bandit 2022-07-21 09:09:12 -04:00
Brendan Reilly
e68f5c4c26 Use repo id instead of latest symlink
Fixes https://pagure.io/fm-orchestrator/issue/1581
2020-04-02 12:12:13 -04:00
Chenxiong Qi
1c0715662a Cleanup module_build_service/__init__.py
Most of the code are moved to dedicated subpackages, but some others
can't due to the cycle dependencies.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-03-03 14:48:48 -05:00
mprahl
81f2bffdda Rearrange the imports to meet the style guide
This also includes `from __future__ import absolute_import`
in every file so that the imports are consistent in Python 2 and 3.
The Python 2 tests fail without this.
2020-03-03 14:48:47 -05:00
mprahl
9ddb35b8d3 Move models.py to common/models.py and views.py to web/views.py 2020-03-03 14:48:47 -05:00
mprahl
b16cb88bc3 Move db_session.py to scheduler/db_session.py 2020-03-03 14:48:47 -05:00
mprahl
98b54d211e Move config.py to common/config.py 2020-03-03 14:48:47 -05:00
mprahl
85e3a2c496 Move utils/reuse.py to scheduler/reuse.py 2020-03-03 14:48:47 -05:00
mprahl
b0a27081f4 Split utils/general.py
This puts backend specific code in either the builder or scheduler
subpackage. This puts API specific code in the new web subpackage.
Lastly, any code shared between the API and backend is placed in the
common subpackage.
2020-03-03 14:48:47 -05:00
mprahl
8e7a43d5ff Move get_session and retry to separate modules to reduce circular imports 2020-03-03 14:48:47 -05:00
Qixiang Wan
510eb908c5 Remove unused handler arguments
The following handler arguments are not used at all:

1. `build_id` in handlers/components.py:build_task_finalize
2. `build_name` in handlers/tags.py:tagged
2020-03-03 14:48:47 -05:00
Qixiang Wan
b782304487 Partially revert the change of split config (a207d97)
It turns out we still have some backend code relies on the flask app,
so revert the change to init_config, and make minor change to create
config object for frontend and backend with the same function.
2020-03-03 14:48:47 -05:00
Qixiang Wan
81d9554af3 Create config for frontend or backend seperately
1. init_web_config: create Config object for frontend, load
   configuration from `web_config.py`.
2. init_backend_config: create Config for backend, load configuration
   from `backend_config.py`.

And two new classes inherit from `Config` in config.py:

1. WebConfig: representing the orchestrator frontend web configuration
2. BackendConfig: representing the orchestrator backend workers
                  configuration

Before calling init_{web,backend}_config, check sys.argv, if
"fedmsg-hub*", "celery" or "build_module_locally" is present, it's
running as backend.
2020-03-03 14:48:47 -05:00
Jan Kaluza
f8079308b1 Replace further work by Scheduler class based on the "sched" module.
To support multiple backend, we need to get rid of `further_work` concept
which is used in multiple places in the MBS code. Before this commit, if
one handler wanted to execute another handler, it planned this work by
constructing fake message and returning it. MBSConsumer then planned
its execution by adding it into the event loop.

In this commit, the new `events.scheduler` instance of new Scheduler
class is used to acomplish this. If handler wants to execute another
handler, it simply schedules it using `events.scheduler.add` method.

In the end of each handler, the `events.scheduler.run` method is
executed which calls all the scheduled handlers.

The idea is that when Celery is enabled, we can change the
`Scheduler.run` method to execute the handlers using the Celery, while
during the local builds, we could execute them directly without Celery.

Use of Scheduler also fixes the issue with ordering of such calls. If
we would call the handlers directly, they could have been executed
in the middle of another handler leading to behavior incompatible
with the current `further_work` concept. Using the Scheduler, these
calls are executed always in the end of the handler no matter when
they have been scheduled.
2020-03-03 14:48:47 -05:00
Chenxiong Qi
b939d53c57 Pass event info arguments to event handler directly
This patch drops message objects, defined by class BaseMessage and its
subclasses, and pass event info arguments to event handler directly.
Different event handler requires different arguments to handle a kind of
specific event. The event info is parsed from the raw message received
from message bus.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-03-03 14:48:47 -05:00
Chenxiong Qi
db20065e74 Clear up module_build_service.messaging
Message classes and FedmsgMessageParser are moved into dedicated Python module
under scheduler/ directory.

FedmsgMessageParser is decoupled from messaging.py by initializing a parser
object with known fedmsg services. This decouple avoids cycle import between
parser.py and messaging.py.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-03-03 14:48:47 -05:00
Chenxiong Qi
3d771aac10 Fix a typo
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-10 16:08:33 +08:00
Brendan Reilly
c349946718 use gssapi if correct python-requests-kerberos is available 2020-01-09 10:01:36 -05:00
mprahl
3051596166 Remove the koji.ClientSession backport
See https://pagure.io/koji/pull-request/1187 for context.
2019-12-02 12:07:40 -05:00
Matt Prahl
f487da140b Merge #1524 Gracefully handle builds without a koji tag 2019-11-22 16:26:12 +00:00
Luiz Carvalho
618eb3a3c6 Gracefully handle builds without a koji tag
MBS will iterate through all the builds in buildrequires to determine
the expected list of arches on the associated Koji tag. In some cases,
these builds do not have a Koji tag. They should be skipped for this
operation.

Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
2019-11-22 10:53:40 -05:00
Christopher O'Brien
12acc9242d allow koji tags to be created with a configurable permission. Fixes #1478 2019-11-22 07:41:16 -05:00
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
Mike Bonnet
e582126106 use the C locale for generating the date string for the specfile changelog
This produces exactly the same output as the en_US locale, and is guaranteed to be supported
in all environments.
2019-11-01 16:50:56 -07: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
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
Chenxiong Qi
6d19a23c17 Refactor buildroot_add_artifacts
* Reuse tag_artifacts.
* Split unblocking packages and adding packages to groups into
  separate methods.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-09-02 20:30:49 +08:00
Chenxiong Qi
6c3721ef75 Update KojiModuleBuilder *_artifacts methods docstring
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-09-02 17:37:13 +08:00
Valerij Maljulin
4b4428a9e3 Fix locale issues with date representations
This fixes #1214
Also fixes tests running on different locales

Signed-off-by: Valerij Maljulin <vmaljuli@redhat.com>
2019-08-22 17:06:26 +02:00
Chenxiong Qi
e1342d8ffc Use dict literal to create dict
Some code create a dict in this way:

some_var = {}
some_var["a"] = 100
some_var["b"] = 200

Using dict literal could make these lines a little bit simpler.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-08-15 21:28:27 +08:00
Qixiang Wan
ab8abef058 Fix recover_orphaned_artifact for module-build-macros
When recover_orphaned_artifact is called for module-build-macros
and the module-build-macros is not tagged in the -build Koji tag,
then the tag_artifacts() is called to tag it there.

This is correct, but the issue is that module-build-macros need
to be added to "build" and "srpm-build" Koji tag groups, otherwise
it is not installed in the buildroot by default.
2019-07-23 16:11:27 +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
ddafbb86ff Allow the poller to clean up module builds without arches 2019-07-10 13:29:58 +00:00
Chenxiong Qi
5bdb77777f Minor fixes to _get_filtered_rpms_on_self_dep
* Add docstring
* Call dict.setdefault to simplify the code a little which constructs the map
  from package name to built RPMs' NVRs.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-06-25 15:13:22 +08:00
Jan Kaluza
c9d2b77167 When no architecture is set in Koji tag, fallback to conf.arches 2019-06-19 14:32:10 +02:00
Jan Kaluza
511cad8c14 Check if buildopts.get_rpm_whitelist() is really set before using it.
This fixes module builds which sets the `buildopts` for something else
than the RPM whitelist.

Before this commit, when `buildopts` was set, the RPM whitelist was
always taken from the buildopts even if it was not defined there.
This resulted in empty `rpm_whitelist` and therefore no pkglist set
in Koji tag.

In this commit, MBS uses whitelist from `buildopts` only if it is
really set by the module maintainer.
2019-06-12 14:17:26 +02:00
Igor Gnatenko
cdb701d525 Allow configuring 'dynamic_buildrequires'
The default is not set because we want to use koji's default if modulemd
does not specify 'dynamic_buildrequires'.

Requires: https://pagure.io/koji/pull-request/1466
Closes: https://pagure.io/fm-orchestrator/issue/1264
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-06-09 18:53:04 +02: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
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
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
559f0dd922 Use dedent when defining the module-build-macros specfile 2019-04-25 15:53:56 -04:00
Owen W. Taylor
da57146bf2 GenericBuilder: Add a boolean 'succeeded' parameter to finalize
Previously MockModuleBuilder was checking the module state to see if
it should run a final createrepo, but since eafa93037f, finalize() is
called before changing the module state; add an explicit boolean to
GenericBuilder.finalize() to avoid worrying about ordering.
2019-04-03 18:12:57 +00:00
Chenxiong Qi
0ee801877b Move module build to ready from done according to Greenwave
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2019-04-02 16:11:43 +08:00
Jan Kaluza
67a5a9d1b0 Allow building module in --offline module with dependencies from local repositories.
There are following changes introduced in this commit:

- The `koji_tag` of module builds imported from the local repositories
  is now in `repofile:///etc/yum.repos.d/some.repo` format to store the
  repository from which the module was imported to local MBS DB.
- The `koji_tag` of fake base module is set to empty `repofile://`
  and in `MockModuleBuilder` the `conf.base_module_repofiles` list
  is used as source for the repositories defining platform. We can't
  simply use single repository, because there might be fedora.repo
  and fedora-update.repo and so on.
- The list of default .repo files for platform are passed using the
  `-r` switch in `build_module_locally` `mbs-manager` command.
- The LocalResolver (subclass of DBResolver) is added which is used
  to resolve the build dependencies when building modules offline
  locally.
- The `MockModuleBuilder` enables the buildrequired modules and
  repositories from which they come in the mock config.

With this commit, it is possible to build testmodule locally
without any external infra.
2019-04-01 13:13:08 +00:00
Jan Kaluza
765e640129 Allow setting the Koji tag extra options using the conf.koji_tag_extra_opts.
The Koji tag extra options used to be hard-coded and to change them,
we had to release new MBS version.

We do not change them often, but right now fedora-infra is requesting
to use new `mock.new_chroot` option and we need to release new MBS
because of that.

This commit makes such changes easier in the future.
2019-03-18 17:27:57 +00:00
Jan Kaluza
9a6646f27c Use the scrmod prefix also for build targets for scratch builds.
Currently, the Koji tags have properly set the scrmod- prefix, but
the build target still sets module- prefix even for scratch builds.

In this commit, build target has the scrmod- prefix too.
2019-03-14 13:10:47 +01: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