Skip to content

Commit

Permalink
Merge pull request #225 from KatharaFramework/develop
Browse files Browse the repository at this point in the history
Kathará v3.6.2
  • Loading branch information
Skazza94 authored Jun 25, 2023
2 parents 56ba82a + 8e3f61f commit 1aebcf4
Show file tree
Hide file tree
Showing 28 changed files with 484 additions and 175 deletions.
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.6.0"
version = "3.6.2"
description = "A lightweight container-based emulation system."
readme = "README.md"
requires-python = ">=3.9"
Expand Down
4 changes: 2 additions & 2 deletions scripts/Linux-Deb/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/make -f

VERSION=3.6.0
VERSION=3.6.2
DEBIAN_PACKAGE_VERSION=1
LAUNCHPAD_NAME=user
NO_BINARY_PACKAGES=pyroute2|pyuv|deepdiff

.PHONY: allSigned docker-build-image prepare-deb-source unpack-deb-source clean-output-folder copy-debian-folder download-pip build-man build-deb-unsigned build-deb-signed ppa clean venv autocompletion

allSigned: clean prepare-deb-source docker-signed_bionic docker-signed_focal docker-signed_jammy docker-signed_kinetic
allSigned: clean prepare-deb-source docker-signed_focal docker-signed_jammy docker-signed_kinetic

docker-unsigned_%: clean prepare-deb-source docker-build-image_%
docker run -ti --rm -v `pwd`/../../:/opt/kathara kathara/linux-build-deb:$* /bin/bash -c \
Expand Down
10 changes: 4 additions & 6 deletions scripts/Linux-Deb/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
kathara (__VERSION__-__DEBIAN_PACKAGE_VERSION____UBUNTU_VERSION__) __UBUNTU_VERSION__; urgency=low

* Add filesystem abstraction that allows Python users to manage network scenarios' files and configurations in memory, without requiring any underlying host filesystem
* Add '.toml' setup file as requested by Python 3.11 specifications
* Fix Quagga permissions that prevent from writing configurations inside 'vtysh'
* Fix deprecation Warnings of 'libtmux' (thanks to Marcel Großmann)
* Add unit tests for CLI commands
* Fix FilesystemMixin APIs for file modifications
* Add a warning if a meta is repeated on the same device
* Add support for Docker Images tags in "kathara settings"
* Minor fixes

-- Mariano Scazzariello <******@gmail.com> __DATE__
-- Kathara Team <[email protected]> __DATE__
10 changes: 8 additions & 2 deletions scripts/Linux-Pkg/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/make -f

VERSION=3.6.0
VERSION=3.6.2
PACKAGE_VERSION=1
AUR_NAME=user
AUR_MAIL[email protected]
Expand All @@ -13,7 +13,7 @@ allRemote: clean docker-build-image docker-build-remote

docker-build-local: docker-build-image
mkdir -p Output
docker run -ti -v `pwd`:/home/builduser/kathara:ro -v `pwd`/Output:/home/builduser/output kathara/linux-build-pkg /usr/bin/su -c \
docker run -ti -v `pwd`:/home/builduser/kathara:ro -v `pwd`/Output:/home/builduser/output -v `pwd`/../..:/home/builduser/kathara-source/Kathara-$(VERSION):ro kathara/linux-build-pkg /usr/bin/su -c \
"make -f /home/builduser/kathara/Makefile build-local" builduser

docker-build-remote: docker-build-image
Expand All @@ -31,15 +31,21 @@ prepare-files:
sed -i -e 's/__PACKAGE_VERSION__/$(PACKAGE_VERSION)/g' /home/builduser/build/PKGBUILD

build-local: prepare-files
mkdir -p /home/builduser/build/src/
cp -r /home/builduser/kathara-source/Kathara-$(VERSION) /home/builduser/build/src
tar -zcf /home/builduser/build/kathara-$(VERSION).tar.gz /home/builduser/build/src/Kathara-$(VERSION)
sed -i -e 's/__PYTHON_DEP__//g' /home/builduser/build/PKGBUILD
sed -i -e 's/__SOURCE__/"kathara-$(VERSION).tar.gz"/g' /home/builduser/build/PKGBUILD
makepkg
mv kathara*.pkg.tar.zst /home/builduser/output/

build-remote: prepare-files
sed -i -e "s/__PYTHON_DEP__/'python310'/g" /home/builduser/build/PKGBUILD
sed -i -e 's/__SOURCE__/"https:\/\/github.com\/KatharaFramework\/Kathara\/archive\/refs\/tags\/\$$\pkgver.tar.gz"/g' /home/builduser/build/PKGBUILD
cp -r /home/builduser/ssh/ /home/builduser/.ssh/ && chmod 600 /home/builduser/.ssh/id_rsa
ssh-keyscan aur.archlinux.org > /home/builduser/.ssh/known_hosts
cd .. && git clone ssh://[email protected]/kathara kathara-aur
cd ../kathara-aur && git checkout master
git config --global user.name "$(AUR_NAME)"
git config --global user.email "$(AUR_MAIL)"
cp -r /home/builduser/build/* ../kathara-aur/
Expand Down
2 changes: 1 addition & 1 deletion scripts/Linux-Pkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
1. `src/Kathara/version.py`
2. `Makefile`
2. Write a proper `changelog` section in `pkginfo/kathara.changelog` file.
3. Run `make`. This will:
3. Run `make all`. This will:
1. Create a proper Docker image for the build environment
2. Run a Docker container with the image built above.
3. Compile Kathara into a binary.
Expand Down
2 changes: 1 addition & 1 deletion scripts/Linux-Pkg/pkginfo/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ optdepends=(
'xterm: for opening devices terminals'
'tmux: for opening many devices terminals'
)
source=("https://github.com/KatharaFramework/Kathara/archive/refs/tags/$pkgver.tar.gz")
source=(__SOURCE__)
md5sums=('SKIP')

prepare() {
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,9 +1,7 @@
__DATE__ Kathara Team <******@kathara.org>

* Release v__VERSION__
* Add filesystem abstraction that allows Python users to manage network scenarios' files and configurations in memory, without requiring any underlying host filesystem
* Add '.toml' setup file as requested by Python 3.11 specifications
* Fix Quagga permissions that prevent from writing configurations inside 'vtysh'
* Fix deprecation Warnings of 'libtmux' (thanks to Marcel Großmann)
* Add unit tests for CLI commands
* Fix FilesystemMixin APIs for file modifications
* Add a warning if a meta is repeated on the same device
* Add support for Docker Images tags in "kathara settings"
* 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.6.0
VERSION=3.6.2
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,9 +68,7 @@ chmod g+s %{_libdir}/kathara/kathara

%changelog
* __DATE__ Kathara Team <******@kathara.org> - __VERSION__-__PACKAGE_VERSION__
- Add filesystem abstraction that allows Python users to manage network scenarios' files and configurations in memory, without requiring any underlying host filesystem
- Add '.toml' setup file as requested by Python 3.11 specifications
- Fix Quagga permissions that prevent from writing configurations inside 'vtysh'
- Fix deprecation Warnings of 'libtmux' (thanks to Marcel Großmann)
- Add unit tests for CLI commands
- Fix FilesystemMixin APIs for file modifications
- Add a warning if a meta is repeated on the same device
- Add support for Docker Images tags in "kathara settings"
- 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.6.0
VERSION=3.6.2
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.6.0"
#define MyAppVersion "3.6.2"
#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.6.0
version = 3.6.2
author = Kathara Framework
author_email = [email protected]
description = A lightweight container based emulation system
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.6.0',
version='3.6.2',
license='gpl-3.0',
description='A lightweight container based emulation system.',
author='Kathara Framework',
author_email='[email protected]',
url='https://www.kathara.org',
download_url='https://github.com/KatharaFramework/Kathara/archive/refs/tags/3.6.0.tar.gz',
download_url='https://github.com/KatharaFramework/Kathara/archive/refs/tags/3.6.2.tar.gz',
keywords=['NETWORK-EMULATION', 'CONTAINERS', 'NFV'],
install_requires=[
"binaryornot>=0.4.4",
Expand Down
6 changes: 2 additions & 4 deletions src/Kathara/cli/ui/setting/CommonOptionsHandler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from . import utils as setting_utils
from ....webhooks.DockerHubApi import DockerHubApi
from ....exceptions import HTTPConnectionError
from ....foundation.cli.ui.setting.OptionsHandler import OptionsHandler
from ....manager.Kathara import Kathara
Expand All @@ -10,6 +9,7 @@
from ....utils import exec_by_platform
from ....validator.ImageValidator import ImageValidator
from ....validator.TerminalValidator import TerminalValidator
from ....webhooks.DockerHubApi import DockerHubApi

SHELLS_HINT = ["/bin/bash", "/bin/sh", "/bin/ash", "/bin/ksh", "/bin/zsh", "/bin/fish", "/bin/csh", "/bin/tcsh"]
TERMINALS_OSX = ["Terminal", "iTerm"]
Expand Down Expand Up @@ -52,9 +52,7 @@ def add_items(self, current_menu: ConsoleMenu, menu_formatter: MenuFormatBuilder
)

try:
for image in DockerHubApi.get_images():
image_name = "%s/%s" % (image['namespace'], image['name'])

for image_name in DockerHubApi.get_tagged_images():
select_image_menu.append_item(FunctionItem(text=image_name,
function=setting_utils.update_setting_value,
args=['image', image_name],
Expand Down
17 changes: 8 additions & 9 deletions src/Kathara/foundation/model/FilesystemMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,10 @@ def write_line_before(self, file_path: str, line_to_add: str, searched_line: str
for line in file_lines:
if searched_line.strip() == line.strip():
if not first_occurrence or (first_occurrence and n_added == 0):
new_lines.append(line_to_add)
new_lines.append(line_to_add + '\n')
n_added += 1
new_lines.append(line.strip())

file.writelines(s + '\n' for s in new_lines)
new_lines.append(line.replace("\n\r", "\n").replace("\r\n", "\n"))
file.writelines(new_lines)

return n_added

Expand Down Expand Up @@ -242,13 +241,13 @@ def write_line_after(self, file_path: str, line_to_add: str, searched_line: str,
file.truncate()
new_lines = []
for line in file_lines:
new_lines.append(line.strip())
new_lines.append(line.replace("\n\r", "\n").replace("\r\n", "\n"))
if searched_line.strip() == line.strip():
if not first_occurrence or (first_occurrence and n_added == 0):
new_lines.append(line_to_add)
new_lines.append(("\n" if not line.endswith("\n") else "") + line_to_add + '\n')
n_added += 1

file.writelines(s + '\n' for s in new_lines)
file.writelines(new_lines)

return n_added

Expand Down Expand Up @@ -284,8 +283,8 @@ def delete_line(self, file_path: str, line_to_delete: str, first_occurrence: boo
n_deleted += 1
continue

new_lines.append(line.strip())
new_lines.append(line.replace("\n\r", "\n").replace("\r\n", "\n"))

file.writelines(s + '\n' for s in new_lines)
file.writelines(new_lines)

return n_deleted
10 changes: 6 additions & 4 deletions src/Kathara/manager/docker/DockerMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ def create(self, machine: Machine) -> None:
options = machine.lab.general_options

# If bridged is required in command line but not defined in machine meta, add it.
if "bridged" in options and not machine.meta['bridged']:
if "bridged" in options and not machine.is_bridged():
machine.add_meta("bridged", True)

if ports and not machine.meta['bridged']:
if ports and not machine.is_bridged():
logging.warning(
"To expose ports of device `%s` on the host, "
"you have to specify the `bridged` option on that device." % machine.name
Expand All @@ -219,7 +219,7 @@ def create(self, machine: Machine) -> None:

# If no interfaces are declared in machine, but bridged mode is required, get bridge as first link.
# Flag that bridged is already connected (because there's another check in `start`).
if first_network is None and machine.meta['bridged']:
if first_network is None and machine.is_bridged():
first_network = machine.lab.get_or_new_link(BRIDGE_LINK_NAME).api_object
machine.add_meta("bridge_connected", True)

Expand Down Expand Up @@ -311,6 +311,7 @@ def connect_to_link(machine: Machine, link: Link) -> None:
DockerPluginError: If Kathara has been left in an inconsistent state.
APIError: If the Docker APIs return an error.
"""
machine.api_object.reload()
attached_networks = machine.api_object.attrs["NetworkSettings"]["Networks"]

if link.api_object.name not in attached_networks:
Expand All @@ -335,6 +336,7 @@ def disconnect_from_link(machine: Machine, link: Link) -> None:
Returns:
None
"""
machine.api_object.reload()
attached_networks = machine.api_object.attrs["NetworkSettings"]["Networks"]

if link.api_object.name in attached_networks:
Expand Down Expand Up @@ -389,7 +391,7 @@ def start(self, machine: Machine) -> None:
raise e

# Bridged connection required but not added in `deploy` method.
if "bridge_connected" not in machine.meta and machine.meta['bridged']:
if "bridge_connected" not in machine.meta and machine.is_bridged():
bridge_link = machine.lab.get_or_new_link(BRIDGE_LINK_NAME).api_object
bridge_link.connect(machine.api_object)

Expand Down
2 changes: 1 addition & 1 deletion src/Kathara/manager/kubernetes/KubernetesMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def create(self, machine: Machine) -> None:
options = machine.lab.general_options

# If bridged is defined for the device, throw a warning.
if "bridged" in options or machine.meta['bridged']:
if "bridged" in options or machine.is_bridged():
logging.warning('Bridged option is not supported on Megalos. It will be ignored.')

# If any exec command is passed in command line, add it.
Expand Down
12 changes: 6 additions & 6 deletions src/Kathara/model/Lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from ..exceptions import LinkNotFoundError, MachineNotFoundError, MachineAlreadyExistsError, LinkAlreadyExistsError
from ..foundation.model.FilesystemMixin import FilesystemMixin

LAB_METADATA: List[str] = ["LAB_NAME", "LAB_DESCRIPTION", "LAB_VERSION", "LAB_AUTHOR", "LAB_EMAIL", "LAB_WEB"]


class Lab(FilesystemMixin):
"""A Kathara network scenario, containing information about devices and collision domains.
Expand Down Expand Up @@ -104,7 +106,7 @@ def connect_machine_to_link(self, machine_name: str, link_name: str, machine_ifa

return machine, link

def assign_meta_to_machine(self, machine_name: str, meta_name: str, meta_value: str) -> 'MachinePackage.Machine':
def assign_meta_to_machine(self, machine_name: str, meta_name: str, meta_value: str) -> Optional[Any]:
"""Assign meta information to the specified device.
Args:
Expand All @@ -113,16 +115,14 @@ def assign_meta_to_machine(self, machine_name: str, meta_name: str, meta_value:
meta_value (str): The value of the meta property.
Returns:
Kathara.model.Machine: The Kathara device specified by the name.
Optional[Any]: Previous value if meta was already assigned, None otherwise.
Raises:
MachineOptionError: If invalid values are specified for meta properties.
"""
machine = self.get_or_new_machine(machine_name)

machine.add_meta(meta_name, meta_value)

return machine
return machine.add_meta(meta_name, meta_value)

def attach_external_links(self, external_links: Dict[str, List[ExternalLink]]) -> None:
"""Attach external collision domains to the network scenario.
Expand Down Expand Up @@ -224,7 +224,7 @@ def new_machine(self, name: str, **kwargs: Dict[str, Any]) -> 'MachinePackage.Ma
MachineAlreadyExistsError: If the device is already in the network scenario.
"""
if name in self.machines:
raise MachineAlreadyExistsError(f"Device {name} already in the network scenario.")
raise MachineAlreadyExistsError(name)

self.machines[name] = MachinePackage.Machine(self, name, **kwargs)

Expand Down
Loading

0 comments on commit 1aebcf4

Please sign in to comment.