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

Handle sysctls maps #764

Merged
merged 2 commits into from
Mar 9, 2024
Merged

Handle sysctls maps #764

merged 2 commits into from
Mar 9, 2024

Conversation

lemmi
Copy link
Contributor

@lemmi lemmi commented Sep 9, 2023

  • Add support to handle sysctls maps.
  • Directly raise an error if sysctls is neither an array nor map instead of letting podman fail with an unhelpful message.

Support for sysctls arrays was added in #261.

Fixes #754: sysctls only works with arrays, not maps

Copy link
Collaborator

@p12tic p12tic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the PR.

Could unit tests be added? There's an example in pytests/test_container_to_args.py.

@lemmi lemmi force-pushed the sysctls-dict branch 2 times, most recently from 1c741d7 to 2f8de64 Compare March 9, 2024 10:07
@lemmi
Copy link
Contributor Author

lemmi commented Mar 9, 2024

When I ran the tests with python -m unittest pytests/test_container_to_args.py, they didn't seem to actually run and I was getting a bunch of warnings like

/usr/lib/python3.12/unittest/case.py:589: RuntimeWarning: coroutine 'TestContainerToArgs.test_minimal' was never awaited
...

I switched the test class over to unittest.IsolatedAsyncioTestCase and with that the tests actually ran and failed when something was wrong.

I'm not very familiar with python or its tooling, so there might be a better solution.

If you want me to move the sysctl test somewhere else or have suggestions for more tests, let me know.

@lemmi lemmi requested a review from p12tic March 9, 2024 10:12

args0 = await container_to_args(c, cnt0)
args1 = await container_to_args(c, cnt1)
self.assertEqual(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this tests performs the check in a roundabout way. It's the actual contents of args which is important, not that two invocations of container_to_args produce identical results. If someone breaks sysctls completely in the future by e.g. ignoring them this test would still pass.

I think it makes sense to split test into two and compare args to an explicit list of strings like in the test above. This is more verbose, but also more readable as it's immediately clear what kind of result we are expecting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense. I split it in two test cases and made the assertion explicit.

@@ -25,7 +25,7 @@ def get_minimal_container():
}


class TestContainerToArgs(unittest.TestCase):
class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great discovery, thanks.

@lemmi lemmi force-pushed the sysctls-dict branch 3 times, most recently from f901a92 to 08cc994 Compare March 9, 2024 10:38
Signed-off-by: lemmi <lemmi@nerd2nerd.org>
- Add support to handle sysctls maps.
- Directly raise an error if sysctls is neither an array nor map instead
  of letting podman fail with an unhelpful message.

Support for sysctls arrays was added in containers#261.

Fixes containers#754: sysctls only works with arrays, not maps

Signed-off-by: lemmi <lemmi@nerd2nerd.org>
@p12tic
Copy link
Collaborator

p12tic commented Mar 9, 2024

Rebased and reordered commits.

Copy link
Collaborator

@p12tic p12tic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@p12tic p12tic merged commit 970e4ac into containers:main Mar 9, 2024
4 checks passed
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.

sysctls only works with arrays, not maps
2 participants