Skip to content

Commit

Permalink
couple of errors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nforsg committed Aug 7, 2023
1 parent 3614f35 commit 9fa34bb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import List, Tuple
from typing import List, Tuple, Union, Any
import subprocess
import time
import docker
Expand Down Expand Up @@ -162,7 +162,7 @@ def rm_image(name) -> bool:
return False

@staticmethod
def list_all_images() -> List[Tuple[str, str, str, str, str]]:
def list_all_images() -> List[Tuple[Any, Any, Any, Any, Any]]:
"""
A utility function for listing all csle images
Expand All @@ -178,7 +178,7 @@ def list_all_images() -> List[Tuple[str, str, str, str, str]]:
return images_names_created_os_architecture_size

@staticmethod
def list_docker_networks() -> Tuple[List[str], List[int]]:
def list_docker_networks():# -> Tuple[List[str], List[int]]:
"""
Lists the csle docker networks
Expand Down Expand Up @@ -249,7 +249,7 @@ def list_all_running_containers() -> List[Tuple[str, str, str]]:
:return: a list of the names of the running containers
"""
parsed_envs = DockerUtil.parse_runnning_emulation_infos()
container_name_image_ip = []
container_name_image_ip: List[Any] = []
for env in parsed_envs:
container_name_image_ip = (container_name_image_ip +
list(map(lambda x: (x.name, x.image_name, x.ip), env.containers)))
Expand Down Expand Up @@ -422,7 +422,10 @@ def connect_containers_to_networks(emulation_env_config: EmulationEnvConfig, phy
# Update IPs of OVS switches
for ovs_sw in emulation_env_config.ovs_config.switch_configs:
node_container_config = emulation_env_config.containers_config.get_container_from_ip(ovs_sw.ip)
ovs_sw.docker_gw_bridge_ip = node_container_config.docker_gw_bridge_ip
if node_container_config is not None:
ovs_sw.docker_gw_bridge_ip = node_container_config.docker_gw_bridge_ip
else:
ovs_sw.docker_gw_bridge_ip = ""

@staticmethod
def connect_container_to_network(container: NodeContainerConfig, logger: logging.Logger) -> None:
Expand Down Expand Up @@ -586,7 +589,7 @@ def create_network_from_dto(network_dto: ContainerNetwork, logger: logging.Logge

@staticmethod
def create_network(name: str, subnetmask: str, logger: logging.Logger,
driver: str = "bridge", existing_network_names: List = None) -> None:
driver: str = "bridge", existing_network_names: Union[List[Any], None] = None) -> None:
"""
Creates a network
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import List, Dict, Any
from typing import List, Dict, Any, Union
import time
import subprocess
import random
Expand Down Expand Up @@ -345,7 +345,7 @@ def run_containers(emulation_execution: EmulationExecution, physical_host_ip: st
for ip_net_resources in r.ips_and_network_configs:
ip, net_resources = ip_net_resources
if ip in ips:
container_resources: NodeResourcesConfig = r
container_resources = r
break
if container_resources is None:
raise ValueError(f"Container resources not found for container with ips:{ips}, "
Expand All @@ -365,7 +365,7 @@ def run_containers(emulation_execution: EmulationExecution, physical_host_ip: st
if emulation_env_config.kafka_config.container.physical_host_ip == physical_host_ip:
# Start the kafka container
c = emulation_env_config.kafka_config.container
container_resources: NodeResourcesConfig = emulation_env_config.kafka_config.resources
container_resources= emulation_env_config.kafka_config.resources
name = c.get_full_name()
cmd = f"docker container run -dt --name {name} " \
f"--hostname={c.name}{c.suffix} --label dir={path} " \
Expand All @@ -381,7 +381,7 @@ def run_containers(emulation_execution: EmulationExecution, physical_host_ip: st
if emulation_env_config.elk_config.container.physical_host_ip == physical_host_ip:
# Start the ELK container
c = emulation_env_config.elk_config.container
container_resources: NodeResourcesConfig = emulation_env_config.elk_config.resources
container_resources = emulation_env_config.elk_config.resources
name = c.get_full_name()
cmd = f"docker container run -dt --name {name} " \
f"--hostname={c.name}{c.suffix} --label dir={path} " \
Expand All @@ -398,7 +398,7 @@ def run_containers(emulation_execution: EmulationExecution, physical_host_ip: st
and emulation_env_config.sdn_controller_config.container.physical_host_ip == physical_host_ip:
# Start the SDN controller container
c = emulation_env_config.sdn_controller_config.container
container_resources: NodeResourcesConfig = emulation_env_config.sdn_controller_config.resources
container_resources = emulation_env_config.sdn_controller_config.resources
name = c.get_full_name()
cmd = f"docker container run -dt --name {name} " \
f"--hostname={c.name}{c.suffix} --label dir={path} " \
Expand Down Expand Up @@ -485,7 +485,7 @@ def run_container(image: str, name: str, logger: logging.Logger, memory: int = 4
subprocess.call(cmd, shell=True)

@staticmethod
def stop_containers(execution: EmulationExecution, physical_server_ip: str, logger: logging.Logger) -> None:
def stop_containers(execution: Union[EmulationExecution, None], physical_server_ip: str, logger: logging.Logger) -> None:
"""
Stop containers in the emulation env config
Expand All @@ -494,8 +494,10 @@ def stop_containers(execution: EmulationExecution, physical_server_ip: str, logg
:param logger: the logger to use for logging
:return: None
"""
emulation_env_config = execution.emulation_env_config

if execution is not None:
emulation_env_config = execution.emulation_env_config
else:
emulation_env_config = None
# Stop regular containers
for c in emulation_env_config.containers_config.containers:
if c.physical_host_ip != physical_server_ip:
Expand Down Expand Up @@ -610,7 +612,7 @@ def clean_all_executions(physical_server_ip: str, logger: logging.Logger, leader
MetastoreFacade.remove_emulation_execution(emulation_execution=exec)

@staticmethod
def rm_containers(execution: EmulationExecution, physical_server_ip: str, logger: logging.Logger) -> None:
def rm_containers(execution: Union[EmulationExecution, None], physical_server_ip: str, logger: logging.Logger) -> None:
"""
Remove containers in the emulation env config for a given execution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def save_config_file(config: Dict[str, Any]) -> None:
f.write(json_str)

@staticmethod
def get_current_config() -> Union["Config", None]:
def get_current_config() -> "Config":
"""
:return: The currently parsed config
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@ def list_emulation_executions() -> List[EmulationExecution]:
return records

@staticmethod
def list_emulation_executions_for_a_given_emulation(emulation_name: str) -> List[EmulationExecution]:
def list_emulation_executions_for_a_given_emulation(emulation_name: str) -> List[Union[None, EmulationExecution]]:
"""
:param emulation_name: the name of the emulation
:return: A list of emulation executions in the metastore for a given emulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def parse_containers(containers, client2) -> List[DockerContainerMetadata]:
return parsed_containers

@staticmethod
def get_docker_gw_bridge_ip(container_id: str) -> str:
def get_docker_gw_bridge_ip(container_id: Union[str, None]) -> str:
"""
Gets the docker gw bridge ip of a container
Expand Down

0 comments on commit 9fa34bb

Please sign in to comment.