55from pytest import Item
66from pyhelper_utils .shell import run_command
77
8- from utilities .exceptions import InvalidArguments
8+ from utilities .exceptions import InvalidArgumentsError
99from utilities .infra import get_rhods_csv_version , get_oc_image_info , generate_openshift_pull_secret_file
1010
1111BASE_DIRECTORY_NAME = "must-gather-collected"
12+ BASE_RESULTS_DIR = "/home/odh/opendatahub-tests/"
1213
1314
1415def get_base_dir () -> str :
15- if os .path .exists ("/home/odh/opendatahub-tests/" ):
16+ if os .path .exists (BASE_RESULTS_DIR ):
1617 # we are running from jenkins.
17- return "/home/odh/opendatahub-tests/ results"
18+ return f" { BASE_RESULTS_DIR } results"
1819 else :
1920 # this is local run
2021 return ""
2122
2223
2324def set_must_gather_collector_values () -> dict [str , str ]:
2425 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 ) ,
2627 }
2728 return py_config ["must_gather_collector" ]
2829
@@ -81,8 +82,22 @@ def run_must_gather(
8182 component_name : str = "" ,
8283 namespaces_dict : dict [str , str ] | None = None ,
8384) -> 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+ """
8499 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" )
86101
87102 must_gather_command = "oc adm must-gather"
88103 if target_dir :
@@ -96,33 +111,37 @@ def run_must_gather(
96111 elif namespaces_dict :
97112 namespace_str = ""
98113 if namespaces_dict .get ("operator" ):
99- namespace_str += f"export OPERATOR_NAMESPACE={ namespaces_dict ['operator' ]} ;"
114+ namespace_str += f"export OPERATOR_NAMESPACE={ shlex . quote ( namespaces_dict ['operator' ]) } ;"
100115 if namespaces_dict .get ("notebooks" ):
101- namespace_str += f"export NOTEBOOKS_NAMESPACE={ namespaces_dict ['notebooks' ]} ;"
116+ namespace_str += f"export NOTEBOOKS_NAMESPACE={ shlex . quote ( namespaces_dict ['notebooks' ]) } ;"
102117 if namespaces_dict .get ("monitoring" ):
103- namespace_str += f"export MONITORING_NAMESPACE={ namespaces_dict ['monitoring' ]} ;"
118+ namespace_str += f"export MONITORING_NAMESPACE={ shlex . quote ( namespaces_dict ['monitoring' ]) } ;"
104119 if namespaces_dict .get ("application" ):
105- namespace_str += f"export APPLICATIONS_NAMESPACE={ namespaces_dict ['application' ]} ;"
120+ namespace_str += f"export APPLICATIONS_NAMESPACE={ shlex . quote ( namespaces_dict ['application' ]) } ;"
106121 if namespaces_dict .get ("model_registries" ):
107- namespace_str += f"export MODEL_REGISTRIES_NAMESPACE={ namespaces_dict ['model_registries' ]} ;"
122+ namespace_str += f"export MODEL_REGISTRIES_NAMESPACE={ shlex . quote ( namespaces_dict ['model_registries' ]) } ;"
108123 if namespaces_dict .get ("ossm" ):
109- namespace_str += f"export OSSM_NS={ namespaces_dict ['ossm' ]} ;"
124+ namespace_str += f"export OSSM_NS={ shlex . quote ( namespaces_dict ['ossm' ]) } ;"
110125 if namespaces_dict .get ("knative" ):
111- namespace_str += f"export KNATIVE_NS={ namespaces_dict ['knative' ]} ;"
126+ namespace_str += f"export KNATIVE_NS={ shlex . quote ( namespaces_dict ['knative' ]) } ;"
112127 if namespaces_dict .get ("auth" ):
113- namespace_str += f"export AUTH_NS={ namespaces_dict ['auth' ]} ;"
114- must_gather_command += " /usr/bin/gather"
128+ namespace_str += f"export AUTH_NS={ shlex . quote ( namespaces_dict ['auth' ]) } ;"
129+ must_gather_command += f" -- ' { namespace_str } /usr/bin/gather' "
115130
116131 return run_command (command = shlex .split (must_gather_command ), check = False )[1 ]
117132
118133
119134def 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
126145
127146
128147def collect_rhoai_must_gather (
0 commit comments