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:
parent
4b6ba90331
commit
bcd9e4ceb1
8 changed files with 26 additions and 22 deletions
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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, [])
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue