-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ruth Netser <[email protected]> Co-authored-by: Miles Dunn <[email protected]>
- Loading branch information
1 parent
2994035
commit e1b3bf4
Showing
6 changed files
with
120 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
from cli.objects.job import Job | ||
from cli.report import Report | ||
|
||
_logger = simple_logger.logger.get_logger(__name__) | ||
LOGGER = simple_logger.logger.get_logger(__name__) | ||
|
||
BUILD_ID_ENV_VAR = "BUILD_ID" | ||
FIREWATCH_DEFAULT_JIRA_PROJECT_ENV_VAR = "FIREWATCH_DEFAULT_JIRA_PROJECT" | ||
|
@@ -54,6 +54,8 @@ | |
["junit_install.xml", "junit_install_status.xml", "junit_symptoms.xml"], | ||
] | ||
|
||
DEFAULT_MOCK_ISSUE_KEY = "LPTOCPCI-MOCK" | ||
|
||
|
||
@pytest.fixture | ||
def jira(jira_config_path): | ||
|
@@ -85,18 +87,18 @@ def job(firewatch_config, build_id): | |
def patch_jira(monkeypatch): | ||
@dataclass | ||
class MockIssue: | ||
key: str = "LPTOCPCI-MOCK" | ||
key: str = DEFAULT_MOCK_ISSUE_KEY | ||
|
||
def create_jira_issue(*args, **kwargs): | ||
_logger.info("Patching Report.create_jira_issue") | ||
_logger.info( | ||
LOGGER.info("Patching Report.create_jira_issue") | ||
LOGGER.info( | ||
f"Attempted call Report.create_issue with the following keywords: \n{pprint.pformat(kwargs)}", | ||
) | ||
return MockIssue() | ||
|
||
def add_duplicate_comment(*args, **kwargs): | ||
_logger.info("Patching Report.add_duplicate_comment") | ||
_logger.info( | ||
LOGGER.info("Patching Report.add_duplicate_comment") | ||
LOGGER.info( | ||
f"Attempted to call Report.add_duplicate_comment with the following keywords: \n{pprint.pformat(kwargs)}", | ||
) | ||
return | ||
|
@@ -128,12 +130,12 @@ def __post_init__(self): | |
cap = CapJira() | ||
|
||
def create_jira_issue(*args, **kwargs): | ||
_logger.info("Patching Report.create_jira_issue") | ||
LOGGER.info("Patching Report.create_jira_issue") | ||
cap.create_jira_issue.append(CapInputs(args, kwargs)) | ||
return MockIssue() | ||
|
||
def add_duplicate_comment(*args, **kwargs): | ||
_logger.info("Patching Report.add_duplicate_comment") | ||
LOGGER.info("Patching Report.add_duplicate_comment") | ||
cap.add_duplicate_comment.append(CapInputs(args, kwargs)) | ||
|
||
monkeypatch.setattr(Report, "create_jira_issue", create_jira_issue) | ||
|
@@ -143,7 +145,7 @@ def add_duplicate_comment(*args, **kwargs): | |
|
||
@pytest.fixture | ||
def patch_job_log_dir(monkeypatch, job_log_dir): | ||
_logger.info("Patching Job log dir path") | ||
LOGGER.info("Patching Job log dir path") | ||
|
||
def _download_logs(*args, **kwargs): | ||
return job_log_dir.as_posix() | ||
|
@@ -153,20 +155,14 @@ def _download_logs(*args, **kwargs): | |
|
||
@pytest.fixture | ||
def patch_job_junit_dir(monkeypatch, job_junit_dir): | ||
_logger.info("Patching Job junit dir path") | ||
LOGGER.info("Patching Job junit dir path") | ||
|
||
def _download_junit(*args, **kwargs): | ||
return job_junit_dir.as_posix() | ||
|
||
monkeypatch.setattr(Job, "_download_junit", _download_junit) | ||
|
||
|
||
@pytest.fixture | ||
def assert_job_dir_exists(job_dir): | ||
job_dir.mkdir(exist_ok=True, parents=True) | ||
assert job_dir.is_dir() | ||
|
||
|
||
@pytest.fixture | ||
def fake_log_secret_path(job_log_dir): | ||
yield job_log_dir.joinpath("fake-step/fake_build_log.txt") | ||
|
@@ -178,10 +174,78 @@ def fake_junit_secret_path(job_junit_dir): | |
|
||
|
||
@pytest.fixture | ||
def assert_jira_config_file_exists(jira_config_path): | ||
if not jira_config_path.is_file(): | ||
jira_config_path.parent.mkdir(exist_ok=True, parents=True) | ||
jira_config_path.write_text( | ||
def firewatch_config_json(monkeypatch): | ||
config_json = json.dumps( | ||
{ | ||
"failure_rules": [ | ||
{ | ||
"step": "exact-step-name", | ||
"failure_type": "pod_failure", | ||
"classification": "Infrastructure", | ||
"jira_project": "!default", | ||
"jira_component": ["some-component"], | ||
"jira_assignee": "[email protected]", | ||
"jira_security_level": "Restricted", | ||
}, | ||
{ | ||
"step": "*partial-name*", | ||
"failure_type": "all", | ||
"classification": "Misc.", | ||
"jira_project": "OTHER", | ||
"jira_component": ["component-1", "component-2", "!default"], | ||
"jira_priority": "major", | ||
"group": {"name": "some-group", "priority": 1}, | ||
}, | ||
{ | ||
"step": "*ends-with-this", | ||
"failure_type": "test_failure", | ||
"classification": "Test failures", | ||
"jira_epic": "!default", | ||
"jira_additional_labels": [ | ||
"test-label-1", | ||
"test-label-2", | ||
"!default", | ||
], | ||
"group": {"name": "some-group", "priority": 2}, | ||
}, | ||
{ | ||
"step": "*ignore*", | ||
"failure_type": "test_failure", | ||
"classification": "NONE", | ||
"jira_project": "NONE", | ||
"ignore": "true", | ||
}, | ||
{ | ||
"step": "affects-version", | ||
"failure_type": "all", | ||
"classification": "Affects Version", | ||
"jira_project": "TEST", | ||
"jira_epic": "!default", | ||
"jira_affects_version": "4.14", | ||
"jira_assignee": "!default", | ||
}, | ||
{ | ||
"step": "affects-version", | ||
"failure_type": "all", | ||
"classification": "Affects Version", | ||
"jira_project": "TEST", | ||
"jira_epic": "!default", | ||
"jira_affects_version": "4.14", | ||
"jira_assignee": "!default", | ||
}, | ||
], | ||
}, | ||
) | ||
monkeypatch.setenv(FIREWATCH_CONFIG_ENV_VAR, config_json) | ||
yield config_json | ||
|
||
|
||
@pytest.fixture | ||
def jira_config_path(tmp_path): | ||
config_path = tmp_path.joinpath("jira_config.json") | ||
if not config_path.is_file(): | ||
config_path.parent.mkdir(exist_ok=True, parents=True) | ||
config_path.write_text( | ||
json.dumps( | ||
{ | ||
"token": os.getenv(JIRA_TOKEN_ENV_VAR), | ||
|
@@ -193,87 +257,7 @@ def assert_jira_config_file_exists(jira_config_path): | |
}, | ||
), | ||
) | ||
assert jira_config_path.is_file() | ||
|
||
|
||
@pytest.fixture | ||
def assert_firewatch_config_in_env(monkeypatch): | ||
monkeypatch.setenv( | ||
FIREWATCH_CONFIG_ENV_VAR, | ||
json.dumps( | ||
{ | ||
"failure_rules": [ | ||
{ | ||
"step": "exact-step-name", | ||
"failure_type": "pod_failure", | ||
"classification": "Infrastructure", | ||
"jira_project": "!default", | ||
"jira_component": ["some-component"], | ||
"jira_assignee": "[email protected]", | ||
"jira_security_level": "Restricted", | ||
}, | ||
{ | ||
"step": "*partial-name*", | ||
"failure_type": "all", | ||
"classification": "Misc.", | ||
"jira_project": "OTHER", | ||
"jira_component": ["component-1", "component-2", "!default"], | ||
"jira_priority": "major", | ||
"group": {"name": "some-group", "priority": 1}, | ||
}, | ||
{ | ||
"step": "*ends-with-this", | ||
"failure_type": "test_failure", | ||
"classification": "Test failures", | ||
"jira_epic": "!default", | ||
"jira_additional_labels": [ | ||
"test-label-1", | ||
"test-label-2", | ||
"!default", | ||
], | ||
"group": {"name": "some-group", "priority": 2}, | ||
}, | ||
{ | ||
"step": "*ignore*", | ||
"failure_type": "test_failure", | ||
"classification": "NONE", | ||
"jira_project": "NONE", | ||
"ignore": "true", | ||
}, | ||
{ | ||
"step": "affects-version", | ||
"failure_type": "all", | ||
"classification": "Affects Version", | ||
"jira_project": "TEST", | ||
"jira_epic": "!default", | ||
"jira_affects_version": "4.14", | ||
"jira_assignee": "!default", | ||
}, | ||
{ | ||
"step": "affects-version", | ||
"failure_type": "all", | ||
"classification": "Affects Version", | ||
"jira_project": "TEST", | ||
"jira_epic": "!default", | ||
"jira_affects_version": "4.14", | ||
"jira_assignee": "!default", | ||
}, | ||
], | ||
}, | ||
), | ||
) | ||
assert os.getenv(FIREWATCH_CONFIG_ENV_VAR) | ||
|
||
|
||
@pytest.fixture | ||
def assert_artifact_dir_exists(artifact_dir): | ||
artifact_dir.mkdir(exist_ok=True, parents=True) | ||
assert artifact_dir.is_dir() | ||
|
||
|
||
@pytest.fixture | ||
def jira_config_path(tmp_path): | ||
yield tmp_path.joinpath("jira_config.json") | ||
yield config_path | ||
|
||
|
||
@pytest.fixture(params=JOB_STEP_DIRS_TO_TEST) | ||
|
@@ -307,14 +291,11 @@ def job_dir_junit_artifact_paths(request, job_junit_step_dirs): | |
|
||
|
||
@pytest.fixture | ||
def assert_artifact_dir_in_env(monkeypatch, artifact_dir): | ||
monkeypatch.setenv(ARTIFACT_DIR_ENV_VAR, artifact_dir.as_posix()) | ||
assert os.getenv(ARTIFACT_DIR_ENV_VAR) | ||
|
||
|
||
@pytest.fixture | ||
def artifact_dir(tmp_path): | ||
yield tmp_path / "artifacts" | ||
def artifact_dir(monkeypatch, tmp_path): | ||
path = tmp_path / "artifacts" | ||
monkeypatch.setenv(ARTIFACT_DIR_ENV_VAR, path.as_posix()) | ||
path.mkdir(exist_ok=True, parents=True) | ||
yield path | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -323,38 +304,28 @@ def job_dir(tmp_path, build_id): | |
|
||
|
||
@pytest.fixture(params=BUILD_IDS_TO_TEST, ids=BUILD_IDS_TO_TEST) | ||
def build_id(request): | ||
yield request.param | ||
def build_id(monkeypatch, request): | ||
param = request.param | ||
monkeypatch.setenv(BUILD_ID_ENV_VAR, param) | ||
yield param | ||
|
||
|
||
@pytest.fixture(params=DEFAULT_JIRA_PROJECTS_TO_TEST, ids=DEFAULT_JIRA_PROJECTS_TO_TEST) | ||
def default_jira_project(request): | ||
yield request.param | ||
def default_jira_project(monkeypatch, request): | ||
param = request.param | ||
monkeypatch.setenv(FIREWATCH_DEFAULT_JIRA_PROJECT_ENV_VAR, param) | ||
yield param | ||
|
||
|
||
@pytest.fixture(params=DEFAULT_JIRA_EPICS_TO_TEST, ids=DEFAULT_JIRA_EPICS_TO_TEST) | ||
def default_jira_epic(request): | ||
yield request.param | ||
|
||
|
||
@pytest.fixture | ||
def assert_build_id_in_env(build_id, monkeypatch): | ||
monkeypatch.setenv(BUILD_ID_ENV_VAR, build_id) | ||
assert os.getenv(BUILD_ID_ENV_VAR) | ||
|
||
|
||
@pytest.fixture | ||
def assert_default_jira_project_in_env(default_jira_project, monkeypatch): | ||
monkeypatch.setenv(FIREWATCH_DEFAULT_JIRA_PROJECT_ENV_VAR, default_jira_project) | ||
assert os.getenv(FIREWATCH_DEFAULT_JIRA_PROJECT_ENV_VAR) | ||
|
||
|
||
@pytest.fixture | ||
def assert_default_jira_epic_in_env(default_jira_epic, monkeypatch): | ||
monkeypatch.setenv(FIREWATCH_DEFAULT_JIRA_EPIC_ENV_VAR, default_jira_epic) | ||
assert os.getenv(FIREWATCH_DEFAULT_JIRA_EPIC_ENV_VAR) | ||
def default_jira_epic(monkeypatch, request): | ||
param = request.param | ||
monkeypatch.setenv(FIREWATCH_DEFAULT_JIRA_EPIC_ENV_VAR, param) | ||
yield param | ||
|
||
|
||
@pytest.fixture | ||
def assert_jira_token_in_env(): | ||
assert os.getenv(JIRA_TOKEN_ENV_VAR) | ||
def jira_token(): | ||
token = os.getenv(JIRA_TOKEN_ENV_VAR) | ||
assert token | ||
yield token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.