From d880960cf7be60f1dc78482b4401dcf7bdc7a697 Mon Sep 17 00:00:00 2001 From: bharnden Date: Sun, 24 Mar 2019 14:13:04 -0700 Subject: [PATCH] grpc added get/set emane config test, fixed logic for setting emane/session configs in grpc server --- daemon/core/grpc/server.py | 6 ++++-- daemon/tests/test_grpc.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/daemon/core/grpc/server.py b/daemon/core/grpc/server.py index dd75bccd..21f00696 100644 --- a/daemon/core/grpc/server.py +++ b/daemon/core/grpc/server.py @@ -320,7 +320,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): def SetSessionOptions(self, request, context): logging.debug("set session options: %s", request) session = self.get_session(request.id, context) - session.options.set_configs(request.config) + config = session.options.get_configs() + config.update(request.config) return core_pb2.SetSessionOptionsResponse(result=True) def GetSession(self, request, context): @@ -898,7 +899,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): def SetEmaneConfig(self, request, context): logging.debug("set emane config: %s", request) session = self.get_session(request.session, context) - session.emane.set_configs(request.config) + config = session.emane.get_configs() + config.update(request.config) return core_pb2.SetEmaneConfigResponse(result=True) def GetEmaneModels(self, request, context): diff --git a/daemon/tests/test_grpc.py b/daemon/tests/test_grpc.py index f6de42b2..9bb15184 100644 --- a/daemon/tests/test_grpc.py +++ b/daemon/tests/test_grpc.py @@ -3,6 +3,7 @@ import time import pytest +from core.emane.ieee80211abg import EmaneIeee80211abgModel from core.emulator.emudata import NodeOptions, LinkOptions from core.grpc import core_pb2 from core.enumerations import NodeTypes, EventTypes @@ -157,6 +158,8 @@ class TestGrpc: # then assert response.result is True assert session.options.get_config(option) == value + config = session.options.get_configs() + assert len(config) > 0 def test_set_session_state(self, grpc_server): # given @@ -401,3 +404,32 @@ class TestGrpc: assert response.result is True config = session.mobility.get_model_config(wlan.objid, BasicRangeModel.name) assert config[range_key] == range_value + + def test_get_emane_config(self, grpc_server): + # given + client = CoreGrpcClient() + session = grpc_server.coreemu.create_session() + + # then + with client.context_connect(): + response = client.get_emane_config(session.session_id) + + # then + assert len(response.groups) > 0 + + def test_set_emane_config(self, grpc_server): + # given + client = CoreGrpcClient() + session = grpc_server.coreemu.create_session() + config_key = "platform_id_start" + config_value = "2" + + # then + with client.context_connect(): + response = client.set_emane_config(session.session_id, {config_key: config_value}) + + # then + assert response.result is True + config = session.emane.get_configs() + assert len(config) > 1 + assert config[config_key] == config_value