diff options
author | Richard Samuels <richard.l.samuels@gmail.com> | 2021-10-04 15:40:33 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-04 16:06:04 +0000 |
commit | 14c12774fa544cd9a709807002daf4be3dc807df (patch) | |
tree | 40327be0c80720917098f7e2820b379e423fae62 /buildscripts | |
parent | e7563044ca02b1d889a57ed0cb35bfe6082210bc (diff) | |
download | mongo-14c12774fa544cd9a709807002daf4be3dc807df.tar.gz |
SERVER-59670 SERVER-60367 hang analyzer: ensure that evg yaml can be found in workdir
Diffstat (limited to 'buildscripts')
-rw-r--r-- | buildscripts/resmokelib/utils/evergreen_conn.py | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/buildscripts/resmokelib/utils/evergreen_conn.py b/buildscripts/resmokelib/utils/evergreen_conn.py index 4b6e9a44bed..c73590a4b7d 100644 --- a/buildscripts/resmokelib/utils/evergreen_conn.py +++ b/buildscripts/resmokelib/utils/evergreen_conn.py @@ -1,6 +1,7 @@ """Helper functions to interact with evergreen.""" import os -from typing import Optional +import pathlib +from typing import Optional, List import requests import structlog @@ -17,8 +18,6 @@ EVERGREEN_CONFIG_LOCATIONS = ( # Common for local machines os.path.expanduser(os.path.join("~", ".evergreen.yml")), ) -if "EVERGREEN_WORKDIR" in os.environ: - EVERGREEN_CONFIG_LOCATIONS = (os.environ["EVERGREEN_WORKDIR"], ) + EVERGREEN_CONFIG_LOCATIONS GENERIC_EDITION = "base" GENERIC_PLATFORM = "linux_x86_64" @@ -33,23 +32,46 @@ class EvergreenConnError(Exception): pass +def _find_evergreen_yaml_candidates() -> List[str]: + # Common for machines in Evergreen + candidates = [os.getcwd()] + + cwd = pathlib.Path(os.getcwd()) + # add every path that is the parent of CWD as well + for parent in cwd.parents: + candidates.append(parent) + + # Common for local machines + candidates.append(os.path.expanduser(os.path.join("~", ".evergreen.yml"))) + + out = [] + for path in candidates: + file = os.path.join(path, ".evergreen.yml") + if os.path.isfile(file): + out.append(file) + + return out + + def get_evergreen_api(evergreen_config=None): """Return evergreen API.""" - config_to_pass = evergreen_config - if not config_to_pass: - # Pickup the first config file found in common locations. - for file in EVERGREEN_CONFIG_LOCATIONS: - if os.path.isfile(file): - config_to_pass = file - break - try: - evg_api = RetryingEvergreenApi.get_api(config_file=config_to_pass) - except Exception as ex: - LOGGER.error("Most likely something is wrong with evergreen config file.", - config_file=config_to_pass) - raise ex + if evergreen_config: + possible_configs = [evergreen_config] else: - return evg_api + possible_configs = _find_evergreen_yaml_candidates() + + last_ex = None + for config in possible_configs: + try: + return RetryingEvergreenApi.get_api(config_file=config) + # + except Exception as ex: # pylint: disable=broad-except + last_ex = ex + continue + + LOGGER.error("Most likely something is wrong with evergreen config file.", + config_file_candidates=possible_configs) + raise last_ex def get_buildvariant_name(config, edition, platform, architecture, major_minor_version): |