Commit Graph

816 Commits

Author SHA1 Message Date
mprahl
af9505b0e1 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-01-16 14:39:46 -05:00
mprahl
f1488967b2 Clean up build logs after each test so that it doesn't affect tests run later
Tests in test_build.py started to affect tests in test_content_generator.py
after test_content_generator.py was moved, which caused those tests to execute
after test_build.py
2020-01-16 14:39:46 -05:00
mprahl
f5ce07569b Move test_content_generator.py to test_builder/test_content_generator.py 2020-01-16 14:39:46 -05:00
mprahl
38b7a3ef2a Move scm.py to common/scm.py 2020-01-16 14:39:46 -05:00
mprahl
a842bd748f Move route.py to scheduler/route.py 2020-01-16 14:39:46 -05:00
mprahl
fce4d05c0c Move logger.py to common/logger.py 2020-01-16 14:39:46 -05:00
mprahl
63baaf9213 Move models.py to common/models.py and views.py to web/views.py 2020-01-16 14:39:46 -05:00
mprahl
5f27e4359f Move errors.py to common/errors.py 2020-01-16 14:39:46 -05:00
mprahl
3091d6cfda Move monitor.py to common/monitor.py 2020-01-16 14:39:46 -05:00
mprahl
15b04a888e Move mmd_resolver.py to web/mmd_resolver.py 2020-01-16 14:39:46 -05:00
mprahl
c2a3b059e9 Move messaging.py to common/messaging.py 2020-01-16 14:39:46 -05:00
mprahl
46dcb2c236 Move db_session.py to scheduler/db_session.py 2020-01-16 14:39:46 -05:00
mprahl
e0fa2371eb Move config.py to common/config.py 2020-01-16 14:39:46 -05:00
mprahl
cfac201b1c Move auth.py to web/auth.py 2020-01-16 14:39:46 -05:00
mprahl
ee3ca47c69 Split utils/submit.py
This moves the code used by the backend and API to common/submit.py,
the code used just by the API to web/submit.py, and the code used
just by the backend to scheduler/submit.py.
2020-01-16 14:39:46 -05:00
mprahl
b03bc41e76 Move utils/reuse.py to scheduler/reuse.py 2020-01-16 14:39:46 -05:00
mprahl
92be7b3b0b Move utils/ursine.py to scheduler/ursine.py 2020-01-16 14:39:46 -05:00
mprahl
78d5a9e482 Split utils/mse.py
This moves the code used by the backend and API to common/resolve.py
and moves the code used just by the API to web/mse.py.
2020-01-16 14:39:46 -05:00
mprahl
5e401bd598 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-01-16 14:39:46 -05:00
mprahl
a8b90c083b Move utils/greenwave.py to scheduler/greenwave.py 2020-01-16 14:39:45 -05:00
mprahl
9f1e3ddee0 Rename test_greenwave.py to test_greenwave_handler.py 2020-01-16 14:39:45 -05:00
mprahl
4590419d22 Move utils/batches.py to scheduler/batches.py 2020-01-16 14:39:45 -05:00
Qixiang Wan
ba22e1f686 Ignore koji_build_change event without task_id 2020-01-16 14:39:45 -05:00
mprahl
4340dea1e5 Move get_session and retry to separate modules to reduce circular imports 2020-01-16 14:39:45 -05:00
mprahl
3dd239dca7 Simplify how MBS is configured
This merges the configuration from conf/config.py to
module_build_service/config.py. This also greatly simplifies the logic
in `init_config`. Additionally, `init_config` is no longer aware of
Flask. This will allow us to eventually break up the configuration
between the API and the backend.
2020-01-16 14:39:45 -05:00
Qixiang Wan
8800134411 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-01-16 14:39:45 -05:00
Qixiang Wan
ca9d3a2af8 Add celery task router
Add route_task function to route celery tasks to different queues.
If we can figure out what the module build is a task ran for by
checking the task arguments, then we route this task to a queue
named:

    "mbs-{}".format(module_build_id % num_workers)

"num_workers" has default value of 1, and can be changed in
backend_config.py. If module build id can't be figured out, task will
be routed to the default queue which is named "mbs-default".

While setting up the workers, the number of workers should match with
"num_workers" in config, and each worker will listen on two queues:

    1. mbs-default
    2. mbs-{number} # for example, the first worker listens on "mbs-0"

By this design, all tasks for a particular module build will be routed
to the same queue and run on the same worker serially.
2020-01-16 14:39:45 -05:00
Qixiang Wan
d01f911bd1 Rename handler.repos.done argument name "repo_tag" to "tag_name"
This to make it same as the `tag_name` argument in
`handlers.tags.tagged`, so we can handle it easily while inspecting the
function signatures.
2020-01-16 14:39:45 -05:00
Qixiang Wan
bc68b3b08c Revert the config split change
Revert the changes in a207d97 and 9a2efb3, at this moment, some code
relies on both settings from frontend and backend, and it's inconvenient
to run unittests with config split up to frontend only and backend
only.
2020-01-16 14:39:45 -05:00
Chenxiong Qi
6154cf5eb7 Convert the Poller to be Celery periodic tasks
Poller methods within original class MBSProducer become module level
functions and are registered as Celery periodic tasks.

Code logging the size of fedmsg-hub queue are removed from log_summary.

process_open_component_builds is still kept there and not converted to a
periodic task.

There are some small refactor:

* do not format string in logging method call.
* reformat some lines of code doing SQLAlchemy database query to make
  them more readable.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Jan Kaluza
e79740a748 Allow building modules locally without fedmsg-hub.
We started using `events.scheduler` to plan fake events instead of internal
queue implemented by fedmsg-hub. Thanks to that, we can stop using fedmsg-hub
completely for local builds.

In this commit, the `scheduler.local.main` is rewritten to not use fedmsg-hub.
The original `scheduler.local.main` is still needed by test_build tests and
therefore it is moved there.
2020-01-16 14:39:45 -05:00
Qixiang Wan
062350031a 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-01-16 14:39:45 -05:00
Qixiang Wan
e07b82e2f9 Register handlers as Celery tasks 2020-01-16 14:39:45 -05:00
Qixiang Wan
d6c5f8c13b 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-01-16 14:39:45 -05:00
Jan Kaluza
473f7e5e5b 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-01-16 14:39:45 -05:00
Chenxiong Qi
5f4ef94103 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-01-16 14:39:45 -05:00
Chenxiong Qi
e1581ac831 Remove config argument from event handlers
For the purpose of migrating to Celery to run event handler inside a
worker, Config object is not serializable. And from the usage of config
argument, every event handler can just access module_build_service.conf
directly. This removal would make the migration easier.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Chenxiong Qi
807acc2fb6 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-01-16 14:39:45 -05:00
Chenxiong Qi
fca0e354c1 Remove unused argument arches from add_default_modules
Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2020-01-16 14:39:45 -05:00
Matt Prahl
66a2362a90 Merge #1552 Fix the provides of base modules 2020-01-16 19:38:55 +00:00
Brendan Reilly
c2561da405 Added unit tests for add_base_module_provides 2020-01-16 14:26:04 -05:00
Hunor Csomortáni
5f7442f8c1 Tests: Create a fixture for scenario configuration
Until now, to access the configuration of a scenario, the full path in
test_env had to be specified.

This might be cumbersome and error prone.

Create a scenario fixture, to make it easier to access the same
configuration.

Instead of

    test_env["testdata"]["my_scenario"]["my_config"]

one can use the following:

    scenario["my_config"]

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
2020-01-16 10:29:14 +01:00
Mariana Ulaieva
c35fe26e73 No components integration test
Implement the Module With No Components integration test.
2020-01-10 14:38:13 +01:00
ejegrova
f61f7afbdd Add integration test for reuse components 2019-12-09 15:18:11 +01:00
Mariana Ulaieva
06974ef202 Reuse all components test
Implement the integration test for the Reuse All components Scenario.
2019-12-09 14:43:38 +01:00
Hunor Csomortáni
eb86e52c29 Merge #1538 Various test improvements 2019-12-09 12:59:40 +00:00
Matt Prahl
f4ab801b3a Merge #1535 Only allow cancelling module builds in the init, wait, and build states 2019-12-06 14:02:13 +00:00
Hunor Csomortáni
35c1097920 Tests: increase koji task timeout to 5 minutes
When running multiple test builds, the 1 minute timeout was often not
enough.

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
2019-12-06 12:33:44 +01:00
Hunor Csomortáni
b2485a6150 Tests: fix koji.PathInfo
This should use "topurl". Remove the "weburl" config as it's not needed
anymore.

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
2019-12-06 12:33:44 +01:00
Hunor Csomortáni
343f1b9818 Tests: separate starting and watching the builds
This makes the tests more explicit, but also prepares the ground to
enable canceling test builds during session teardown in the future.

Signed-off-by: Hunor Csomortáni <csomh@redhat.com>
2019-12-06 12:33:44 +01:00