Skip to content

Commit

Permalink
wp.device & wp.processor: Add proper config error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkajetanp committed Sep 7, 2023
1 parent 20aeef2 commit 52db714
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
15 changes: 10 additions & 5 deletions wp/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@
from devlib.exception import TargetStableCalledProcessError

from wp.constants import APP_NAME
from wp.exception import WPConfigError


class WorkloadDevice:
def __init__(self):
self.config = confuse.Configuration(APP_NAME, __name__)
"""Handle for the `Confuse` configuration object."""
self.device = Target.from_conf(
TargetConf.from_yaml_map(
Path(self.config['target']['target_conf'].get()).expanduser()
)
)
self.device = None
"""Handle for the Target device"""
try:
self.device = Target.from_conf(
TargetConf.from_yaml_map(
Path(self.config['target']['target_conf'].get()).expanduser()
)
)
except FileNotFoundError:
raise WPConfigError('target_conf was not properly set in the config')

self.device.execute("setenforce 0", as_root=True)

Expand Down
3 changes: 3 additions & 0 deletions wp/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ class WorkloadProcessingError(Exception):

class WPMetricFailedError(Exception):
pass

class WPConfigError(Exception):
pass
8 changes: 6 additions & 2 deletions wp/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from wp.constants import APP_NAME, SUPPORTED_WORKLOADS
from wp.helpers import wa_output_to_mock_traces, wa_output_to_traces, cpu_cluster
from wp.helpers import df_sort_by_clusters, df_add_wa_output_tags, df_iterations_mean
from wp.exception import WPMetricFailedError, WorkloadProcessorError
from wp.exception import WPMetricFailedError, WorkloadProcessorError, WPConfigError


class WorkloadProcessor:
Expand Down Expand Up @@ -45,7 +45,11 @@ def __init__(self, output_path, config=None):
self.plat_info = None
plat_info_path = os.path.expanduser(self.config['target']['plat_info'].get(str))
if plat_info_path is not None:
self.plat_info = PlatformInfo.from_yaml_map(plat_info_path)
try:
self.plat_info = PlatformInfo.from_yaml_map(plat_info_path)
except FileNotFoundError:
raise WPConfigError('plat_info was not properly set in the config')


trace_parquet_found = shutil.which('trace-parquet') is not None
no_parser = self.config['no_parser'].get(False)
Expand Down

0 comments on commit 52db714

Please sign in to comment.