KatharaFramework / Kathara

A lightweight container-based network emulation system.
https://www.kathara.org/
GNU General Public License v3.0
461 stars 64 forks source link

Add ability for kathara exec to return same status code as executed command #292

Open Thomas-McKanna opened 6 months ago

Thomas-McKanna commented 6 months ago

Related Bug

No response

Feature Description

I've been starting to use Kathara to build out labs for some training seminars, and I love the tool. One problem I have encountered is grading/checking student environments. It would be nice if there was a simple way that students could check if their changes to the Kathara configuration are correct. I was hoping to use kathara exec to run commands on various devices to do the checking, using the exit code of the command to determine whether or not the check passed. But it seems that kathara exec always returns a status code of 0, even if the command executed on the device did not return a status code of 0.

My feature suggestion is to add a flag or make it the default behavior such that kathara exec returns the same status code as the command which was executed on the device.

As an example, I'd like to writer a checker script that looks something like this:

#!/bin/bash

katahara exec mydevice "ping -c 1 10.10.1.1"

if [ $? -eq 0 ]; then
    echo "Problem 1: Passed"
else
    echo "Problem 1: Failed"
    exit 1
fi

If there is another preferred way to check lab configurations, this would be good to put in the wiki. But I wasn't able to find any content about it.

Solution

No response

Alternative Solutions

No response

Additional Context

No response

tcaiazzi commented 6 months ago

Hi @Thomas-McKanna,

Thanks for reaching out! We are super happy you like the tool!

My feature suggestion is to add a flag or make it the default behavior such that kathara exec returns the same status code as the command which was executed on the device

Yes, I agree with you, this is an interesting suggestion, and we will consider it in the future developments.

If there is another preferred way to check lab configurations, this would be good to put in the wiki. But I wasn't able to find any content about it.

Actually, we developed a tool to automatically check labs by configuring a json file (I was boring to do it manually). We used it to grade students during this year, but probably it is not ready for the publication since it lacks of some documentation.

Basically, the tool can check:

We missed many checks, especially on IGPs, but I will implement them for the next year's exams. I tried to make the tool as modular as possible, to facilitate integrations.

The repository contains an example to run, but probably it is not updated with all the possible checks.

You can find it here: https://github.com/tcaiazzi/kathara-lab-checker/tree/main

Please let me know if you can use it (if you have time to try 😇), and do not hesitate to open issues or discussion there (especially on the types of checks you need).

I have a deadline in the following weeks, but as I find some time, I can try to write some documentation or to help you with using the lab-checker.

Anyway, we will also consider your suggestion on the exec command.

Thanks!

Thomas-McKanna commented 6 months ago

@tcaiazzi Thank you for the quick reply! The repository you linked to looks like it will work well for my needs. I'll be taking a closer look at it in the week to come. Thanks!

larsks commented 2 months ago

Hi, I was about to open the same issue: I just want something like kathara exec mymachine false to propogate the command exit code back to the caller; just like the docker exec command.

Skazza94 commented 2 months ago

Hey @larsks, there is a way to get the actual exit code from a "streamed" exec in docker-py.

I will try to implement it in the next weeks.

larsks commented 2 months ago

@Skazza94, that's great news! This might be a related question: is there a way to get kathara report when a startup script fails?

Skazza94 commented 2 months ago

Hey @larsks, what do you need exactly?

larsks commented 2 months ago

I've lost time by having a typo in my startup scripts causing things to not get set up correctly. Some indication from Kathara that there was a failure would help identify problems more quickly.

tcaiazzi commented 1 month ago

Dear @larsks,

Apologies for the delayed response!

Commands in the startup files are logged, along with their results, in the /cat/var/log/startup.log file on each device. By default, these commands are also printed to the shell when the device terminals open at startup.

If you need more advanced functionality, you might find the kathara-lab-checker tool useful, depending on your requirements.

I hope this helps! Feel free to reach out if you have any further questions.