switched session.metadata to just be a standard dict, fixed shutdown service issue during session.data_collect
This commit is contained in:
parent
fe95f246d4
commit
79dfbaa3ec
7 changed files with 22 additions and 40 deletions
|
@ -343,8 +343,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("get session metadata: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = session.metadata.get_configs()
|
||||
return core_pb2.GetSessionMetadataResponse(config=config)
|
||||
return core_pb2.GetSessionMetadataResponse(config=session.metadata)
|
||||
|
||||
def SetSessionMetadata(self, request, context):
|
||||
"""
|
||||
|
@ -357,7 +356,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("set session metadata: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
session.metadata.set_configs(request.config)
|
||||
session.metadata = dict(request.config)
|
||||
return core_pb2.SetSessionMetadataResponse(result=True)
|
||||
|
||||
def GetSession(self, request, context):
|
||||
|
|
|
@ -430,9 +430,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
tlv_data += coreapi.CoreRegisterTlv.pack(
|
||||
self.session.options.config_type, self.session.options.name
|
||||
)
|
||||
tlv_data += coreapi.CoreRegisterTlv.pack(
|
||||
self.session.metadata.config_type, self.session.metadata.name
|
||||
)
|
||||
tlv_data += coreapi.CoreRegisterTlv.pack(RegisterTlvs.UTILITY.value, "metadata")
|
||||
|
||||
return coreapi.CoreRegMessage.pack(MessageFlags.ADD.value, tlv_data)
|
||||
|
||||
|
@ -1046,7 +1044,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
replies = self.handle_config_session(message_type, config_data)
|
||||
elif config_data.object == self.session.location.name:
|
||||
self.handle_config_location(message_type, config_data)
|
||||
elif config_data.object == self.session.metadata.name:
|
||||
elif config_data.object == "metadata":
|
||||
replies = self.handle_config_metadata(message_type, config_data)
|
||||
elif config_data.object == "broker":
|
||||
self.handle_config_broker(message_type, config_data)
|
||||
|
@ -1132,7 +1130,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
replies = []
|
||||
if message_type == ConfigFlags.REQUEST:
|
||||
node_id = config_data.node
|
||||
metadata_configs = self.session.metadata.get_configs()
|
||||
metadata_configs = self.session.metadata
|
||||
if metadata_configs is None:
|
||||
metadata_configs = {}
|
||||
data_values = "|".join(
|
||||
|
@ -1142,7 +1140,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
config_response = ConfigData(
|
||||
message_type=0,
|
||||
node=node_id,
|
||||
object=self.session.metadata.name,
|
||||
object="metadata",
|
||||
type=ConfigFlags.NONE.value,
|
||||
data_types=data_types,
|
||||
data_values=data_values,
|
||||
|
@ -1152,7 +1150,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
values = ConfigShim.str_to_dict(config_data.data_values)
|
||||
for key in values:
|
||||
value = values[key]
|
||||
self.session.metadata.set_config(key, value)
|
||||
self.session.metadata[key] = value
|
||||
return replies
|
||||
|
||||
def handle_config_broker(self, message_type, config_data):
|
||||
|
@ -1951,18 +1949,17 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.session.broadcast_config(config_data)
|
||||
|
||||
# send session metadata
|
||||
metadata_configs = self.session.metadata.get_configs()
|
||||
metadata_configs = self.session.metadata
|
||||
if metadata_configs:
|
||||
data_values = "|".join(
|
||||
[f"{x}={metadata_configs[x]}" for x in metadata_configs]
|
||||
)
|
||||
data_types = tuple(
|
||||
ConfigDataTypes.STRING.value
|
||||
for _ in self.session.metadata.get_configs()
|
||||
ConfigDataTypes.STRING.value for _ in self.session.metadata
|
||||
)
|
||||
config_data = ConfigData(
|
||||
message_type=0,
|
||||
object=self.session.metadata.name,
|
||||
object="metadata",
|
||||
type=ConfigFlags.NONE.value,
|
||||
data_types=data_types,
|
||||
data_values=data_values,
|
||||
|
|
|
@ -26,7 +26,7 @@ from core.emulator.emudata import (
|
|||
link_config,
|
||||
)
|
||||
from core.emulator.enumerations import EventTypes, ExceptionLevels, LinkTypes, NodeTypes
|
||||
from core.emulator.sessionconfig import SessionConfig, SessionMetaData
|
||||
from core.emulator.sessionconfig import SessionConfig
|
||||
from core.errors import CoreError
|
||||
from core.location.corelocation import CoreLocation
|
||||
from core.location.event import EventLoop
|
||||
|
@ -129,7 +129,7 @@ class Session:
|
|||
for key in config:
|
||||
value = config[key]
|
||||
self.options.set_config(key, value)
|
||||
self.metadata = SessionMetaData()
|
||||
self.metadata = {}
|
||||
|
||||
# distributed support and logic
|
||||
self.distributed = DistributedController(self)
|
||||
|
@ -1513,9 +1513,8 @@ class Session:
|
|||
for node_id in self.nodes:
|
||||
node = self.nodes[node_id]
|
||||
if isinstance(node, CoreNodeBase):
|
||||
self.services.stop_services(node)
|
||||
args = (node,)
|
||||
funcs.append((self.services.stop_services, args, {}))
|
||||
args = (node,)
|
||||
funcs.append((self.services.stop_services, args, {}))
|
||||
utils.threadpool(funcs)
|
||||
|
||||
# shutdown emane
|
||||
|
|
|
@ -87,14 +87,3 @@ class SessionConfig(ConfigurableManager, ConfigurableOptions):
|
|||
if value is not None:
|
||||
value = int(value)
|
||||
return value
|
||||
|
||||
|
||||
class SessionMetaData(ConfigurableManager):
|
||||
"""
|
||||
Metadata is simply stored in a configs[] dict. Key=value pairs are
|
||||
passed in from configure messages destined to the "metadata" object.
|
||||
The data is not otherwise interpreted or processed.
|
||||
"""
|
||||
|
||||
name = "metadata"
|
||||
config_type = RegisterTlvs.UTILITY.value
|
||||
|
|
|
@ -313,13 +313,13 @@ class CoreXmlWriter:
|
|||
def write_session_metadata(self):
|
||||
# metadata
|
||||
metadata_elements = etree.Element("session_metadata")
|
||||
config = self.session.metadata.get_configs()
|
||||
config = self.session.metadata
|
||||
if not config:
|
||||
return
|
||||
|
||||
for _id in config:
|
||||
value = config[_id]
|
||||
add_configuration(metadata_elements, _id, value)
|
||||
for key in config:
|
||||
value = config[key]
|
||||
add_configuration(metadata_elements, key, value)
|
||||
|
||||
if metadata_elements.getchildren():
|
||||
self.scenario.append(metadata_elements)
|
||||
|
@ -574,7 +574,7 @@ class CoreXmlReader:
|
|||
value = data.get("value")
|
||||
configs[name] = value
|
||||
logging.info("reading session metadata: %s", configs)
|
||||
self.session.metadata.set_configs(configs)
|
||||
self.session.metadata = configs
|
||||
|
||||
def read_session_options(self):
|
||||
session_options = self.scenario.find("session_options")
|
||||
|
|
|
@ -296,9 +296,7 @@ class TestGrpc:
|
|||
|
||||
# then
|
||||
assert response.result is True
|
||||
assert session.metadata.get_config(key) == value
|
||||
config = session.metadata.get_configs()
|
||||
assert len(config) > 0
|
||||
assert session.metadata[key] == value
|
||||
|
||||
def test_get_session_metadata(self, grpc_server):
|
||||
# given
|
||||
|
@ -306,7 +304,7 @@ class TestGrpc:
|
|||
session = grpc_server.coreemu.create_session()
|
||||
key = "meta1"
|
||||
value = "value1"
|
||||
session.metadata.set_config(key, value)
|
||||
session.metadata[key] = value
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
|
|
|
@ -741,7 +741,7 @@ class TestGui:
|
|||
|
||||
coretlv.handle_message(message)
|
||||
|
||||
assert coretlv.session.metadata.get_config(test_key) == test_value
|
||||
assert coretlv.session.metadata[test_key] == test_value
|
||||
|
||||
def test_config_broker_request(self, coretlv):
|
||||
server = "test"
|
||||
|
|
Loading…
Reference in a new issue