From ad09bd55045f3126a883d4e6ed085dc9fb0cfd8e Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Fri, 7 May 2021 13:10:05 -0700 Subject: [PATCH] initial changes to mark older style services as deprecated and make configurable services the defaults for the python gui, added attribute to still allow supporting the legacy gui for time being and logic to compensate --- daemon/core/api/tlv/corehandlers.py | 2 +- daemon/core/configservices/quaggaservices/services.py | 4 ++-- daemon/core/emane/emanemanager.py | 2 +- daemon/core/emulator/data.py | 1 + daemon/core/emulator/session.py | 10 +++++++--- daemon/core/gui/coreclient.py | 6 +++--- daemon/core/gui/dialogs/emaneconfig.py | 2 +- daemon/core/gui/dialogs/nodeservice.py | 2 +- daemon/core/gui/dialogs/serviceconfig.py | 2 +- daemon/core/gui/graph/node.py | 4 +++- daemon/tests/conftest.py | 1 + daemon/tests/test_grpc.py | 3 ++- 12 files changed, 24 insertions(+), 15 deletions(-) diff --git a/daemon/core/api/tlv/corehandlers.py b/daemon/core/api/tlv/corehandlers.py index 631b5491..527924c1 100644 --- a/daemon/core/api/tlv/corehandlers.py +++ b/daemon/core/api/tlv/corehandlers.py @@ -688,8 +688,8 @@ class CoreHandler(socketserver.BaseRequestHandler): options = NodeOptions( name=message.get_tlv(NodeTlvs.NAME.value), model=message.get_tlv(NodeTlvs.MODEL.value), + legacy=True, ) - options.set_position( x=message.get_tlv(NodeTlvs.X_POSITION.value), y=message.get_tlv(NodeTlvs.Y_POSITION.value), diff --git a/daemon/core/configservices/quaggaservices/services.py b/daemon/core/configservices/quaggaservices/services.py index 07ce4644..922117cb 100644 --- a/daemon/core/configservices/quaggaservices/services.py +++ b/daemon/core/configservices/quaggaservices/services.py @@ -102,9 +102,9 @@ class Zebra(ConfigService): ip4s = [] ip6s = [] for ip4 in iface.ip4s: - ip4s.append(str(ip4.ip)) + ip4s.append(str(ip4)) for ip6 in iface.ip6s: - ip6s.append(str(ip6.ip)) + ip6s.append(str(ip6)) ifaces.append((iface, ip4s, ip6s, iface.control)) return dict( diff --git a/daemon/core/emane/emanemanager.py b/daemon/core/emane/emanemanager.py index 3eabf54e..11eda990 100644 --- a/daemon/core/emane/emanemanager.py +++ b/daemon/core/emane/emanemanager.py @@ -208,7 +208,7 @@ class EmaneManager: self.node_models.clear() else: self.node_configs.get(node_id, {}).clear() - del self.node_models[node_id] + self.node_models.pop(node_id, None) def deleteeventservice(self) -> None: if self.service: diff --git a/daemon/core/emulator/data.py b/daemon/core/emulator/data.py index 68a92eea..f56ce569 100644 --- a/daemon/core/emulator/data.py +++ b/daemon/core/emulator/data.py @@ -91,6 +91,7 @@ class NodeOptions: server: str = None image: str = None emane: str = None + legacy: bool = False def set_position(self, x: float, y: float) -> None: """ diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index ced59d56..ae1bb185 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -549,12 +549,16 @@ class Session: # add services to needed nodes if isinstance(node, (CoreNode, PhysicalNode)): node.type = options.model - logger.debug("set node type: %s", node.type) - self.services.add_services(node, node.type, options.services) + if options.legacy or options.services: + logger.debug("set node type: %s", node.type) + self.services.add_services(node, node.type, options.services) # add config services + config_services = options.config_services + if not options.legacy and not config_services: + config_services = self.services.default_services.get(node.type, []) logger.info("setting node config services: %s", options.config_services) - for name in options.config_services: + for name in config_services: service_class = self.service_manager.get_service(name) node.add_config_service(service_class) diff --git a/daemon/core/gui/coreclient.py b/daemon/core/gui/coreclient.py index 628569a2..05fe7960 100644 --- a/daemon/core/gui/coreclient.py +++ b/daemon/core/gui/coreclient.py @@ -393,7 +393,7 @@ class CoreClient: self.client.connect() # get current core configurations services/config services core_config = self.client.get_config() - self.emane_models = core_config.emane_models + self.emane_models = sorted(core_config.emane_models) for service in core_config.services: group_services = self.services.setdefault(service.group, set()) group_services.add(service.name) @@ -664,12 +664,12 @@ class CoreClient: ) if nutils.is_custom(node): services = nutils.get_custom_services(self.app.guiconfig, model) - node.services = set(services) + node.config_services = set(services) # assign default services to CORE node else: services = self.session.default_services.get(model) if services: - node.services = services.copy() + node.config_services = services.copy() logger.info( "add node(%s) to session(%s), coordinates(%s, %s)", node.name, diff --git a/daemon/core/gui/dialogs/emaneconfig.py b/daemon/core/gui/dialogs/emaneconfig.py index ef446a62..9d9090b6 100644 --- a/daemon/core/gui/dialogs/emaneconfig.py +++ b/daemon/core/gui/dialogs/emaneconfig.py @@ -116,7 +116,7 @@ class EmaneConfigDialog(Dialog): self.radiovar.set(1) self.emane_models: List[str] = [ - x.split("_")[1] for x in sorted(self.app.core.emane_models) + x.split("_")[1] for x in self.app.core.emane_models ] model = self.emane_models[0] self.emane_model: tk.StringVar = tk.StringVar(value=model) diff --git a/daemon/core/gui/dialogs/nodeservice.py b/daemon/core/gui/dialogs/nodeservice.py index 09732e73..f27f9cf5 100644 --- a/daemon/core/gui/dialogs/nodeservice.py +++ b/daemon/core/gui/dialogs/nodeservice.py @@ -17,7 +17,7 @@ if TYPE_CHECKING: class NodeServiceDialog(Dialog): def __init__(self, app: "Application", node: Node) -> None: - title = f"{node.name} Services" + title = f"{node.name} Services (Deprecated)" super().__init__(app, title) self.node: Node = node self.groups: Optional[ListboxScroll] = None diff --git a/daemon/core/gui/dialogs/serviceconfig.py b/daemon/core/gui/dialogs/serviceconfig.py index 16d3a951..16c3374e 100644 --- a/daemon/core/gui/dialogs/serviceconfig.py +++ b/daemon/core/gui/dialogs/serviceconfig.py @@ -28,7 +28,7 @@ class ServiceConfigDialog(Dialog): def __init__( self, master: tk.BaseWidget, app: "Application", service_name: str, node: Node ) -> None: - title = f"{service_name} Service" + title = f"{service_name} Service (Deprecated)" super().__init__(app, title, master=master) self.core: "CoreClient" = app.core self.node: Node = node diff --git a/daemon/core/gui/graph/node.py b/daemon/core/gui/graph/node.py index 1b79e530..2bd4ae40 100644 --- a/daemon/core/gui/graph/node.py +++ b/daemon/core/gui/graph/node.py @@ -255,10 +255,12 @@ class CanvasNode: else: self.context.add_command(label="Configure", command=self.show_config) if nutils.is_container(self.core_node): - self.context.add_command(label="Services", command=self.show_services) self.context.add_command( label="Config Services", command=self.show_config_services ) + self.context.add_command( + label="Services (Deprecated)", command=self.show_services + ) if is_emane: self.context.add_command( label="EMANE Config", command=self.show_emane_config diff --git a/daemon/tests/conftest.py b/daemon/tests/conftest.py index a558fcec..5ced3fc8 100644 --- a/daemon/tests/conftest.py +++ b/daemon/tests/conftest.py @@ -78,6 +78,7 @@ def global_coreemu(patcher): def global_session(request, patcher, global_coreemu): mkdir = not request.config.getoption("mock") session = Session(1000, {"emane_prefix": "/usr"}, mkdir) + session.service_manager = global_coreemu.service_manager yield session session.shutdown() diff --git a/daemon/tests/test_grpc.py b/daemon/tests/test_grpc.py index bcdd7104..e836251e 100644 --- a/daemon/tests/test_grpc.py +++ b/daemon/tests/test_grpc.py @@ -702,7 +702,8 @@ class TestGrpc: # given client = CoreGrpcClient() session = grpc_server.coreemu.create_session() - node = session.add_node(CoreNode) + options = NodeOptions(legacy=True) + node = session.add_node(CoreNode, options=options) service_name = "DefaultRoute" # then