From b9884b1cf7a5f63a06c0c74b135d1e4a171ff84b Mon Sep 17 00:00:00 2001 From: Vallari Agrawal Date: Tue, 1 Jul 2025 20:42:53 +0530 Subject: [PATCH] tests: add unit test test_update_key and test_sha1 Signed-off-by: Vallari Agrawal --- teuthology/suite/test/test_run_.py | 28 ++++++++++++++++++++++++++++ teuthology/test/test_misc.py | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/teuthology/suite/test/test_run_.py b/teuthology/suite/test/test_run_.py index a8a0aaaa93..3459e79ad8 100644 --- a/teuthology/suite/test/test_run_.py +++ b/teuthology/suite/test/test_run_.py @@ -205,12 +205,40 @@ class TestRun(object): del self.args['distro'] run_ = run.Run(self.args) run_.base_args = run_.build_base_args() + run_.base_config = run_.build_base_config() configs = [ ["desc", [], {"os_type": "debian", "os_version": "8.0"}], + ["desc", [], {"os_type": "ubuntu", "os_version": "24.0"}], ] missing, to_schedule = run_.collect_jobs('x86_64', configs, False, False) assert to_schedule[0]['yaml']['os_type'] == "debian" assert to_schedule[0]['yaml']['os_version'] == "8.0" + assert to_schedule[1]['yaml']['os_type'] == "ubuntu" + assert to_schedule[1]['yaml']['os_version'] == "24.0" + + @patch('teuthology.suite.run.util.fetch_repos') + @patch('teuthology.suite.util.git_ls_remote') + @patch('teuthology.suite.run.util.package_version_for_hash') + def test_sha1(self, m_pvfh, m_git_ls_remote, m_fetch_repos): + m_git_ls_remote.return_value = "sha1" + del self.args['distro'] + run_ = run.Run(self.args) + run_.base_args = run_.build_base_args() + for i in range(5): # mock backtracking + run_.config_input['ceph_hash'] = f"boo{i}" + run_.config_input['suite_hash'] = f"bar{i}" + run_.base_config = run_.build_base_config() + configs = [ + ["desc", [], {"os_type": "debian", "os_version": "8.0", + "sha1": "old_sha", "suite_sha1": "old_sha", + "overrides": { "workunit": {"sha1": "old_sha"}, "ceph": {"sha1": "old_sha"} } + }], + ] + missing, to_schedule = run_.collect_jobs('x86_64', configs, False, False) + assert to_schedule[0]['yaml']['sha1'] == "boo4" + assert to_schedule[0]['yaml']['suite_sha1'] == "bar4" + assert to_schedule[0]['yaml']['overrides']['workunit']["sha1"] == "bar4" + assert to_schedule[0]['yaml']['overrides']['ceph']["sha1"] == "boo4" class TestScheduleSuite(object): klass = run.Run diff --git a/teuthology/test/test_misc.py b/teuthology/test/test_misc.py index f2a6ebfb81..ca7533643d 100644 --- a/teuthology/test/test_misc.py +++ b/teuthology/test/test_misc.py @@ -242,6 +242,13 @@ def test_split_role(): actual_split = misc.split_role(role) assert actual_split == expected_split +def test_update_key(): + a = { "sha": "foo", "workunit": { "sha": "foo" }, "tasks": [{"task1": "ceph"}], "overrides": [{"sha": "foo"}] } + b = { "sha": "blah", "workunit": { "sha": "bar" }, "tasks": [] } + + misc.update_key("sha", a, b) + assert a == { "sha": "blah", "workunit": { "sha": "bar" }, "tasks": [{"task1": "ceph"}], "overrides": [{"sha": "foo"}] } + class TestHostnames(object): def setup_method(self): config._conf = dict() -- 2.39.5