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

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

Open
Thomas-McKanna opened this issue May 3, 2024 · 8 comments

Comments

@Thomas-McKanna
Copy link

Thomas-McKanna commented May 3, 2024

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
Copy link
Member

tcaiazzi commented May 3, 2024

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:

  • Device's existence and reachability;
  • Devices' routing tables;
  • Daemon process on devices;
  • Interface configurations (ipv4 and ipv6);
  • bridge configurations on device;
  • DNS configurations
  • BGP (or EVPN BGP) configurations (we use it for checking data center scenarios)

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
Copy link
Author

@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
Copy link

larsks commented Sep 5, 2024

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
Copy link
Member

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
Copy link

larsks commented Sep 12, 2024

@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
Copy link
Member

Hey @larsks,
what do you need exactly?

@larsks
Copy link

larsks commented Sep 13, 2024

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
Copy link
Member

tcaiazzi commented Sep 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants