Skip to content

Commit

Permalink
Merge pull request #280 from KatharaFramework/develop
Browse files Browse the repository at this point in the history
Kathará v3.7.4
  • Loading branch information
tcaiazzi committed Mar 27, 2024
2 parents d9d60aa + 1c487f9 commit 721da0f
Show file tree
Hide file tree
Showing 21 changed files with 354 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ body:
attributes:
label: Kathará Version
description: "Please provide the Kathará version you are using (`kathara -v`)."
placeholder: "3.7.3"
placeholder: "3.7.4"
validations:
required: true
- type: textarea
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We release patches for security vulnerabilities only for the last version:

| Version | Supported Versions |
|---------|--------------------|
| 3.7.3 | :white_check_mark: |
| 3.7.4 | :white_check_mark: |

## Reporting a Vulnerability

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "kathara"
version = "3.7.3"
version = "3.7.4"
description = "A lightweight container-based network emulation tool."
readme = "README.md"
requires-python = ">=3.9"
Expand Down
2 changes: 1 addition & 1 deletion scripts/Linux-Deb/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/make -f

VERSION=3.7.3
VERSION=3.7.4
DEBIAN_PACKAGE_VERSION=1
LAUNCHPAD_NAME=user
NO_BINARY_PACKAGES=pyroute2|pyuv|deepdiff
Expand Down
8 changes: 3 additions & 5 deletions scripts/Linux-Deb/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
kathara (__VERSION__-__DEBIAN_PACKAGE_VERSION____UBUNTU_VERSION__) __UBUNTU_VERSION__; urgency=low

* New CLI UI using "rich" library!
* (Docker) Show progress during Docker image pull, similarly to the official "docker pull" command
* (Docker) It is now correctly possible to specify a "linux/amd64" image on Apple Silicon (which can be run using Rosetta)
* Add "gnome-terminal" as official supported terminal emulator
* Several API improvements and bug fixes
* (Docker) Fix "rp_filter" on "eth0" that was causing startup errors on some distributions
* (Megalos) Fix watch methods while starting/stopping devices that were causing "lstart"/"lclean" to hang indefinitely
* Minor fixes

-- Kathara Team <contact@kathara.org> __DATE__
2 changes: 1 addition & 1 deletion scripts/Linux-Pkg/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/make -f

VERSION=3.7.3
VERSION=3.7.4
PACKAGE_VERSION=1
AUR_NAME=user
AUR_MAIL=contact@kathara.org
Expand Down
8 changes: 3 additions & 5 deletions scripts/Linux-Pkg/pkginfo/kathara.changelog
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
__DATE__ Kathara Team <******@kathara.org>

* Release v__VERSION__
* New CLI UI using "rich" library!
* (Docker) Show progress during Docker image pull, similarly to the official "docker pull" command
* (Docker) It is now correctly possible to specify a "linux/amd64" image on Apple Silicon (which can be run using Rosetta)
* Add "gnome-terminal" as official supported terminal emulator
* Several API improvements and bug fixes
* (Docker) Fix "rp_filter" on "eth0" that was causing startup errors on some distributions
* (Megalos) Fix watch methods while starting/stopping devices that were causing "lstart"/"lclean" to hang indefinitely
* Minor fixes
2 changes: 1 addition & 1 deletion scripts/Linux-Rpm/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/make -f

VERSION=3.7.3
VERSION=3.7.4
PACKAGE_VERSION=1

.PHONY: all clean docker-build-image prepare-source prepare-man-pages prepare-bash-completion pack-source build
Expand Down
8 changes: 3 additions & 5 deletions scripts/Linux-Rpm/rpm/kathara.spec
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ chmod g+s %{_libdir}/kathara/kathara

%changelog
* __DATE__ Kathara Team <******@kathara.org> - __VERSION__-__PACKAGE_VERSION__
- New CLI UI using "rich" library!
- (Docker) Show progress during Docker image pull, similarly to the official "docker pull" command
- (Docker) It is now correctly possible to specify a "linux/amd64" image on Apple Silicon (which can be run using Rosetta)
- Add "gnome-terminal" as official supported terminal emulator
- Several API improvements and bug fixes
- (Docker) Fix "rp_filter" on "eth0" that was causing startup errors on some distributions
- (Megalos) Fix watch methods while starting/stopping devices that were causing "lstart"/"lclean" to hang indefinitely
- Minor fixes
2 changes: 1 addition & 1 deletion scripts/OSX/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/make -s

PRODUCT=Kathara
VERSION=3.7.3
VERSION=3.7.4
TARGET_DIRECTORY=Output
APPLE_DEVELOPER_CERTIFICATE_ID=FakeID
ROFF_DIR=../../docs/Roff
Expand Down
2 changes: 1 addition & 1 deletion scripts/Windows/installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Kathara"
#define MyAppVersion "3.7.3"
#define MyAppVersion "3.7.4"
#define MyAppPublisher "Kathara Team"
#define MyAppURL "https://www.kathara.org"
#define MyAppExeName "kathara.exe"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = kathara
version = 3.7.3
version = 3.7.4
author = Kathara Framework
author_email = contact@kathara.org
description = A lightweight container-based network emulation tool.
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
package_dir={'': 'src'},
packages=find_packages('src'),
py_modules=['kathara'],
version='3.7.3',
version='3.7.4',
license='gpl-3.0',
description='A lightweight container-based network emulation tool.',
author='Kathara Framework',
author_email='contact@kathara.org',
url='https://www.kathara.org',
download_url='https://github.com/KatharaFramework/Kathara/archive/refs/tags/3.7.3.tar.gz',
download_url='https://github.com/KatharaFramework/Kathara/archive/refs/tags/3.7.4.tar.gz',
keywords=['NETWORK-EMULATION', 'CONTAINERS', 'NFV'],
install_requires=[
"binaryornot>=0.4.4",
Expand Down
2 changes: 1 addition & 1 deletion src/Kathara/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, path: str) -> None:

class DockerDaemonConnectionError(Exception):
def __init__(self, message: str) -> None:
super().__init__(f"Cannot connect to Docker Daemon: {message}")
super().__init__(f"Cannot connect to Docker Daemon, this may indicate that it is not running. {message}")


class NotSupportedError(Exception):
Expand Down
16 changes: 12 additions & 4 deletions src/Kathara/manager/docker/DockerMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,20 @@ def create(self, machine: Machine) -> None:

# Sysctl params to pass to the container creation
sysctl_parameters = {RP_FILTER_NAMESPACE % x: 0 for x in ["all", "default", "lo"]}
sysctl_parameters["net.ipv4.ip_forward"] = 1
sysctl_parameters["net.ipv4.icmp_ratelimit"] = 0

sysctl_first_interface = {}
if first_machine_iface:
sysctl_parameters[RP_FILTER_NAMESPACE % "eth0"] = 0
def sysctl_linux():
if utils.is_wsl_platform():
return {RP_FILTER_NAMESPACE % "eth0": 0}
return {}

sysctl_parameters["net.ipv4.ip_forward"] = 1
sysctl_parameters["net.ipv4.icmp_ratelimit"] = 0
def sysctl_windows():
return {RP_FILTER_NAMESPACE % "eth0": 0}

sysctl_first_interface = utils.exec_by_platform(sysctl_linux, sysctl_windows, lambda: {})

if machine.is_ipv6_enabled():
sysctl_parameters["net.ipv6.conf.all.forwarding"] = 1
Expand All @@ -252,7 +260,7 @@ def create(self, machine: Machine) -> None:
sysctl_parameters["net.ipv6.conf.all.disable_ipv6"] = 0

# Merge machine sysctls
sysctl_parameters = {**sysctl_parameters, **machine.meta['sysctls']}
sysctl_parameters = {**sysctl_parameters, **machine.meta['sysctls'], **sysctl_first_interface}

volumes = {}

Expand Down
18 changes: 11 additions & 7 deletions src/Kathara/manager/docker/DockerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import docker
import docker.models.containers
import docker.models.networks
from docker.errors import DockerException
from requests.exceptions import ConnectionError as RequestsConnectionError

from .DockerImage import DockerImage
Expand Down Expand Up @@ -59,13 +60,16 @@ class DockerManager(IManager):
@check_docker_status
def __init__(self) -> None:
remote_url = Setting.get_instance().remote_url
if remote_url is None:
self.client: docker.DockerClient = docker.from_env(timeout=None, max_pool_size=utils.get_pool_size())
else:
tls_config = docker.tls.TLSConfig(ca_cert=Setting.get_instance().cert_path)
self.client: docker.DockerClient = docker.DockerClient(base_url=remote_url, timeout=None,
max_pool_size=utils.get_pool_size(),
tls=tls_config)
try:
if remote_url is None:
self.client: docker.DockerClient = docker.from_env(timeout=None, max_pool_size=utils.get_pool_size())
else:
tls_config = docker.tls.TLSConfig(ca_cert=Setting.get_instance().cert_path)
self.client: docker.DockerClient = docker.DockerClient(
base_url=remote_url, timeout=None, max_pool_size=utils.get_pool_size(), tls=tls_config
)
except DockerException as e:
raise DockerDaemonConnectionError(str(e))

docker_plugin = DockerPlugin(self.client)
docker_plugin.check_and_download_plugin()
Expand Down
38 changes: 19 additions & 19 deletions src/Kathara/manager/kubernetes/KubernetesMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ def deploy_machines(self, lab: Lab, selected_machines: Set[str] = None) -> None:
# Do not open terminals on Megalos
Setting.get_instance().open_terminals = False

wait_thread = threading.Thread(
target=self._wait_machines_startup,
args=(lab, selected_machines if selected_machines else None)
)
wait_thread.start()

# Deploy all lab machines.
# If there is no lab.dep file, machines can be deployed using multithreading.
# If not, they're started sequentially
Expand All @@ -171,7 +177,7 @@ def deploy_machines(self, lab: Lab, selected_machines: Set[str] = None) -> None:
for item in machines:
self._deploy_machine(item)

self._wait_machines_startup(lab, selected_machines if selected_machines else None)
wait_thread.join()

def _wait_machines_startup(self, lab: Lab, selected_machines: Set[str]) -> None:
"""Wait the startup of the selected machines. Return when the selected machines become `Ready`.
Expand Down Expand Up @@ -492,14 +498,17 @@ def undeploy(self, lab_hash: str, selected_machines: Optional[Set[str]] = None)
selected_machines = {item.metadata.labels["name"] for item in pods}

if len(pods) > 0:
wait_thread = threading.Thread(target=self._wait_machines_shutdown, args=(lab_hash, selected_machines))
wait_thread.start()

pool_size = utils.get_pool_size()
items = utils.chunk_list(pods, pool_size)

with Pool(pool_size) as machines_pool:
for chunk in items:
machines_pool.map(func=self._undeploy_machine, iterable=chunk)

self._wait_machines_shutdown(lab_hash, selected_machines)
wait_thread.join()

def _wait_machines_shutdown(self, lab_hash: str, selected_machines: Set[str]):
"""Wait the shutdown of the selected machines. Return when all the selected machines are terminated.
Expand Down Expand Up @@ -576,24 +585,15 @@ def _delete_machine(self, pod_api_object: client.V1Pod) -> None:
try:
shell_env_value = self.get_env_var_value_from_pod(pod_api_object, "_MEGALOS_SHELL")
shell = shell_env_value if shell_env_value else Setting.get_instance().device_shell
output = self.exec(machine_namespace,
machine_name,
command=[shell, '-c', shutdown_commands_string],
)

try:
next(output)
except StopIteration:
pass

deployment_name = self.get_deployment_name(machine_name)
self.kubernetes_config_map.delete_for_machine(deployment_name, machine_namespace)

self.client.delete_namespaced_deployment(name=deployment_name,
namespace=machine_namespace
)
self.exec(machine_namespace, machine_name, command=[shell, '-c', shutdown_commands_string], is_stream=False)
except ApiException:
return
pass
except MachineNotRunningError:
pass

deployment_name = self.get_deployment_name(machine_name)
self.kubernetes_config_map.delete_for_machine(deployment_name, machine_namespace)
self.client.delete_namespaced_deployment(name=deployment_name, namespace=machine_namespace)

def connect(self, lab_hash: str, machine_name: str, shell: Union[str, List[str]] = None, logs: bool = False) \
-> None:
Expand Down
3 changes: 1 addition & 2 deletions src/Kathara/os/Networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ def remove_interface_ns(interface_name: str, switch_path: str, ns_pid: int) -> N
logging.debug("Killing vde_ext process in namespace `%s`." % switch_path)

pid_path = os.path.join(switch_path, f"pid_{interface_name}")
command = f"/bin/sh -c 'kill -2 $(cat {pid_path})'"

command = f"/bin/sh -c 'if [ -f \"{pid_path}\" ]; then kill -2 $(cat {pid_path}); fi'"
logging.debug("Running command `%s` in namespace `%s`..." % (command, switch_path))
nsenter(ns_pid, command, ns_types=['ipc', 'net', 'pid', 'uts'])

Expand Down
7 changes: 7 additions & 0 deletions src/Kathara/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def is_platform(desired_platform: str) -> bool:
return _platform == desired_platform


def is_wsl_platform() -> bool:
if _platform == LINUX or _platform == LINUX2:
info = os.uname()
return 'microsoft' in info.release.lower()
return False


def exec_by_platform(fun_linux: Callable, fun_windows: Callable, fun_mac: Callable) -> Any:
if _platform == LINUX or _platform == LINUX2:
return fun_linux()
Expand Down
2 changes: 1 addition & 1 deletion src/Kathara/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Tuple

CURRENT_VERSION = "3.7.3"
CURRENT_VERSION = "3.7.4"


def parse(version: str) -> Tuple:
Expand Down
Loading

0 comments on commit 721da0f

Please sign in to comment.