forked from p15670423/monkey
Island: Add locks to remote_run_aws.py
Locks will avoid the situation where is_running_on_aws is called before this service finished initializing
This commit is contained in:
parent
d3c1ff89e9
commit
8535118e4f
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
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
|
||||||
|
@ -7,6 +8,7 @@ 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()
|
||||||
|
|
||||||
|
|
||||||
class RemoteRunAwsService:
|
class RemoteRunAwsService:
|
||||||
|
@ -23,15 +25,8 @@ class RemoteRunAwsService:
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if RemoteRunAwsService.aws_instance is None:
|
if RemoteRunAwsService.aws_instance is None:
|
||||||
RemoteRunAwsService.try_init_aws_instance()
|
with aws_lock:
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def try_init_aws_instance():
|
|
||||||
# noinspection PyBroadException
|
|
||||||
try:
|
|
||||||
RemoteRunAwsService.aws_instance = AwsInstance()
|
RemoteRunAwsService.aws_instance = AwsInstance()
|
||||||
except Exception:
|
|
||||||
logger.error("Failed init aws instance. Exception info: ", exc_info=True)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run_aws_monkeys(instances, island_ip):
|
def run_aws_monkeys(instances, island_ip):
|
||||||
|
@ -53,6 +48,7 @@ class RemoteRunAwsService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_running_on_aws():
|
def is_running_on_aws():
|
||||||
|
with aws_lock:
|
||||||
return RemoteRunAwsService.aws_instance.is_instance()
|
return RemoteRunAwsService.aws_instance.is_instance()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue