|
5 | 5 | from pytest import Item |
6 | 6 | from pyhelper_utils.shell import run_command |
7 | 7 |
|
8 | | -from utilities.exceptions import InvalidArguments |
| 8 | +from utilities.exceptions import InvalidArgumentsError |
9 | 9 | from utilities.infra import get_rhods_csv_version, get_oc_image_info, generate_openshift_pull_secret_file |
10 | 10 |
|
11 | 11 | BASE_DIRECTORY_NAME = "must-gather-collected" |
| 12 | +RESULTS_DIR = "/home/odh/opendatahub-tests/" |
12 | 13 |
|
13 | 14 |
|
14 | 15 | def get_base_dir() -> str: |
15 | | - if os.path.exists("/home/odh/opendatahub-tests/"): |
| 16 | + if os.path.exists(RESULTS_DIR): |
16 | 17 | # we are running from jenkins. |
17 | | - return "/home/odh/opendatahub-tests/results" |
| 18 | + return RESULTS_DIR |
18 | 19 | else: |
19 | 20 | # this is local run |
20 | 21 | return "" |
21 | 22 |
|
22 | 23 |
|
23 | 24 | def set_must_gather_collector_values() -> dict[str, str]: |
24 | 25 | py_config["must_gather_collector"] = { |
25 | | - "must_gather_base_directory": f"{get_base_dir()}{BASE_DIRECTORY_NAME}", |
| 26 | + "must_gather_base_directory": os.path.join(get_base_dir(), BASE_DIRECTORY_NAME), |
26 | 27 | } |
27 | 28 | return py_config["must_gather_collector"] |
28 | 29 |
|
@@ -81,8 +82,22 @@ def run_must_gather( |
81 | 82 | component_name: str = "", |
82 | 83 | namespaces_dict: dict[str, str] | None = None, |
83 | 84 | ) -> str: |
| 85 | + """ |
| 86 | + Process the arguments to build must-gather command and run the same |
| 87 | +
|
| 88 | + Args: |
| 89 | + image_url (str): must-gather image url |
| 90 | + target_dir (str): must-gather target directory |
| 91 | + since (str): duration in seconds for must-gather log collection |
| 92 | + component_name (str): must-gather component name |
| 93 | + namespaces_dict (dict[str, str] | None): namespaces dict for extra data collection from different component |
| 94 | + namespaces |
| 95 | +
|
| 96 | + Returns: |
| 97 | + str: must-gather output |
| 98 | + """ |
84 | 99 | if component_name and namespaces_dict: |
85 | | - raise InvalidArguments("component name and namespaces can't be passed together") |
| 100 | + raise InvalidArgumentsError("component name and namespaces can't be passed together") |
86 | 101 |
|
87 | 102 | must_gather_command = "oc adm must-gather" |
88 | 103 | if target_dir: |
@@ -117,12 +132,16 @@ def run_must_gather( |
117 | 132 |
|
118 | 133 |
|
119 | 134 | def get_must_gather_image_info(architecture: str = "linux/amd64") -> str: |
120 | | - csv_version = get_rhods_csv_version() |
121 | | - must_gather_image_manifest = f"quay.io/modh/must-gather:rhoai-{csv_version.major}.{csv_version.minor}" |
122 | | - image_info = get_oc_image_info( |
123 | | - image=must_gather_image_manifest, architecture=architecture, pull_secret=generate_openshift_pull_secret_file() |
124 | | - ) |
125 | | - return f"quay.io/modh/must-gather@{image_info['digest']}" |
| 135 | + try: |
| 136 | + csv_version = get_rhods_csv_version() |
| 137 | + must_gather_image_manifest = f"quay.io/modh/must-gather:rhoai-{csv_version.major}.{csv_version.minor}" |
| 138 | + pull_secret = generate_openshift_pull_secret_file() |
| 139 | + image_info = get_oc_image_info( |
| 140 | + image=must_gather_image_manifest, architecture=architecture, pull_secret=pull_secret |
| 141 | + ) |
| 142 | + return f"quay.io/modh/must-gather@{image_info['digest']}" |
| 143 | + except Exception as exec: |
| 144 | + raise RuntimeError(f"Failed to retrieve must-gather image info: {str(exec)}") from exec |
126 | 145 |
|
127 | 146 |
|
128 | 147 | def collect_rhoai_must_gather( |
|
0 commit comments