Skip to content

Commit

Permalink
suite: add pytests for schedule_fail
Browse files Browse the repository at this point in the history
Signed-off-by: Vallari Agrawal <val.agl002@gmail.com>
  • Loading branch information
VallariAg committed Jul 19, 2022
1 parent 149b8e4 commit 90e79ed
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
24 changes: 24 additions & 0 deletions teuthology/suite/test/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pytest
import time

from teuthology.exceptions import ScheduleFailError

def get_fake_time_and_sleep():
# Below we set m_time.side_effect, but we also set m_time.return_value.
Expand Down Expand Up @@ -179,6 +180,29 @@ def fake_false(*args, **kwargs):
'--throttle', throttle,
'--machine-type', machine_type,
])

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"

def test_schedule_suite_noverify(self):
suite_name = 'noop'
Expand Down
11 changes: 11 additions & 0 deletions teuthology/suite/test/test_run_.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ def test_sha1_nonexistent(
with pytest.raises(ScheduleFailError):
self.klass(self.args)

@patch('teuthology.suite.util.git_ls_remote')
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)

@patch('teuthology.suite.run.util.fetch_repos')
@patch('teuthology.suite.run.util.git_branch_exists')
@patch('teuthology.suite.run.util.package_version_for_hash')
Expand Down
12 changes: 12 additions & 0 deletions teuthology/suite/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from teuthology.config import config
from teuthology.orchestra.opsys import OS
from teuthology.suite import util
from teuthology.exceptions import ScheduleFailError


REPO_PROJECTS_AND_URLS = [
Expand Down Expand Up @@ -50,6 +51,17 @@ class TestUtil(object):
def setup(self):
config.use_shaman = False

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!"

@patch('requests.get')
def test_get_hash_success(self, m_get):
mock_resp = Mock()
Expand Down

0 comments on commit 90e79ed

Please sign in to comment.