Skip to content

Commit

Permalink
Bug fix: declare log.fatal as typing.NoReturn
Browse files Browse the repository at this point in the history
  • Loading branch information
ipspace committed Jul 8, 2023
1 parent 4c559cf commit 13b99f6
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 17 deletions.
1 change: 0 additions & 1 deletion netsim/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def get_message(topology: Box, action: str, default_message: bool = False) -> ty

if not isinstance(topology.message,Box): # Otherwise we should be dealing with a dict
common.fatal('topology message should be a string or a dict')
return None

return topology.message.get(action,None) # Return action-specific message if it exists

Expand Down
4 changes: 0 additions & 4 deletions netsim/cli/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def inventory(name: str) -> typing.Optional[dict]:
return json.loads(result.stdout)
except:
common.fatal('Cannot parse JSON data returned by ansible-inventory','inventory')
return None

except:
try:
Expand All @@ -44,13 +43,10 @@ def inventory(name: str) -> typing.Optional[dict]:

common.fatal('Cannot get Ansible inventory data for %s with ansible-inventory. Is the host name correct?' % name,'inventory')

return None

def playbook(name: str, args: typing.List[str]) -> None:
pbname = find_playbook(name)
if not pbname:
common.fatal("Cannot find Ansible playbook %s, aborting" % name)
return

if common.VERBOSE:
print("Running Ansible playbook %s" % pbname)
Expand Down
2 changes: 0 additions & 2 deletions netsim/cli/clab.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def clab_config_adjust(infile: str, outfile: str, configs: str) -> None:
clab = read_topology.read_yaml(infile)
if not clab:
common.fatal("Cannot read clab.yml configuration file, aborting")
return

clab_yml = common.get_yaml_string(clab)
if not ('topology' in clab and 'nodes' in clab.topology):
Expand Down Expand Up @@ -129,7 +128,6 @@ def run(cli_args: typing.List[str]) -> None:

if not settings:
common.fatal("Cannot read the system defaults","clab")
return

if cli_args[0] == 'tarball':
clab_tarball(cli_args[1:],settings)
Expand Down
1 change: 0 additions & 1 deletion netsim/cli/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,3 @@ def run(cli_args: typing.List[str]) -> None:
connect_to_tool(host,rest,topology,log_level)
else:
common.fatal(f'Unknown host or external tool {host}')
return
1 change: 0 additions & 1 deletion netsim/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def install_parse(args: typing.List[str]) -> argparse.Namespace:
def run(cli_args: typing.List[str]) -> None:
if not cli_args:
common.fatal("Specify an installation script to run or use -h to get help","install")
return

args = install_parse(cli_args)

Expand Down
1 change: 0 additions & 1 deletion netsim/cli/libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ def run(cli_args: typing.List[str]) -> None:
topology = read_topology.load("package:cli/empty.yml","","package:topology-defaults.yml")
if not topology:
common.fatal("Cannot read the system defaults","libvirt")
return

if not cli_args:
libvirt_usage()
Expand Down
1 change: 0 additions & 1 deletion netsim/cli/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def get_modlist(settings: Box, args: argparse.Namespace) -> list:
return [ args.module ]
else:
common.fatal(f'Unknown module: {args.module}')
return []

return sorted([ m for m in settings.keys() if 'supported_on' in settings[m]])

Expand Down
1 change: 0 additions & 1 deletion netsim/cli/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,3 @@ def run(cli_args: typing.List[str]) -> None:
action_map[args.action](topology,args,lab_states)
else:
common.fatal(f'Unknown action {args.action}')
return
2 changes: 0 additions & 2 deletions netsim/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ def run(cli_args: typing.List[str]) -> None:
settings = read_topology.read_yaml('package:topology-defaults.yml')
if not cli_args:
common.fatal("Specify the virtualization environment to test or use -h to get help","test")
return

if not settings:
common.fatal("Cannot read the global defaults","test")
return

args = test_parse(cli_args,settings)
if os.path.exists(args.workdir):
Expand Down
2 changes: 0 additions & 2 deletions netsim/cli/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def get_topology(args: argparse.Namespace, cli_args: typing.List[str]) -> Box:
topology = read_topology.read_yaml(filename=args.snapshot)
if topology is None:
common.fatal(f'Cannot read snapshot file {args.snapshot}, aborting...')
return Box({}) # pragma: no-cover

print(f"Using transformed lab topology from snapshot file {args.snapshot}")
else: # No snapshot file, use 'netlab create' parser
Expand Down Expand Up @@ -281,7 +280,6 @@ def run(cli_args: typing.List[str]) -> None:
status_start_lab(topology)
if 'err_conflict' in topology.defaults:
common.fatal(f'race condition, lab instance already running in {topology.defaults.err_conflict}')
return

if not is_dry_run():
status.lock_directory()
Expand Down
2 changes: 1 addition & 1 deletion netsim/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FatalError(Warning):
class ErrorAbort(Exception):
pass

def fatal(text: str, module: str = 'netlab') -> None:
def fatal(text: str, module: str = 'netlab') -> typing.NoReturn:
global err_count
err_count = err_count + 1
if RAISE_ON_ERROR:
Expand Down

0 comments on commit 13b99f6

Please sign in to comment.