mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-23 18:21:42 +08:00
Rewrite import_mmd
* xmd/mbs is always set if it is not present in xmd, so move the code on the top of function. This change is also helpful for accessing keys under xmd/mbs. * By setting xmd/mbs in the beginning, code is simplified to get disttag_marking and virtual_streams. The result is much straightforwar for getting a default value for them. * Move disttag_marking validation code next to the line getting disttag_marking from xmd/mbs. As a result, the code structure is easier to read as getting disttag_marking and validate it, getting virtual_streams and validate. * Rewrite the part of code for check_buildrequires. Always set xmd/mbs/buildrequires if it is not present and check_buildrequires is set to True, as it is required by ModuleBuild.get_buildrequired_base_modules. * Using in operator instead of dict.get to check if key koji_tag exists. Using dict.get would be ambiguous because even if koji_tag exists under xmd/mbs, but due to its value is set to None occasionally, there is still a message logged to tell koji_tag is not set. * Rwrite all lines of code for updating virtual streams. A new method update_virtual_streams is added to ModuleBuild. This also fixes FACTORY-4561. * Tests are added for the rewrite of virtual streams update. Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
@@ -455,6 +455,63 @@ class TestUtils:
|
||||
else:
|
||||
module_build_service.utils.import_mmd(db_session, mmd)
|
||||
|
||||
def test_import_mmd_remove_dropped_virtual_streams(self, db_session):
|
||||
mmd = load_mmd(read_staged_data("formatted_testmodule"))
|
||||
|
||||
# Add some virtual streams
|
||||
xmd = mmd.get_xmd()
|
||||
xmd["mbs"]["virtual_streams"] = ["f28", "f29", "f30"]
|
||||
mmd.set_xmd(xmd)
|
||||
|
||||
# Import mmd into database to simulate the next step to reimport a module
|
||||
module_build_service.utils.general.import_mmd(db_session, mmd)
|
||||
|
||||
# Now, remove some virtual streams from module metadata
|
||||
xmd = mmd.get_xmd()
|
||||
xmd["mbs"]["virtual_streams"] = ["f28", "f29"] # Note that, f30 is removed
|
||||
mmd.set_xmd(xmd)
|
||||
|
||||
# Test import modulemd again and the f30 should be removed from database.
|
||||
module_build, _ = module_build_service.utils.general.import_mmd(db_session, mmd)
|
||||
|
||||
db_session.refresh(module_build)
|
||||
assert ["f28", "f29"] == sorted(item.name for item in module_build.virtual_streams)
|
||||
assert 0 == db_session.query(models.VirtualStream).filter_by(name="f30").count()
|
||||
|
||||
def test_import_mmd_dont_remove_dropped_virtual_streams_associated_with_other_modules(
|
||||
self, db_session
|
||||
):
|
||||
mmd = load_mmd(read_staged_data("formatted_testmodule"))
|
||||
# Add some virtual streams to this module metadata
|
||||
xmd = mmd.get_xmd()
|
||||
xmd["mbs"]["virtual_streams"] = ["f28", "f29", "f30"]
|
||||
mmd.set_xmd(xmd)
|
||||
module_build_service.utils.general.import_mmd(db_session, mmd)
|
||||
|
||||
# Import another module which has overlapping virtual streams
|
||||
another_mmd = load_mmd(read_staged_data("formatted_testmodule-more-components"))
|
||||
# Add some virtual streams to this module metadata
|
||||
xmd = another_mmd.get_xmd()
|
||||
xmd["mbs"]["virtual_streams"] = ["f29", "f30"]
|
||||
another_mmd.set_xmd(xmd)
|
||||
another_module_build, _ = module_build_service.utils.general.import_mmd(
|
||||
db_session, another_mmd)
|
||||
|
||||
# Now, remove f30 from mmd
|
||||
xmd = mmd.get_xmd()
|
||||
xmd["mbs"]["virtual_streams"] = ["f28", "f29"]
|
||||
mmd.set_xmd(xmd)
|
||||
|
||||
# Reimport formatted_testmodule again
|
||||
module_build, _ = module_build_service.utils.general.import_mmd(db_session, mmd)
|
||||
|
||||
db_session.refresh(module_build)
|
||||
assert ["f28", "f29"] == sorted(item.name for item in module_build.virtual_streams)
|
||||
|
||||
# The overlapped f30 should be still there.
|
||||
db_session.refresh(another_module_build)
|
||||
assert ["f29", "f30"] == sorted(item.name for item in another_module_build.virtual_streams)
|
||||
|
||||
def test_get_rpm_release_mse(self, db_session):
|
||||
init_data(contexts=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user