grpc update to get session and get sessions
This commit is contained in:
parent
1f3e72e014
commit
c6cfe1a8f4
3 changed files with 23 additions and 16 deletions
|
@ -279,10 +279,10 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
response = core_pb2.GetSessionsResponse()
|
||||
for session_id in self.coreemu.sessions:
|
||||
session = self.coreemu.sessions[session_id]
|
||||
session_data = response.sessions.add()
|
||||
session_data.id = session_id
|
||||
session_data.state = session.state
|
||||
session_data.nodes = session.get_node_count()
|
||||
session_summary = response.sessions.add()
|
||||
session_summary.id = session_id
|
||||
session_summary.state = session.state
|
||||
session_summary.nodes = session.get_node_count()
|
||||
return response
|
||||
|
||||
def GetSessionLocation(self, request, context):
|
||||
|
@ -368,7 +368,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
logging.debug("get session: %s", request)
|
||||
session = self.get_session(request.id, context)
|
||||
response = core_pb2.GetSessionResponse()
|
||||
response.state = session.state
|
||||
response.session.state = session.state
|
||||
|
||||
for node_id in session.objects:
|
||||
node = session.objects[node_id]
|
||||
|
@ -376,7 +376,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
if not isinstance(node.objid, int):
|
||||
continue
|
||||
|
||||
node_proto = response.nodes.add()
|
||||
node_proto = response.session.nodes.add()
|
||||
node_proto.id = node.objid
|
||||
node_proto.name = node.name
|
||||
node_proto.type = nodeutils.get_node_type(node.__class__).value
|
||||
|
@ -405,7 +405,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
|
||||
links_data = node.all_link_data(0)
|
||||
for link_data in links_data:
|
||||
link = response.links.add()
|
||||
link = response.session.links.add()
|
||||
convert_link(session, link_data, link)
|
||||
|
||||
return response
|
||||
|
|
|
@ -141,7 +141,7 @@ message GetSessionsRequest {
|
|||
}
|
||||
|
||||
message GetSessionsResponse {
|
||||
repeated Session sessions = 1;
|
||||
repeated SessionSummary sessions = 1;
|
||||
}
|
||||
|
||||
message GetSessionRequest {
|
||||
|
@ -149,9 +149,7 @@ message GetSessionRequest {
|
|||
}
|
||||
|
||||
message GetSessionResponse {
|
||||
SessionState state = 1;
|
||||
repeated Node nodes = 2;
|
||||
repeated Link links = 3;
|
||||
Session session = 1;
|
||||
}
|
||||
|
||||
message GetSessionOptionsRequest {
|
||||
|
@ -712,6 +710,13 @@ message ConfigOption {
|
|||
}
|
||||
|
||||
message Session {
|
||||
int32 id = 1;
|
||||
SessionState state = 2;
|
||||
repeated Node nodes = 3;
|
||||
repeated Link links = 4;
|
||||
}
|
||||
|
||||
message SessionSummary {
|
||||
int32 id = 1;
|
||||
SessionState state = 2;
|
||||
int32 nodes = 3;
|
||||
|
|
|
@ -66,9 +66,9 @@ class TestGrpc:
|
|||
response = client.get_session(session.session_id)
|
||||
|
||||
# then
|
||||
assert response.state == core_pb2.DEFINITION
|
||||
assert len(response.nodes) == 1
|
||||
assert len(response.links) == 0
|
||||
assert response.session.state == core_pb2.DEFINITION
|
||||
assert len(response.session.nodes) == 1
|
||||
assert len(response.session.links) == 0
|
||||
|
||||
def test_get_sessions(self, grpc_server):
|
||||
# given
|
||||
|
@ -147,12 +147,14 @@ class TestGrpc:
|
|||
session = grpc_server.coreemu.create_session()
|
||||
|
||||
# then
|
||||
option = "enablerj45"
|
||||
value = "1"
|
||||
with client.context_connect():
|
||||
response = client.set_session_options(session.session_id, {"preservedir": "1"})
|
||||
response = client.set_session_options(session.session_id, {option: value})
|
||||
|
||||
# then
|
||||
assert response.result is True
|
||||
assert session.options.get_config("preservedir") == "1"
|
||||
assert session.options.get_config(option) == value
|
||||
|
||||
def test_set_session_state(self, grpc_server):
|
||||
# given
|
||||
|
|
Loading…
Reference in a new issue