From 7a93b86938c959409dca1f3c153db16add36d957 Mon Sep 17 00:00:00 2001 From: foroogh shahab Date: Sun, 25 Aug 2024 12:26:59 +0200 Subject: [PATCH 1/3] cli test, ls containers is revised. --- .../libs/csle-cli/tests/test_cli.py | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/simulation-system/libs/csle-cli/tests/test_cli.py b/simulation-system/libs/csle-cli/tests/test_cli.py index 504827c3f..22cc9af3e 100644 --- a/simulation-system/libs/csle-cli/tests/test_cli.py +++ b/simulation-system/libs/csle-cli/tests/test_cli.py @@ -1,9 +1,6 @@ -from typing import List from click.testing import CliRunner from csle_cli.cli import ls -from csle_cluster.cluster_manager.cluster_manager_pb2 import DockerContainerDTO - class TestCSLECliSuite: """ @@ -12,7 +9,7 @@ class TestCSLECliSuite: def test_ls_all(self) -> None: """ - Tests the ls command + Tests the ls command for --all :return: None """ @@ -20,30 +17,44 @@ def test_ls_all(self) -> None: result = runner.invoke(ls, ["--all"]) assert result.exit_code == 0 - def test_ls_running_containers(self) -> None: + def test_ls_containers(self) -> None: + """ + Tests the ls command for containers + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["containers", "--all"]) + assert result.exit_code == 0 + + runner = CliRunner() + result = runner.invoke(ls, ["containers", "--running"]) + assert result.exit_code == 0 + + runner = CliRunner() + result = runner.invoke(ls, ["containers", "--stopped"]) + assert result.exit_code == 0 + + def test_ls_networks(self) -> None: + """ + Tests the ls command for containers + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["networks"]) + assert result.exit_code == 0 + + def test_ls_emulations(self) -> None: """ - Tests the ls command + Tests the ls command for containers :return: None """ - import csle_common.constants.constants as constants - from csle_common.metastore.metastore_facade import MetastoreFacade - from csle_cluster.cluster_manager.cluster_controller import ClusterController - config = MetastoreFacade.get_config(id=1) - running_containers: List[DockerContainerDTO] = [] - for node in config.cluster_config.cluster_nodes: - running_containers_dto = ClusterController.list_all_running_containers( - ip=node.ip, port=constants.GRPC_SERVERS.CLUSTER_MANAGER_PORT) - running_containers_dtos = list(running_containers_dto.runningContainers) - running_containers = running_containers + running_containers_dtos runner = CliRunner() - result = runner.invoke(ls, ["containers"]) - cli_output = result.stdout_bytes.decode('utf-8') - cli_output_lines = cli_output.strip().split('\n') - number_of_containers_from_cli = 0 - for line in cli_output_lines: - if "[running]" in line: - number_of_containers_from_cli += 1 - - assert number_of_containers_from_cli == len(running_containers) + result = runner.invoke(ls, ["emulations", "--all"]) + assert result.exit_code == 0 + + runner = CliRunner() + result = runner.invoke(ls, ["emulations", "--stopped"]) assert result.exit_code == 0 From f710b6f9dd373cb5aea3d39b90f182f5ce6dca8f Mon Sep 17 00:00:00 2001 From: foroogh shahab Date: Sun, 25 Aug 2024 12:36:59 +0200 Subject: [PATCH 2/3] cli test, ls more entities are added. --- .../libs/csle-cli/tests/test_cli.py | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/simulation-system/libs/csle-cli/tests/test_cli.py b/simulation-system/libs/csle-cli/tests/test_cli.py index 22cc9af3e..2979968fc 100644 --- a/simulation-system/libs/csle-cli/tests/test_cli.py +++ b/simulation-system/libs/csle-cli/tests/test_cli.py @@ -37,7 +37,7 @@ def test_ls_containers(self) -> None: def test_ls_networks(self) -> None: """ - Tests the ls command for containers + Tests the ls command for networks :return: None """ @@ -47,7 +47,7 @@ def test_ls_networks(self) -> None: def test_ls_emulations(self) -> None: """ - Tests the ls command for containers + Tests the ls command for emulations :return: None """ @@ -58,3 +58,53 @@ def test_ls_emulations(self) -> None: runner = CliRunner() result = runner.invoke(ls, ["emulations", "--stopped"]) assert result.exit_code == 0 + + def test_ls_environments(self) -> None: + """ + Tests the ls command for environments + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["environments"]) + assert result.exit_code == 0 + + def test_ls_prometheus(self) -> None: + """ + Tests the ls command for prometheus + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["prometheus"]) + assert result.exit_code == 0 + + def test_ls_node_exporter(self) -> None: + """ + Tests the ls command for node_exporter + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["node_exporter"]) + assert result.exit_code == 0 + + def test_ls_cadvisor(self) -> None: + """ + Tests the ls command for cadvisor + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["cadvisor"]) + assert result.exit_code == 0 + + def test_ls_nginx(self) -> None: + """ + Tests the ls command for nginx + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["nginx"]) + assert result.exit_code == 0 From 99c9d84decb7157fff598ea2e13223c98491af78 Mon Sep 17 00:00:00 2001 From: foroogh shahab Date: Sun, 25 Aug 2024 12:44:06 +0200 Subject: [PATCH 3/3] cli test, all ls entities that do not need input are added. --- .../libs/csle-cli/tests/test_cli.py | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/simulation-system/libs/csle-cli/tests/test_cli.py b/simulation-system/libs/csle-cli/tests/test_cli.py index 2979968fc..9a8c7c1f1 100644 --- a/simulation-system/libs/csle-cli/tests/test_cli.py +++ b/simulation-system/libs/csle-cli/tests/test_cli.py @@ -108,3 +108,83 @@ def test_ls_nginx(self) -> None: runner = CliRunner() result = runner.invoke(ls, ["nginx"]) assert result.exit_code == 0 + + def test_ls_postgresql(self) -> None: + """ + Tests the ls command for postgresql + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["postgresql"]) + assert result.exit_code == 0 + + def test_ls_docker(self) -> None: + """ + Tests the ls command for docker + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["docker"]) + assert result.exit_code == 0 + + def test_ls_pgadmin(self) -> None: + """ + Tests the ls command for pgadmin + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["pgadmin"]) + assert result.exit_code == 0 + + def test_ls_grafana(self) -> None: + """ + Tests the ls command for grafana + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["grafana"]) + assert result.exit_code == 0 + + def test_ls_flask(self) -> None: + """ + Tests the ls command for flask + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["flask"]) + assert result.exit_code == 0 + + def test_ls_statsmanager(self) -> None: + """ + Tests the ls command for statsmanager + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["statsmanager"]) + assert result.exit_code == 0 + + def test_ls_simulations(self) -> None: + """ + Tests the ls command for simulations + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["simulations"]) + assert result.exit_code == 0 + + def test_ls_emulation_executions(self) -> None: + """ + Tests the ls command for emulation_executions + + :return: None + """ + runner = CliRunner() + result = runner.invoke(ls, ["emulation_executions"]) + assert result.exit_code == 0