Skip to content

Commit

Permalink
[JUnit] Raise error on datadog-ci command not found (#31687)
Browse files Browse the repository at this point in the history
  • Loading branch information
amenasria authored Dec 3, 2024
1 parent 5f0dfcf commit 29a7ac9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 10 additions & 6 deletions tasks/libs/common/junit_upload_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
E2E_INTERNAL_ERROR_STRING = "E2E INTERNAL ERROR"
CODEOWNERS_ORG_PREFIX = "@DataDog/"
REPO_NAME_PREFIX = "github.com/DataDog/datadog-agent/"
if platform.system() == "Windows":
DATADOG_CI_COMMAND = [r"c:\devtools\datadog-ci\datadog-ci", "junit", "upload"]
else:
DATADOG_CI_COMMAND = [which("datadog-ci"), "junit", "upload"]
JOB_ENV_FILE_NAME = "job_env.txt"
TAGS_FILE_NAME = "tags.txt"


def get_datadog_ci_command():
path_datadog_ci = which("datadog-ci")
if path_datadog_ci is None:
raise FileNotFoundError("datadog-ci command not found")
return path_datadog_ci


def enrich_junitxml(xml_path: str, flavor: AgentFlavor):
"""
Modifies the JUnit XML file:
Expand Down Expand Up @@ -232,6 +235,7 @@ def upload_junitxmls(team_dir: Path):
"""
Upload all per-team split JUnit XMLs from given directory.
"""
datadog_ci_command = [get_datadog_ci_command(), "junit", "upload"]
additional_tags = read_additional_tags(team_dir.parent)
process_env = _update_environ(team_dir.parent)
processes = []
Expand All @@ -242,15 +246,15 @@ def upload_junitxmls(team_dir: Path):
for flags, files in xml_files.items():
args = set_tags(owner, flavor, flags, additional_tags, files[0])
args.extend(files)
processes.append(Popen(DATADOG_CI_COMMAND + args, bufsize=-1, env=process_env, stdout=PIPE, stderr=PIPE))
processes.append(Popen(datadog_ci_command + args, bufsize=-1, env=process_env, stdout=PIPE, stderr=PIPE))

for process in processes:
stdout, stderr = process.communicate()
print(stdout)
print(f" Uploaded {len(tuple(team_dir.iterdir()))} files for {team_dir.name}")
if stderr:
print(f"Failed uploading junit:\n{stderr.decode()}", file=sys.stderr)
raise CalledProcessError(process.returncode, DATADOG_CI_COMMAND)
raise CalledProcessError(process.returncode, datadog_ci_command)
return "" # For ThreadPoolExecutor.map. Without this it prints None in the log output.


Expand Down
4 changes: 3 additions & 1 deletion tasks/unit_tests/junit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ class TestJUnitUploadFromTGZ(unittest.TestCase):
@patch.dict("os.environ", {"CI_PIPELINE_ID": "1664"})
@patch.dict("os.environ", {"CI_PIPELINE_SOURCE": "beer"})
@patch("tasks.libs.common.junit_upload_core.Popen")
def test_e2e(self, mock_popen):
@patch("tasks.libs.common.junit_upload_core.which")
def test_e2e(self, mock_which, mock_popen):
mock_instance = MagicMock()
mock_instance.communicate.return_value = (b"stdout", b"")
mock_popen.return_value = mock_instance
mock_which.side_effect = lambda cmd: f"/usr/local/bin/{cmd}"
junit.junit_upload_from_tgz("tasks/unit_tests/testdata/testjunit-tests_deb-x64-py3.tgz")
mock_popen.assert_called()
self.assertEqual(mock_popen.call_count, 31)

0 comments on commit 29a7ac9

Please sign in to comment.