Skip to content

feat(cgroup): verify effective cgroup resource limits - #509

Open
imshubham22apr-gif wants to merge 1 commit into
ossf:mainfrom
imshubham22apr-gif:fix/verify-cgroup-limits
Open

imshubham22apr-gif wants to merge 1 commit into
ossf:mainfrom
imshubham22apr-gif:fix/verify-cgroup-limits

Conversation

@imshubham22apr-gif

Copy link
Copy Markdown
Contributor

Summary

Adds verify_cgroup_limits(cgroup_path, expected_cpuset, expected_memory_bytes) in oss_crs.src.cgroup to assert that effective resource limits applied by cgroup v2 actually match configured allocations on disk.

Changes

  1. oss_crs/src/cgroup.py:
    • Implemented verify_cgroup_limits(cgroup_path, expected_cpuset=None, expected_memory_bytes=None) -> tuple[bool, list[str]].
    • Reads memory.max and compares against expected_memory_bytes (ignoring "max" representing unlimited limits, and catching malformed contents).
    • Reads cpuset.cpus and normalizes ranges via parse_cpuset() (with fallback to exact string matching) to compare actual vs. expected CPU sets.
  2. oss_crs/tests/unit/test_cgroup_verify.py:
    • Added unit test suite covering missing cgroup directory, matching/mismatched memory, "max" unlimited handling, missing limit files, corrupted contents, and canonical cpuset range matching.
  3. CHANGELOG.md:
    • Documented the new utility function under [Unreleased] ### Added.

Testing

  • uv run pytest oss_crs/tests/unit/test_cgroup_verify.py (12 passed)
  • uv run ruff check and uv run ruff format --check (clean)
  • uv run pyright (clean)
  • DCO signed-off commit.

Signed-off-by: imshubham22apr-gif <imshubham.22apr@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant