cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-95023: Added os.setns and os.unshare to easily switch between namespaces on Linux

Open noamcohen97 opened this issue 2 years ago • 28 comments

  • Issue: gh-95023

noamcohen97 avatar Jul 20 '22 09:07 noamcohen97

Most changes to Python require a NEWS entry.

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

bedevere-bot avatar Jul 20 '22 09:07 bedevere-bot

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.

MaxwellDupre avatar Jul 21 '22 10:07 MaxwellDupre

@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.

erlend-aasland avatar Jul 21 '22 16:07 erlend-aasland

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.

MaxwellDupre avatar Jul 21 '22 17:07 MaxwellDupre

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!

bedevere-bot avatar Jul 26 '22 08:07 bedevere-bot

I have made the requested changes; please review again.

noamcohen97 avatar Jul 26 '22 12:07 noamcohen97

Thanks for making the requested changes!

@erlend-aasland, @tiran: please review the changes made to this pull request.

bedevere-bot avatar Jul 26 '22 12:07 bedevere-bot

It looks like you need a clinic regen. Also, you may consider to summon the @python/proofreaders to scrutinize the added docs.

erlend-aasland avatar Jul 26 '22 12:07 erlend-aasland

summon the @python/proofreaders

@erlend-aasland How do you do that?

noamcohen97 avatar Jul 26 '22 13:07 noamcohen97

summon the @python/proofreaders

How do you do that?

👉🏻 @python/proofreaders: would you mind taking a look at the docs changes in this PR?

erlend-aasland avatar Jul 26 '22 13:07 erlend-aasland

It won't work when I do it. I cant even access https://github.com/orgs/python/teams/proofreaders, getting a 404 from GitHub @python/proofreaders

noamcohen97 avatar Jul 26 '22 13:07 noamcohen97

Yeah, there's definitely an access problem of some sort. @erlend-aasland's ping rendered in my email notification; @noamcohen97's didn't.

image

bskinn avatar Jul 26 '22 13:07 bskinn

~High level question, coming from a completely naive perspective on this: are os.setns and os.unshare opposites? That is, say, does os.unshare undo what os.setns does? If so, why aren't the names more obviously opposites of one another? Are they aligning with something in the underlying OS?~

Never mind, became clear after starting review.

bskinn avatar Jul 26 '22 13:07 bskinn

unshare moves the calling thread / process into a new namespace. It creates a new namespace.

The setns syscall moves a process into an existing namespace of another process.

The functions are low level wrappers around Linux syscalls. You may be familiar with them from Linux container runtimes like Docker.

tiran avatar Jul 26 '22 13:07 tiran

All commit authors signed the Contributor License Agreement.
CLA signed

cpython-cla-bot[bot] avatar Jul 26 '22 14:07 cpython-cla-bot[bot]

Review completed, @noamcohen97 -- my apologies if I got any of the technical details wrong in my comments. Feel free to accept/modify/reject as you prefer!

bskinn avatar Jul 26 '22 14:07 bskinn

It looks like all conversations are resolved. I'll wait a couple of days before landing this.

BTW, you could add yourself in Misc/ACKS, and also, please regenerate clinic.

I'll also wait for @tiran's final approve, since he requested changes.

erlend-aasland avatar Jul 28 '22 06:07 erlend-aasland

Any news with that?

noamcohen97 avatar Aug 21 '22 21:08 noamcohen97

@tiran @erlend-aasland ping

CAM-Gerlach avatar Aug 23 '22 04:08 CAM-Gerlach

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

erlend-aasland avatar Aug 23 '22 04:08 erlend-aasland

@tiran ?

noamcohen97 avatar Sep 09 '22 07:09 noamcohen97

#98056 fixed the failing tests

noamcohen97 avatar Oct 08 '22 05:10 noamcohen97

I've pinged @tiran again out of band

CAM-Gerlach avatar Oct 12 '22 08:10 CAM-Gerlach

:robot: New build scheduled with the buildbot fleet by @encukou for commit b14396e342d156ca620c25c5aed8e2e7520e747c :robot:

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

bedevere-bot avatar Oct 12 '22 14:10 bedevere-bot

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.

encukou avatar Oct 12 '22 15:10 encukou

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

noamcohen97 avatar Oct 14 '22 22:10 noamcohen97

I've triggered a re-run of the buildbots

CAM-Gerlach avatar Oct 15 '22 00:10 CAM-Gerlach

:robot: New build scheduled with the buildbot fleet by @CAM-Gerlach for commit 50c48098f21be3e2648c55935fad5adb82319ea7 :robot:

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

bedevere-bot avatar Oct 15 '22 00:10 bedevere-bot

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 ;-)

vstinner avatar Oct 20 '22 09:10 vstinner