Skip to content

Commit

Permalink
fix(parameter): throws error when param tree not found during apply
Browse files Browse the repository at this point in the history
Applying config parameter trees that do not exist did not throw an
error. This gave an impression to the end user that the operation was
successful. While this may make the command seem idempotent, it may have
side effects when the users do want to know if the operation was
actually successful.

Wrike Ticket: https://www.wrike.com/open.htm?id=1182861754
  • Loading branch information
pallabpain committed Jan 21, 2024
1 parent 20b21e2 commit cb50d82
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions riocli/parameter/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from riocli.config import new_client
from riocli.constants import Colors, Symbols
from riocli.utils import tabulate_data, print_separator
from riocli.parameter.utils import list_trees


@click.command(
Expand All @@ -44,7 +45,7 @@
help="Skip confirmation")
def apply_configurations(
devices: typing.List,
tree_names: str = None,
tree_names: typing.List[str] = None,
retry_limit: int = 0,
silent: bool = False,
) -> None:
Expand All @@ -54,6 +55,9 @@ def apply_configurations(
try:
client = new_client()

if tree_names:
validate_trees(tree_names)

online_devices = client.get_all_devices(online_device=True)
device_map = {d.name: d for d in online_devices}

Expand Down Expand Up @@ -100,7 +104,12 @@ def apply_configurations(
result.append([device_name, success])

tabulate_data(result, headers=["Device", "Success"])
except IOError as e:
click.secho(str(e.__traceback__), fg=Colors.RED)
click.secho(str(e), fg=Colors.RED)
except Exception as e:
click.secho('{} Failed to apply configs: {}'.format(Symbols.ERROR, e), fg=Colors.RED)
raise SystemExit(1) from e


def validate_trees(tree_names: typing.List[str]) -> None:
available_trees = set(list_trees())
if not set(tree_names).issubset(available_trees):
raise Exception('one or more specified tree names are invalid')

0 comments on commit cb50d82

Please sign in to comment.