fixed exception catches for get_node expecting KeyError to expect CoreError
This commit is contained in:
parent
0db3031b15
commit
32bfa4b2f9
8 changed files with 23 additions and 26 deletions
|
@ -198,7 +198,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
def get_node(self, session, node_id, context):
|
||||
try:
|
||||
return session.get_node(node_id)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
context.abort(
|
||||
grpc.StatusCode.NOT_FOUND, "node {} not found".format(node_id)
|
||||
)
|
||||
|
|
|
@ -489,12 +489,10 @@ class CoreBroker(object):
|
|||
:param int node_id: node id of network to add tunnel to
|
||||
:return: list of gre taps
|
||||
:rtype: list
|
||||
:raises core.CoreError: when node to add net tunnel to does not exist
|
||||
"""
|
||||
try:
|
||||
net = self.session.get_node(node_id)
|
||||
logging.info("adding net tunnel for: id(%s) %s", node_id, net)
|
||||
except KeyError:
|
||||
raise KeyError("network node %s not found" % node_id)
|
||||
net = self.session.get_node(node_id)
|
||||
logging.info("adding net tunnel for: id(%s) %s", node_id, net)
|
||||
|
||||
# add other nets here that do not require tunnels
|
||||
if nodeutils.is_node(net, NodeTypes.EMANE_NET):
|
||||
|
|
|
@ -14,7 +14,7 @@ from builtins import range
|
|||
from itertools import repeat
|
||||
from queue import Empty, Queue
|
||||
|
||||
from core import utils
|
||||
from core import CoreError, utils
|
||||
from core.api.tlv import coreapi, dataconversion, structutils
|
||||
from core.config import ConfigShim
|
||||
from core.emulator.data import ConfigData, EventData, ExceptionData, FileData
|
||||
|
@ -913,7 +913,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
utils.mute_detach(command)
|
||||
else:
|
||||
node.cmd(command, wait=False)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
logging.exception("error getting object: %s", node_num)
|
||||
# XXX wait and queue this message to try again later
|
||||
# XXX maybe this should be done differently
|
||||
|
@ -1420,7 +1420,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
node = self.session.get_node(node_id)
|
||||
if object_name == BasicRangeModel.name:
|
||||
node.updatemodel(parsed_config)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
logging.error(
|
||||
"skipping mobility configuration for unknown node: %s", node_id
|
||||
)
|
||||
|
@ -1581,6 +1581,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
:param core.api.tlv.coreapi.CoreEventMessage message: event message to handle
|
||||
:return: reply messages
|
||||
:raises core.CoreError: when event type <= SHUTDOWN_STATE and not a known node id
|
||||
"""
|
||||
event_data = EventData(
|
||||
node=message.get_tlv(EventTlvs.NODE.value),
|
||||
|
@ -1599,10 +1600,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
logging.debug("handling event %s at %s", event_type.name, time.ctime())
|
||||
if event_type.value <= EventTypes.SHUTDOWN_STATE.value:
|
||||
if node_id is not None:
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
except KeyError:
|
||||
raise KeyError("Event message for unknown node %d" % node_id)
|
||||
node = self.session.get_node(node_id)
|
||||
|
||||
# configure mobility models for WLAN added during runtime
|
||||
if event_type == EventTypes.INSTANTIATION_STATE and nodeutils.is_node(
|
||||
|
@ -1706,7 +1704,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
logging.warning(
|
||||
"ignoring event for service '%s', unknown node '%s'", name, node_id
|
||||
)
|
||||
|
|
|
@ -7,7 +7,7 @@ import logging
|
|||
import os
|
||||
import threading
|
||||
|
||||
from core import CoreCommandError, constants, utils
|
||||
from core import CoreCommandError, CoreError, constants, utils
|
||||
from core.api.tlv import coreapi, dataconversion
|
||||
from core.config import ConfigGroup, ConfigShim, Configuration, ModelManager
|
||||
from core.emane import emanemanifest
|
||||
|
@ -950,7 +950,7 @@ class EmaneManager(ModelManager):
|
|||
# generate a node message for this location update
|
||||
try:
|
||||
node = self.session.get_node(n)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
logging.exception(
|
||||
"location event NEM %s has no corresponding node %s" % (nemid, n)
|
||||
)
|
||||
|
|
|
@ -4,6 +4,7 @@ Defines Emane Models used within CORE.
|
|||
import logging
|
||||
import os
|
||||
|
||||
from core import CoreError
|
||||
from core.config import ConfigGroup, Configuration
|
||||
from core.emane import emanemanifest
|
||||
from core.emulator.enumerations import ConfigDataTypes
|
||||
|
@ -142,7 +143,7 @@ class EmaneModel(WirelessModel):
|
|||
try:
|
||||
wlan = self.session.get_node(self.id)
|
||||
wlan.setnempositions(moved_netifs)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
logging.exception("error during update")
|
||||
|
||||
def linkconfig(
|
||||
|
|
|
@ -1663,7 +1663,7 @@ class Session(object):
|
|||
return None
|
||||
|
||||
return control_net
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
if remove:
|
||||
return None
|
||||
|
||||
|
@ -1807,7 +1807,7 @@ class Session(object):
|
|||
|
||||
try:
|
||||
control_net = self.get_control_net(net_index)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
logging.exception("error retrieving control net node")
|
||||
return
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import time
|
|||
from builtins import int
|
||||
from functools import total_ordering
|
||||
|
||||
from core import utils
|
||||
from core import CoreError, utils
|
||||
from core.config import ConfigGroup, ConfigurableOptions, Configuration, ModelManager
|
||||
from core.emulator.data import EventData, LinkData
|
||||
from core.emulator.enumerations import (
|
||||
|
@ -79,7 +79,7 @@ class MobilityManager(ModelManager):
|
|||
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
logging.warning(
|
||||
"skipping mobility configuration for unknown node: %s", node_id
|
||||
)
|
||||
|
@ -112,7 +112,7 @@ class MobilityManager(ModelManager):
|
|||
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
logging.exception(
|
||||
"Ignoring event for model '%s', unknown node '%s'", name, node_id
|
||||
)
|
||||
|
@ -203,7 +203,7 @@ class MobilityManager(ModelManager):
|
|||
for node_id in self.nodes():
|
||||
try:
|
||||
node = self.session.get_node(node_id)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
continue
|
||||
if node.model:
|
||||
node.model.update(moved, moved_netifs)
|
||||
|
|
|
@ -7,7 +7,7 @@ import socket
|
|||
|
||||
from future.moves.urllib.parse import urlparse
|
||||
|
||||
from core import constants
|
||||
from core import CoreError, constants
|
||||
from core.emulator.enumerations import (
|
||||
EventTypes,
|
||||
LinkTlvs,
|
||||
|
@ -438,7 +438,7 @@ class Sdt(object):
|
|||
|
||||
try:
|
||||
node = self.session.get_node(nodenum)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
node = None
|
||||
if node:
|
||||
self.updatenode(
|
||||
|
@ -508,7 +508,7 @@ class Sdt(object):
|
|||
else:
|
||||
try:
|
||||
n = self.session.get_node(nodenum)
|
||||
except KeyError:
|
||||
except CoreError:
|
||||
return False
|
||||
if nodeutils.is_node(n, (NodeTypes.WIRELESS_LAN, NodeTypes.EMANE)):
|
||||
return True
|
||||
|
|
Loading…
Reference in a new issue