From 19e8042ee49bd7c067e3bf944b7949955919c52e Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 2 Jun 2021 15:39:49 -0400 Subject: [PATCH] island: Construct mongo run command in MongoDbProcess constructor --- .../cc/setup/mongo/mongo_db_process.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/monkey/monkey_island/cc/setup/mongo/mongo_db_process.py b/monkey/monkey_island/cc/setup/mongo/mongo_db_process.py index 0d517bf6d..61fc6943a 100644 --- a/monkey/monkey_island/cc/setup/mongo/mongo_db_process.py +++ b/monkey/monkey_island/cc/setup/mongo/mongo_db_process.py @@ -1,7 +1,6 @@ import logging import os import subprocess -from typing import List from monkey_island.cc.server_utils.consts import MONGO_EXECUTABLE_PATH @@ -18,20 +17,19 @@ class MongoDbProcess: @param db_dir: Path where a folder for database contents will be created @param logging_dir: Path to a folder where mongodb logs will be created """ - self._db_dir = db_dir + self._mongo_run_cmd = [MONGO_EXECUTABLE_PATH, DB_DIR_PARAM, db_dir] self._log_file = os.path.join(logging_dir, MONGO_LOG_FILENAME) self._process = None def start(self): logger.info("Starting MongoDB process.") - - mongo_run_cmd = MongoDbProcess._build_mongo_run_cmd(MONGO_EXECUTABLE_PATH, self._db_dir) - - logger.info(f"MongoDB will be launched with command: {' '.join(mongo_run_cmd)}.") + logger.debug(f"MongoDB will be launched with command: {' '.join(self._mongo_run_cmd)}.") logger.info(f"MongoDB log will be available at {self._log_file}.") with open(self._log_file, "w") as log: - self._process = subprocess.Popen(mongo_run_cmd, stderr=subprocess.STDOUT, stdout=log) + self._process = subprocess.Popen( + self._mongo_run_cmd, stderr=subprocess.STDOUT, stdout=log + ) logger.info("MongoDB launched successfully!") @@ -51,7 +49,3 @@ class MongoDbProcess: f"MongoDB did not terminate gracefully and will be forcefully killed: {te}" ) self._process.kill() - - @staticmethod - def _build_mongo_run_cmd(exec_path: str, db_dir: str) -> List[str]: - return [exec_path, DB_DIR_PARAM, db_dir]