Adjusting cli exception handling

Signed-off-by: Maisam Arif <maisarif@amd.com>
Change-Id: I37f44f0d07a8d1fc65e6109edf9b4cf7f30695a9
Signed-off-by: Maisam Arif <maisarif@amd.com>
This commit is contained in:
Maisam Arif
2023-10-16 03:26:17 -05:00
committed by Maisam Arif
parent ddc63db14c
commit 2468a6039c
4 changed files with 14 additions and 8 deletions
+2 -1
View File
@@ -22,6 +22,7 @@
import json
AMDSMI_ERROR_MESSAGES = {
0: "Sucess",
1: "Invalid parameters",
@@ -117,7 +118,7 @@ class AmdSmiDeviceNotFoundException(AmdSmiException):
self.command = command
self.output_format = outputformat
common_message = f"GPU Device with GPU_INDEX '{self.command}' cannot be found on the system."
common_message = f"Can not find a GPU with the corresponding identifier: '{self.command}'"
self.json_message["error"] = common_message
self.json_message["code"] = self.value
-1
View File
@@ -659,7 +659,6 @@ class AMDSMICommands():
args.retired = args.pending = args.un_res = True
values_dict = {}
bad_page_err_output = ''
# Get gpu_id for logging
gpu_id = self.helpers.get_gpu_id_from_device_handle(args.gpu)
+7 -4
View File
@@ -27,6 +27,7 @@ import time
from subprocess import run
from subprocess import PIPE, STDOUT
from typing import List
from amdsmi_init import *
from BDF import BDF
@@ -169,11 +170,11 @@ class AMDSMIHelpers():
return (gpu_choices, gpu_choices_str)
def get_device_handles_from_gpu_selections(self, gpu_selections, gpu_choices=None):
def get_device_handles_from_gpu_selections(self, gpu_selections: List[str], gpu_choices=None):
"""Convert provided gpu_selections to device_handles
Args:
gpu_selections (list[str]): This will be the GPU ID, BDF, or UUID:
gpu_selections (list[str]): Selected GPU ID(s), BDF(s), or UUID(s):
ex: ID:0 | BDF:0000:23:00.0 | UUID:ffffffff-0000-1000-0000-000000000000
gpu_choices (dict{gpu_choices}): This is a dictionary of the possible gpu_choices
Returns:
@@ -181,7 +182,7 @@ class AMDSMIHelpers():
amdsmi device_handles
(False, str): Return False, and the first input that failed to be converted
"""
if gpu_selections == ["all"]:
if 'all' in gpu_selections:
return (True, amdsmi_interface.amdsmi_get_processor_handles())
if isinstance(gpu_selections, str):
@@ -307,7 +308,9 @@ class AMDSMIHelpers():
for gpu_index, device_handle in enumerate(device_handles):
if input_device_handle.value == device_handle.value:
return gpu_index
raise IndexError("Unable to find gpu ID from device_handle")
raise amdsmi_exception.AmdSmiParameterException(input_device_handle,
amdsmi_interface.amdsmi_wrapper.amdsmi_processor_handle,
"Unable to find gpu ID from device_handle")
def get_amd_gpu_bdfs(self):
+5 -2
View File
@@ -24,9 +24,10 @@
import argparse
import errno
import os
import time
from pathlib import Path
import sys
import time
from pathlib import Path
from _version import __version__
from amdsmi_helpers import AMDSMIHelpers
@@ -205,6 +206,8 @@ class AMDSMIParser(argparse.ArgumentParser):
ouputformat=self.helpers.get_output_format()
# Checks the values
def __call__(self, parser, args, values, option_string=None):
if "all" in gpu_choices:
del gpu_choices["all"]
status, selected_device_handles = amdsmi_helpers.get_device_handles_from_gpu_selections(gpu_selections=values,
gpu_choices=gpu_choices)
if status: