daemon: properly go through the data collect state for grpc session shutdown, also check and avoid repeating data collect or shutdown when already past those states

This commit is contained in:
Blake Harnden 2020-12-05 09:01:53 -08:00
parent b762fe664b
commit a23ef7d603
4 changed files with 19 additions and 7 deletions

View file

@ -315,6 +315,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
"""
logging.debug("stop session: %s", request)
session = self.get_session(request.session_id, context)
session.data_collect()
session.shutdown()
return core_pb2.StopSessionResponse(result=True)

View file

@ -144,6 +144,7 @@ class CoreEmu:
result = False
if session:
logging.info("shutting session down: %s", _id)
session.data_collect()
session.shutdown()
result = True
else:

View file

@ -106,6 +106,9 @@ class EventTypes(Enum):
def should_start(self) -> bool:
return self.value > self.DEFINITION_STATE.value
def already_collected(self) -> bool:
return self.value >= self.DATACOLLECT_STATE.value
class ExceptionLevels(Enum):
"""

View file

@ -770,10 +770,11 @@ class Session:
"""
Shutdown all session nodes and remove the session directory.
"""
if self.state == EventTypes.SHUTDOWN_STATE:
logging.info("session(%s) state(%s) already shutdown", self.id, self.state)
return
logging.info("session(%s) state(%s) shutting down", self.id, self.state)
if self.state != EventTypes.SHUTDOWN_STATE:
self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
# clear out current core session
self.clear()
# shutdown sdt
@ -1258,6 +1259,14 @@ class Session:
:return: nothing
"""
if self.state.already_collected():
logging.info(
"session(%s) state(%s) already data collected", self.id, self.state
)
return
logging.info("session(%s) state(%s) data collection", self.id, self.state)
self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
# stop event loop
self.event_loop.stop()
@ -1279,10 +1288,8 @@ class Session:
self.update_control_iface_hosts(remove=True)
# remove all four possible control networks
self.add_remove_control_net(0, remove=True)
self.add_remove_control_net(1, remove=True)
self.add_remove_control_net(2, remove=True)
self.add_remove_control_net(3, remove=True)
for i in range(4):
self.add_remove_control_net(i, remove=True)
def short_session_id(self) -> str:
"""