forked from p15670423/monkey
Refactored mongo executable path to be calculated in consts, since this is a trivial calculation.
This commit is contained in:
parent
f7674b0635
commit
5aeab3a56c
|
@ -20,13 +20,16 @@ DEFAULT_DATA_DIR = os.path.expandvars(get_default_data_dir())
|
|||
|
||||
DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS = 60 * 5
|
||||
|
||||
_MONGO_BINARY_DIR = os.path.join(MONKEY_ISLAND_ABS_PATH, "bin", "mongodb")
|
||||
_MONGO_EXECUTABLE_PATH_WIN = os.path.join(_MONGO_BINARY_DIR, "mongod.exe")
|
||||
_MONGO_EXECUTABLE_PATH_LINUX = os.path.join(_MONGO_BINARY_DIR, "bin", "mongod")
|
||||
MONGO_EXECUTABLE_PATH = (
|
||||
_MONGO_EXECUTABLE_PATH_WIN if is_windows_os() else _MONGO_EXECUTABLE_PATH_LINUX
|
||||
)
|
||||
|
||||
DEFAULT_SERVER_CONFIG_PATH = os.path.expandvars(
|
||||
os.path.join(DEFAULT_DATA_DIR, SERVER_CONFIG_FILENAME)
|
||||
)
|
||||
_MONGO_EXECUTABLE_PATH = os.path.join(MONKEY_ISLAND_ABS_PATH, "bin", "mongodb")
|
||||
MONGO_EXECUTABLE_PATH_WIN = os.path.join(_MONGO_EXECUTABLE_PATH, "mongod.exe")
|
||||
MONGO_EXECUTABLE_PATH_LINUX = os.path.join(_MONGO_EXECUTABLE_PATH, "bin", "mongod")
|
||||
|
||||
|
||||
DEFAULT_DEVELOP_SERVER_CONFIG_PATH = os.path.join(
|
||||
MONKEY_ISLAND_ABS_PATH, "cc", f"{SERVER_CONFIG_FILENAME}.develop"
|
||||
|
|
|
@ -3,11 +3,7 @@ import os
|
|||
import subprocess
|
||||
from typing import List
|
||||
|
||||
from monkey_island.cc.environment.utils import is_windows_os
|
||||
from monkey_island.cc.server_utils.consts import (
|
||||
MONGO_EXECUTABLE_PATH_LINUX,
|
||||
MONGO_EXECUTABLE_PATH_WIN,
|
||||
)
|
||||
from monkey_island.cc.server_utils.consts import MONGO_EXECUTABLE_PATH
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -39,9 +35,8 @@ class MongoDbRunner:
|
|||
|
||||
def _start_mongodb_process(self, db_dir_path: str):
|
||||
logger.info("Starting MongoDb process.")
|
||||
mongo_exec = MongoDbRunner._get_path_of_mongo_exec()
|
||||
|
||||
mongo_run_cmd = MongoDbRunner._build_mongo_launch_cmd(mongo_exec, db_dir_path)
|
||||
mongo_run_cmd = MongoDbRunner._build_mongo_launch_cmd(MONGO_EXECUTABLE_PATH, db_dir_path)
|
||||
logger.info(f"Mongodb will be launched with command: f{' '.join(mongo_run_cmd)}.")
|
||||
|
||||
mongo_log_path = os.path.join(self.logging_dir_path, MONGO_LOG_FILENAME)
|
||||
|
@ -51,13 +46,6 @@ class MongoDbRunner:
|
|||
subprocess.Popen(mongo_run_cmd, stderr=subprocess.STDOUT, stdout=log)
|
||||
logger.info("MongoDb launched successfully!")
|
||||
|
||||
@staticmethod
|
||||
def _get_path_of_mongo_exec():
|
||||
if is_windows_os():
|
||||
return MONGO_EXECUTABLE_PATH_WIN
|
||||
else:
|
||||
return MONGO_EXECUTABLE_PATH_LINUX
|
||||
|
||||
@staticmethod
|
||||
def _build_mongo_launch_cmd(exec_path: str, db_path: str) -> List[str]:
|
||||
return [exec_path, DB_DIR_PARAM, db_path]
|
||||
|
|
Loading…
Reference in New Issue