Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-mode: T6586: add a distinct exception for unconfigured objects (as opposed to entire subsystems) #3818

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion python/vyos/opmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ class Error(Exception):

class UnconfiguredSubsystem(Error):
""" Requested operation is valid, but cannot be completed
because corresponding subsystem is not configured and running.
because corresponding subsystem is not configured
and thus is not running.
"""
pass

class UnconfiguredObject(UnconfiguredSubsystem):
""" Requested operation is valid but cannot be completed
because its parameter refers to an object that does not exist
in the system configuration.
"""
pass

Expand Down
2 changes: 1 addition & 1 deletion src/op_mode/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _get_raw_data_fdb(bridge):
# From iproute2 fdb.c, fdb_show() will only exit(-1) in case of
# non-existent bridge device; raise error.
if code == 255:
raise vyos.opmode.UnconfiguredSubsystem(f"no such bridge device {bridge}")
raise vyos.opmode.UnconfiguredObject(f"bridge {bridge} does not exist in the system")
data_dict = json.loads(json_data)
return data_dict

Expand Down
2 changes: 1 addition & 1 deletion src/op_mode/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def _wrapper(*args, **kwargs):

# Check if config does not exist
if not config.exists(f'interfaces {interface_path} address dhcp{v}'):
raise vyos.opmode.UnconfiguredSubsystem(unconf_message)
raise vyos.opmode.UnconfiguredObject(unconf_message)
return func(*args, **kwargs)
return _wrapper

Expand Down
2 changes: 1 addition & 1 deletion src/op_mode/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def show_fingerprints(raw: bool, ascii: bool):
def show_dynamic_protection(raw: bool):
config = ConfigTreeQuery()
if not config.exists(['service', 'ssh', 'dynamic-protection']):
raise vyos.opmode.UnconfiguredSubsystem("SSH server dynamic-protection is not enabled.")
raise vyos.opmode.UnconfiguredObject("SSH server dynamic-protection is not enabled.")

attackers = []
try:
Expand Down
4 changes: 2 additions & 2 deletions src/op_mode/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _convert_config(zones_config: dict, zone: str = None) -> list:
if zones_config:
output = [_convert_one_zone_data(zone, zones_config)]
else:
raise vyos.opmode.DataUnavailable(f'Zone {zone} not found')
raise vyos.opmode.UnconfiguredObject(f'Zone {zone} not found')
else:
if zones_config:
output = _convert_zones_data(zones_config)
Expand Down Expand Up @@ -212,4 +212,4 @@ def show(raw: bool, zone: typing.Optional[str]):
print(res)
except (ValueError, vyos.opmode.Error) as e:
print(e)
sys.exit(1)
sys.exit(1)
2 changes: 2 additions & 0 deletions src/services/api/graphql/session/errors/op_mode_errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
op_mode_err_msg = {
"UnconfiguredSubsystem": "subsystem is not configured or not running",
"UnconfiguredObject": "object does not exist in the system configuration",
"DataUnavailable": "data currently unavailable",
"PermissionDenied": "client does not have permission",
"InsufficientResources": "insufficient system resources",
Expand All @@ -9,6 +10,7 @@

op_mode_err_code = {
"UnconfiguredSubsystem": 2000,
"UnconfiguredObject": 2003,
"DataUnavailable": 2001,
"InsufficientResources": 2002,
"PermissionDenied": 1003,
Expand Down
Loading