Commit Graph

2992 Commits

Author SHA1 Message Date
Brendan Reilly
d676e06396 Merge #1745 Resolve issues reported by bandit 2022-07-21 13:10:10 +00:00
Brendan Reilly
d4c213d678 Resolve issues reported by bandit 2022-07-21 09:09:12 -04:00
Brendan Reilly
5066752004 Merge #1753 Pass connect args to sqlalchemy 2022-07-12 20:23:39 +00:00
Brendan Reilly
fedbfc37e1 Pass connect args to sqlalchemy 2022-06-22 13:59:44 -04:00
Brendan Reilly
3111c70f8a Merge #1744 Also run bandit during py3 unit tests 2022-05-25 15:57:17 +00:00
Brendan Reilly
3231d3584c Merge #1675 Don't traceback on failed builds 2022-05-19 18:30:20 +00:00
Brendan Reilly
687191681d Merge #1673 Improve exception and SIGINT handling for tests/test_build 2022-05-16 18:33:59 +00:00
Brendan Reilly
17819cf6a6 Merge #1671 Avoid deep recursion when handling a large queue of events 2022-05-13 16:56:00 +00:00
Brendan Reilly
c24038198e Merge #1672 Don't pass SQLAlchemy objects between threads 2022-05-13 16:47:07 +00:00
Brendan Reilly
f4040c09f4 Merge #1670 Go back to using a file-backed SQLite database for tests 2022-05-03 18:35:13 +00:00
Brendan Reilly
a06d1a678d Merge #1746 Add default branch configuration option 2022-05-03 16:48:24 +00:00
Brendan Reilly
1da34c1649 Merge #1662 Improve test coverage for MockModuleBuilder 2022-05-03 16:43:27 +00:00
Brendan Reilly
6b76877d6d Merge #1661 MBSResolver - caching, tests, fixes 2022-05-03 16:42:22 +00:00
Brendan Reilly
9e8e296667 Merge #1658 Log cleanups for local builds 2022-05-03 16:41:17 +00:00
Owen W. Taylor
d050108d13 MBSResolver: cache results of MBS queries
Use dogpile.cache to avoid repeatedly making the same queries to the MBS.

We frequently query a list of modules, and then later in the build go
back and ask for details of those modules again by nsvc, so special case
querying a single module by nsvc and prime the cache for this from lists
of results.
2022-04-29 15:49:19 -04:00
Owen W. Taylor
c27e77c59d MBSResolver: improve efficiency of querying latest version
Only get 5 results at a time, and if we see that we're already
retrieving an old versions, stop requesting more pages.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
31fca9a962 100% test coverage for MBSResolver.py
Add new tests and modify existing tests so that test_mbs.py entirely
covers MBSResolver.py. To make the tests simpler, change from
explicitly expectations about the MBS API request => response sequence
to a stub local implementatin of the MBS API.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
80c7e20bfa resolver: remove unused state/states parameter to get_module()
BaseResolver.get_module() and DBResolver.get_module() to a state
parameter, MBSResolver took a states parameter - neither was used
anywhere.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
7d2e754f35 Fix handling of getting "modulemd: null" in MBS verbose response
The code made some half-hearted attemps to handle a MBS verbose query
missing the modulemd data, but it didn't do anything logically
consistent - fix it to consistently ignore such modules.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
960058fe9d MBSResolver: fix 'either...or' => 'both....and' 2022-04-29 15:47:08 -04:00
Owen W. Taylor
70ed42885e MBSResolver: local modules can't be metadata-only
A module added with --add-local-build  can't have koji_tag=None, since
koji_tag is set to the directory where the module is.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
7d6c7876b1 MBSResolver: fix a RuntimeError to not reference None 2022-04-29 15:47:08 -04:00
Owen W. Taylor
7e33935760 MBSResolver: remove non-functional handling of RPM filtering
Code in MBSResolver.resolve_requires() to compute filtered_rpms()
assumed the response from MBS has a "rpms" key with binary RPMS
from the build, but this was never implemented.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
abd731397f MBSResolver: use requests.Response.raise_for_status()
Simplify and avoid extra uncovered code paths.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
7788c4f3f7 local builds: provide a useful error message for a non-xyz base module
If allow_only_compatible_base_modules=True, then it's an error if the
module buildrequires a non-xyz base module stream. Give an error message
that says how to override the base module in the modulemd file.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
4026900f4f Add --buildrequires/--requires options to build_module_locally
Overriding the platform stream with, e.g, platform:el8.3.1
is necessary to correctly pick up the right build dependencies for some
configurations. Match the fedpkg/rhpkg module-build way of doing this by adding
--buildrequires and --requires options to build_module_locally.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
7761bbf5b4 Tweak behavior of get_compatible_base_module_modulemds
Fix some oddities in the DBResolver implementation of
get_compatible_base_module_modulemds() and make the MBSResolver version -
which was previously just buggy - match that. (Tests for the MBSResolver
version are added in a subsequent commit.)

 * If an empty virtual_streams argument was passed in, *all* streams
   were considered compatible. Throw an exception in this case - it
   should be considered an error.
 * If stream_version_lte=True, but the stream from the base module
   wasn't in the form FOOx.y.z, then throw an exception. This was
   previously treated like stream_version_lte=False, which is just
   a recipe for confusion and mistakes.

test_get_reusable_module_use_latest_build() is rewritten to
comprehensively test all possibilities, including the case that changed
above.

test_add_default_modules_compatible_platforms() is changed to run
under allow_only_compatible_base_modules=False, since it expected
Fedora-style virtual streams (versions not in FOOx.y.z form, all
share the same stream), which doesn't make sense with
allow_only_compatible_base_modules=True.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
c4230a352d LocalBuildConfiguration: Set ALLOW_ONLY_COMPATIBLE_BASE_MODULES = False
The default LocalBuildConfiguration builds against Fedora - which has
ALLOW_ONLY_COMPATIBLE_BASE_MODULES = False on the server side. Match that
to avoid warnings that f33 isn't in <stream>x.y.z form.
2022-04-29 15:47:08 -04:00
Owen W. Taylor
e48983132c Clarify the meaning conf.allow_only_compatible_base_modules=False
config.allow_compatible_base_modules=False does different things for
build-requires selection and for module reuse. Clarify this in the config
key documentation.

(This config key is really: True: "do what RHEL expects"
False: "do what Fedora expects")
2022-04-29 15:47:08 -04:00
Owen W. Taylor
e5c51d924f Don't traceback on failed builds
Just failing a build isn't a reason to die with a traceback - exit with
a status instead.

Fixes: #1364
2022-04-26 17:20:49 -04:00
Owen W. Taylor
0d0d8091ac test_build: leave Control-C working
Two problems occurred with the moksha/twisted handling of SIGINT:

 * While KeyboardInterrupt caused the moksha loop to exit, it just
   left the test in a confused state, instead of triggering standard
   pytest behavior and aborting the entire test run.
 * The handler was left-over for remaining tests that prevent Control-C
   from working at all.

Fix that by using mock.patch to override moksha's signal handler with
our own signal handler that stores the KeyboardInterrupt in the
current EventTrap, and restores the default signal handler after
the loop ends.

Note that since the KeyboardInterrupt is always handled in the main thread,
we don't get a useful backtrace from the child thread.
2022-04-26 17:12:16 -04:00
Owen W. Taylor
4ddd3c2637 test_build: exit rather than hanging on event handler exception
Event handlers decorated with @celery_app_task don't raise an exception -
they just log the exception, leaving the Moksha hub running. This meant
that any failures in test_build would result in the test suite hanging
rather than failing usefully.

We solve this by adding a new class EventTrap which acts as a context
manager. Any exceptions that occur in event handlers are set on the
current EventTrap, and the test_build tests re-raise the exception.
2022-04-26 17:12:16 -04:00
Owen W. Taylor
5dcd63ebf9 batches.py: Don't pass SQLAlchemy objects between threads
SQLAlchemy objects can't be used from multiple threads - so when starting
threads for builds, pass the ComponentBuild id rather than the object.
(Note that despite the comment that the threads were sharing a session,
they weren't - what was passed to the thread was a scoped_session that
acts as a separate thread-local session per-thread.)

BUILD_COMPONENT_DB_SESSION_LOCK - a threading.Lock() object that was used
in a few places - but not nearly enough places to effectively lock usage
of a shared session - is removed.
2022-04-26 17:04:40 -04:00
Owen W. Taylor
4a3e6fb0fa start_build_component: add missing db_session parameter 2022-04-26 17:04:40 -04:00
Owen W. Taylor
3b8cdd342a Avoid deep recursion when handling a large queue of events
Because each event handler wrapper would call scheduler.run() at the end before
returning, with a queue of 100 events to process we'd end up
with:

 Event handler 1 wrapper
   scheduler.run()
     Event handler 2 wrapper
       scheduler.run()
         .....
            .... Event handler 100 wrapper

Which would eventually exhaust the Python stack limit. Fix this by making scheduler.run()
no-op if the scheduler is already processing the queue in the current thread.
2022-04-26 17:02:09 -04:00
Owen W. Taylor
a96774a1fd Go back to using a file-backed SQLite database for tests
Using a memory database causes tests/test_build to intermittently
fail, because using the same pysqlite3 connection object from multiple
threads - as was done so that the threads shared the same memory database
- is not, in the end, thread safe. One thread will stomp on the transaction
state of other threads, resulting in errors from starting a new transaction
when another is already in progress, or trying to commit a transaction
that is not in progress.

To avoid a significant speed penalty, the session-scope fixture sets up
a database in the pytest temporary directory, which will typically be on
tmpfs. Time to complete all tests:

 memory backend:               38 seconds
 file on tmpfs:                40 seconds
 file on nvme ssd with btrfs: 137 seconds

MBSSQLAlchemy, which attempted to make the memory backend work, is removed.

Session hooks are installed on the Session class rather than on the
scoped_session instance - this works better when we're changing from
one database to another at test setup time.
2022-04-26 16:59:59 -04:00
Owen W. Taylor
9c1fc386ff Improve test coverage for MockModuleBuilder
Test coverage for this file improves from 55% => 89%
2022-04-26 16:58:30 -04:00
Owen W. Taylor
48224c7853 MockModuleBuilder: fix an encoding error running under Python 2.7 2022-04-26 16:58:30 -04:00
Owen W. Taylor
f5c7c6b9f4 MockModuleBuilder.py: remove stale code to remove -srpm-stdout.log
This log is no longer generated, since the code was switched to use
Mock SCM.
2022-04-26 16:58:30 -04:00
Owen W. Taylor
0b3df48700 MockModuleBuilder.SCMBuilder: remove unused method 2022-04-26 16:58:30 -04:00
Owen W. Taylor
c35730cb33 MockModuleBuilder: move get_average_build_time() to the right class 2022-04-26 16:58:30 -04:00
Owen W. Taylor
5bb5733e82 MockModuleBuilder: fix repo_name for local repositories 2022-04-26 16:58:30 -04:00
Owen W. Taylor
e06a7e33cd Move 'Connecting to koji <url>' messages to debug 2022-04-25 12:27:02 -04:00
Owen W. Taylor
c1cc9a1a42 Local builds: Don't log 'Getting tag for %s:%s:%s'
Don't log about calling out to koji for a module tag when we don't
actually do so and just use a predictable format.
2022-04-25 12:27:02 -04:00
Owen W. Taylor
53d35e546d Local builds: avoid 'Hub not initialized. Queueing on the side' warnings
We don't need messages at all for local builds, so use a separate "drop"
backend and reserve the "in_memory" backend for tests, where we sometimes
want to inspect the messages. This avoids a warning for each published
message.
2022-04-25 12:27:01 -04:00
Owen W. Taylor
192eefb641 Squash 'Cannot find qpid python module' warnings from Moksha
Importing moksha causes a 'Cannot find qpid python module' warning if
it's not installed, but we don't need the QPid support.
2022-04-25 12:26:06 -04:00
Owen W. Taylor
1f2fbca7d4 Check dnf version before skipping base module conflicts
The base module conflict generation was skipped for local builds
in 6b2e5be93a because libdnf wasn't ported to libmodulemd yet -
that was done in libdnf-0.45, so only warn and skip for versions of
dnf too old to require libdnf-0.45.

(Don't just unconditionally skip check/warning in case someone is
doing local module builds on RHEL 8.)
2022-04-25 12:25:19 -04:00
Owen W. Taylor
c66eca6044 Local builds: fix logging to the module build log file
Ever since local builds were changed to call handlers directly
instead of going through the scheduler, the current module ID wasn't
set, causing no logs to be written to the module build log file.
2022-04-25 12:25:19 -04:00
Brendan Reilly
3a633967ec Merge #1737 Remove Greenwave Code 2022-04-14 19:50:11 +00:00
Brendan Reilly
6cd10004c8 Add default branch configuration option
Fixes: #1735
2022-04-13 10:42:53 -04:00