Skip to content

Commit

Permalink
Merge pull request #15 from KatharaFramework/develop
Browse files Browse the repository at this point in the history
Version 0.1.4
  • Loading branch information
tcaiazzi authored Oct 22, 2024
2 parents ab24778 + 4955189 commit 17c51b0
Show file tree
Hide file tree
Showing 38 changed files with 104 additions and 97 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ directory containing all the results for each network scenario, including the re

The repository already provide a complete example with the results of the tests.

- Check the test configuration by inspecting: [configuration_palabra.json](examples/palabra/configuration_palabra.json).
- Check the test configuration by inspecting: [configuration_palabra.json](examples/palabra/correction.json).
- Check the network topology and requisites: [palabra.pdf](examples/palabra/palabra.pdf)
- Check final results summary: [results.xlsx](examples/palabra/results.xlsx)

You can re-run the example by typing the following command in the root directory of the project:

```bash
python3 -m kathara_lab_checker --config examples/palabra/configuration_palabra.json --no-cache --labs examples/palabra/labs
python3 -m kathara_lab_checker --config examples/palabra/correction.json --no-cache --labs examples/palabra/labs
```

The `--no-cache` flag force to repeat already executed tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"convergence_time": 10,
"structure": "examples/palabra/palabra.conf",
"structure": "examples/palabra/structure",
"default_image": "kathara/frr",
"test": {
"requiring_startup": [
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "kathara-lab-checker"
version = "0.1.3"
version = "0.1.4"
description = "Tool to automatically check Kathará network scenarios based on a configuration file."
readme = "README.md"
requires-python = ">=3.11"
Expand Down Expand Up @@ -33,7 +33,7 @@ dependencies = [
]

[project.scripts]
kathara-lab-checker = "kathara_lab_checker:main"
kathara_lab_checker = "kathara_lab_checker.__main__:main"

[project.urls]
"Bug Reports" = "https://github.com/KatharaFramework/kathara-lab-checker/issues"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 36 additions & 29 deletions src/kathara_lab_checker.py → src/kathara_lab_checker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,32 @@
from Kathara.setting.Setting import Setting
from tqdm import tqdm

from lab_checker.TestCollector import TestCollector
from lab_checker.checks.BridgeCheck import BridgeCheck
from lab_checker.checks.CollisionDomainCheck import CollisionDomainCheck
from lab_checker.checks.CustomCommandCheck import CustomCommandCheck
from lab_checker.checks.DaemonCheck import DaemonCheck
from lab_checker.checks.DeviceExistenceCheck import DeviceExistenceCheck
from lab_checker.checks.IPv6EnabledCheck import IPv6EnabledCheck
from lab_checker.checks.InterfaceIPCheck import InterfaceIPCheck
from lab_checker.checks.KernelRouteCheck import KernelRouteCheck
from lab_checker.checks.ReachabilityCheck import ReachabilityCheck
from lab_checker.checks.StartupExistenceCheck import StartupExistenceCheck
from lab_checker.checks.SysctlCheck import SysctlCheck
from lab_checker.checks.applications.dns.DNSAuthorityCheck import DNSAuthorityCheck
from lab_checker.checks.applications.dns.DNSRecordCheck import DNSRecordCheck
from lab_checker.checks.applications.dns.LocalNSCheck import LocalNSCheck
from lab_checker.checks.protocols.AnnouncedNetworkCheck import AnnouncedNetworkCheck
from lab_checker.checks.protocols.ProtocolRedistributionCheck import ProtocolRedistributionCheck
from lab_checker.checks.protocols.bgp.BGPPeeringCheck import BGPPeeringCheck
from lab_checker.checks.protocols.evpn.AnnouncedVNICheck import AnnouncedVNICheck
from lab_checker.checks.protocols.evpn.EVPNSessionCheck import EVPNSessionCheck
from lab_checker.checks.protocols.evpn.VTEPCheck import VTEPCheck
from lab_checker.excel_utils import write_final_results_to_excel, write_result_to_excel
from lab_checker.utils import reverse_dictionary

VERSION = "0.1.3"
from kathara_lab_checker.TestCollector import TestCollector
from kathara_lab_checker.checks.BridgeCheck import BridgeCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.checks.CollisionDomainCheck import CollisionDomainCheck
from kathara_lab_checker.checks.CustomCommandCheck import CustomCommandCheck
from kathara_lab_checker.checks.DaemonCheck import DaemonCheck
from kathara_lab_checker.checks.DeviceExistenceCheck import DeviceExistenceCheck
from kathara_lab_checker.checks.IPv6EnabledCheck import IPv6EnabledCheck
from kathara_lab_checker.checks.InterfaceIPCheck import InterfaceIPCheck
from kathara_lab_checker.checks.KernelRouteCheck import KernelRouteCheck
from kathara_lab_checker.checks.ReachabilityCheck import ReachabilityCheck
from kathara_lab_checker.checks.StartupExistenceCheck import StartupExistenceCheck
from kathara_lab_checker.checks.SysctlCheck import SysctlCheck
from kathara_lab_checker.checks.applications.dns.DNSAuthorityCheck import DNSAuthorityCheck
from kathara_lab_checker.checks.applications.dns.DNSRecordCheck import DNSRecordCheck
from kathara_lab_checker.checks.applications.dns.LocalNSCheck import LocalNSCheck
from kathara_lab_checker.checks.protocols.AnnouncedNetworkCheck import AnnouncedNetworkCheck
from kathara_lab_checker.checks.protocols.ProtocolRedistributionCheck import ProtocolRedistributionCheck
from kathara_lab_checker.checks.protocols.bgp.BGPPeeringCheck import BGPPeeringCheck
from kathara_lab_checker.checks.protocols.evpn.AnnouncedVNICheck import AnnouncedVNICheck
from kathara_lab_checker.checks.protocols.evpn.EVPNSessionCheck import EVPNSessionCheck
from kathara_lab_checker.checks.protocols.evpn.VTEPCheck import VTEPCheck
from kathara_lab_checker.excel_utils import write_final_results_to_excel, write_result_to_excel
from kathara_lab_checker.utils import reverse_dictionary

VERSION = "0.1.4"
CURRENT_LAB: Optional[Lab] = None


Expand Down Expand Up @@ -87,10 +88,14 @@ def run_on_single_network_scenario(
CURRENT_LAB = lab
except IOError as e:
logger.warning(f"{str(e)} Skipping directory")
return
check_results = [CheckResult("The lab.conf cannot be parsed", False, str(e))]
test_collector.add_check_results(lab_name, check_results)
return test_collector
except MachineCollisionDomainError as e:
logger.warning(f"{str(e)} Skipping directory")
return
check_results = [CheckResult("The lab.conf cannot be parsed", False, str(e))]
test_collector.add_check_results(lab_name, check_results)
return test_collector

if not live:
logger.info(f"Undeploying network scenario in case it was running...")
Expand Down Expand Up @@ -279,7 +284,9 @@ def run_on_multiple_network_scenarios(

def parse_arguments():
parser = argparse.ArgumentParser(
description="A tool for automatically check Kathará network scenarios", add_help=True
description="A tool for automatically check Kathará network scenarios",
prog="kathara_lab_checker",
add_help=True
)

parser.add_argument(
Expand Down Expand Up @@ -362,7 +369,7 @@ def main():
if not os.path.exists(conf["structure"]):
logger.error(f"The structure file {conf['structure']} does not exist")
exit(1)

template_lab = LabParser().parse(
os.path.dirname(conf["structure"]),
conf_name=os.path.basename(conf["structure"]),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.utils import get_output
from kathara_lab_checker.utils import get_output
from .AbstractCheck import AbstractCheck
from .CheckResult import CheckResult

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from lab_checker.utils import green, red
from kathara_lab_checker.utils import green, red


class CheckResult:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def check(self, device_name: str, command_entry: dict[str, str | int], lab: Lab)
machine_name=device.name, lab_hash=lab.hash, command=command_entry["command"], stream=False
)

stdout = stdout.decode("utf-8").strip() if stdout else stderr.decode("utf-8").strip()
stdout = stdout.decode("utf-8").strip() if stdout else (stderr.decode("utf-8").strip() if stderr else "")

if "exit_code" in command_entry:
self.description = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.utils import get_output
from kathara_lab_checker.utils import get_output
from .AbstractCheck import AbstractCheck
from .CheckResult import CheckResult

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from Kathara.exceptions import MachineNotRunningError
from Kathara.model.Lab import Lab

from lab_checker.utils import get_interfaces_addresses
from kathara_lab_checker.utils import get_interfaces_addresses
from .AbstractCheck import AbstractCheck
from .CheckResult import CheckResult

Expand Down Expand Up @@ -31,7 +31,7 @@ def check(self, device_name: str, interface_number: int, ip: str, dumped_iface:
if addr_info["prefixlen"] == prefix_len:
return CheckResult(self.description, True, "OK")
else:
reason = f"The IP address has a wrong netmask ({prefix_len})"
reason = f"The IP address has a wrong netmask ({addr_info['prefixlen']})"
return CheckResult(self.description, False, reason)

reason = (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.utils import get_output
from kathara_lab_checker.utils import get_output
from .AbstractCheck import AbstractCheck
from .CheckResult import CheckResult

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import re

import jc
import os
from Kathara.exceptions import MachineNotRunningError
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.checks.AbstractCheck import AbstractCheck
from lab_checker.checks.CheckResult import CheckResult
from lab_checker.utils import get_output, find_lines_with_string, find_device_name_from_ip
from kathara_lab_checker.checks.AbstractCheck import AbstractCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.utils import get_output, find_lines_with_string, find_device_name_from_ip


class DNSAuthorityCheck(AbstractCheck):
def check(
self, domain: str, authority_ip: str, device_name: str, device_ip: str, lab: Lab
) -> CheckResult:
self.description = (
f"Checking on `{device_name}` that `{authority_ip}` is the authority for domain `{domain}`"
)
def check(self, domain: str, authority_ip: str, device_name: str, device_ip: str, lab: Lab) -> CheckResult:
self.description = f"Checking on `{device_name}` that `{authority_ip}` is the authority for domain `{domain}`"
kathara_manager: Kathara = Kathara.get_instance()
try:
exec_output_gen = kathara_manager.exec(
Expand All @@ -31,8 +28,8 @@ def check(

result = jc.parse("dig", output)
if result:
if result[0]["status"] == "NOERROR":
result = result.pop()
result = result.pop()
if result["status"] == "NOERROR" and "answer" in result:
root_servers = list(map(lambda x: x["data"].split(" ")[0], result["answer"]))
authority_ips = []
for root_server in root_servers:
Expand All @@ -51,40 +48,43 @@ def check(
else:
reason = (
f"named on {device_name} is running but answered "
f"with {result[0]['status']} when quering for {domain}"
f"with {result['status']} when quering for {domain}"
)
return CheckResult(self.description, False, reason)
else:
with lab.fs.open(f"{device_name}.startup", "r") as startup_file:
systemctl_lines = find_lines_with_string(startup_file.readline(), "systemctl")
if os.path.exists(f"{device_name}.startup"):
with lab.fs.open(f"{device_name}.startup", "r") as startup_file:
systemctl_lines = find_lines_with_string(startup_file.readline(), "systemctl")

for line in systemctl_lines:
if re.search(rf"^\s*systemctl\s*start\s*named\s*$", line):
exec_output_gen = kathara_manager.exec(
machine_name=device_name,
command=f"named -d 5 -g",
lab_hash=lab.hash,
)
for line in systemctl_lines:
if re.search(rf"^\s*systemctl\s*start\s*named\s*$", line):
exec_output_gen = kathara_manager.exec(
machine_name=device_name,
command=f"named -d 5 -g",
lab_hash=lab.hash,
)

output = get_output(exec_output_gen)
output = get_output(exec_output_gen)

date_pattern = r"\d{2}-[Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec]{3}-\d{4} \d{2}:\d{2}:\d{2}\.\d{3}"
date_pattern = (
r"\d{2}-[Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec]{3}-\d{4} \d{2}:\d{2}:\d{2}\.\d{3}"
)

reason_list = find_lines_with_string(output, "could not")
reason_list_no_dates = [re.sub(date_pattern, "", line) for line in reason_list]
reason = "\n".join(reason_list_no_dates)
reason_list = find_lines_with_string(output, "could not")
reason_list_no_dates = [re.sub(date_pattern, "", line) for line in reason_list]
reason = "\n".join(reason_list_no_dates)

return CheckResult(self.description, False, reason)
return CheckResult(self.description, False, reason)

reason = f"named not started in the startup file of `{device_name}`"
return CheckResult(self.description, False, reason)

def run(
self,
zone_to_authoritative_ips: dict[str, list[str]],
local_nameservers: list[str],
ip_mapping: dict[str, dict[str, str]],
lab: Lab,
self,
zone_to_authoritative_ips: dict[str, list[str]],
local_nameservers: list[str],
ip_mapping: dict[str, dict[str, str]],
lab: Lab,
) -> list[CheckResult]:
results = []
for domain, name_servers in zone_to_authoritative_ips.items():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.checks.AbstractCheck import AbstractCheck
from lab_checker.checks.CheckResult import CheckResult
from lab_checker.utils import get_output
from kathara_lab_checker.checks.AbstractCheck import AbstractCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.utils import get_output


class DNSRecordCheck(AbstractCheck):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.checks.AbstractCheck import AbstractCheck
from lab_checker.checks.CheckResult import CheckResult
from lab_checker.utils import get_output
from kathara_lab_checker.checks.AbstractCheck import AbstractCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.utils import get_output


class LocalNSCheck(AbstractCheck):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.checks.AbstractCheck import AbstractCheck
from lab_checker.checks.CheckResult import CheckResult
from lab_checker.utils import get_output
from kathara_lab_checker.checks.AbstractCheck import AbstractCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.utils import get_output


class AnnouncedNetworkCheck(AbstractCheck):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.checks.AbstractCheck import AbstractCheck
from lab_checker.checks.CheckResult import CheckResult
from lab_checker.utils import get_output
from kathara_lab_checker.checks.AbstractCheck import AbstractCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.utils import get_output


class ProtocolRedistributionCheck(AbstractCheck):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.checks.AbstractCheck import AbstractCheck
from lab_checker.checks.CheckResult import CheckResult
from lab_checker.utils import get_output
from kathara_lab_checker.checks.AbstractCheck import AbstractCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.utils import get_output


class BGPPeeringCheck(AbstractCheck):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.checks.AbstractCheck import AbstractCheck
from lab_checker.checks.CheckResult import CheckResult
from lab_checker.utils import get_output
from kathara_lab_checker.checks.AbstractCheck import AbstractCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.utils import get_output


class AnnouncedVNICheck(AbstractCheck):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

from lab_checker.checks.AbstractCheck import AbstractCheck
from lab_checker.checks.CheckResult import CheckResult
from lab_checker.utils import get_output
from kathara_lab_checker.checks.AbstractCheck import AbstractCheck
from kathara_lab_checker.checks.CheckResult import CheckResult
from kathara_lab_checker.utils import get_output


class EVPNSessionCheck(AbstractCheck):
Expand Down
Loading

0 comments on commit 17c51b0

Please sign in to comment.