3636from dags .tpu_observability .configs .common import MachineConfigMap , GCS_CONFIG_PATH
3737
3838
39- def run_command (info , pod_name : str , tpu_args : str ) -> str :
39+ def execute_tpu_info_cli_command (info , pod_name : str , tpu_args : str ) -> str :
4040 """Helper to handle KUBECONFIG and execute kubectl."""
4141 with tempfile .NamedTemporaryFile () as temp_config_file :
4242 env = os .environ .copy ()
@@ -49,7 +49,9 @@ def run_command(info, pod_name: str, tpu_args: str) -> str:
4949 return subprocess .run_exec (cmd , env = env )
5050
5151
52- def check_output_contains (output : str , patterns : List [str ], context : str ):
52+ def verify_output_contains_patterns (
53+ output : str , patterns : List [str ], context : str
54+ ):
5355 """Helper to verify expected strings in output."""
5456 for pattern in patterns :
5557 if pattern not in output :
@@ -60,7 +62,7 @@ def check_output_contains(output: str, patterns: List[str], context: str):
6062
6163@task
6264def validate_help (info , pod_name : str ) -> str :
63- output = run_command (info , pod_name , "tpu-info -help" )
65+ output = execute_tpu_info_cli_command (info , pod_name , "tpu-info -help" )
6466 patterns = [
6567 "Display TPU info and metrics." ,
6668 "options:" ,
@@ -71,21 +73,21 @@ def validate_help(info, pod_name: str) -> str:
7173 "--rate RATE" ,
7274 "--list_metrics" ,
7375 ]
74- check_output_contains (output , patterns , "tpu-info -help" )
76+ verify_output_contains_patterns (output , patterns , "tpu-info -help" )
7577 return output
7678
7779
7880@task
7981def validate_version (info , pod_name : str ) -> str :
80- output = run_command (info , pod_name , "tpu-info --version" )
82+ output = execute_tpu_info_cli_command (info , pod_name , "tpu-info --version" )
8183 patterns = ["tpu-info version:" , "libtpu version:" , "accelerator type:" ]
82- check_output_contains (output , patterns , "tpu-info --version" )
84+ verify_output_contains_patterns (output , patterns , "tpu-info --version" )
8385 return output
8486
8587
8688@task
8789def validate_process (info , pod_name : str ) -> str :
88- output = run_command (info , pod_name , "tpu-info --process" )
90+ output = execute_tpu_info_cli_command (info , pod_name , "tpu-info --process" )
8991 patterns = [
9092 "TPU Process Info" ,
9193 "Chip" ,
@@ -94,7 +96,7 @@ def validate_process(info, pod_name: str) -> str:
9496 "/dev/vfio/" ,
9597 "python" ,
9698 ]
97- check_output_contains (output , patterns , "tpu-info --process" )
99+ verify_output_contains_patterns (output , patterns , "tpu-info --process" )
98100 return output
99101
100102
0 commit comments