| |
@@ -0,0 +1,112 @@
|
| |
+ import copy
|
| |
+ import pytest
|
| |
+
|
| |
+
|
| |
+ def extracted_test_method(repo, pkg_util,
|
| |
+ rebuild_strategy,
|
| |
+ first_build_rpms, second_build_rpms,
|
| |
+ expected_reused, expected_rebuilt):
|
| |
+ """
|
| |
+ :param utils.Repo repo: repo fixture
|
| |
+ :param utils.PackagingUtility pkg_util: pkg_util fixture
|
| |
+ :param str rebuild_strategy: rebuild strategy for the 2nd build
|
| |
+ :param dict first_build_rpms: dictionary of RPMs (modulemd format)
|
| |
+ :param dict second_build_rpms: dictionary of RPMs (modulemd format)
|
| |
+ :param dict expected_reused: dictionary of RPMs (modulemd format)
|
| |
+ :param dict expected_rebuilt: dictionary of RPMs (modulemd format)
|
| |
+
|
| |
+ Prerequisites:
|
| |
+ EMPTY (no components/RPMs) module MD file
|
| |
+ Steps:
|
| |
+ 1) Make changes to the modulemd according to test scenario (first build)
|
| |
+ 2) Make a clean build (rebuild strategy : all).
|
| |
+ 3) Add/remove RPMs according to test scenario (second build)
|
| |
+ 4) Rebuild, rebuild strategy according to test scenario
|
| |
+ 5) Revert the initial change.
|
| |
+ """
|
| |
+ # Save initial state
|
| |
+ original_metadata = repo.modulemd
|
| |
+
|
| |
+ # Prepare initial build metadata & push
|
| |
+ tmp_metadata = copy.deepcopy(original_metadata)
|
| |
+ tmp_metadata["data"]["components"]["rpms"] = first_build_rpms
|
| |
+ repo.write_to_modulemd(tmp_metadata)
|
| |
+ repo.add_all_commit_and_push(f'Add "{first_build_rpms.keys()}"')
|
| |
+
|
| |
+ try:
|
| |
+ # Make an initial build (to be later reused)
|
| |
+ builds = pkg_util.run("--watch", "--optional", "rebuild_strategy=all")
|
| |
+ assert len(builds) == 1, "Initial build failed!"
|
| |
+
|
| |
+ # Prepare 2nd build metadata & push
|
| |
+ tmp_metadata["data"]["components"]["rpms"] = second_build_rpms
|
| |
+ repo.write_to_modulemd(tmp_metadata)
|
| |
+ repo.add_all_commit_and_push(f'Add "{second_build_rpms.keys()}"')
|
| |
+
|
| |
+ # Make a new build
|
| |
+ builds = pkg_util.run("--watch", "--optional", f"rebuild_strategy={rebuild_strategy}")
|
| |
+ assert len(builds) == 1, "Second (re)build failed!"
|
| |
+
|
| |
+ build = builds[0]
|
| |
+ # we don"t care about module-build-macros
|
| |
+ build_components = [c for c in build.components() if c["package"] != "module-build-macros"]
|
| |
+
|
| |
+ # Partition components by "reused" state - package name only
|
| |
+ reused_msg = "Reused component from previous module build"
|
| |
+ actually_reused = {
|
| |
+ c["package"] for c in build_components if c["state_reason"] == reused_msg
|
| |
+ }
|
| |
+ actually_rebuilt = {
|
| |
+ c["package"] for c in build_components if c["state_reason"] != reused_msg
|
| |
+ }
|
| |
+
|
| |
+ assert actually_reused == expected_reused.keys()
|
| |
+ assert actually_rebuilt == expected_rebuilt.keys()
|
| |
+
|
| |
+ finally: # Revert the change
|
| |
+ repo.write_to_modulemd(original_metadata)
|
| |
+ repo.add_all_commit_and_push(f"Revert to empty md file")
|
| |
+
|
| |
+
|
| |
+ # Same test logic is split into 2 methods (different repositories) to enable parallel execution.
|
| |
+ # In case of more scenarios and longer execution times, split into more functions.
|
| |
+ def test_reuse_components_if_added(pkg_util, test_env, scenario, repo):
|
| |
+ """
|
| |
+ Test case wrapper for parametrization based on test.env.yaml
|
| |
+ """
|
| |
+ test_rpms = test_env.get("testdata").get("rpms")
|
| |
+ if not test_rpms:
|
| |
+ pytest.skip("No RPMs in test.env.yaml: ['testdata']['rpms']")
|
| |
+ if not scenario.get('scenarios'):
|
| |
+ pytest.skip("No scenarios for test branch '{}'".format(scenario["branch"]))
|
| |
+
|
| |
+ for index, test_scenario in enumerate(scenario['scenarios']):
|
| |
+ try:
|
| |
+ first_build_rpms = [test_rpms[i] for i in test_scenario["first_build"]]
|
| |
+ first_build_rpms = {k: v for rpm in first_build_rpms for k, v in rpm.items()}
|
| |
+
|
| |
+ second_build_rpms = [test_rpms[i] for i in test_scenario["second_build"]]
|
| |
+ second_build_rpms = {k: v for rpm in second_build_rpms for k, v in rpm.items()}
|
| |
+
|
| |
+ expected_reused = [test_rpms[i] for i in test_scenario["expected_reused"]]
|
| |
+ expected_reused = {k: v for rpm in expected_reused for k, v in rpm.items()}
|
| |
+
|
| |
+ expected_rebuilt = [test_rpms[i] for i in test_scenario["expected_rebuilt"]]
|
| |
+ expected_rebuilt = {k: v for rpm in expected_rebuilt for k, v in rpm.items()}
|
| |
+
|
| |
+ rebuild_strategy = test_scenario["rebuild_strategy"]
|
| |
+ except IndexError:
|
| |
+ pytest.skip(f"Index error, see test.env.yaml '{scenario['branch']}', scenario {index}")
|
| |
+ else:
|
| |
+ # TC itself
|
| |
+ extracted_test_method(repo, pkg_util, rebuild_strategy,
|
| |
+ first_build_rpms, second_build_rpms,
|
| |
+ expected_reused, expected_rebuilt)
|
| |
+
|
| |
+
|
| |
+ def test_reuse_components_if_removed(pkg_util, test_env, scenario, repo):
|
| |
+ """
|
| |
+ Test case wrapper for parametrization based on test.env.yaml
|
| |
+ """
|
| |
+
|
| |
+ test_reuse_components_if_added(pkg_util, test_env, scenario, repo)
|
| |
FACTORY-6005: add test_reuse_components_if_added
This is testing: https://pagure.io/fm-orchestrator/pull-request/1475#