fixed session.add_hook to not require a source, since it was not typically used an None was being passed, cleaned up some bad type hinting in related to session.py

This commit is contained in:
Blake Harnden 2020-05-21 00:20:05 -07:00
parent 4b6ba90331
commit bcd9e4ceb1
8 changed files with 26 additions and 22 deletions

View file

@ -1,4 +1,4 @@
from typing import List, Optional
from typing import List, Optional, Union
import netaddr
@ -21,7 +21,7 @@ class IdGen:
def link_config(
network: CoreNetworkBase,
node: Union[CoreNetworkBase, PhysicalNode],
interface: CoreInterface,
link_options: LinkOptions,
devname: str = None,
@ -30,7 +30,7 @@ def link_config(
"""
Convenience method for configuring a link,
:param network: network to configure link for
:param node: network to configure link for
:param interface: interface to configure
:param link_options: data to configure link with
:param devname: device name, default is None
@ -49,10 +49,10 @@ def link_config(
# hacky check here, because physical and emane nodes do not conform to the same
# linkconfig interface
if not isinstance(network, (EmaneNet, PhysicalNode)):
if not isinstance(node, (EmaneNet, PhysicalNode)):
config["devname"] = devname
network.linkconfig(**config)
node.linkconfig(**config)
class NodeOptions:

View file

@ -196,7 +196,11 @@ class Session:
def _link_nodes(
self, node_one_id: int, node_two_id: int
) -> Tuple[
Optional[NodeBase], Optional[NodeBase], CoreNetworkBase, CoreNetworkBase, GreTap
Optional[CoreNode],
Optional[CoreNode],
Optional[CoreNetworkBase],
Optional[CoreNetworkBase],
GreTap,
]:
"""
Convenience method for retrieving nodes within link data.
@ -856,19 +860,19 @@ class Session:
CoreXmlWriter(self).write(file_name)
def add_hook(
self, state: EventTypes, file_name: str, source_name: str, data: str
self, state: EventTypes, file_name: str, data: str, source_name: str = None
) -> None:
"""
Store a hook from a received file message.
:param state: when to run hook
:param file_name: file name for hook
:param source_name: source name
:param data: hook data
:param source_name: source name
:return: nothing
"""
logging.info(
"setting state hook: %s - %s from %s", state, file_name, source_name
"setting state hook: %s - %s source(%s)", state, file_name, source_name
)
hook = file_name, data
state_hooks = self._hooks.setdefault(state, [])