grpc: removed set session state, states are a by product of actions done within a session and probably best to automate that instead of relying on clients responsibly setting proper values
This commit is contained in:
parent
d40435fa68
commit
598cb0f10d
4 changed files with 0 additions and 68 deletions
|
@ -408,21 +408,6 @@ class CoreGrpcClient:
|
|||
response = self.stub.GetSession(request)
|
||||
return wrappers.Session.from_proto(response.session)
|
||||
|
||||
def set_session_state(self, session_id: int, state: wrappers.SessionState) -> bool:
|
||||
"""
|
||||
Set session state.
|
||||
|
||||
:param session_id: id of session
|
||||
:param state: session state to transition to
|
||||
:return: True for success, False otherwise
|
||||
:raises grpc.RpcError: when session doesn't exist
|
||||
"""
|
||||
request = core_pb2.SetSessionStateRequest(
|
||||
session_id=session_id, state=state.value
|
||||
)
|
||||
response = self.stub.SetSessionState(request)
|
||||
return response.result
|
||||
|
||||
def alert(
|
||||
self,
|
||||
session_id: int,
|
||||
|
|
|
@ -402,35 +402,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
sessions.append(session_summary)
|
||||
return core_pb2.GetSessionsResponse(sessions=sessions)
|
||||
|
||||
def SetSessionState(
|
||||
self, request: core_pb2.SetSessionStateRequest, context: ServicerContext
|
||||
) -> core_pb2.SetSessionStateResponse:
|
||||
"""
|
||||
Set session state
|
||||
|
||||
:param request: set-session-state request
|
||||
:param context:context object
|
||||
:return: set-session-state response
|
||||
"""
|
||||
logger.debug("set session state: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
try:
|
||||
state = EventTypes(request.state)
|
||||
session.set_state(state)
|
||||
if state == EventTypes.INSTANTIATION_STATE:
|
||||
session.directory.mkdir(exist_ok=True)
|
||||
session.instantiate()
|
||||
elif state == EventTypes.SHUTDOWN_STATE:
|
||||
session.shutdown()
|
||||
elif state == EventTypes.DATACOLLECT_STATE:
|
||||
session.data_collect()
|
||||
elif state == EventTypes.DEFINITION_STATE:
|
||||
session.clear()
|
||||
result = True
|
||||
except KeyError:
|
||||
result = False
|
||||
return core_pb2.SetSessionStateResponse(result=result)
|
||||
|
||||
def CheckSession(
|
||||
self, request: core_pb2.GetSessionRequest, context: ServicerContext
|
||||
) -> core_pb2.CheckSessionResponse:
|
||||
|
|
|
@ -25,8 +25,6 @@ service CoreApi {
|
|||
}
|
||||
rpc CheckSession (CheckSessionRequest) returns (CheckSessionResponse) {
|
||||
}
|
||||
rpc SetSessionState (SetSessionStateRequest) returns (SetSessionStateResponse) {
|
||||
}
|
||||
rpc SessionAlert (SessionAlertRequest) returns (SessionAlertResponse) {
|
||||
}
|
||||
|
||||
|
@ -216,15 +214,6 @@ message GetSessionResponse {
|
|||
Session session = 1;
|
||||
}
|
||||
|
||||
message SetSessionStateRequest {
|
||||
int32 session_id = 1;
|
||||
SessionState.Enum state = 2;
|
||||
}
|
||||
|
||||
message SetSessionStateResponse {
|
||||
bool result = 1;
|
||||
}
|
||||
|
||||
message SessionAlertRequest {
|
||||
int32 session_id = 1;
|
||||
ExceptionLevel.Enum level = 2;
|
||||
|
|
|
@ -243,19 +243,6 @@ class TestGrpc:
|
|||
assert len(sessions) == 1
|
||||
assert found_session is not None
|
||||
|
||||
def test_set_session_state(self, grpc_server: CoreGrpcServer):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
result = client.set_session_state(session.id, SessionState.DEFINITION)
|
||||
|
||||
# then
|
||||
assert result is True
|
||||
assert session.state == EventTypes.DEFINITION_STATE
|
||||
|
||||
def test_add_node(self, grpc_server: CoreGrpcServer):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
|
|
Loading…
Reference in a new issue