grpc: removed add hook and get gooks, can be achieved with get session and start session
This commit is contained in:
parent
634341dd03
commit
f271b0289e
6 changed files with 0 additions and 184 deletions
|
@ -646,38 +646,6 @@ class CoreGrpcClient:
|
||||||
)
|
)
|
||||||
return self.stub.DeleteLink(request)
|
return self.stub.DeleteLink(request)
|
||||||
|
|
||||||
def get_hooks(self, session_id: int) -> core_pb2.GetHooksResponse:
|
|
||||||
"""
|
|
||||||
Get all hook scripts.
|
|
||||||
|
|
||||||
:param session_id: session id
|
|
||||||
:return: response with a list of hooks
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.GetHooksRequest(session_id=session_id)
|
|
||||||
return self.stub.GetHooks(request)
|
|
||||||
|
|
||||||
def add_hook(
|
|
||||||
self,
|
|
||||||
session_id: int,
|
|
||||||
state: core_pb2.SessionState,
|
|
||||||
file_name: str,
|
|
||||||
file_data: str,
|
|
||||||
) -> core_pb2.AddHookResponse:
|
|
||||||
"""
|
|
||||||
Add hook scripts.
|
|
||||||
|
|
||||||
:param session_id: session id
|
|
||||||
:param state: state to trigger hook
|
|
||||||
:param file_name: name of file for hook script
|
|
||||||
:param file_data: hook script contents
|
|
||||||
:return: response with result of success or failure
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
hook = core_pb2.Hook(state=state, file=file_name, data=file_data)
|
|
||||||
request = core_pb2.AddHookRequest(session_id=session_id, hook=hook)
|
|
||||||
return self.stub.AddHook(request)
|
|
||||||
|
|
||||||
def get_mobility_configs(self, session_id: int) -> GetMobilityConfigsResponse:
|
def get_mobility_configs(self, session_id: int) -> GetMobilityConfigsResponse:
|
||||||
"""
|
"""
|
||||||
Get all mobility configurations.
|
Get all mobility configurations.
|
||||||
|
|
|
@ -66,7 +66,6 @@ from core.api.grpc.wlan_pb2 import (
|
||||||
WlanConfig,
|
WlanConfig,
|
||||||
WlanLinkRequest,
|
WlanLinkRequest,
|
||||||
)
|
)
|
||||||
from core.api.grpc.wrappers import Hook
|
|
||||||
from core.emulator.data import IpPrefixes
|
from core.emulator.data import IpPrefixes
|
||||||
from core.errors import CoreError
|
from core.errors import CoreError
|
||||||
|
|
||||||
|
@ -764,35 +763,6 @@ class CoreGrpcClient:
|
||||||
response = self.stub.DeleteLink(request)
|
response = self.stub.DeleteLink(request)
|
||||||
return response.result
|
return response.result
|
||||||
|
|
||||||
def get_hooks(self, session_id: int) -> List[wrappers.Hook]:
|
|
||||||
"""
|
|
||||||
Get all hook scripts.
|
|
||||||
|
|
||||||
:param session_id: session id
|
|
||||||
:return: list of hooks
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.GetHooksRequest(session_id=session_id)
|
|
||||||
response = self.stub.GetHooks(request)
|
|
||||||
hooks = []
|
|
||||||
for hook_proto in response.hooks:
|
|
||||||
hook = wrappers.Hook.from_proto(hook_proto)
|
|
||||||
hooks.append(hook)
|
|
||||||
return hooks
|
|
||||||
|
|
||||||
def add_hook(self, session_id: int, hook: Hook) -> bool:
|
|
||||||
"""
|
|
||||||
Add hook scripts.
|
|
||||||
|
|
||||||
:param session_id: session id
|
|
||||||
:param hook: hook to add
|
|
||||||
:return: True for success, False otherwise
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.AddHookRequest(session_id=session_id, hook=hook.to_proto())
|
|
||||||
response = self.stub.AddHook(request)
|
|
||||||
return response.result
|
|
||||||
|
|
||||||
def get_mobility_configs(
|
def get_mobility_configs(
|
||||||
self, session_id: int
|
self, session_id: int
|
||||||
) -> Dict[int, Dict[str, wrappers.ConfigOption]]:
|
) -> Dict[int, Dict[str, wrappers.ConfigOption]]:
|
||||||
|
|
|
@ -920,38 +920,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
session.broadcast_link(link_data)
|
session.broadcast_link(link_data)
|
||||||
return core_pb2.DeleteLinkResponse(result=True)
|
return core_pb2.DeleteLinkResponse(result=True)
|
||||||
|
|
||||||
def GetHooks(
|
|
||||||
self, request: core_pb2.GetHooksRequest, context: ServicerContext
|
|
||||||
) -> core_pb2.GetHooksResponse:
|
|
||||||
"""
|
|
||||||
Retrieve all hooks from a session
|
|
||||||
|
|
||||||
:param request: get-hook request
|
|
||||||
:param context: context object
|
|
||||||
:return: get-hooks response about all the hooks in all session states
|
|
||||||
"""
|
|
||||||
logger.debug("get hooks: %s", request)
|
|
||||||
session = self.get_session(request.session_id, context)
|
|
||||||
hooks = grpcutils.get_hooks(session)
|
|
||||||
return core_pb2.GetHooksResponse(hooks=hooks)
|
|
||||||
|
|
||||||
def AddHook(
|
|
||||||
self, request: core_pb2.AddHookRequest, context: ServicerContext
|
|
||||||
) -> core_pb2.AddHookResponse:
|
|
||||||
"""
|
|
||||||
Add hook to a session
|
|
||||||
|
|
||||||
:param request: add-hook request
|
|
||||||
:param context: context object
|
|
||||||
:return: add-hook response
|
|
||||||
"""
|
|
||||||
logger.debug("add hook: %s", request)
|
|
||||||
session = self.get_session(request.session_id, context)
|
|
||||||
hook = request.hook
|
|
||||||
state = EventTypes(hook.state)
|
|
||||||
session.add_hook(state, hook.file, hook.data)
|
|
||||||
return core_pb2.AddHookResponse(result=True)
|
|
||||||
|
|
||||||
def GetMobilityConfigs(
|
def GetMobilityConfigs(
|
||||||
self, request: GetMobilityConfigsRequest, context: ServicerContext
|
self, request: GetMobilityConfigsRequest, context: ServicerContext
|
||||||
) -> GetMobilityConfigsResponse:
|
) -> GetMobilityConfigsResponse:
|
||||||
|
|
|
@ -66,12 +66,6 @@ service CoreApi {
|
||||||
rpc DeleteLink (DeleteLinkRequest) returns (DeleteLinkResponse) {
|
rpc DeleteLink (DeleteLinkRequest) returns (DeleteLinkResponse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook rpc
|
|
||||||
rpc GetHooks (GetHooksRequest) returns (GetHooksResponse) {
|
|
||||||
}
|
|
||||||
rpc AddHook (AddHookRequest) returns (AddHookResponse) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// mobility rpc
|
// mobility rpc
|
||||||
rpc GetMobilityConfigs (mobility.GetMobilityConfigsRequest) returns (mobility.GetMobilityConfigsResponse) {
|
rpc GetMobilityConfigs (mobility.GetMobilityConfigsRequest) returns (mobility.GetMobilityConfigsResponse) {
|
||||||
}
|
}
|
||||||
|
@ -492,23 +486,6 @@ message DeleteLinkResponse {
|
||||||
bool result = 1;
|
bool result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetHooksRequest {
|
|
||||||
int32 session_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetHooksResponse {
|
|
||||||
repeated Hook hooks = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message AddHookRequest {
|
|
||||||
int32 session_id = 1;
|
|
||||||
Hook hook = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message AddHookResponse {
|
|
||||||
bool result = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message SaveXmlRequest {
|
message SaveXmlRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -351,41 +351,6 @@ class TestGrpc:
|
||||||
# then
|
# then
|
||||||
assert response.terminal is not None
|
assert response.terminal is not None
|
||||||
|
|
||||||
def test_get_hooks(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
file_name = "test"
|
|
||||||
file_data = "echo hello"
|
|
||||||
session.add_hook(EventTypes.RUNTIME_STATE, file_name, file_data)
|
|
||||||
|
|
||||||
# then
|
|
||||||
with client.context_connect():
|
|
||||||
response = client.get_hooks(session.id)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert len(response.hooks) == 1
|
|
||||||
hook = response.hooks[0]
|
|
||||||
assert hook.state == core_pb2.SessionState.RUNTIME
|
|
||||||
assert hook.file == file_name
|
|
||||||
assert hook.data == file_data
|
|
||||||
|
|
||||||
def test_add_hook(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
|
|
||||||
# then
|
|
||||||
file_name = "test"
|
|
||||||
file_data = "echo hello"
|
|
||||||
with client.context_connect():
|
|
||||||
response = client.add_hook(
|
|
||||||
session.id, core_pb2.SessionState.RUNTIME, file_name, file_data
|
|
||||||
)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert response.result is True
|
|
||||||
|
|
||||||
def test_save_xml(self, grpc_server: CoreGrpcServer, tmpdir: TemporaryFile):
|
def test_save_xml(self, grpc_server: CoreGrpcServer, tmpdir: TemporaryFile):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
|
|
@ -408,38 +408,6 @@ class TestGrpcw:
|
||||||
# then
|
# then
|
||||||
assert terminal is not None
|
assert terminal is not None
|
||||||
|
|
||||||
def test_get_hooks(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
file_name = "test"
|
|
||||||
file_data = "echo hello"
|
|
||||||
session.add_hook(EventTypes.RUNTIME_STATE, file_name, file_data)
|
|
||||||
|
|
||||||
# then
|
|
||||||
with client.context_connect():
|
|
||||||
hooks = client.get_hooks(session.id)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert len(hooks) == 1
|
|
||||||
hook = hooks[0]
|
|
||||||
assert hook.state == SessionState.RUNTIME
|
|
||||||
assert hook.file == file_name
|
|
||||||
assert hook.data == file_data
|
|
||||||
|
|
||||||
def test_add_hook(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
hook = Hook(SessionState.RUNTIME, "test", "echo hello")
|
|
||||||
|
|
||||||
# then
|
|
||||||
with client.context_connect():
|
|
||||||
result = client.add_hook(session.id, hook)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert result is True
|
|
||||||
|
|
||||||
def test_save_xml(self, grpc_server: CoreGrpcServer, tmpdir: TemporaryFile):
|
def test_save_xml(self, grpc_server: CoreGrpcServer, tmpdir: TemporaryFile):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
|
Loading…
Reference in a new issue