diff --git a/simulation-system/libs/csle-cli/src/csle_cli/cli.py b/simulation-system/libs/csle-cli/src/csle_cli/cli.py index 891e43cd4..9d4877097 100755 --- a/simulation-system/libs/csle-cli/src/csle_cli/cli.py +++ b/simulation-system/libs/csle-cli/src/csle_cli/cli.py @@ -727,7 +727,7 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "") -> None: stop_statsmanager(ip=ip) elif entity == "emulation_executions": stop_emulation_executions() - elif entity == "hostmanager": + elif entity == "hostmanagers": stop_host_managers(ip=ip, emulation=name, ip_first_octet=id) else: container_stopped = False @@ -914,8 +914,8 @@ def stop_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None: config = MetastoreFacade.get_config(id=1) for node in config.cluster_config.cluster_nodes: if node.ip == ip or ip == "": - stopped = ClusterController.stop_host_managers(ip=ip, port= constants.GRPC_SERVERS.CLUSTER_MANAGER_PORT, - emulation=emulation, ip_first_octet=ip_first_octet) + stopped = ClusterController.stop_host_managers(ip=ip, port=constants.GRPC_SERVERS.CLUSTER_MANAGER_PORT, + emulation=emulation, ip_first_octet=ip_first_octet) if stopped: click.secho(f"Stopping host managers on port:{constants.GRPC_SERVERS.CLUSTER_MANAGER_PORT}") else: @@ -923,7 +923,6 @@ def stop_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None: bold=False) - @click.argument('max_workers', default=10, type=int) @click.argument('log_file', default="docker_statsmanager.log", type=str) @click.argument('log_dir', default="/var/log/csle", type=str) @@ -1341,16 +1340,16 @@ def start_statsmanager(ip: str) -> None: if node.ip == ip or ip == "": ClusterController.start_docker_statsmanager(ip=node.ip, port=constants.GRPC_SERVERS.CLUSTER_MANAGER_PORT) + def start_host_manager(ip: str, emulation: str, ip_first_octet: int): """ - Utility function for starting host manager + Utility function for starting host manager - :param ip: the ip of the node to start host manager - :param emulation: the emulation of the execution - :param ip_first_octet: the ID of the execution - - :return: None - """ + :param ip: the ip of the node to start host manager + :param emulation: the emulation of the execution + :param ip_first_octet: the ID of the execution + :return: None + """ import csle_common.constants.constants as constants from csle_common.metastore.metastore_facade import MetastoreFacade config = MetastoreFacade.get_config(id=1) @@ -1746,24 +1745,26 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str, else: click.secho(f"entity: {entity} is not recognized", fg="red", bold=True) -def list_host_managers(ip: str, emulation: str , ip_first_octet: int) -> None: + +def list_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None: """ - Utility function for listing host managers + Utility function for listing host managers - :param ip: the ip of the node to start host manager - :param emulation: the emulation of the execution - :param ip_first_octet: the ID of the execution + :param ip: the ip of the node to start host manager + :param emulation: the emulation of the execution + :param ip_first_octet: the ID of the execution - :return: None - """ + :return: None + """ import csle_common.constants.constants as constants from csle_common.metastore.metastore_facade import MetastoreFacade config = MetastoreFacade.get_config(id=1) for node in config.cluster_config.cluster_nodes: if node.ip == ip or ip == "": - host_manage_info = ClusterController.get_host_managers_info(ip=ip, port=constants.GRPC_SERVERS.CLUSTER_MANAGER_PORT, - emulation=emulation, ip_first_octet=ip_first_octet) - host_managers = host_manage_info.hostManagersStatuses + host_manager_info = ClusterController.get_host_managers_info( + ip=ip, port=constants.GRPC_SERVERS.CLUSTER_MANAGER_PORT, emulation=emulation, + ip_first_octet=ip_first_octet) + host_managers = host_manager_info.hostManagersStatuses click.secho('+' + '-' * 50 + '+', fg='white') click.secho(f'|{"Host IP":^30}|{"Running Status":^19}|', fg='white') diff --git a/simulation-system/libs/csle-common/src/csle_common/controllers/host_controller.py b/simulation-system/libs/csle-common/src/csle_common/controllers/host_controller.py index 0b8305d20..b220c40d6 100644 --- a/simulation-system/libs/csle-common/src/csle_common/controllers/host_controller.py +++ b/simulation-system/libs/csle-common/src/csle_common/controllers/host_controller.py @@ -1308,7 +1308,7 @@ def get_host_managers_info(emulation_env_config: EmulationEnvConfig, active_ips: host_managers_statuses.append((status, ip)) else: host_managers_statuses.append( - csle_collector.host_manager.host_manager_util.HostManagerUtil.host_monitor_dto_empty()) + (csle_collector.host_manager.host_manager_util.HostManagerUtil.host_monitor_dto_empty(), ip)) host_managers_running.append(running) execution_id = emulation_env_config.execution_id emulation_name = emulation_env_config.name diff --git a/simulation-system/libs/csle-common/tests/test_management_util.py b/simulation-system/libs/csle-common/tests/test_management_util.py index 1815e3b62..fb3f6d198 100644 --- a/simulation-system/libs/csle-common/tests/test_management_util.py +++ b/simulation-system/libs/csle-common/tests/test_management_util.py @@ -2,6 +2,7 @@ from csle_common.util.management_util import ManagementUtil from unittest.mock import patch + class TestManagementUtilSuite: """ Test suite for management util @@ -12,7 +13,7 @@ class TestManagementUtilSuite: @patch("bcrypt.hashpw") @patch("csle_common.metastore.metastore_facade.MetastoreFacade.save_management_user") def test_create_default_management_admin_account( - self, mock_save_management_user, mock_hashpw, mock_gensalt, mock_list_management_users + self, mock_save_management_user, mock_hashpw, mock_gensalt, mock_list_management_users ) -> None: """ Test the method that creates the default management admin account @@ -48,7 +49,7 @@ def test_create_default_management_admin_account( @patch("bcrypt.hashpw") @patch("csle_common.metastore.metastore_facade.MetastoreFacade.save_management_user") def test_create_default_management_guest_account( - self, mock_save_management_user, mock_hashpw, mock_gensalt, mock_list_management_users + self, mock_save_management_user, mock_hashpw, mock_gensalt, mock_list_management_users ) -> None: """ Test the method that creates the default management guest account