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

Can't undeploy link on running lab using Kathara.get_instance().undeploy_link() with the python api #284

Closed
BMG-DYNAMIT opened this issue Apr 11, 2024 · 2 comments
Assignees
Milestone

Comments

@BMG-DYNAMIT
Copy link

BMG-DYNAMIT commented Apr 11, 2024

Operating System

Ubuntu 22.04

Kathará Version

3.7.4

Bug Description

If I deploy a lab and remove a link with Kathara.get_instance().undeploy_link() the link does not get removed and still exists after that.

Steps To Reproduce

Try the following test script:

import logging

from Kathara.manager.Kathara import Kathara
from Kathara.model.Lab import Lab

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

if __name__ == '__main__':
    logger.info("Creating Lab BGP Announcement...")
    lab = Lab("BGP Announcement")

    logger.info("Creating router1...")
    # Create router1 with image "kathara/frr"
    router1 = lab.new_machine("router1", **{"image": "kathara/frr"})

    link = lab.get_or_new_link("A")

    # Create and connect router1 interfaces
    lab.connect_machine_to_link(router1.name, link.name)

    logger.info("Creating router2...")
    # Create router2 with image "kathara/frr"
    router2 = lab.new_machine("router2", **{"image": "kathara/frr"})

    # Create and connect router1 interfaces
    lab.connect_machine_to_link(router2.name, link.name)

    logger.info("Deploying BGP Announcement lab...")
    Kathara.get_instance().deploy_lab(lab)

    # Link "A" exists
    print("Existing Links before undeploy:")
    for linkName, link in lab.links.items():
        print(linkName)

    Kathara.get_instance().undeploy_link(link)

    # Link "A" still exists, but should be removed!
    print("Existing Links after undeploy:")
    for linkName, link in lab.links.items():
        print(linkName)

    logger.info("Undeploying BGP Announcement lab...")
    Kathara.get_instance().undeploy_lab(lab_name=lab.name)

The Link with the name "A" does not get removed by undeploy_link().

It does not work neither with docker or kubernetes.

Expected Behavior

The Link with the name "A" should be undeployed.

Check Command Output

┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                     System Check                                                     │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Current Manager is:             Docker (Kathara)
Manager version is:             26.0.0
Python version is:              3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Kathara version is:             3.7.4
Operating System version is:    Linux-5.15.0-101-generic-x86_64
[Deploying devices]   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1/1
[Deleting devices]   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1/1
✓ Container run successfully.
@tcaiazzi
Copy link
Member

Hi @BMG-DYNAMIT,

Thanks for opening the issue!

To undeploy a link, first you must undeploy all the devices attached to it.

To disconnect a device from a link, you can use the disconnect_machine_from_link method:

def disconnect_machine_from_link(self, machine: Machine, link: Link) -> None:
"""Disconnect a Kathara device from a collision domain.
Args:
machine (Kathara.model.Machine): A Kathara machine object.
link (Kathara.model.Link): The Kathara collision domain from which disconnect the device.
Returns:
None
Raises:
LabNotFoundError: If the device specified is not associated to any network scenario.
LabNotFoundError: If the collision domain is not associated to any network scenario.
MachineCollisionDomainConflictError: If the device is not connected to the collision domain.
"""
self.manager.disconnect_machine_from_link(machine, link)

After all the devices connected to the link are disconnected, you can undeploy the link.

We will update the undeploy_link method's documentation to make that clear.

Thanks,
Tommaso

@BMG-DYNAMIT
Copy link
Author

Thanks for the help!

It works now,

Moritz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants