diff --git a/daemon/core/api/grpc/server.py b/daemon/core/api/grpc/server.py index 5fae97dc..ae3ec1ec 100644 --- a/daemon/core/api/grpc/server.py +++ b/daemon/core/api/grpc/server.py @@ -232,7 +232,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): # add all hooks for hook in request.hooks: state = EventTypes(hook.state) - session.add_hook(state, hook.file, None, hook.data) + session.add_hook(state, hook.file, hook.data) # create nodes _, exceptions = grpcutils.create_nodes(session, request.nodes) @@ -918,7 +918,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): session = self.get_session(request.session_id, context) hook = request.hook state = EventTypes(hook.state) - session.add_hook(state, hook.file, None, hook.data) + session.add_hook(state, hook.file, hook.data) return core_pb2.AddHookResponse(result=True) def GetMobilityConfigs( diff --git a/daemon/core/api/tlv/corehandlers.py b/daemon/core/api/tlv/corehandlers.py index 02a6294c..1a22cedd 100644 --- a/daemon/core/api/tlv/corehandlers.py +++ b/daemon/core/api/tlv/corehandlers.py @@ -1501,7 +1501,7 @@ class CoreHandler(socketserver.BaseRequestHandler): return () state = int(state) state = EventTypes(state) - self.session.add_hook(state, file_name, source_name, data) + self.session.add_hook(state, file_name, data, source_name) return () # writing a file to the host diff --git a/daemon/core/emulator/emudata.py b/daemon/core/emulator/emudata.py index 6a0ec8a6..79c586a3 100644 --- a/daemon/core/emulator/emudata.py +++ b/daemon/core/emulator/emudata.py @@ -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: diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index 6f112ccf..8259803d 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -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, []) diff --git a/daemon/core/nodes/base.py b/daemon/core/nodes/base.py index 61e9e8fb..71870cd9 100644 --- a/daemon/core/nodes/base.py +++ b/daemon/core/nodes/base.py @@ -413,14 +413,14 @@ class CoreNodeBase(NodeBase): netif.setposition() def commonnets( - self, obj: "CoreNodeBase", want_ctrl: bool = False - ) -> List[Tuple[NodeBase, CoreInterface, CoreInterface]]: + self, node: "CoreNodeBase", want_ctrl: bool = False + ) -> List[Tuple["CoreNetworkBase", CoreInterface, CoreInterface]]: """ Given another node or net object, return common networks between this node and that object. A list of tuples is returned, with each tuple consisting of (network, interface1, interface2). - :param obj: object to get common network with + :param node: node to get common network with :param want_ctrl: flag set to determine if control network are wanted :return: tuples of common networks """ @@ -428,7 +428,7 @@ class CoreNodeBase(NodeBase): for netif1 in self.netifs(): if not want_ctrl and hasattr(netif1, "control"): continue - for netif2 in obj.netifs(): + for netif2 in node.netifs(): if netif1.net == netif2.net: common.append((netif1.net, netif1, netif2)) return common @@ -1041,7 +1041,7 @@ class CoreNetworkBase(NodeBase): """ pass - def getlinknetif(self, net: "CoreNetworkBase") -> CoreInterface: + def getlinknetif(self, net: "CoreNetworkBase") -> Optional[CoreInterface]: """ Return the interface of that links this net with another net. @@ -1049,7 +1049,7 @@ class CoreNetworkBase(NodeBase): :return: interface the provided network is linked to """ for netif in self.netifs(): - if hasattr(netif, "othernet") and netif.othernet == net: + if getattr(netif, "othernet", None) == net: return netif return None diff --git a/daemon/core/xml/corexml.py b/daemon/core/xml/corexml.py index ddb51b28..efbf85c8 100644 --- a/daemon/core/xml/corexml.py +++ b/daemon/core/xml/corexml.py @@ -662,7 +662,7 @@ class CoreXmlReader: state = EventTypes(state) data = hook.text logging.info("reading hook: state(%s) name(%s)", state, name) - self.session.add_hook(state, name, None, data) + self.session.add_hook(state, name, data) def read_session_origin(self) -> None: session_origin = self.scenario.find("session_origin") diff --git a/daemon/tests/test_grpc.py b/daemon/tests/test_grpc.py index 5f34e2e2..5e765f42 100644 --- a/daemon/tests/test_grpc.py +++ b/daemon/tests/test_grpc.py @@ -450,7 +450,7 @@ class TestGrpc: session = grpc_server.coreemu.create_session() file_name = "test" file_data = "echo hello" - session.add_hook(EventTypes.RUNTIME_STATE, file_name, None, file_data) + session.add_hook(EventTypes.RUNTIME_STATE, file_name, file_data) # then with client.context_connect(): diff --git a/daemon/tests/test_xml.py b/daemon/tests/test_xml.py index 897bb6fb..bb5a6bf9 100644 --- a/daemon/tests/test_xml.py +++ b/daemon/tests/test_xml.py @@ -23,12 +23,12 @@ class TestXml: file_name = "runtime_hook.sh" data = "#!/bin/sh\necho hello" state = EventTypes.RUNTIME_STATE - session.add_hook(state, file_name, None, data) + session.add_hook(state, file_name, data) file_name = "instantiation_hook.sh" data = "#!/bin/sh\necho hello" state = EventTypes.INSTANTIATION_STATE - session.add_hook(state, file_name, None, data) + session.add_hook(state, file_name, data) # save xml xml_file = tmpdir.join("session.xml")