Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suite: Do not send emails with --dry-run at schedule_fail #1778

Merged
merged 2 commits into from
Jul 25, 2022

Conversation

VallariAg
Copy link
Member

Do not send emails with --dry-run on schedule failures.

Signed-off-by: Vallari Agrawal val.agl002@gmail.com

Signed-off-by: Vallari Agrawal <val.agl002@gmail.com>
@VallariAg VallariAg requested a review from kamoltat July 13, 2022 08:31
@kamoltat
Copy link
Member

Overall looks good, just need to add a unit test.

return suite_repo_path


def schedule_fail(message, name=''):
def schedule_fail(message, name='', dry_run=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a unit test in teuthology/suite/test/test_util.py, for testing different scenarios of schedule failures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, working on it! 👍

Copy link
Member

@kamoltat kamoltat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job with implementing the unit test and making use of existing code to your advantage. Just left some comments for you to make a few changes, after that this should be good.

Comment on lines 184 to 210
def test_machine_type_multi_error(self):
with pytest.raises(ScheduleFailError) as exc:
main([
'--ceph', 'main',
'--suite', 'suite_name',
'--throttle', '3',
'--machine-type', 'multi',
'--dry-run'
])
assert str(exc.value) == "Scheduling failed: 'multi' is not a valid machine_type. \
Maybe you want 'gibba,smithi,mira' or similar"

def test_machine_type_none_error(self):
with pytest.raises(ScheduleFailError) as exc:
main([
'--ceph', 'main',
'--suite', 'suite_name',
'--throttle', '3',
'--machine-type', 'None',
'--dry-run'
])
assert str(exc.value) == "Scheduling failed: Must specify a machine_type"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well as unit testing these specific exceptions and making sure that the exception output is correct. We also want to make sure that with --dry-run, the function util.schedule_fail()
is not hitting smtp.sendmail() in util.schedule_fail(). We can do this by importing teuthology.suite.util.schedule_fail, patching it, and add something like assert m_schedule_fail.smtp.sendmail.called == False. You might have to mock more stuff but this should get you started.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you! Will add this!

Comment on lines 145 to 159
def test_teuthology_branch_nonexistent(
self,
m_git_ls_remote
):
config.teuthology_path = None
m_git_ls_remote.return_value = None
self.args.teuthology_branch = 'no_branch'
with pytest.raises(ScheduleFailError):
self.klass(self.args)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here

Comment on lines 54 to 85
def test_schedule_fail(self):
with pytest.raises(ScheduleFailError) as exc:
util.schedule_fail(message="error msg")
assert str(exc.value) == "Scheduling failed: error msg"

def test_fetch_repo_no_branch(self):
with pytest.raises(ScheduleFailError) as exc:
util.fetch_repos("no-branch", "test1", None)
assert str(exc.value) == "Scheduling test1 failed: \
Branch 'no-branch' not found in repo: https://github.com/ceph/ceph-ci.git!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here, but might not have to mock as much stuff.

@VallariAg VallariAg force-pushed the no-mails-with-dryrun branch from 90e79ed to 8ab4131 Compare July 21, 2022 15:27
@kamoltat
Copy link
Member

Saw your new push, looks good! I should have addressed this in my last comment but I think we also want a unit-test case where --dry-run is not present in the command and we are expecting to hit smtp.sendmail. I know it's tedious but a good unit test makes the code more bullet-proof 😊

@VallariAg
Copy link
Member Author

Saw your new push, looks good! I should have addressed this in my last comment but I think we also want a unit-test case where --dry-run is not present in the command and we are expecting to hit smtp.sendmail. I know it's tedious but a good unit test makes the code more bullet-proof

Sounds good! I'll add that as well!

@kamoltat
Copy link
Member

@VallariAg

I grep -nr "schedule_fail" and I found that:

you're missing dry_run=self.args.dry_run in:

util.schedule_fail('Backtrack for --newest failed', name)

Signed-off-by: Vallari Agrawal <val.agl002@gmail.com>
@VallariAg VallariAg force-pushed the no-mails-with-dryrun branch from 526dc37 to 2d57263 Compare July 23, 2022 13:09
@VallariAg
Copy link
Member Author

I grep -nr "schedule_fail" and I found that:
you're missing dry_run=self.args.dry_run in

My bad, added the parameter now!

Copy link
Member

@kamoltat kamoltat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kamoltat kamoltat merged commit efc3ff7 into main Jul 25, 2022
@zmc zmc deleted the no-mails-with-dryrun branch January 14, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants