From 149b8e4a37472b18bbcc14b24e9b6eaea4a3cb3e Mon Sep 17 00:00:00 2001 From: Vallari Agrawal Date: Mon, 11 Jul 2022 18:25:46 +0530 Subject: [PATCH] suite: Do not send emails with --dry-run at schedule_fail Signed-off-by: Vallari Agrawal --- teuthology/suite/__init__.py | 5 +++-- teuthology/suite/run.py | 27 +++++++++++++++------------ teuthology/suite/util.py | 9 +++++---- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/teuthology/suite/__init__.py b/teuthology/suite/__init__.py index b7f0466649..45aa799c16 100644 --- a/teuthology/suite/__init__.py +++ b/teuthology/suite/__init__.py @@ -109,14 +109,15 @@ def main(args): if conf.verbose: teuthology.log.setLevel(logging.DEBUG) + dry_run = conf.dry_run or None if not conf.machine_type or conf.machine_type == 'None': if not config.default_machine_type or config.default_machine_type == 'None': - schedule_fail("Must specify a machine_type") + schedule_fail("Must specify a machine_type", dry_run=dry_run) else: conf.machine_type = config.default_machine_type elif 'multi' in conf.machine_type: schedule_fail("'multi' is not a valid machine_type. " + - "Maybe you want 'gibba,smithi,mira' or similar") + "Maybe you want 'gibba,smithi,mira' or similar", dry_run=dry_run) if conf.email: config.results_email = conf.email diff --git a/teuthology/suite/run.py b/teuthology/suite/run.py index 7ae4a37646..aeeabe5963 100644 --- a/teuthology/suite/run.py +++ b/teuthology/suite/run.py @@ -100,7 +100,7 @@ class Run(object): self.suite_repo_path = self.args.suite_dir else: self.suite_repo_path = util.fetch_repos( - suite_branch, test_name=self.name) + suite_branch, test_name=self.name, dry_run=self.args.dry_run) teuthology_branch, teuthology_sha1 = self.choose_teuthology_branch() @@ -144,7 +144,8 @@ class Run(object): if not kernel_hash: util.schedule_fail( "Kernel branch '{branch}' not found".format( - branch=self.args.kernel_branch) + branch=self.args.kernel_branch), + dry_run=self.args.dry_run, ) if kernel_hash: log.info("kernel sha1: {hash}".format(hash=kernel_hash)) @@ -172,7 +173,7 @@ class Run(object): self.args.ceph_sha1, '%s.git' % repo_name ) - util.schedule_fail(message=str(exc), name=self.name) + util.schedule_fail(message=str(exc), name=self.name, dry_run=self.args.dry_run) log.info("ceph sha1 explicitly supplied") elif self.args.ceph_branch: @@ -183,7 +184,7 @@ class Run(object): self.args.ceph_branch, '%s.git' % repo_name ) - util.schedule_fail(message=str(exc), name=self.name) + util.schedule_fail(message=str(exc), name=self.name, dry_run=self.args.dry_run) log.info("ceph sha1: {hash}".format(hash=ceph_hash)) return ceph_hash @@ -198,7 +199,7 @@ class Run(object): self.args.distro_version, self.args.machine_type, ) except Exception as exc: - util.schedule_fail(str(exc), self.name) + util.schedule_fail(str(exc), self.name, dry_run=self.args.dry_run) log.info("ceph version: {ver}".format(ver=ceph_version)) return ceph_version else: @@ -268,7 +269,7 @@ class Run(object): ) if not teuthology_sha1: exc = BranchNotFoundError(teuthology_branch, build_git_url('teuthology')) - util.schedule_fail(message=str(exc), name=self.name) + util.schedule_fail(message=str(exc), name=self.name, dry_run=self.args.dry_run) log.info("teuthology branch: %s %s", teuthology_branch, teuthology_sha1) return teuthology_branch, teuthology_sha1 @@ -301,7 +302,7 @@ class Run(object): suite_branch ): exc = BranchNotFoundError(suite_branch, suite_repo_name) - util.schedule_fail(message=str(exc), name=self.name) + util.schedule_fail(message=str(exc), name=self.name, dry_run=self.args.dry_run) elif not suite_branch: # Decide what branch of the suite repo to use if util.git_branch_exists(suite_repo_project_or_url, ceph_branch): @@ -325,7 +326,7 @@ class Run(object): ) if not suite_hash: exc = BranchNotFoundError(suite_branch, suite_repo_name) - util.schedule_fail(message=str(exc), name=self.name) + util.schedule_fail(message=str(exc), name=self.name, dry_run=self.args.dry_run) log.info("%s branch: %s %s", suite_repo_name, suite_branch, suite_hash) return suite_hash @@ -513,6 +514,7 @@ class Run(object): "At least one job needs packages that don't exist for " "hash {sha1}.".format(sha1=self.base_config.sha1), name, + dry_run=self.args.dry_run, ) util.teuthology_schedule( args=job['args'], @@ -538,11 +540,11 @@ Use the following testing priority 200 to 1000: Large test runs that can be done over the course of a week. Note: To force run, use --force-priority''' if priority < 50: - util.schedule_fail(msg) + util.schedule_fail(msg, dry_run=self.args.dry_run) elif priority < 75 and jobs_to_schedule > 25: - util.schedule_fail(msg) + util.schedule_fail(msg, dry_run=self.args.dry_run) elif priority < 150 and jobs_to_schedule > 100: - util.schedule_fail(msg) + util.schedule_fail(msg, dry_run=self.args.dry_run) def check_num_jobs(self, jobs_to_schedule): """ @@ -553,7 +555,7 @@ Note: To force run, use --force-priority''' Note: If you still want to go ahead, use --job-threshold 0''' if threshold and jobs_to_schedule > threshold: - util.schedule_fail(msg) + util.schedule_fail(msg, dry_run=self.args.dry_run) def schedule_suite(self): """ @@ -659,6 +661,7 @@ Note: If you still want to go ahead, use --job-threshold 0''' util.schedule_fail( 'Exceeded %d backtracks; raise --newest value' % limit, name, + dry_run=self.args.dry_run, ) if self.args.dry_run: diff --git a/teuthology/suite/util.py b/teuthology/suite/util.py index 67ac324109..9b4cade7bf 100644 --- a/teuthology/suite/util.py +++ b/teuthology/suite/util.py @@ -29,7 +29,7 @@ CONTAINER_DISTRO = 'centos/8' # the one to check for build_complete CONTAINER_FLAVOR = 'default' -def fetch_repos(branch, test_name): +def fetch_repos(branch, test_name, dry_run): """ Fetch the suite repo (and also the teuthology repo) so that we can use it to build jobs. Repos are stored in ~/src/. @@ -51,17 +51,18 @@ def fetch_repos(branch, test_name): fetch_teuthology('main') suite_repo_path = fetch_qa_suite(branch) except BranchNotFoundError as exc: - schedule_fail(message=str(exc), name=test_name) + schedule_fail(message=str(exc), name=test_name, dry_run=dry_run) return suite_repo_path -def schedule_fail(message, name=''): +def schedule_fail(message, name='', dry_run=None): """ If an email address has been specified anywhere, send an alert there. Then raise a ScheduleFailError. + Don't send the mail if --dry-run has been passed. """ email = config.results_email - if email: + if email and not dry_run: subject = "Failed to schedule {name}".format(name=name) msg = MIMEText(message) msg['Subject'] = subject -- 2.39.5