grpc added mobility tests

This commit is contained in:
bharnden 2019-03-25 12:59:07 -07:00
parent 03c221efa9
commit b15e525cc1
3 changed files with 65 additions and 5 deletions

View file

@ -731,7 +731,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
def GetMobilityConfigs(self, request, context):
logging.debug("get mobility configs: %s", request)
session = self.get_session(request.session, context)
mobility_configs = {}
response = core_pb2.GetMobilityConfigsResponse()
for node_id, model_config in session.mobility.node_configurations.iteritems():
if node_id == -1:
continue
@ -740,8 +740,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
continue
config = session.mobility.get_model_config(node_id, model_name)
groups = get_config_groups(config, Ns2ScriptedMobility)
mobility_configs[node_id] = groups
return core_pb2.GetMobilityConfigsResponse(configs=mobility_configs)
response.configs[node_id].groups.extend(groups)
return response
def GetMobilityConfig(self, request, context):
logging.debug("get mobility config: %s", request)

View file

@ -73,7 +73,6 @@ service CoreApi {
rpc MobilityAction (MobilityActionRequest) returns (MobilityActionResponse) {
}
// service rpc
rpc GetServices (GetServicesRequest) returns (GetServicesResponse) {
}

View file

@ -8,7 +8,7 @@ from core.emulator.emudata import NodeOptions, LinkOptions
from core.grpc import core_pb2
from core.enumerations import NodeTypes, EventTypes
from core.grpc.client import CoreGrpcClient
from core.mobility import BasicRangeModel
from core.mobility import BasicRangeModel, Ns2ScriptedMobility
MODELS = [
"router",
@ -503,3 +503,64 @@ class TestGrpc:
# then
assert len(response.models) > 0
def test_get_mobility_configs(self, grpc_server):
# given
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
session.mobility.set_model_config(wlan.objid, Ns2ScriptedMobility.name, {})
# then
with client.context_connect():
response = client.get_mobility_configs(session.session_id)
# then
assert len(response.configs) > 0
assert wlan.objid in response.configs
def test_get_mobility_config(self, grpc_server):
# given
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
session.mobility.set_model_config(wlan.objid, Ns2ScriptedMobility.name, {})
# then
with client.context_connect():
response = client.get_mobility_config(session.session_id, wlan.objid)
# then
assert len(response.groups) > 0
def test_set_mobility_config(self, grpc_server):
# given
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
config_key = "refresh_ms"
config_value = "60"
# then
with client.context_connect():
response = client.set_mobility_config(session.session_id, wlan.objid, {config_key: config_value})
# then
assert response.result is True
config = session.mobility.get_model_config(wlan.objid, Ns2ScriptedMobility.name)
assert config[config_key] == config_value
def test_mobility_action(self, grpc_server):
# given
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
session.mobility.set_model_config(wlan.objid, Ns2ScriptedMobility.name, {})
session.instantiate()
# then
with client.context_connect():
response = client.mobility_action(session.session_id, wlan.objid, core_pb2.MOBILITY_STOP)
# then
assert response.result is True