Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Limmen committed Jul 24, 2024
1 parent 8d8bd9e commit d79cbf8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
43 changes: 22 additions & 21 deletions simulation-system/libs/csle-cli/src/csle_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -914,16 +914,15 @@ 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:
click.secho(f"Host managers are not stopped:{constants.GRPC_SERVERS.CLUSTER_MANAGER_PORT}",
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from csle_common.util.management_util import ManagementUtil
from unittest.mock import patch


class TestManagementUtilSuite:
"""
Test suite for management util
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d79cbf8

Please sign in to comment.