diff --git a/tasks/libs/common/junit_upload_core.py b/tasks/libs/common/junit_upload_core.py index 54d01fc2af0a4..b7282d9bf4ebc 100644 --- a/tasks/libs/common/junit_upload_core.py +++ b/tasks/libs/common/junit_upload_core.py @@ -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: @@ -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 = [] @@ -242,7 +246,7 @@ 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() @@ -250,7 +254,7 @@ def upload_junitxmls(team_dir: Path): 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. diff --git a/tasks/unit_tests/junit_tests.py b/tasks/unit_tests/junit_tests.py index 58ae7f10a6e5c..6dfa6e0fe57ac 100644 --- a/tasks/unit_tests/junit_tests.py +++ b/tasks/unit_tests/junit_tests.py @@ -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)