From 47b7862c56ff87cfccb6ca05c5d366611d85bc5f Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 15 Mar 2023 15:54:28 -0600 Subject: [PATCH] Fix more circular imports Signed-off-by: Zack Cerza --- teuthology/dispatcher/__init__.py | 6 +++--- teuthology/nuke/__init__.py | 8 ++++---- teuthology/task/ansible.py | 5 +++-- teuthology/test/task/test_ansible.py | 10 +++++----- teuthology/test/test_worker.py | 16 ++++++++-------- teuthology/worker.py | 28 +++++++++++++++++----------- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/teuthology/dispatcher/__init__.py b/teuthology/dispatcher/__init__.py index 3d31a1f2a5..b6b03dd5a9 100644 --- a/teuthology/dispatcher/__init__.py +++ b/teuthology/dispatcher/__init__.py @@ -16,13 +16,13 @@ from teuthology import ( beanstalk, nuke, report, + repo_utils, worker, ) from teuthology.config import config as teuth_config from teuthology.dispatcher import supervisor from teuthology.exceptions import SkipJob from teuthology.lock import ops as lock_ops -from teuthology.repo_utils import fetch_qa_suite, fetch_teuthology from teuthology import safepath log = logging.getLogger(__name__) @@ -100,8 +100,8 @@ def main(args): result_proc = None if teuth_config.teuthology_path is None: - fetch_teuthology('main') - fetch_qa_suite('main') + repo_utils.fetch_teuthology('main') + repo_utils.fetch_qa_suite('main') keep_running = True job_procs = set() diff --git a/teuthology/nuke/__init__.py b/teuthology/nuke/__init__.py index 77d48ccc00..25f145c65d 100644 --- a/teuthology/nuke/__init__.py +++ b/teuthology/nuke/__init__.py @@ -30,7 +30,7 @@ from teuthology.misc import ( from teuthology.openstack import OpenStack, OpenStackInstance, enforce_json_dictionary from teuthology.orchestra.remote import Remote from teuthology.parallel import parallel -from teuthology.task.internal import check_lock, add_remotes, connect +from teuthology.task import internal log = logging.getLogger(__name__) @@ -314,7 +314,7 @@ def nuke_helper(ctx, should_unlock, keep_logs, should_reboot): if ctx.check_locks: # does not check to ensure if the node is 'up' # we want to be able to nuke a downed node - check_lock.check_lock(ctx, None, check_up=False) + internal.check_lock.check_lock(ctx, None, check_up=False) status = get_status(host) if status['machine_type'] in provision.fog.get_types(): remote.console.power_off() @@ -337,8 +337,8 @@ def nuke_helper(ctx, should_unlock, keep_logs, should_reboot): log.info("Will attempt to connect via SSH") remote = Remote(host) remote.connect() - add_remotes(ctx, None) - connect(ctx, None) + internal.add_remotes(ctx, None) + internal.connect(ctx, None) clear_firewall(ctx) shutdown_daemons(ctx) kill_valgrind(ctx) diff --git a/teuthology/task/ansible.py b/teuthology/task/ansible.py index 8dd20c3203..23453c1238 100644 --- a/teuthology/task/ansible.py +++ b/teuthology/task/ansible.py @@ -8,15 +8,16 @@ import shutil from tempfile import mkdtemp, NamedTemporaryFile +from teuthology import repo_utils from teuthology.config import config as teuth_config from teuthology.exceptions import CommandFailedError, AnsibleFailedError from teuthology.job_status import set_status -from teuthology.repo_utils import fetch_repo from teuthology.task import Task log = logging.getLogger(__name__) + class LoggerFile(object): """ A thin wrapper around a logging.Logger instance that provides a file-like @@ -141,7 +142,7 @@ class Ansible(Task): """ repo = self.config.get('repo', '.') if repo.startswith(('http://', 'https://', 'git@', 'git://')): - repo_path = fetch_repo( + repo_path = repo_utils.fetch_repo( repo, self.config.get('branch', 'main'), ) diff --git a/teuthology/test/task/test_ansible.py b/teuthology/test/task/test_ansible.py index 745b2723bd..eb98fc378d 100644 --- a/teuthology/test/task/test_ansible.py +++ b/teuthology/test/task/test_ansible.py @@ -121,7 +121,7 @@ class TestAnsibleTask(TestTask): task.find_repo() assert task.repo_path == os.path.expanduser(self.task_config['repo']) - @patch('teuthology.task.ansible.fetch_repo') + @patch('teuthology.repo_utils.fetch_repo') def test_find_repo_path_remote(self, m_fetch_repo): self.task_config.update(dict( repo='git://fake_host/repo.git', @@ -131,7 +131,7 @@ class TestAnsibleTask(TestTask): task.find_repo() assert task.repo_path == os.path.expanduser('/tmp/repo') - @patch('teuthology.task.ansible.fetch_repo') + @patch('teuthology.repo_utils.fetch_repo') def test_find_repo_http(self, m_fetch_repo): self.task_config.update(dict( repo='http://example.com/my/repo', @@ -141,7 +141,7 @@ class TestAnsibleTask(TestTask): m_fetch_repo.assert_called_once_with(self.task_config['repo'], 'main') - @patch('teuthology.task.ansible.fetch_repo') + @patch('teuthology.repo_utils.fetch_repo') def test_find_repo_git(self, m_fetch_repo): self.task_config.update(dict( repo='git@example.com/my/repo', @@ -521,7 +521,7 @@ class TestCephLabTask(TestAnsibleTask): def start_patchers(self): super(TestCephLabTask, self).start_patchers() self.patchers['fetch_repo'] = patch( - 'teuthology.task.ansible.fetch_repo', + 'teuthology.repo_utils.fetch_repo', ) self.patchers['fetch_repo'].return_value = 'PATH' @@ -536,7 +536,7 @@ class TestCephLabTask(TestAnsibleTask): for name in self.patchers.keys(): self.start_patcher(name) - @patch('teuthology.task.ansible.fetch_repo') + @patch('teuthology.repo_utils.fetch_repo') def test_find_repo_http(self, m_fetch_repo): repo = os.path.join(config.ceph_git_base_url, 'ceph-cm-ansible.git') diff --git a/teuthology/test/test_worker.py b/teuthology/test/test_worker.py index 97a4d738d8..1fe9d57b00 100644 --- a/teuthology/test/test_worker.py +++ b/teuthology/test/test_worker.py @@ -177,11 +177,11 @@ class TestWorker(object): worker.run_with_watchdog(process, config) m_symlink_log.assert_called_with(config["worker_log"], config["archive_path"]) - @patch("teuthology.worker.ls_remote") + @patch("teuthology.repo_utils.ls_remote") @patch("os.path.isdir") - @patch("teuthology.worker.fetch_teuthology") + @patch("teuthology.repo_utils.fetch_teuthology") @patch("teuthology.worker.teuth_config") - @patch("teuthology.worker.fetch_qa_suite") + @patch("teuthology.repo_utils.fetch_qa_suite") def test_prep_job(self, m_fetch_qa_suite, m_teuth_config, m_fetch_teuthology, m_isdir, m_ls_remote): config = dict( @@ -234,8 +234,8 @@ class TestWorker(object): @patch("teuthology.worker.run_job") @patch("teuthology.worker.prep_job") @patch("beanstalkc.Job", autospec=True) - @patch("teuthology.worker.fetch_qa_suite") - @patch("teuthology.worker.fetch_teuthology") + @patch("teuthology.repo_utils.fetch_qa_suite") + @patch("teuthology.repo_utils.fetch_teuthology") @patch("teuthology.worker.beanstalk.watch_tube") @patch("teuthology.worker.beanstalk.connect") @patch("os.path.isdir", return_value=True) @@ -269,12 +269,12 @@ class TestWorker(object): job.bury.assert_called_once_with() job.delete.assert_called_once_with() - @patch("teuthology.worker.ls_remote") + @patch("teuthology.repo_utils.ls_remote") @patch("teuthology.worker.report.try_push_job_info") @patch("teuthology.worker.run_job") @patch("beanstalkc.Job", autospec=True) - @patch("teuthology.worker.fetch_qa_suite") - @patch("teuthology.worker.fetch_teuthology") + @patch("teuthology.repo_utils.fetch_qa_suite") + @patch("teuthology.repo_utils.fetch_teuthology") @patch("teuthology.worker.beanstalk.watch_tube") @patch("teuthology.worker.beanstalk.connect") @patch("os.path.isdir", return_value=True) diff --git a/teuthology/worker.py b/teuthology/worker.py index cb3030da11..b23b6120a5 100644 --- a/teuthology/worker.py +++ b/teuthology/worker.py @@ -8,14 +8,20 @@ import yaml from datetime import datetime -from teuthology import setup_log_file, install_except_hook, kill -from teuthology import beanstalk -from teuthology import report -from teuthology import safepath +from teuthology import ( + # non-modules + setup_log_file, + install_except_hook, + # modules + beanstalk, + kill, + report, + repo_utils, + safepath, +) from teuthology.config import config as teuth_config from teuthology.config import set_config_attr from teuthology.exceptions import BranchNotFoundError, CommitNotFoundError, SkipJob, MaxWhileTries -from teuthology.repo_utils import fetch_qa_suite, fetch_teuthology, ls_remote, build_git_url log = logging.getLogger(__name__) start_time = datetime.utcnow() @@ -78,8 +84,8 @@ def main(ctx): result_proc = None if teuth_config.teuthology_path is None: - fetch_teuthology('main') - fetch_qa_suite('main') + repo_utils.fetch_teuthology('main') + repo_utils.fetch_qa_suite('main') keep_running = True while keep_running: @@ -149,8 +155,8 @@ def prep_job(job_config, log_file_path, archive_dir): job_config['teuthology_branch'] = teuthology_branch teuthology_sha1 = job_config.get('teuthology_sha1') if not teuthology_sha1: - repo_url = build_git_url('teuthology', 'ceph') - teuthology_sha1 = ls_remote(repo_url, teuthology_branch) + repo_url = repo_utils.build_git_url('teuthology', 'ceph') + teuthology_sha1 = repo_utils.ls_remote(repo_url, teuthology_branch) if not teuthology_sha1: reason = "Teuthology branch {} not found; marking job as dead".format(teuthology_branch) log.error(reason) @@ -166,7 +172,7 @@ def prep_job(job_config, log_file_path, archive_dir): if teuth_config.teuthology_path is not None: teuth_path = teuth_config.teuthology_path else: - teuth_path = fetch_teuthology(branch=teuthology_branch, + teuth_path = repo_utils.fetch_teuthology(branch=teuthology_branch, commit=teuthology_sha1) # For the teuthology tasks, we look for suite_branch, and if we # don't get that, we look for branch, and fall back to 'main'. @@ -178,7 +184,7 @@ def prep_job(job_config, log_file_path, archive_dir): if suite_repo: teuth_config.ceph_qa_suite_git_url = suite_repo job_config['suite_path'] = os.path.normpath(os.path.join( - fetch_qa_suite(suite_branch, suite_sha1), + repo_utils.fetch_qa_suite(suite_branch, suite_sha1), job_config.get('suite_relpath', ''), )) except (BranchNotFoundError, CommitNotFoundError) as exc: -- 2.39.5