Agent: Add block parameter to IMaster.terminate()
This allows the caller to decide whether or not they're willing to wait for the master to finish shutting down.
This commit is contained in:
parent
a051759764
commit
f46bb60da5
|
@ -10,9 +10,10 @@ class IMaster(metaclass=abc.ABCMeta):
|
|||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def terminate(self) -> None:
|
||||
def terminate(self, block: bool = False) -> None:
|
||||
"""
|
||||
Stop the master and interrupt any actions that are currently being executed.
|
||||
:param bool block: Whether or not to block and wait for the master to terminate.
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
|
|
|
@ -52,12 +52,15 @@ class AutomatedMaster(IMaster):
|
|||
self._master_thread.join()
|
||||
logger.info("The simulation has been shutdown.")
|
||||
|
||||
def terminate(self):
|
||||
def terminate(self, block: bool = False):
|
||||
logger.info("Stopping automated breach and attack simulation")
|
||||
self._stop.set()
|
||||
|
||||
if self._master_thread.is_alive():
|
||||
if self._master_thread.is_alive() and block:
|
||||
self._master_thread.join()
|
||||
# We can only have confidence that the master terminated successfully if block is set
|
||||
# and join() has returned.
|
||||
logger.info("AutomatedMaster successfully terminated.")
|
||||
|
||||
def _run_master_thread(self):
|
||||
self._simulation_thread.start()
|
||||
|
|
|
@ -124,7 +124,7 @@ class MockMaster(IMaster):
|
|||
self._telemetry_messenger.send_telemetry(FileEncryptionTelem(path, success, error))
|
||||
logger.info("Finished running payloads")
|
||||
|
||||
def terminate(self) -> None:
|
||||
def terminate(self, block: bool = False) -> None:
|
||||
logger.info("Terminating MockMaster")
|
||||
|
||||
def cleanup(self) -> None:
|
||||
|
|
Loading…
Reference in New Issue