forked from p15670423/monkey
Island: Refactor lock to event in remote_run_aws.py
This commit is contained in:
parent
fead7f602e
commit
b58d847e22
|
@ -1,5 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
from threading import Lock
|
from threading import Event
|
||||||
|
|
||||||
from common.cloud.aws.aws_instance import AwsInstance
|
from common.cloud.aws.aws_instance import AwsInstance
|
||||||
from common.cloud.aws.aws_service import AwsService
|
from common.cloud.aws.aws_service import AwsService
|
||||||
|
@ -8,7 +8,8 @@ from common.cmd.cmd import Cmd
|
||||||
from common.cmd.cmd_runner import CmdRunner
|
from common.cmd.cmd_runner import CmdRunner
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
aws_lock = Lock()
|
AWS_INFO_FETCH_TIMEOUT = 10 # Seconds
|
||||||
|
aws_info_fetch_done = Event()
|
||||||
|
|
||||||
|
|
||||||
class RemoteRunAwsService:
|
class RemoteRunAwsService:
|
||||||
|
@ -25,8 +26,8 @@ class RemoteRunAwsService:
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if RemoteRunAwsService.aws_instance is None:
|
if RemoteRunAwsService.aws_instance is None:
|
||||||
with aws_lock:
|
|
||||||
RemoteRunAwsService.aws_instance = AwsInstance()
|
RemoteRunAwsService.aws_instance = AwsInstance()
|
||||||
|
aws_info_fetch_done.set()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run_aws_monkeys(instances, island_ip):
|
def run_aws_monkeys(instances, island_ip):
|
||||||
|
@ -48,7 +49,7 @@ class RemoteRunAwsService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_running_on_aws():
|
def is_running_on_aws():
|
||||||
with aws_lock:
|
aws_info_fetch_done.wait(AWS_INFO_FETCH_TIMEOUT)
|
||||||
return RemoteRunAwsService.aws_instance.is_instance
|
return RemoteRunAwsService.aws_instance.is_instance
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue