GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-95023: Added os.setns and os.unshare to easily switch between namespaces on Linux by noamcohen97 · Pull Request #95046 · python/cpython

Conversation

@noamcohen97

@noamcohen97 noamcohen97 commented Jul 20, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: Implement os.setns, os.unshare to allow changing namespaces in Linux #95023

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot

bedevere-bot commented Jul 20, 2022

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting review label Jul 20, 2022
@noamcohen97
noamcohen97 force-pushed the namespaces branch 2 times, most recently from 868fe76 to 92a6d73 Compare July 20, 2022 13:21
@noamcohen97
noamcohen97 marked this pull request as ready for review July 20, 2022 13:26
@noamcohen97
pythongh-95023: added os.setns and os.unshare for namespaces switchin…
0bdd8bc
…g on Linux
@noamcohen97
noamcohen97 force-pushed the namespaces branch from 7aea95f to 0bdd8bc Compare July 20, 2022 14:07
@noamcohen97
remove gil release
3685a27
@serhiy-storchaka
serhiy-storchaka self-requested a review July 21, 2022 07:25
@MaxwellDupre

MaxwellDupre commented Jul 21, 2022

Copy link
Copy Markdown
Contributor

I would like to understand more about why I would want to use these functions, how to use and caveats. Just providing the bear functions with out examples and descriptions seems like half a job. Due to the current excellent documentation and current direction of the docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

noamcohen97 added 4 commits July 21, 2022 16:54
@noamcohen97
better setns, unshare doc
8f22740
@noamcohen97
added example to setns
5115c8a
@noamcohen97
added note about fileno for setns
8845a86
@noamcohen97
added see also section for os.unshare
d7bb582
@erlend-aasland

erlend-aasland commented Jul 21, 2022

Copy link
Copy Markdown
Contributor

@MaxwellDupre:

Just providing the bear functions with out examples and descriptions seems like half a job.

There is no need for such a negative tone; please try to be more encouraging when leaving review comments. Noam has followed the dev flow by creating an issue, explaining the need for this change, and has provided a very well written patch, complete with docs, tests, and a NEWS entry. I think he has done a great job, and I welcome his interest in making CPython better.

I welcome your interest in helping review PRs. Reviewing PRs is a difficult task; often more difficult than writing the code (or the docs) itself. I know the devguide is lacking when it comes to "how to review PRs". For now, the best thing to do is IMO to observe how others, more experienced reviewers, perform this task, and learn from them. Personally, I often find reviewing PRs difficult, and I often use far more time when reviewing a PR than I would use to write one.

serhiy-storchaka, JelleZijlstra, and dorukcan reacted with thumbs up emoji noamcohen97 reacted with laugh emoji
All reactions
  • 👍 3 reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MaxwellDupre

MaxwellDupre commented Jul 21, 2022

Copy link
Copy Markdown
Contributor

Understand, I did think about how to phrase and just went with the shortest. I realise how it maybe seen as negative and will try to improve.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland
erlend-aasland requested changes Jul 26, 2022
View reviewed changes
Comment thread Doc/library/os.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/os.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/os.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/os.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/os.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/os.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/os.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Core and Builtins/2022-07-20-09-04-55.gh-issue-95023.bs-xd7.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting changes and removed awaiting review labels Jul 26, 2022
@bedevere-bot

bedevere-bot commented Jul 26, 2022

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tiran
tiran suggested changes Jul 26, 2022
View reviewed changes
Comment thread Lib/test/test_posix.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_posix.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_posix.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread configure.ac Resolved

Uh oh!

There was an error while loading. Please reload this page.

noamcohen97 and others added 7 commits July 26, 2022 12:12
@noamcohen97 @tiran
Update configure.ac
987613a
Co-authored-by: Christian Heimes <[email protected]>
@noamcohen97
Revert "remove gil release"
4c91413
This reverts commit 3685a27.
@noamcohen97
better docs
7d23963
@noamcohen97
assume Linux platform has a working readlink
b7abf20
@noamcohen97
change ifdefs
af74db5
@noamcohen97
added missing CLONE_* consts
5181126
also, alphabetically order consts in doc
@noamcohen97
run unshare in a different process
3a37ac2
@noamcohen97

noamcohen97 commented Jul 26, 2022

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting changes label Jul 26, 2022
@CAM-Gerlach

CAM-Gerlach commented Aug 23, 2022

Copy link
Copy Markdown
Member

@tiran @erlend-aasland ping

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland

erlend-aasland commented Aug 23, 2022

Copy link
Copy Markdown
Contributor

I'm waiting for Christian, since he requested changes. For me, the PR is good to go.

CAM-Gerlach and noamcohen97 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@noamcohen97

noamcohen97 commented Sep 9, 2022

Copy link
Copy Markdown
Contributor Author

@tiran ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

noamcohen97 added 3 commits October 7, 2022 23:33
@noamcohen97
Merge remote-tracking branch 'upstream/main' into namespaces
cc44f01
@noamcohen97
Merge branch 'main' into namespaces
58bc8a6
@noamcohen97
Merge remote-tracking branch 'upstream/main' into namespaces
b14396e
@noamcohen97

noamcohen97 commented Oct 8, 2022

Copy link
Copy Markdown
Contributor Author

#98056 fixed the failing tests

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CAM-Gerlach

CAM-Gerlach commented Oct 12, 2022

Copy link
Copy Markdown
Member

I've pinged @tiran again out of band

noamcohen97 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 12, 2022
@bedevere-bot

bedevere-bot commented Oct 12, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit b14396e 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 12, 2022
@encukou

encukou commented Oct 12, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

As far as I know, Christian is quite busy these days. Don't wait for him too long if he didn't request that you do. He can always do a post-merge review.

I started a buildbot check, since this looks like it might have platform-specific issues.

noamcohen97 and erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@noamcohen97
Merge branch 'main' into namespaces
50c4809
@noamcohen97

noamcohen97 commented Oct 14, 2022

Copy link
Copy Markdown
Contributor Author

@encukou Looks like failures are related to #98216
I have updated the branch, can you started the buildbot check again please?

guybensimhon reacted with thumbs down emoji
All reactions
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CAM-Gerlach

CAM-Gerlach commented Oct 15, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I've triggered a re-run of the buildbots

noamcohen97 and erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@CAM-Gerlach CAM-Gerlach added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 15, 2022
@bedevere-bot

bedevere-bot commented Oct 15, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @CAM-Gerlach for commit 50c4809 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 15, 2022
vstinner
vstinner reviewed Oct 17, 2022
View reviewed changes
Comment thread Lib/test/test_posix.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread configure.ac Resolved

Uh oh!

There was an error while loading. Please reload this page.

@noamcohen97
do not use stdout for test
de7dd3d
vstinner
vstinner reviewed Oct 18, 2022
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The doc might be elaborated, but since there are young functions, I'm fine with redirecting users to their manual pages. Here is another review on the test.

Overall, the change LGTM. But I would prefer a few more adjustements of the test before approving it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

noamcohen97 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/test/test_posix.py Outdated

if rc == 2:
e = int(err[0])
self.assertIn(e, (errno.EPERM, errno.EINVAL, errno.ENOSPC, errno.ENOSYS))

@vstinner vstinner Oct 18, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I would prefer to move these checks inside the child process code. I don't think that skipping the test if unshare() or setns() fails matters. Just exit the child process early with a success (exit code 0, well, just exit) if you get one of these errors, no? If the child process must always succeed, you can use test.suppot.script_helper.assert_python_ok() which captures stdout and stderr and raises an exception with all data if the process fails.

Maybe it would make sense to add a except PermissionError: instead. Would you mind to add a comment explaining why/how PermissionError can happen?

ENOSPC is expected on unshare() if we exceed some limits on namespaces? If it can only happen on unshare(), maybe add a try/except only on this function call?

Why is EINVAL expected? Can it be raised if there is a bug in the test? Or can it be raised depending on the kernel configuration?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

noamcohen97 reacted with laugh emoji
All reactions
  • 😄 1 reaction

@noamcohen97 noamcohen97 Oct 19, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Cool! did not know about assert_python_ok

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@noamcohen97 noamcohen97 Oct 19, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

EINVAL could be raised the kernel was not configured with the CONFIG_UTS_NS option.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@noamcohen97
move all test login to subprocess
5c1bbdd
vstinner
vstinner reviewed Oct 19, 2022
View reviewed changes
Comment thread Lib/test/test_posix.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_posix.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_posix.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

noamcohen97 and others added 3 commits October 20, 2022 07:52
@noamcohen97 @vstinner
Update Lib/test/test_posix.py
29129d9
Co-authored-by: Victor Stinner <[email protected]>
@noamcohen97
add comments to tests
94883a4
@noamcohen97
bugfix in test while handling ENOSPC
3e365d2
@vstinner
vstinner merged commit a371a7e into python:main Oct 20, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Oct 20, 2022
@vstinner

vstinner commented Oct 20, 2022

Copy link
Copy Markdown
Member

Ok, enough nitpicking. This version is good enough to be merged. We can always enhance tests and doc later if needed. Thanks a lot @noamcohen97 for updating your PR many times. I like it and merged your PR.

unshare() and setns() are important functions nowadays on Linux. By the way, I like the "unshare" command line tool ;-)

noamcohen97 and erlend-aasland reacted with hooray emoji noamcohen97 reacted with heart emoji
All reactions
  • 🎉 2 reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

carljm added a commit to carljm/cpython that referenced this pull request Oct 20, 2022
@carljm
Merge branch 'main' into typewatch
8bba5da
* main: (40 commits)
  pythongh-98461: Fix source location in comprehensions bytecode (pythonGH-98464)
  pythongh-98421: Clean Up PyObject_Print (pythonGH-98422)
  pythongh-98360: multiprocessing now spawns children on Windows with correct argv[0] in virtual environments (pythonGH-98462)
  CODEOWNERS: Become a typing code owner (python#98480)
  [doc] Improve logging cookbook example. (pythonGH-98481)
  Add more tkinter.Canvas tests (pythonGH-98475)
  pythongh-95023: Added os.setns and os.unshare functions (python#95046)
  pythonGH-98363: Presize the list for batched() (pythonGH-98419)
  pythongh-98374: Suppress ImportError for invalid query for help() command. (pythongh-98450)
  typing tests: `_overload_dummy` raises `NotImplementedError`, not `RuntimeError` (python#98351)
  pythongh-98354: Add unicode check for 'name' attribute in _imp_create_builtin (pythonGH-98412)
  pythongh-98257: Make _PyEval_SetTrace() reentrant (python#98258)
  pythongh-98414: py.exe launcher does not use defaults for -V:company/ option (pythonGH-98460)
  pythongh-98417: Store int_max_str_digits on the Interpreter State (pythonGH-98418)
  Doc: Remove title text from internal links (python#98409)
  [doc] Refresh the venv introduction documentation, and correct the statement about VIRTUAL_ENV (pythonGH-98350)
  Docs: Bump sphinx-lint and fix unbalanced inline literal markup (python#98441)
  pythongh-92886: Replace assertion statements in `handlers.BaseHandler` to support running with optimizations (`-O`) (pythonGH-93231)
  pythongh-92886: Fix tests that fail when running with optimizations (`-O`) in `_test_multiprocessing.py` (pythonGH-93233)
  pythongh-92886: Fix tests that fail when running with optimizations (`-O`) in `test_py_compile.py` (pythonGH-93235)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@erlend-aasland erlend-aasland erlend-aasland approved these changes
@CAM-Gerlach CAM-Gerlach CAM-Gerlach approved these changes
@serhiy-storchaka serhiy-storchaka Awaiting requested review from serhiy-storchaka
@tiran tiran Awaiting requested review from tiran
+2 more reviewers
@mwichmann mwichmann mwichmann left review comments
@bskinn bskinn bskinn left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@noamcohen97 @bedevere-bot @MaxwellDupre @erlend-aasland @bskinn @tiran @CAM-Gerlach @encukou @vstinner @mwichmann
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.