def test_resolve_requires_siblings(self): tests.clean_database() resolver = mbs_resolver.GenericResolver.create(db_session, conf, backend="db") mmd = load_mmd(tests.read_staged_data("formatted_testmodule")) for i in range(3): build = tests.module_build_from_modulemd(mmd_to_str(mmd)) build.context = "f6e2ae" + str(i) build.build_context = "f6e2aeec7576196241b9afa0b6b22acf2b6873d" + str(i) build.runtime_context = "bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c" + str(i) build.state = models.BUILD_STATES["ready"] db_session.add(build) db_session.commit() build_one = ModuleBuild.get_by_id(db_session, 2) nsvc = ":".join([build_one.name, build_one.stream, build_one.version, build_one.context]) result = resolver.resolve_requires([nsvc]) assert result == { "testmodule": { "stream": build_one.stream, "version": build_one.version, "context": build_one.context, "ref": "65a7721ee4eff44d2a63fb8f3a8da6e944ab7f4d", "koji_tag": None } } db_session.commit()
def test_transform_from_done_to_ready(self, ClientSession, publish): clean_database() # This build should be queried and transformed to ready state module_build = make_module_in_db( "pkg:0.1:1:c1", [{ "requires": { "platform": ["el8"] }, "buildrequires": { "platform": ["el8"] }, }], ) module_build.transition(db_session, conf, BUILD_STATES["done"], "Move to done directly for running test.") db_session.commit() # Assert this call below first_publish_call = call( "module.state.change", module_build.json(db_session, show_tasks=False), conf, "mbs", ) ClientSession.return_value.getBuild.return_value = { "extra": { "typeinfo": { "module": { "module_build_service_id": module_build.id } } } } msg = { "msg_id": "msg-id-1", "topic": "org.fedoraproject.prod.greenwave.decision.update", "msg": { "decision_context": "test_dec_context", "policies_satisfied": True, "subject_identifier": "pkg-0.1-1.c1", }, } hub = Mock(config={"validate_signatures": False}) consumer = MBSConsumer(hub) consumer.consume(msg) db_session.add(module_build) # Load module build again to check its state is moved correctly db_session.refresh(module_build) assert BUILD_STATES["ready"] == module_build.state publish.assert_has_calls([ first_publish_call, call("module.state.change", module_build.json(db_session, show_tasks=False), conf, "mbs"), ])
def test_add_default_modules_request_failed(mock_get_dm): """ Test that an exception is raised when the call to _get_default_modules failed. """ clean_database() make_module_in_db("python:3:12345:1") make_module_in_db("nodejs:11:2345:2") mmd = load_mmd(read_staged_data("formatted_testmodule.yaml")) xmd_brs = mmd.get_xmd()["mbs"]["buildrequires"] assert set(xmd_brs.keys()) == {"platform"} platform = ModuleBuild.get_build_from_nsvc( db_session, "platform", xmd_brs["platform"]["stream"], xmd_brs["platform"]["version"], xmd_brs["platform"]["context"], ) assert platform platform_mmd = platform.mmd() platform_xmd = mmd.get_xmd() platform_xmd["mbs"]["use_default_modules"] = True platform_mmd.set_xmd(platform_xmd) platform.modulemd = mmd_to_str(platform_mmd) db_session.commit() expected_error = "some error" mock_get_dm.side_effect = ValueError(expected_error) with pytest.raises(ValueError, match=expected_error): default_modules.add_default_modules(mmd)
def test_add_default_modules_not_linked(mock_get_dm): """ Test that no default modules are added when they aren't linked from the base module. """ clean_database() mmd = load_mmd(read_staged_data("formatted_testmodule.yaml")) assert set(mmd.get_xmd()["mbs"]["buildrequires"].keys()) == {"platform"} default_modules.add_default_modules(mmd) assert set(mmd.get_xmd()["mbs"]["buildrequires"].keys()) == {"platform"} mock_get_dm.assert_not_called()
def setup_method(self, test_method): self.fn = module_build_service.scheduler.handlers.modules.init testmodule_yml_path = read_staged_data("testmodule_init") mmd = load_mmd(testmodule_yml_path) # Set the name and stream mmd = mmd.copy("testmodule", "1") scmurl = "git://pkgs.domain.local/modules/testmodule?#620ec77" clean_database() ModuleBuild.create(db_session, conf, "testmodule", "1", 3, mmd_to_str(mmd), scmurl, "mprahl")
def test_resolve_profiles_local_module(self, local_builds, conf_system, formatted_testmodule_mmd): tests.clean_database(add_platform_module=False) load_local_builds(["platform:f28"]) resolver = mbs_resolver.GenericResolver.create(db_session, conf, backend="mbs") result = resolver.resolve_profiles(formatted_testmodule_mmd, ("buildroot", "srpm-buildroot")) expected = {"buildroot": {"foo"}, "srpm-buildroot": {"bar"}} assert result == expected
def test_add_default_modules_platform_not_available(): """ Test that an exception is raised when the platform module that is buildrequired is missing. This error should never occur in practice. """ clean_database(False, False) mmd = load_mmd(read_staged_data("formatted_testmodule.yaml")) expected_error = "Failed to retrieve the module platform:f28:3:00000000 from the database" with pytest.raises(RuntimeError, match=expected_error): default_modules.add_default_modules(mmd)
def test_add_default_modules_compatible_platforms(mock_get_dm): """ Test that default modules built against compatible base module streams are added. """ clean_database(add_platform_module=False) # Create compatible base modules. mmd = load_mmd(read_staged_data("platform")) for stream in ["f27", "f28"]: mmd = mmd.copy("platform", stream) # Set the virtual stream to "fedora" to make these base modules compatible. xmd = mmd.get_xmd() xmd["mbs"]["virtual_streams"] = ["fedora"] xmd["mbs"]["use_default_modules"] = True mmd.set_xmd(xmd) import_mmd(db_session, mmd) mmd = load_mmd(read_staged_data("formatted_testmodule.yaml")) xmd_brs = mmd.get_xmd()["mbs"]["buildrequires"] assert set(xmd_brs.keys()) == {"platform"} platform_f27 = ModuleBuild.get_build_from_nsvc( db_session, "platform", "f27", "3", "00000000") assert platform_f27 # Create python default module which requires platform:f27 and therefore cannot be used # as default module for platform:f28. dependencies = [ {"requires": {"platform": ["f27"]}, "buildrequires": {"platform": ["f27"]}}] make_module_in_db("python:3:12345:1", base_module=platform_f27, dependencies=dependencies) # Create nodejs default module which requries any platform stream and therefore can be used # as default module for platform:f28. dependencies[0]["requires"]["platform"] = [] make_module_in_db("nodejs:11:2345:2", base_module=platform_f27, dependencies=dependencies) db_session.commit() mock_get_dm.return_value = { "nodejs": "11", "python": "3", "ruby": "2.6", } defaults_added = default_modules.add_default_modules(mmd) # Make sure that the default modules were added. ruby:2.6 will be ignored since it's not in # the database assert set(mmd.get_xmd()["mbs"]["buildrequires"].keys()) == {"nodejs", "platform"} mock_get_dm.assert_called_once_with( "f28", "https://pagure.io/releng/fedora-module-defaults.git", ) assert defaults_added is True
def test_import_mmd_base_module(stream, disttag_marking, error_msg): clean_database(add_platform_module=False) mmd = load_mmd(read_staged_data("platform")) mmd = mmd.copy(mmd.get_module_name(), stream) if disttag_marking: xmd = mmd.get_xmd() xmd["mbs"]["disttag_marking"] = disttag_marking mmd.set_xmd(xmd) if error_msg: with pytest.raises(UnprocessableEntity, match=error_msg): import_mmd(db_session, mmd) else: import_mmd(db_session, mmd)
def test_send_messages_after_several_state_transitions(mock_publish): """ Ensure all module build state change messages are sent after multiple ModuleBuild.transitions are committed at once """ clean_database() build = make_module_in_db("testmodule:1:2:c3") build.transition(db_session, conf, models.BUILD_STATES["wait"]) build.transition(db_session, conf, models.BUILD_STATES["done"]) assert 0 == mock_publish.call_count db_session.commit() assert 2 == mock_publish.call_count
def test_get_buildrequired_modulemds_local_builds(self, local_builds, conf_system): tests.clean_database() with app.app_context(): load_local_builds(["testmodule"]) resolver = mbs_resolver.GenericResolver.create(db_session, conf, backend="mbs") result = resolver.get_buildrequired_modulemds( "testmodule", "master", "platform:f28:1:00000000") assert 1 == len(result) mmd = result[0] assert "testmodule" == mmd.get_module_name() assert "master" == mmd.get_stream_name() assert 20170816080816 == mmd.get_version() assert "321" == mmd.get_context()
def test_add_default_modules(mock_get_dm, mock_hc): """ Test that default modules present in the database are added, and the others are ignored. """ clean_database() mmd = load_mmd(read_staged_data("formatted_testmodule.yaml")) xmd_brs = mmd.get_xmd()["mbs"]["buildrequires"] assert set(xmd_brs.keys()) == {"platform"} platform = ModuleBuild.get_build_from_nsvc( db_session, "platform", xmd_brs["platform"]["stream"], xmd_brs["platform"]["version"], xmd_brs["platform"]["context"], ) assert platform platform_mmd = platform.mmd() platform_xmd = mmd.get_xmd() platform_xmd["mbs"]["use_default_modules"] = True platform_mmd.set_xmd(platform_xmd) platform.modulemd = mmd_to_str(platform_mmd) dependencies = [ {"requires": {"platform": ["f28"]}, "buildrequires": {"platform": ["f28"]}}] make_module_in_db("python:3:12345:1", base_module=platform, dependencies=dependencies) make_module_in_db("nodejs:11:2345:2", base_module=platform, dependencies=dependencies) db_session.commit() mock_get_dm.return_value = { "nodejs": "11", "python": "3", "ruby": "2.6", } defaults_added = default_modules.add_default_modules(mmd) # Make sure that the default modules were added. ruby:2.6 will be ignored since it's not in # the database assert set(mmd.get_xmd()["mbs"]["buildrequires"].keys()) == {"nodejs", "platform", "python"} mock_get_dm.assert_called_once_with( "f28", "https://pagure.io/releng/fedora-module-defaults.git", ) assert "ursine_rpms" not in mmd.get_xmd()["mbs"] assert defaults_added is True
def setup_method(self): clean_database() self.tmp_srpm_build_dir = tempfile.mkdtemp(prefix="test-koji-builder-") self.spec_file = os.path.join(self.tmp_srpm_build_dir, "module-build-macros.spec") self.srpms_dir = os.path.join(self.tmp_srpm_build_dir, "SRPMS") os.mkdir(self.srpms_dir) self.expected_srpm_file = os.path.join(self.srpms_dir, "module-build-macros.src.rpm") # Don't care about the content, just assert the existence. with open(self.expected_srpm_file, "w") as f: f.write("") self.module_nsvc = dict( name="testmodule", stream="master", version="1", context=module_build_service.common.models.DEFAULT_MODULE_CONTEXT, ) self.xmd = { "mbs": { "buildrequires": { "modulea": { "filtered_rpms": ["baz-devel-0:0.1-6.fc28", "baz-doc-0:0.1-6.fc28"] }, "platform": { "filtered_rpms": [], "stream_collision_modules": ["modulefoo-s-v-c"], "ursine_rpms": ["foo-0:1.0-1.fc28", "bar-0:2.0-1.fc28"], }, }, "ursine_rpms": ["pizza-0:4.0-1.fc32", "spaghetti-0:3.0-1.fc32"], "koji_tag": "module-{name}-{stream}-{version}-{context}".format( **self.module_nsvc), } }
def test_monitor_state_changing_success(succ_cnt, failed_cnt): clean_database(add_platform_module=False, add_default_arches=False) b = make_module_in_db( "pkg:0.1:1:c1", [{ "requires": { "platform": ["el8"] }, "buildrequires": { "platform": ["el8"] }, }], ) b.transition(db_session, conf, models.BUILD_STATES["wait"]) b.transition(db_session, conf, models.BUILD_STATES["build"]) b.transition(db_session, conf, models.BUILD_STATES["done"]) db_session.commit() succ_cnt.assert_called_once() failed_cnt.assert_not_called()
def model_tests_init_data(): """Initialize data for model tests This is refactored from tests/test_models/__init__.py, which was able to be called directly inside setup_method generally. The reason to convert it to this fixture 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. """ clean_database() model_test_data_dir = os.path.join(os.path.dirname(__file__), "test_common", "test_models", "data") for filename in os.listdir(model_test_data_dir): with open(os.path.join(model_test_data_dir, filename), "r") as f: yaml = f.read() build = module_build_from_modulemd(yaml) db_session.add(build) db_session.commit()
def setup_method(self, test_method): clean_database() # Do not allow flask_script exits by itself because we have to assert # something after the command finishes. self.sys_exit_patcher = patch("sys.exit") self.mock_sys_exit = self.sys_exit_patcher.start() # The consumer is not required to run actually, so it does not make # sense to publish message after creating a module build. self.publish_patcher = patch( "module_build_service.common.messaging.publish") self.mock_publish = self.publish_patcher.start() # Don't allow conf.set_item call to modify conf actually inside command self.set_item_patcher = patch( "module_build_service.manage.conf.set_item") self.mock_set_item = self.set_item_patcher.start() # Avoid to create the local sqlite database for the command, which is # useless for running tests here. self.create_all_patcher = patch( "module_build_service.manage.db.create_all") self.mock_create_all = self.create_all_patcher.start()
def test_format_mmd_arches(self, mocked_scm): with app.app_context(): clean_database() mocked_scm.return_value.commit = "620ec77321b2ea7b0d67d82992dda3e1d67055b4" mocked_scm.return_value.get_latest.side_effect = [ "4ceea43add2366d8b8c5a622a2fb563b625b9abf", "fbed359411a1baa08d4a88e0d12d426fbf8f602c", "dbed259411a1baa08d4a88e0d12d426fbf8f6037", "4ceea43add2366d8b8c5a622a2fb563b625b9abf", "fbed359411a1baa08d4a88e0d12d426fbf8f602c", "dbed259411a1baa08d4a88e0d12d426fbf8f6037", ] testmodule_mmd_path = staged_data_filename("testmodule.yaml") test_archs = ["powerpc", "i486"] mmd1 = load_mmd_file(testmodule_mmd_path) format_mmd(mmd1, None) for pkg_name in mmd1.get_rpm_component_names(): pkg = mmd1.get_rpm_component(pkg_name) assert set(pkg.get_arches()) == set(conf.arches) mmd2 = load_mmd_file(testmodule_mmd_path) for pkg_name in mmd2.get_rpm_component_names(): pkg = mmd2.get_rpm_component(pkg_name) pkg.reset_arches() for arch in test_archs: pkg.add_restricted_arch(arch) format_mmd(mmd2, None) for pkg_name in mmd2.get_rpm_component_names(): pkg = mmd2.get_rpm_component(pkg_name) assert set(pkg.get_arches()) == set(test_archs)
def teardown_method(self, test_method): clean_database() shutil.rmtree(self.resultdir)
def setup_method(self): clean_database() events.scheduler.reset()
def teardown_method(self): clean_database() events.scheduler.reset()
def teardown_method(self): shutil.rmtree(self.tmp_srpm_build_dir) clean_database()
def setup_method(self, method): clean_database()
def create_database(request): """Drop and recreate all tables""" clean_database(add_platform_module=False, add_default_arches=False)
def teardown_method(self, test_method): self.p_read_config.stop() clean_database()
def setup_method(self, test_method): clean_database() self.resultdir = tempfile.mkdtemp()
def setup_method(self): clean_database(False)
def setup_method(self, test_method): clean_database(False)
def reuse_component_init_data(): clean_database() mmd = load_mmd(read_staged_data("formatted_testmodule")) build_one = module_build_service.common.models.ModuleBuild( name="testmodule", stream="master", version='20170109091357', state=BUILD_STATES["ready"], runtime_context="ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0", build_context="ac4de1c346dcf09ce77d38cd4e75094ec1c08eb1", context="78e4a6fd", koji_tag="module-testmodule-master-20170109091357-78e4a6fd", scmurl= "https://src.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79", batch=3, owner="Tom Brady", time_submitted=datetime(2017, 2, 15, 16, 8, 18), time_modified=datetime(2017, 2, 15, 16, 19, 35), time_completed=datetime(2017, 2, 15, 16, 19, 35), rebuild_strategy="changed-and-after", ) build_one_component_release = get_rpm_release(db_session, build_one) mmd.set_version(int(build_one.version)) xmd = mmd.get_xmd() xmd["mbs"]["scmurl"] = build_one.scmurl xmd["mbs"]["commit"] = "ff1ea79fc952143efeed1851aa0aa006559239ba" mmd.set_xmd(xmd) build_one.modulemd = mmd_to_str(mmd) contexts = module_build_service.common.models.ModuleBuild.contexts_from_mmd( build_one.modulemd) build_one.build_context = contexts.build_context build_one.build_context_no_bms = contexts.build_context_no_bms db_session.add(build_one) db_session.commit() db_session.refresh(build_one) platform_br = module_build_service.common.models.ModuleBuild.get_by_id( db_session, 1) build_one.buildrequires.append(platform_br) arch = db_session.query( module_build_service.common.models.ModuleArch).get(1) build_one.arches.append(arch) db_session.add_all([ module_build_service.common.models.ComponentBuild( module_id=build_one.id, package="perl-Tangerine", scmurl="https://src.fedoraproject.org/rpms/perl-Tangerine" "?#4ceea43add2366d8b8c5a622a2fb563b625b9abf", format="rpms", task_id=90276227, state=koji.BUILD_STATES["COMPLETE"], nvr="perl-Tangerine-0.23-1.{0}".format( build_one_component_release), batch=2, ref="4ceea43add2366d8b8c5a622a2fb563b625b9abf", tagged=True, tagged_in_final=True, ), module_build_service.common.models.ComponentBuild( module_id=build_one.id, package="perl-List-Compare", scmurl="https://src.fedoraproject.org/rpms/perl-List-Compare" "?#76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb", format="rpms", task_id=90276228, state=koji.BUILD_STATES["COMPLETE"], nvr="perl-List-Compare-0.53-5.{0}".format( build_one_component_release), batch=2, ref="76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb", tagged=True, tagged_in_final=True, ), module_build_service.common.models.ComponentBuild( module_id=build_one.id, package="tangerine", scmurl="https://src.fedoraproject.org/rpms/tangerine" "?#fbed359411a1baa08d4a88e0d12d426fbf8f602c", format="rpms", task_id=90276315, state=koji.BUILD_STATES["COMPLETE"], nvr="tangerine-0.22-3.{0}".format(build_one_component_release), batch=3, ref="fbed359411a1baa08d4a88e0d12d426fbf8f602c", tagged=True, tagged_in_final=True, ), module_build_service.common.models.ComponentBuild( module_id=build_one.id, package="module-build-macros", scmurl= "/tmp/module_build_service-build-macrosqr4AWH/SRPMS/module-build-" "macros-0.1-1.module_testmodule_master_20170109091357.src.rpm", format="rpms", task_id=90276181, state=koji.BUILD_STATES["COMPLETE"], nvr="module-build-macros-0.1-1.{0}".format( build_one_component_release), batch=1, tagged=True, build_time_only=True, ), ]) # Commit component builds added to build_one db_session.commit() build_two = module_build_service.common.models.ModuleBuild( name="testmodule", stream="master", version='20170219191323', state=BUILD_STATES["build"], runtime_context="ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0", build_context="ac4de1c346dcf09ce77d38cd4e75094ec1c08eb1", context="c40c156c", koji_tag="module-testmodule-master-20170219191323-c40c156c", scmurl= "https://src.stg.fedoraproject.org/modules/testmodule.git?#55f4a0a", batch=1, owner="Tom Brady", time_submitted=datetime(2017, 2, 19, 16, 8, 18), time_modified=datetime(2017, 2, 19, 16, 8, 18), rebuild_strategy="changed-and-after", ) build_two_component_release = get_rpm_release(db_session, build_two) mmd.set_version(int(build_one.version)) xmd = mmd.get_xmd() xmd["mbs"]["scmurl"] = build_one.scmurl xmd["mbs"]["commit"] = "55f4a0a2e6cc255c88712a905157ab39315b8fd8" mmd.set_xmd(xmd) build_two.modulemd = mmd_to_str(mmd) contexts = module_build_service.common.models.ModuleBuild.contexts_from_mmd( build_two.modulemd) build_two.build_context = contexts.build_context build_two.build_context_no_bms = contexts.build_context_no_bms db_session.add(build_two) db_session.commit() db_session.refresh(build_two) build_two.arches.append(arch) build_two.buildrequires.append(platform_br) db_session.add_all([ module_build_service.common.models.ComponentBuild( module_id=build_two.id, package="perl-Tangerine", scmurl="https://src.fedoraproject.org/rpms/perl-Tangerine" "?#4ceea43add2366d8b8c5a622a2fb563b625b9abf", format="rpms", batch=2, ref="4ceea43add2366d8b8c5a622a2fb563b625b9abf", ), module_build_service.common.models.ComponentBuild( module_id=build_two.id, package="perl-List-Compare", scmurl="https://src.fedoraproject.org/rpms/perl-List-Compare" "?#76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb", format="rpms", batch=2, ref="76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb", ), module_build_service.common.models.ComponentBuild( module_id=build_two.id, package="tangerine", scmurl="https://src.fedoraproject.org/rpms/tangerine" "?#fbed359411a1baa08d4a88e0d12d426fbf8f602c", format="rpms", batch=3, ref="fbed359411a1baa08d4a88e0d12d426fbf8f602c", ), module_build_service.common.models.ComponentBuild( module_id=build_two.id, package="module-build-macros", scmurl= "/tmp/module_build_service-build-macrosqr4AWH/SRPMS/module-build-" "macros-0.1-1.module_testmodule_master_20170219191323.src.rpm", format="rpms", task_id=90276186, state=koji.BUILD_STATES["COMPLETE"], nvr="module-build-macros-0.1-1.{0}".format( build_two_component_release), batch=1, tagged=True, build_time_only=True, ), ]) db_session.commit()
def teardown_method(self, test_method): clean_database()
def teardown_method(self): clean_database()