Skip to content

Commit

Permalink
Merge pull request #426 from Limmen/elk
Browse files Browse the repository at this point in the history
fixed linter and typecheck
  • Loading branch information
Limmen authored Aug 21, 2024
2 parents 7abec26 + 3ec57a8 commit ee321e8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 36 deletions.
5 changes: 2 additions & 3 deletions emulation-system/tests/test_start_client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
from docker.types import IPAMConfig, IPAMPool
import time
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
from csle_common.util.emulation_util import EmulationUtil
import csle_common.constants.constants as constants
import csle_collector.client_manager.client_manager_pb2_grpc
import csle_collector.client_manager.client_manager_pb2
import csle_collector.client_manager.query_clients
from csle_common.metastore.metastore_facade import MetastoreFacade
from IPython.lib.editorhooks import emacs
from typing import Generator


@pytest.fixture(scope="module")
Expand All @@ -27,7 +26,7 @@ def docker_client() -> None:


@pytest.fixture(scope="module")
def network(docker_client) -> None:
def network(docker_client) -> Generator:
"""
Create a custom network with a specific subnet
Expand Down
8 changes: 3 additions & 5 deletions emulation-system/tests/test_start_elk_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
from docker.types import IPAMConfig, IPAMPool
import time
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
from csle_common.util.emulation_util import EmulationUtil
import csle_common.constants.constants as constants
from csle_common.controllers.elk_controller import ELKController
import csle_collector.elk_manager.elk_manager_pb2_grpc
import csle_collector.elk_manager.elk_manager_pb2
import csle_collector.elk_manager.query_elk_manager
from csle_common.metastore.metastore_facade import MetastoreFacade
from IPython.lib.editorhooks import emacs
from typing import Generator


@pytest.fixture(scope="module")
Expand All @@ -28,14 +26,14 @@ def docker_client() -> None:


@pytest.fixture(scope="module")
def network(docker_client) -> None:
def network(docker_client) -> Generator:
"""
Create a custom network with a specific subnet
:param docker_client: docker_client
:yield: network
:return: None
:return: Generator
"""
subnet = "15.15.15.0/24"
ipam_pool = IPAMPool(subnet=subnet)
Expand Down
6 changes: 4 additions & 2 deletions emulation-system/tests/test_start_host_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import csle_collector.host_manager.host_manager_pb2
import csle_collector.host_manager.query_host_manager
from csle_common.metastore.metastore_facade import MetastoreFacade
from typing import List
from typing import Generator


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -42,13 +44,13 @@ def network(docker_client) -> Generator:
network.remove()


def get_derived_containers(docker_client, excluded_tag="blank") -> None:
def get_derived_containers(docker_client, excluded_tag="blank") -> List:
"""
Get all the containers except the blank ones
:param docker_client: docker_client
:return: None
:return: List of Images
"""
# Get all images except those with the excluded tag
config = MetastoreFacade.get_config(id=1)
Expand Down
7 changes: 3 additions & 4 deletions emulation-system/tests/test_start_kafka_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
from docker.types import IPAMConfig, IPAMPool
import time
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
from csle_common.util.emulation_util import EmulationUtil
import csle_common.constants.constants as constants
import csle_collector.kafka_manager.kafka_manager_pb2_grpc
import csle_collector.kafka_manager.kafka_manager_pb2
import csle_collector.kafka_manager.query_kafka_server
from csle_common.metastore.metastore_facade import MetastoreFacade
from IPython.lib.editorhooks import emacs
from typing import Generator


@pytest.fixture(scope="module")
Expand All @@ -27,14 +26,14 @@ def docker_client() -> None:


@pytest.fixture(scope="module")
def network(docker_client) -> None:
def network(docker_client) -> Generator:
"""
Create a custom network with a specific subnet
:param docker_client: docker_client
:yield: network
:return: None
:return: Generator
"""
subnet = "15.15.15.0/24"
ipam_pool = IPAMPool(subnet=subnet)
Expand Down
7 changes: 3 additions & 4 deletions emulation-system/tests/test_start_ossec_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
from docker.types import IPAMConfig, IPAMPool
import time
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
from csle_common.util.emulation_util import EmulationUtil
import csle_common.constants.constants as constants
import csle_collector.ossec_ids_manager.ossec_ids_manager_pb2_grpc
import csle_collector.ossec_ids_manager.ossec_ids_manager_pb2
import csle_collector.ossec_ids_manager.query_ossec_ids_manager
from csle_common.metastore.metastore_facade import MetastoreFacade
from IPython.lib.editorhooks import emacs
from typing import Generator


@pytest.fixture(scope="module")
Expand All @@ -27,14 +26,14 @@ def docker_client() -> None:


@pytest.fixture(scope="module")
def network(docker_client) -> None:
def network(docker_client) -> Generator:
"""
Create a custom network with a specific subnet
:param docker_client: docker_client
:yield: network
:return: None
:return: Generator
"""
subnet = "15.15.15.0/24"
ipam_pool = IPAMPool(subnet=subnet)
Expand Down
7 changes: 3 additions & 4 deletions emulation-system/tests/test_start_ryu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
from docker.types import IPAMConfig, IPAMPool
import time
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
from csle_common.util.emulation_util import EmulationUtil
import csle_common.constants.constants as constants
import csle_collector.ryu_manager.ryu_manager_pb2_grpc
import csle_collector.ryu_manager.ryu_manager_pb2
import csle_collector.ryu_manager.query_ryu_manager
from csle_common.metastore.metastore_facade import MetastoreFacade
from IPython.lib.editorhooks import emacs
from typing import Generator


@pytest.fixture(scope="module")
Expand All @@ -27,14 +26,14 @@ def docker_client() -> None:


@pytest.fixture(scope="module")
def network(docker_client) -> None:
def network(docker_client) -> Generator:
"""
Create a custom network with a specific subnet
:param docker_client: docker_client
:yield: network
:return: None
:return: Generator
"""
subnet = "15.15.15.0/24"
ipam_pool = IPAMPool(subnet=subnet)
Expand Down
14 changes: 6 additions & 8 deletions emulation-system/tests/test_start_snort_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
from docker.types import IPAMConfig, IPAMPool
import time
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
from csle_common.util.emulation_util import EmulationUtil
import csle_common.constants.constants as constants
from csle_common.controllers.snort_ids_controller import SnortIDSController
import csle_collector.snort_ids_manager.snort_ids_manager_pb2_grpc
import csle_collector.snort_ids_manager.snort_ids_manager_pb2
from csle_common.metastore.metastore_facade import MetastoreFacade
from IPython.lib.editorhooks import emacs
from typing import Generator


@pytest.fixture(scope="module")
Expand All @@ -27,14 +25,14 @@ def docker_client() -> None:


@pytest.fixture(scope="module")
def network(docker_client) -> None:
def network(docker_client) -> Generator:
"""
Create a custom network with a specific subnet
:param docker_client: docker_client
:yield: network
:return: None
:return: Generator
"""
subnet = "15.15.15.0/24"
ipam_pool = IPAMPool(subnet=subnet)
Expand Down Expand Up @@ -64,7 +62,7 @@ def get_derived_containers(docker_client, excluded_tag=constants.CONTAINER_IMAGE
and all(constants.CONTAINER_IMAGES.BASE not in tag for tag in image.tags)
and all(excluded_tag not in tag for tag in image.tags)
]
return derived_images
return derived_images


@pytest.fixture(scope="module", params=get_derived_containers(docker.from_env()))
Expand All @@ -81,7 +79,7 @@ def container_setup(request, docker_client, network) -> Generator:
# Create and start each derived container
image = request.param
container = docker_client.containers.create(
image.tags[0],
image.tags[0],
command="sh -c 'while true; do sleep 3600; done'",
detach=True,
)
Expand Down Expand Up @@ -144,7 +142,7 @@ def test_start_snort_manager(container_setup) -> None:
with grpc.insecure_channel(f"{ip}:{port}", options=constants.GRPC_SERVERS.GRPC_OPTIONS) as channel:
stub = csle_collector.snort_ids_manager.snort_ids_manager_pb2_grpc.SnortIdsManagerStub(channel)
status = csle_collector.snort_ids_manager.query_snort_ids_manager.get_snort_ids_monitor_status(stub=stub)
assert status
assert status
except Exception as e:
print(f"Error occurred in container {container_setup.name}: {e}")
failed_containers.append(container_setup.name)
Expand Down
10 changes: 4 additions & 6 deletions emulation-system/tests/test_start_traffic_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
from docker.types import IPAMConfig, IPAMPool
import time
from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
from csle_common.util.emulation_util import EmulationUtil
import csle_common.constants.constants as constants
import csle_collector.traffic_manager.traffic_manager_pb2_grpc
import csle_collector.traffic_manager.traffic_manager_pb2
import csle_collector.traffic_manager.query_traffic_manager
from csle_common.metastore.metastore_facade import MetastoreFacade
from IPython.lib.editorhooks import emacs

from typing import Generator

@pytest.fixture(scope="module")
def docker_client() -> None:
Expand All @@ -27,14 +25,14 @@ def docker_client() -> None:


@pytest.fixture(scope="module")
def network(docker_client) -> None:
def network(docker_client) -> Generator:
"""
Create a custom network with a specific subnet
:param docker_client: docker_client
:yield: network
:return: None
:return: Generator
"""
subnet = "15.15.15.0/24"
ipam_pool = IPAMPool(subnet=subnet)
Expand Down Expand Up @@ -64,7 +62,7 @@ def get_derived_containers(docker_client, excluded_tag=constants.CONTAINER_IMAGE
and all(constants.CONTAINER_IMAGES.BASE not in tag for tag in image.tags)
and all(excluded_tag not in tag for tag in image.tags)
]
return derived_images
return derived_images[:1]


@pytest.fixture(scope="module", params=get_derived_containers(docker.from_env()))
Expand Down

0 comments on commit ee321e8

Please sign in to comment.