Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kathará 3.5.1 #187

Merged
merged 65 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
23f93f6
More generic env regex (fix #168)
Skazza94 May 17, 2022
3f26501
Merge branch '168-env-regex-match-failure' into develop
Skazza94 May 17, 2022
d441b4e
Lab hash is computed on Lab name if present (#163)
Skazza94 May 30, 2022
a26d5df
Merge branch '163-compute-labhash-from-labname-if-it-is-present' into…
Skazza94 May 30, 2022
a90c16c
Link object has list of connected machines
Skazza94 May 30, 2022
1474ccd
Merge branch 'main' into develop
Skazza94 Jun 5, 2022
6b2561a
Add more Kubernetes Manager tests
Skazza94 Jun 5, 2022
4019538
Update Machine.py (#174)
whatever4711 Jul 6, 2022
cf3195b
Check that specified Docker Images are compatible with host arch (#178)
Skazza94 Jul 22, 2022
4046fda
Merge branch '178-add-architecture-compatibility-check-for-docker-ima…
Skazza94 Jul 22, 2022
1e78263
Add the possibility to specify device in lrestart (#177)
tcaiazzi Jul 22, 2022
fb7e43d
Handle exception in case binaryornot heuristics fail
Skazza94 Jul 22, 2022
0552dae
Test fix
Skazza94 Jul 22, 2022
aa48d86
add lab tests
tcaiazzi Jul 22, 2022
9e8b657
Add unit tests for deploy_lab method of managers
tcaiazzi Jul 26, 2022
3a98e6f
Add deploy_machine and deploy_link methods (#173)
Skazza94 Jul 26, 2022
6db8d03
Add localhost IPv6 mapping in default /etc/hosts
Skazza94 Aug 2, 2022
bbb94d7
Add undeploy_machine and undeploy_link methods (#173)
Skazza94 Aug 3, 2022
13465af
Replace update_lab method with connect_machine_to_link (#173)
Skazza94 Aug 4, 2022
ee3b84d
Merge branch '177-add-to-lrestart-the-possibilty-to-specify-devices' …
tcaiazzi Aug 24, 2022
8b703dd
Add change_link to manager and add unit tests
tcaiazzi Aug 25, 2022
de84915
Fix change_link (#173)
Skazza94 Aug 25, 2022
98f0e52
Add disconnect_from_link (#173)
Skazza94 Aug 26, 2022
1afe5f2
Remove swap + Add --rm to vconfig (#173)
Skazza94 Aug 26, 2022
467ad18
Add method to DockerManager to build a lab from api (#173)
tcaiazzi Aug 31, 2022
f363523
Minor polish (#173)
Skazza94 Sep 1, 2022
581bdd0
get_lab_from_api in KubernetesManager (#173)
Skazza94 Sep 1, 2022
fc11d5c
Add the possibility to disconnect devices in lconfig
tcaiazzi Sep 1, 2022
688ec6f
Fix + add unit tests for get_lab_from_api and update_lab_from_api (#173)
tcaiazzi Sep 1, 2022
a37d14f
Change 'lab' string to 'network scenario'
Skazza94 Sep 1, 2022
aed191c
Fix doc (#173)
tcaiazzi Sep 1, 2022
242161d
fix docstyle
tcaiazzi Sep 1, 2022
6907dad
Fix k8s tests
tcaiazzi Sep 1, 2022
21ddf8c
Merge branch '173-methods-to-manager' into develop
tcaiazzi Sep 1, 2022
96d1191
minor fixes
tcaiazzi Sep 1, 2022
a77ad19
Minor fixes + Polish
Skazza94 Sep 2, 2022
fb3c86f
Add k8s tests for get_lab_from_api
Skazza94 Sep 2, 2022
9004f67
Add custom exceptions (#179)
tcaiazzi Sep 2, 2022
a394295
fix (#179)
tcaiazzi Sep 2, 2022
f028926
Update pydoc with exceptions (#179)
tcaiazzi Sep 2, 2022
b8f3297
Add custom exceptions to unit tests + fix pydocs (#179)
tcaiazzi Sep 5, 2022
36c6f74
Skip k8s ConfigMap deletion if not present
Skazza94 Sep 5, 2022
21e26eb
fix option parser tests
tcaiazzi Sep 5, 2022
2fce681
Merge branch '179-add-custom-exceptions' into develop
tcaiazzi Sep 5, 2022
e1cef32
add get/new machine methods + unit tests (#181)
tcaiazzi Sep 5, 2022
1e86d73
Add get/new link method to Lab + unit tests (#181)
tcaiazzi Sep 5, 2022
e0a3152
fix test (#181)
tcaiazzi Sep 5, 2022
d864b97
Exceptions polish
Skazza94 Sep 5, 2022
f4be5b3
Merge branch '181-add-lab-methods-to-manage-links-and-machines' into …
tcaiazzi Sep 6, 2022
ac9fb87
Change pyuv to point to py3.10 compatible version on git (closes #182)
Skazza94 Sep 6, 2022
67e54fa
Merge branch '182-pyuv-broken-with-python-310x' into develop
Skazza94 Sep 6, 2022
e3506a1
Polish exceptions strings
Skazza94 Sep 6, 2022
ff920c3
Bump version + Changelog (ready to merge)
Skazza94 Sep 6, 2022
c50d76e
Docs update
Skazza94 Sep 6, 2022
cb1eddd
Update README
Skazza94 Sep 6, 2022
8734bf2
Remove Ubuntu Impish build
Skazza94 Sep 8, 2022
63b74f9
Add better error handling for kathara np exceptions (#183)
tcaiazzi Sep 9, 2022
7551574
add unit tests (#183)
tcaiazzi Sep 9, 2022
560641e
Merge branch '183-better-error-handling-kathara-np' into develop
tcaiazzi Sep 9, 2022
0482b3c
Fix cleaning with custom shell (#186)
tcaiazzi Sep 27, 2022
1ac4a18
Merge branch '186-bug-in-cleaning-devices-with-custom-shell' into dev…
tcaiazzi Sep 28, 2022
52dd468
Switch windows 10 build to Python3.10
Skazza94 Sep 29, 2022
e47b965
Fix Dockerfile for Linux-Pkg
tcaiazzi Sep 29, 2022
c26b66f
Fix Dockerfile for Debian releases
tcaiazzi Sep 29, 2022
2477d16
fix AUR dependencies
tcaiazzi Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Exceptions polish
  • Loading branch information
Skazza94 committed Sep 5, 2022
commit d864b97933f66e11b85afdb711262e291d27cb92
2 changes: 1 addition & 1 deletion src/Kathara/cli/command/LstartCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def run(self, current_path: str, argv: List[str]) -> Lab:
logging.info(format_headers())

if len(lab.machines) <= 0:
raise EmptyLabError("No devices in the current network scenario. Exiting...")
raise EmptyLabError()

try:
options = OptionParser.parse(args['options'])
Expand Down
57 changes: 35 additions & 22 deletions src/Kathara/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ class InvocationError(Exception):

# Settings Exceptions
class SettingsError(Exception):
def __init__(self, message) -> None:
super().__init__("Settings file is not valid: %s\nFix it or delete it before launching." % message)
def __init__(self, message: str) -> None:
super().__init__(f"Settings file is not valid: {message} Fix it or delete it before launching.")


class SettingsNotFoundError(Exception):
pass
def __init__(self, path: str) -> None:
super().__init__(f"Settings file not found in path `{path}`.")


class DockerDaemonConnectionError(Exception):
pass
def __init__(self, message: str) -> None:
super().__init__(f"Cannot connect to Docker Daemon: {message}")


class NotSupportedError(Exception):
def __init__(self, message) -> None:
super().__init__("Not Supported: %s" % message)
def __init__(self, message: str) -> None:
super().__init__(f"Not Supported: {message}")


# OS Exceptions
Expand All @@ -43,6 +45,11 @@ class InterfaceNotFoundError(Exception):
pass


class HostArchitectureError(Exception):
def __init__(self, architecture: str) -> None:
super().__init__(f"Not implemented for host architecture `{architecture}`.")


# Lab Exceptions
class LabAlreadyExistsError(Exception):
pass
Expand All @@ -53,7 +60,8 @@ class LabNotFoundError(Exception):


class EmptyLabError(Exception):
pass
def __init__(self) -> None:
super().__init__("No devices in the current network scenario.")


class MachineDependencyError(Exception):
Expand All @@ -66,18 +74,20 @@ class MountDeniedError(Exception):


class MachineAlreadyExistsError(Exception):
pass
def __init__(self, machine_name: str) -> None:
super().__init__(f"Device with name `{machine_name}` already exists.")


class NonSequentialMachineInterfaceError(Exception):
pass
def __init__(self, iface_num: int, machine_name: str) -> None:
super().__init__(f"Interface `{iface_num}` missing on device `{machine_name}`.")


class MachineOptionError(Exception):
pass


class MachineCollisionDomainConflictError(Exception):
class MachineCollisionDomainError(Exception):
pass


Expand All @@ -86,48 +96,51 @@ class MachineNotFoundError(Exception):


class MachineNotReadyError(Exception):
pass
def __init__(self, machine_name: str) -> None:
super().__init__(f"Device `{machine_name}` is not ready.")


# Link Exceptions
class LinkNotFoundError(Exception):
pass


# Architecture Excpetion
class ArchitectureError(Exception):
pass


# Test Exceptions
class TestError(Exception):
pass


class MachineSignatureNotFoundError(TestError):
pass
__slots__ = ['machine_name']

def __init__(self, machine_name: str):
self.machine_name: str = machine_name

def __str__(self):
return f"Signature for device `{self.machine_name}` not found!"


# Docker Exceptions
class InvalidImageArchitectureError(ValueError):
__slots__ = ['image_name', 'arch']

def __init__(self, image_name, arch):
self.image_name = image_name
self.arch = arch
def __init__(self, image_name: str, arch: str):
self.image_name: str = image_name
self.arch: str = arch

def __str__(self):
return f"Docker Image `{self.image_name}` is not compatible with your host architecture `{self.arch}`"


class DockerImageNotFoundError(Exception):
pass
def __init__(self, image_name: str) -> None:
super().__init__(f"Docker Image `{image_name}` is not available neither on Docker Hub nor in local repository!")


class DockerPluginError(Exception):
pass


# Kubernetes Exception
# Kubernetes Exceptions
class KubernetesConfigMapError(Exception):
pass
5 changes: 1 addition & 4 deletions src/Kathara/manager/docker/DockerImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ def _check_and_pull(self, image_name: str, pull: bool = True) -> None:
"no Internet connection is available to pull it from Docker Hub." % image_name
)
else:
raise DockerImageNotFoundError(
"Docker Image `%s` is not available neither on Docker Hub "
"nor in local repository!" % image_name
)
raise DockerImageNotFoundError(image_name)
except InvalidImageArchitectureError as e:
raise e

Expand Down
2 changes: 1 addition & 1 deletion src/Kathara/manager/docker/DockerMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def create(self, machine: Machine) -> None:
containers = self.get_machines_api_objects_by_filters(machine_name=machine.name, lab_hash=machine.lab.hash,
user=utils.get_current_user_name())
if containers:
raise MachineAlreadyExistsError("Device with name `%s` already exists." % machine.name)
raise MachineAlreadyExistsError(machine.name)

image = machine.get_image()
memory = machine.get_mem()
Expand Down
10 changes: 5 additions & 5 deletions src/Kathara/manager/docker/DockerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .stats.DockerMachineStats import DockerMachineStats
from ... import utils
from ...decorators import privileged
from ...exceptions import DockerDaemonConnectionError, LinkNotFoundError, MachineCollisionDomainConflictError, \
from ...exceptions import DockerDaemonConnectionError, LinkNotFoundError, MachineCollisionDomainError, \
InvocationError, LabNotFoundError
from ...foundation.manager.IManager import IManager
from ...model.Lab import Lab
Expand Down Expand Up @@ -55,9 +55,9 @@ def check_docker(*args, **kw):
try:
client.ping()
except RequestsConnectionError as e:
raise DockerDaemonConnectionError("Can not connect to Docker Daemon. %s" % str(e))
raise DockerDaemonConnectionError(str(e))
except pywintypes.error as e:
raise DockerDaemonConnectionError("Can not connect to Docker Daemon. %s" % str(e))
raise DockerDaemonConnectionError(str(e))

return check_docker

Expand Down Expand Up @@ -173,7 +173,7 @@ def connect_machine_to_link(self, machine: Machine, link: Link) -> None:
raise LabNotFoundError(f"Collision domain `{link.name}` is not associated to a network scenario.")

if machine.name in link.machines:
raise MachineCollisionDomainConflictError(
raise MachineCollisionDomainError(
f"Device `{machine.name}` is already connected to collision domain `{link.name}`."
)

Expand Down Expand Up @@ -205,7 +205,7 @@ def disconnect_machine_from_link(self, machine: Machine, link: Link) -> None:
raise LabNotFoundError(f"Collision domain `{link.name}` is not associated to a network scenario.")

if machine.name not in link.machines:
raise MachineCollisionDomainConflictError(
raise MachineCollisionDomainError(
f"Device `{machine.name}` is not connected to collision domain `{link.name}`."
)

Expand Down
4 changes: 2 additions & 2 deletions src/Kathara/manager/kubernetes/KubernetesMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def create(self, machine: Machine) -> None:
)
except ApiException as e:
if e.status == 409 and 'Conflict' in e.reason:
raise MachineAlreadyExistsError("Device with name `%s` already exists." % machine.name)
raise MachineAlreadyExistsError(machine.name)
else:
raise e

Expand Down Expand Up @@ -503,7 +503,7 @@ def connect(self, lab_hash: str, machine_name: str, shell: Union[str, List[str]]
deployment = pods.pop()

if 'Running' not in deployment.status.phase:
raise MachineNotReadyError('Device `%s` is not ready.' % machine_name)
raise MachineNotReadyError(machine_name)

if not shell:
shell_env_value = self.get_env_var_value_from_pod(deployment, "_MEGALOS_SHELL")
Expand Down
4 changes: 2 additions & 2 deletions src/Kathara/model/Lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,6 @@ def __str__(self) -> str:
lab_info += "Email: %s\n" % self.email

if self.web:
lab_info += "Website: %s" % self.web
lab_info += "Website: %s\n" % self.web

return lab_info
return lab_info[0:-1] # Remove trailing new line
10 changes: 5 additions & 5 deletions src/Kathara/model/Machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from . import Link as LinkPackage
from .Link import Link
from .. import utils
from ..exceptions import NonSequentialMachineInterfaceError, MachineOptionError, MachineCollisionDomainConflictError
from ..exceptions import NonSequentialMachineInterfaceError, MachineOptionError, MachineCollisionDomainError
from ..setting.Setting import Setting


Expand Down Expand Up @@ -105,10 +105,10 @@ def add_interface(self, link: 'LinkPackage.Link', number: int = None) -> None:
number = len(self.interfaces.keys())

if number in self.interfaces:
raise MachineCollisionDomainConflictError(f"Interface {number} already set on device `{self.name}`.")
raise MachineCollisionDomainError(f"Interface {number} already set on device `{self.name}`.")

if self.name in link.machines:
raise MachineCollisionDomainConflictError(
raise MachineCollisionDomainError(
f"Device `{self.name}` is already connected to collision domain `{link.name}`."
)

Expand All @@ -128,7 +128,7 @@ def remove_interface(self, link: 'LinkPackage.Link') -> None:
MachineCollisionDomainConflictError: If the device is not connected to the collision domain.
"""
if self.name not in link.machines:
raise MachineCollisionDomainConflictError(
raise MachineCollisionDomainError(
f"Device `{self.name}` is not connected to collision domain `{link.name}`.")

self.interfaces = collections.OrderedDict(
Expand Down Expand Up @@ -225,7 +225,7 @@ def check(self) -> None:

for i, (num_iface, _) in enumerate(sorted_interfaces):
if num_iface != i:
raise NonSequentialMachineInterfaceError("Interface %d missing on device %s." % (i, self.name))
raise NonSequentialMachineInterfaceError(i, self.name)

self.interfaces = collections.OrderedDict(sorted_interfaces)

Expand Down
2 changes: 1 addition & 1 deletion src/Kathara/parser/netkit/DepParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse(path: str) -> Optional[List[str]]:
# Dependencies are saved as dependencies[machine3] = [machine1, machine2]
dependencies[key] = deps
else:
raise SyntaxError(f"[ERROR] In lab.dep - line {line_number}: Syntax error.")
raise SyntaxError(f"In lab.dep - line {line_number}: Syntax error.")

line_number += 1
line = dep_mem_file.readline().decode('utf-8')
Expand Down
5 changes: 2 additions & 3 deletions src/Kathara/parser/netkit/ExtParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ def parse(path: str) -> Optional[Dict[str, List[ExternalLink]]]:

if vlan:
if 0 <= vlan >= 4095:
raise ValueError(f"[ERROR] In file lab.ext, line {line_number}: "
"VLAN ID must be in range [1, 4094].")
raise ValueError(f"In file lab.ext, line {line_number}: VLAN ID must be in range [1, 4094].")

if link not in external_links:
external_links[link] = []

external_links[link].append(ExternalLink(interface, vlan))
elif not line.startswith('#') and line.strip():
raise SyntaxError(f"[ERROR] In file lab.ext, line {line_number} malformed.")
raise SyntaxError(f"In file lab.ext, line {line_number} malformed.")

line_number += 1
line = ext_mem_file.readline().decode('utf-8')
Expand Down
9 changes: 4 additions & 5 deletions src/Kathara/parser/netkit/LabParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def parse(path: str) -> Lab:
value = matches.group("value").replace('"', '').replace("'", '')

if key in RESERVED_MACHINE_NAMES:
raise ValueError("[ERROR] In line %d: "
raise ValueError("In line %d: "
"`%s` is a reserved name, you can not use it for a device." % (line_number, key))

try:
Expand All @@ -59,9 +59,8 @@ def parse(path: str) -> Lab:
if re.search(r"^\w+$", value):
lab.connect_machine_to_link(key, value, machine_iface_number=interface_number)
else:
raise ValueError("[ERROR] In line %d: "
"Collision domain `%s` contains non-alphanumeric characters." % (line_number,
value))
raise ValueError("In line %d: Collision domain `%s` contains non-alphanumeric characters." %
(line_number, value))
except ValueError:
# Not an interface, add it to the machine metas.
lab.assign_meta_to_machine(key, arg, value)
Expand All @@ -74,7 +73,7 @@ def parse(path: str) -> Lab:
not line.startswith("LAB_AUTHOR=") and \
not line.startswith("LAB_EMAIL=") and \
not line.startswith("LAB_WEB="):
raise SyntaxError("[ERROR] In line %d: Invalid characters `%s`." % (line_number, line))
raise SyntaxError("In line %d: Invalid characters `%s`." % (line_number, line))
else:
(key, value) = line.split("=")
key = key.replace("LAB_", "").lower()
Expand Down
2 changes: 1 addition & 1 deletion src/Kathara/setting/Setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def load_from_disk(self, path: Optional[str] = None) -> None:
settings_path = os.path.join(path, SETTINGS_FILENAME) if path is not None else DEFAULT_SETTINGS_PATH

if not os.path.exists(settings_path): # Requested settings file doesn't exist, throw exception
raise SettingsNotFoundError("Settings file not found in specified path.")
raise SettingsNotFoundError(settings_path)
else: # Requested settings file exists, read it and check values
settings = {}
with open(settings_path, 'r') as settings_file:
Expand Down
2 changes: 1 addition & 1 deletion src/Kathara/test/BuiltinTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test(self) -> bool:
with open(machine_signature_path, 'r') as machine_signature_file:
machine_signature = json.loads(machine_signature_file.read())
else:
raise MachineSignatureNotFoundError("Signature for device `%s` not found! Exiting..." % machine_name)
raise MachineSignatureNotFoundError(machine_name)

# Save machine state into result file
machine_result_path = "%s/%s.builtin" % (self.results_path, machine.name)
Expand Down
4 changes: 1 addition & 3 deletions src/Kathara/test/UserTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def test(self) -> bool:
with open(machine_signature_path, 'r') as machine_signature_file:
machine_signature = machine_signature_file.read()
else:
raise MachineSignatureNotFoundError("Signature for device `%s` not found! Exiting..." %
machine_name
)
raise MachineSignatureNotFoundError(machine_name)

# Save machine state into result file
machine_result_path = "%s/%s.user" % (self.results_path, machine.name)
Expand Down
4 changes: 2 additions & 2 deletions src/Kathara/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from binaryornot.check import is_binary
from slug import slug

from .exceptions import ArchitectureError
from .exceptions import HostArchitectureError

# Platforms constants definition.
MAC_OS: str = "darwin"
Expand Down Expand Up @@ -139,7 +139,7 @@ def get_architecture() -> str:
elif architecture == "armv6l":
return "armv6"
else:
raise ArchitectureError("Not implemented for %s." % architecture)
raise HostArchitectureError(architecture)


def convert_win_2_linux(filename: str) -> bytes:
Expand Down
Loading