From eed8db868706e5d70de9f90d8e6acac8f1478c5a Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Jun 03 2020 05:59:55 +0000 Subject: Allow setting --tree-arch and --skip-phase to not build full compose if it is not needed for PR tests. --- diff --git a/cccc/__main__.py b/cccc/__main__.py index f3dbd8d..061897a 100644 --- a/cccc/__main__.py +++ b/cccc/__main__.py @@ -69,6 +69,25 @@ def main(argv=None): help="PR module-defaults repository", ) + odcs_compose_group = parser.add_argument_group( + "ODCS compose configuration arguments") + odcs_compose_group.add_argument( + "--tree-arch", + type=list, + default=[], + required=False, + help="Architecture(s) the ODCS compose is built for.", + dest="tree_arches", + ) + odcs_compose_group.add_argument( + "--skip-phase", + type=list, + default=[], + required=False, + help="Pungi phase(s) skipped in the ODCS compose.", + dest="skip_phases", + ) + args = parser.parse_args(argv) # at least one of the PR arguments is required diff --git a/cccc/cli.py b/cccc/cli.py index 2ed8c2a..a42e4ca 100644 --- a/cccc/cli.py +++ b/cccc/cli.py @@ -124,6 +124,10 @@ def _merge_updated_config(conf, args, merged_dir, scratch_dir): p.set_comps_file_url(args.pr_comps_repo) if args.pr_mod_defaults_repo: p.set_module_defaults_dir_url(args.pr_mod_defaults_repo) + if args.tree_arches: + p.set_tree_arches(args.tree_arches) + if args.skip_phases: + p.skip_phases(args.skip_phases) # write the updated pungi config file with the file name expected by ODCS merged_pungi_config_file = os.path.join(merged_dir, conf["merged_repo_pungi_config"]) diff --git a/cccc/pungi.py b/cccc/pungi.py index 8a179ac..199e5eb 100644 --- a/cccc/pungi.py +++ b/cccc/pungi.py @@ -151,3 +151,21 @@ class PungiConfig(object): :return: None """ self._set_scm_url("module_defaults_dir", url) + + def set_tree_arches(self, arches): + """ + Sets the `tree_arches` configuration option to list `arches`. + + :return: None + """ + self.conf["tree_arches"] = arches + + def skip_phases(self, phases): + """ + Ensures that phases defined in `phases` list are skipped in the compose. + + :return: None + """ + if "skip_phases" not in self.conf: + self.conf["skip_phases"] = [] + self.conf["skip_phases"] = list(set(self.conf["skip_phases"]) | set(phases)) diff --git a/tests/test_cli.py b/tests/test_cli.py index da0e4d9..4937fb2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -27,7 +27,8 @@ class Args(object): """ Simple object to serve as fake argparse.ArgumentParser() object """ - def __init__(self, pr_pungi_repo=None, pr_comps_repo=None, pr_mod_defaults_repo=None): + def __init__(self, pr_pungi_repo=None, pr_comps_repo=None, pr_mod_defaults_repo=None, + tree_arches=None, skip_phases=None): # create attributes for all of the command line arguments self.verbose = None self.debug = None @@ -37,59 +38,86 @@ class Args(object): self.pr_pungi_repo = pr_pungi_repo self.pr_comps_repo = pr_comps_repo self.pr_mod_defaults_repo = pr_mod_defaults_repo + self.tree_arches = tree_arches or [] + self.skip_phases = skip_phases or [] class TestCLI(unittest.TestCase): @parameterized.expand([ - # (testcase_name, pr_pungi_repo, pr_comps_repo, pr_mod_defaults_repo) + # (testcase_name, pr_pungi_repo, pr_comps_repo, pr_mod_defaults_repo, + # tree_arches, skip_phases) ( "none", None, None, None, + None, + None, ), ( "mod_defaults only", None, None, "https://example.com/pr-module-defaults-repo.git", + None, + None, ), ( "comps only", None, "https://example.com/pr-comps-repo.git", None, + None, + None, ), ( "comps+mod_defaults", None, "https://example.com/pr-comps-repo.git", "https://example.com/pr-module-defaults-repo.git", + None, + None, ), ( "pungi only", "https://example.com/pr-pungi-repo.git", None, None, + None, + None, ), ( "pungi+mod_defaults", "https://example.com/pr-pungi-repo.git", None, "https://example.com/pr-module-defaults-repo.git", + None, + None, ), ( "pungi+comps", "https://example.com/pr-pungi-repo.git", "https://example.com/pr-comps-repo.git", None, + None, + None, + ), + ( + "pungi+comps+mod_defaults", + "https://example.com/pr-pungi-repo.git", + "https://example.com/pr-comps-repo.git", + "https://example.com/pr-module-defaults-repo.git", + None, + None, ), ( "pungi+comps+mod_defaults", "https://example.com/pr-pungi-repo.git", "https://example.com/pr-comps-repo.git", "https://example.com/pr-module-defaults-repo.git", + ["x86_64", "ppc64le"], + ["buildinstall"], ), ]) @patch("cccc.compose.generate_compose") @@ -101,6 +129,7 @@ class TestCLI(unittest.TestCase): @patch("cccc.git.clone_repo") def test_cli(self, testcase_name, pr_pungi_repo, pr_comps_repo, pr_mod_defaults_repo, + tree_arches, skip_phases, mock_git_clone, mock_git_newbranch, mock_git_commit, @@ -113,6 +142,8 @@ class TestCLI(unittest.TestCase): pr_pungi_repo=pr_pungi_repo, pr_comps_repo=pr_comps_repo, pr_mod_defaults_repo=pr_mod_defaults_repo, + tree_arches=tree_arches, + skip_phases=skip_phases, ) mock_git_commit.side_effect = [ "commit1", @@ -165,6 +196,36 @@ class TestCLI(unittest.TestCase): else: self.assertEqual(mock_git_merge.call_count, 0) + if tree_arches: + mock_pungi_config.assert_has_calls([ + call().set_tree_arches(args.tree_arches), + ]) + else: + # mock has no direct way to assert that methods are NOT called + try: + mock_pungi_config.assert_has_calls([ + call().set_tree_arches(args.tree_arches), + ]) + raise AssertionError("PungiConfig.set_tree_arches() " + "was called but should NOT have been") + except AssertionError: + pass + + if skip_phases: + mock_pungi_config.assert_has_calls([ + call().skip_phases(args.skip_phases), + ]) + else: + # mock has no direct way to assert that methods are NOT called + try: + mock_pungi_config.assert_has_calls([ + call().skip_phases(args.skip_phases), + ]) + raise AssertionError("PungiConfig.skip_phases() " + "was called but should NOT have been") + except AssertionError: + pass + # PungiConfig.__init__ method should be called twice self.assertEqual(mock_pungi_config.call_count, 2) diff --git a/tests/test_pungi.py b/tests/test_pungi.py index c8daebe..8061aae 100644 --- a/tests/test_pungi.py +++ b/tests/test_pungi.py @@ -49,6 +49,36 @@ class TestPungi(unittest.TestCase): q = PungiConfig(tmpfile) self.assertDictEqual(p.conf, q.conf) + def test_set_tree_arches(self): + """ + Tests that tree_arches can be edited. + """ + p = PungiConfig(os.path.join(DATA_DIR, "c8.conf")) + self.assertEqual( + set(p.conf["tree_arches"]), + set(["ppc64le", "x86_64", "i386", "aarch64"]) + ) + + p.set_tree_arches(["x86_64"]) + self.assertEqual(set(p.conf["tree_arches"]), set(["x86_64"])) + + def test_skip_phases(self): + """ + Tests that skip_phases can be edited. + """ + p = PungiConfig(os.path.join(DATA_DIR, "c8.conf")) + p.skip_phases(["buildinstall", "ostree_installer"]) + self.assertEqual( + set(p.conf["skip_phases"]), + set(["buildinstall", "ostree_installer"]) + ) + + p.skip_phases(["buildinstall", "ostree"]) + self.assertEqual( + set(p.conf["skip_phases"]), + set(["buildinstall", "ostree_installer", "ostree"]) + ) + def test_scm_read(self): """ Tests that a structured config file with our interesting SCM