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 2 commits
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
2 changes: 1 addition & 1 deletion src/Kathara/cli/command/CheckCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def linux_platform_info():
args['no_shared'] = False
args['no_hosthome'] = False

lab = Lab("kathara_vlab")
lab = Lab("kathara_test")
lab.get_or_new_machine("hello_world")

try:
Expand Down
14 changes: 9 additions & 5 deletions src/Kathara/cli/command/ConnectCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from ... import utils
from ...foundation.cli.command.Command import Command
from ...manager.Kathara import Kathara
from ...model.Lab import Lab
from ...parser.netkit.LabParser import LabParser
from ...strings import strings, wiki_description


Expand Down Expand Up @@ -59,14 +61,16 @@ def run(self, current_path: str, argv: List[str]) -> None:
args = self.get_args()

if args['vmachine']:
lab_path = "kathara_vlab"
lab = Lab("kathara_vlab")
else:
lab_path = args['directory'].replace('"', '').replace("'", '') if args['directory'] else current_path
lab_path = utils.get_absolute_path(lab_path)
try:
lab = LabParser.parse(lab_path)
except (Exception, IOError):
lab = Lab(None, path=lab_path)

logging.debug("Executing `connect` command in path `%s`..." % lab_path)
logging.debug("Executing `connect` command with hash `%s`..." % lab.hash)

lab_hash = utils.generate_urlsafe_hash(lab_path)

Kathara.get_instance().connect_tty(machine_name=args['machine_name'], lab_hash=lab_hash, shell=args['shell'],
Kathara.get_instance().connect_tty(machine_name=args['machine_name'], lab_hash=lab.hash, shell=args['shell'],
logs=args['logs'])
11 changes: 8 additions & 3 deletions src/Kathara/cli/command/ExecCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from ... import utils
from ...foundation.cli.command.Command import Command
from ...manager.Kathara import Kathara
from ...model.Lab import Lab
from ...parser.netkit.LabParser import LabParser
from ...strings import strings, wiki_description


Expand Down Expand Up @@ -67,13 +69,16 @@ def run(self, current_path: str, argv: List[str]) -> None:
args = self.get_args()

if args['vmachine']:
lab_path = "kathara_vlab"
lab = Lab("kathara_vlab")
else:
lab_path = args['directory'].replace('"', '').replace("'", '') if args['directory'] else current_path
lab_path = utils.get_absolute_path(lab_path)
try:
lab = LabParser.parse(lab_path)
except (Exception, IOError):
lab = Lab(None, path=lab_path)

lab_hash = utils.generate_urlsafe_hash(lab_path)
exec_output = Kathara.get_instance().exec(args['machine_name'], args['command'], lab_hash=lab_hash)
exec_output = Kathara.get_instance().exec(args['machine_name'], args['command'], lab_hash=lab.hash)

try:
while True:
Expand Down
10 changes: 7 additions & 3 deletions src/Kathara/cli/command/LcleanCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from ... import utils
from ...foundation.cli.command.Command import Command
from ...manager.Kathara import Kathara
from ...model.Lab import Lab
from ...parser.netkit.LabParser import LabParser
from ...strings import strings, wiki_description


Expand Down Expand Up @@ -45,9 +47,11 @@ def run(self, current_path: str, argv: List[str]) -> None:

lab_path = args['directory'].replace('"', '').replace("'", '') if args['directory'] else current_path
lab_path = utils.get_absolute_path(lab_path)

lab_hash = utils.generate_urlsafe_hash(lab_path)
try:
lab = LabParser.parse(lab_path)
except (Exception, IOError):
lab = Lab(None, path=lab_path)

logging.info(format_headers("Stopping Network Scenario"))

Kathara.get_instance().undeploy_lab(lab_hash=lab_hash, selected_machines=set(args['machine_names']))
Kathara.get_instance().undeploy_lab(lab_hash=lab.hash, selected_machines=set(args['machine_names']))
23 changes: 15 additions & 8 deletions src/Kathara/cli/command/LconfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ...foundation.cli.command.Command import Command
from ...manager.Kathara import Kathara
from ...model.Lab import Lab
from ...parser.netkit.LabParser import LabParser
from ...strings import strings, wiki_description


Expand Down Expand Up @@ -53,9 +54,6 @@ def run(self, current_path: str, argv: List[str]) -> None:
self.parse_args(argv)
args = self.get_args()

lab_path = args['directory'].replace('"', '').replace("'", '') if args['directory'] else current_path
lab_path = utils.get_absolute_path(lab_path)

for eth in args['eths']:
# Only alphanumeric characters are allowed
matches = re.search(r"^\w+$", eth)
Expand All @@ -65,13 +63,22 @@ def run(self, current_path: str, argv: List[str]) -> None:
self.parser.print_help()
exit(1)

lab = Lab(None, path=lab_path)
lab_path = args['directory'].replace('"', '').replace("'", '') if args['directory'] else current_path
lab_path = utils.get_absolute_path(lab_path)
try:
lab = LabParser.parse(lab_path)
except (Exception, IOError):
lab = Lab(None, path=lab_path)

device = lab.get_or_new_machine(args['name'])
device.api_object = Kathara.get_instance().get_machine_api_object(args['name'], lab_hash=lab.hash)
machine_name = args['name']
device = lab.get_or_new_machine(machine_name)
device.api_object = Kathara.get_instance().get_machine_api_object(machine_name, lab_hash=lab.hash)

for eth in args['eths']:
logging.info("Adding interface to device `%s` for collision domain `%s`..." % (args['name'], eth))
lab.connect_machine_to_link(args['name'], eth)
logging.info("Adding interface to device `%s` for collision domain `%s`..." % (machine_name, eth))
lab.connect_machine_to_link(machine_name, eth)

# Remove all the lab machines, except the one to update
lab.machines = {machine_name: device}

Kathara.get_instance().update_lab(lab)
27 changes: 15 additions & 12 deletions src/Kathara/cli/command/LinfoCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ... import utils
from ...foundation.cli.command.Command import Command
from ...manager.Kathara import Kathara
from ...model.Lab import Lab
from ...model.Link import BRIDGE_LINK_NAME
from ...parser.netkit.LabParser import LabParser
from ...strings import strings, wiki_description
Expand Down Expand Up @@ -65,45 +66,48 @@ def run(self, current_path: str, argv: List[str]) -> None:

lab_path = args['directory'].replace('"', '').replace("'", '') if args['directory'] else current_path
lab_path = utils.get_absolute_path(lab_path)
lab_hash = utils.generate_urlsafe_hash(lab_path)
try:
lab = LabParser.parse(lab_path)
except (Exception, IOError):
lab = Lab(None, path=lab_path)

if args['live']:
if args['name']:
self._get_machine_live_info(lab_hash, args['name'])
self._get_machine_live_info(lab, args['name'])
else:
self._get_lab_live_info(lab_hash)
self._get_lab_live_info(lab)

return

if args['conf']:
self._get_conf_info(lab_path, machine_name=args['name'])
self._get_conf_info(lab, machine_name=args['name'])
return

if args['name']:
print(format_headers("Device Information"))
print(str(next(Kathara.get_instance().get_machine_stats(args['name'], lab_hash))))
print(str(next(Kathara.get_instance().get_machine_stats(args['name'], lab.hash))))
print(format_headers())
else:
machines_stats = Kathara.get_instance().get_machines_stats(lab_hash)
machines_stats = Kathara.get_instance().get_machines_stats(lab.hash)
print(next(create_table(machines_stats)))

@staticmethod
def _get_machine_live_info(lab_hash: str, machine_name: str) -> None:
def _get_machine_live_info(lab: Lab, machine_name: str) -> None:
Curses.get_instance().init_window()

try:
while True:
Curses.get_instance().print_string(
format_headers("Device Information") + "\n" +
str(next(Kathara.get_instance().get_machine_stats(machine_name, lab_hash))) + "\n" +
str(next(Kathara.get_instance().get_machine_stats(machine_name, lab.hash))) + "\n" +
format_headers()
)
finally:
Curses.get_instance().close()

@staticmethod
def _get_lab_live_info(lab_hash: str) -> None:
machines_stats = Kathara.get_instance().get_machines_stats(lab_hash)
def _get_lab_live_info(lab: Lab) -> None:
machines_stats = Kathara.get_instance().get_machines_stats(lab.hash)
table = create_table(machines_stats)

Curses.get_instance().init_window()
Expand All @@ -117,8 +121,7 @@ def _get_lab_live_info(lab_hash: str) -> None:
Curses.get_instance().close()

@staticmethod
def _get_conf_info(lab_path: str, machine_name: str = None) -> None:
lab = LabParser.parse(lab_path)
def _get_conf_info(lab: Lab, machine_name: str = None) -> None:
if machine_name:
print(format_headers("Device Information"))
print(str(lab.machines[machine_name]))
Expand Down
7 changes: 3 additions & 4 deletions src/Kathara/cli/command/VcleanCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import logging
from typing import List

from ... import utils
from ...foundation.cli.command.Command import Command
from ...manager.Kathara import Kathara
from ...model.Lab import Lab
from ...strings import strings, wiki_description


Expand Down Expand Up @@ -37,8 +37,7 @@ def run(self, current_path: str, argv: List[str]) -> None:
self.parse_args(argv)
args = self.get_args()

lab_hash = utils.generate_urlsafe_hash("kathara_vlab")

Kathara.get_instance().undeploy_lab(lab_hash=lab_hash, selected_machines={args['name']})
lab = Lab("kathara_vlab")
Kathara.get_instance().undeploy_lab(lab_name=lab.name, selected_machines={args['name']})

logging.info("Device `%s` deleted successfully!" % args['name'])
9 changes: 5 additions & 4 deletions src/Kathara/cli/command/VconfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ def run(self, current_path: str, argv: List[str]) -> None:

lab = Lab("kathara_vlab")

device = lab.get_or_new_machine(args['name'])
device.api_object = Kathara.get_instance().get_machine_api_object(args['name'], lab_name=lab.name)
machine_name = args['name']
device = lab.get_or_new_machine(machine_name)
device.api_object = Kathara.get_instance().get_machine_api_object(machine_name, lab_name=lab.name)

for eth in args['eths']:
logging.info("Adding interface to device `%s` for collision domain `%s`..." % (args['name'], eth))
lab.connect_machine_to_link(args['name'], eth)
logging.info("Adding interface to device `%s` for collision domain `%s`..." % (machine_name, eth))
lab.connect_machine_to_link(machine_name, eth)

Kathara.get_instance().update_lab(lab)
22 changes: 14 additions & 8 deletions src/Kathara/model/Lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Lab(object):
shared_shutdown_path(str) The path of the shared shutdown file, if exists.
shared_folder(str) The path of the shared folder, if exists.
"""
__slots__ = ['name', 'description', 'version', 'author', 'email', 'web',
__slots__ = ['_name', 'description', 'version', 'author', 'email', 'web',
'path', 'hash', 'machines', 'links', 'general_options', 'has_dependencies',
'shared_startup_path', 'shared_shutdown_path', 'shared_folder']

Expand All @@ -45,7 +45,7 @@ def __init__(self, name: Optional[str], path: str = None) -> None:
Returns:
None
"""
self.name: Optional[str] = name
self._name: Optional[str] = name
self.description: Optional[str] = None
self.version: Optional[str] = None
self.author: Optional[str] = None
Expand All @@ -63,20 +63,26 @@ def __init__(self, name: Optional[str], path: str = None) -> None:
self.shared_startup_path: Optional[str] = None
self.shared_shutdown_path: Optional[str] = None

self.hash: str = ""
self.hash: str = utils.generate_urlsafe_hash(self.path if self._name is None else self._name)

if self.path:
self.hash = utils.generate_urlsafe_hash(self.path)
shared_startup_file = os.path.join(self.path, 'shared.startup')
self.shared_startup_path = shared_startup_file if os.path.exists(shared_startup_file) else None

shared_shutdown_file = os.path.join(self.path, 'shared.shutdown')
self.shared_shutdown_path = shared_shutdown_file if os.path.exists(shared_shutdown_file) else None
else:
self.hash = utils.generate_urlsafe_hash(self.name)

self.shared_folder: Optional[str] = None

@property
def name(self):
return self._name

@name.setter
def name(self, value):
self._name = value
self.hash = utils.generate_urlsafe_hash(value)

def connect_machine_to_link(self, machine_name: str, link_name: str, machine_iface_number: int = None) -> None:
"""Connect the specified device to the specified collision domain.

Expand Down Expand Up @@ -258,8 +264,8 @@ def __repr__(self) -> str:
def __str__(self) -> str:
lab_info = ""

if self.name:
lab_info += "Name: %s\n" % self.name
if self._name:
lab_info += "Name: %s\n" % self._name

if self.description:
lab_info += "Description: %s\n" % self.description
Expand Down
32 changes: 31 additions & 1 deletion tests/model/lab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def default_scenario():
return Lab("default_scenario")


@pytest.fixture()
def default_scenario_path():
return Lab(None, path="/lab/path")


@pytest.fixture()
def temporary_path():
return mkdtemp("kathara_test")
Expand Down Expand Up @@ -47,6 +52,31 @@ def test_default_scenario_creation(default_scenario: Lab):
assert default_scenario.hash == utils.generate_urlsafe_hash(default_scenario.name)


def test_default_scenario_creation_with_path(default_scenario_path: Lab):
assert default_scenario_path.name is None
assert default_scenario_path.description is None
assert default_scenario_path.version is None
assert default_scenario_path.author is None
assert default_scenario_path.email is None
assert default_scenario_path.web is None
assert default_scenario_path.machines == {}
assert default_scenario_path.links == {}
assert default_scenario_path.general_options == {}
assert not default_scenario_path.has_dependencies
assert default_scenario_path.path == "/lab/path"
assert default_scenario_path.shared_shutdown_path is None
assert default_scenario_path.shared_startup_path is None
assert default_scenario_path.shared_folder is None
assert default_scenario_path.hash == utils.generate_urlsafe_hash(default_scenario_path.path)


def test_default_scenario_creation_with_path_and_name(default_scenario_path: Lab):
default_scenario_path.name = "lab_with_path"
assert default_scenario_path.name == "lab_with_path"
assert default_scenario_path.path == "/lab/path"
assert default_scenario_path.hash == utils.generate_urlsafe_hash(default_scenario_path.name)


def test_directory_scenario_creation_no_shared_files(directory_scenario: Lab, temporary_path: str):
assert directory_scenario.name == "directory_scenario"
assert directory_scenario.description is None
Expand All @@ -62,7 +92,7 @@ def test_directory_scenario_creation_no_shared_files(directory_scenario: Lab, te
assert directory_scenario.shared_shutdown_path == os.path.join(temporary_path, 'shared.shutdown')
assert directory_scenario.shared_startup_path == os.path.join(temporary_path, 'shared.startup')
assert directory_scenario.shared_folder is None
assert directory_scenario.hash == utils.generate_urlsafe_hash(temporary_path)
assert directory_scenario.hash == utils.generate_urlsafe_hash(directory_scenario.name)


def test_get_or_new_machine_not_exist(default_scenario: Lab):
Expand Down