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

Testing in containers #3916

Open
arif-ali opened this issue Jan 30, 2025 · 2 comments
Open

Testing in containers #3916

arif-ali opened this issue Jan 30, 2025 · 2 comments
Labels
Kind/Testing Related to Testing

Comments

@arif-ali
Copy link
Member

Just bring this here based on some of the work I have been looking into.

As part of the testing on Debian/Ubuntu and the work happening to bring Avocado to Debian/Ubuntu, we will be eventually do unit and stageone testing as part of our builds.

In those particular scenarios the testing will happen in Docker style containers, so on thoses cases some of the tests will fail, like /boot not existing.

The plan is to potentially to create a new function in sos_tests.py that detects if you're in a container (in_container()), so that those tests can be predicated against the test.

This is low priority, as we still have a couple of months before we will be able to do any proper work on this as we need Avocado to land in debian

For reference, avocado-framework/avocado#6106 issue n avocado to track the Debian preliminary work needed to actually upload the package and make it available. Once uploaded, it can take a month for a new package to be accepted, so potentially ready for 4.9.1 or 4.9.2

@arif-ali arif-ali added the Kind/Testing Related to Testing label Jan 30, 2025
@pmoravec
Copy link
Contributor

Maybe a silly question, but can't the container bind mount /boot volume for the testing..?

@arif-ali
Copy link
Member Author

The infrastructure is not under my control, have to deal with what I get. So helpful to test if we're running in a container or not.

After doing some research, this is something I came up with

def in_container():
    """Check if running inside a container."""
    try:
        with open("/proc/1/cgroup", "r") as f:
            content = f.read()
            if any(keyword in content for keyword in ["docker", "lxc", "podman"]):
                return True
    except FileNotFoundError:
        pass
    return os.path.exists("/.dockerenv") or os.path.exists("/run/systemd/container")

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

No branches or pull requests

2 participants