Skip to content

orchestra/remote: extend mktemp() to accept data #1634

Merged
batrick merged 1 commit intoceph:masterfrom
rishabh-d-dave:no-sudo-for-tmp-files
Mar 31, 2021
Merged

orchestra/remote: extend mktemp() to accept data #1634
batrick merged 1 commit intoceph:masterfrom
rishabh-d-dave:no-sudo-for-tmp-files

Conversation

@rishabh-d-dave
Copy link
Contributor

@rishabh-d-dave rishabh-d-dave commented Mar 26, 2021

No description provided.

Comment on lines +612 to +613
kwargs['path'] = self.mktemp(kwargs.pop('suffix', None),
kwargs.pop('parentdir', None))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
kwargs['path'] = self.mktemp(kwargs.pop('suffix', None),
kwargs.pop('parentdir', None))
kwargs['path'] = self.mktemp(suffix=suffix, parentdir=parentdir)

Copy link
Contributor

@kshtsk kshtsk left a comment

Choose a reason for hiding this comment

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

I suggest to just use mktemp with data paremeter, then adding another one write_file method.

@rishabh-d-dave rishabh-d-dave force-pushed the no-sudo-for-tmp-files branch from 18caf08 to 69ad856 Compare March 30, 2021 09:25
@rishabh-d-dave
Copy link
Contributor Author

Removed write_temp_file() and upgraded mktemp() instead in last push.

path = self.sh(args).strip()

if data:
# sudo is set to False since root user can't write files in /tmp
Copy link
Contributor

Choose a reason for hiding this comment

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

this is strange clause, root user can write to any directory in fact

Copy link
Contributor

Choose a reason for hiding this comment

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

And btw, if the file is created by other user, than current, you must use sudo, but the whole idea of temporary files is to use the same user you operate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it can not anymore. Try writing files using sudo on kernel version post 4.19, I guess. Try ubuntu 20. This is what the entire is about. Please take a look at the commit message/PR description and at the ticket linked.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah... I see it is because of the new kernel feature, but anyways, why would you explicitly declare False, if it is already a default value?

Copy link
Contributor

Choose a reason for hiding this comment

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

As for https://tracker.ceph.com/issues/49466 this looks like a test bug, not the teuthology. The client code should care about tracking users or just always use default and not use sudo_write_file when it is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah... I see it is because of the new kernel feature, but anyways, why would you explicitly declare False, if it is already a default value?

So that the reader know it's intentional and required even if the reader isn't aware of context.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is self explanatory, if you create a random file and use write_file api, it is with user without sudo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is self explanatory, if you create a random file and use write_file api, it is with user without sudo.

If it was, I wouldn't have written this in the first place - #1634 (comment). :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I am sorry :-) I don't get it, what can be read differently when we have sudo_write_file and write_file? Why would we have sudo_write_file if write_file would have sudo=True?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's worth mentioning why we need sudo should be set ot False IMHO (the note is more comprehensible if it's immediately visible that sudo is set to False). However, I've gotten rid of the comment and "redundant" parameter from the call.

@kshtsk
Copy link
Contributor

kshtsk commented Mar 30, 2021

The bug referred in the commit message is related to the code from
qa/tasks/cephfs/cephfs_test_case.py:

    def create_keyring_file(self, remote, keyring):
        keyring_path = remote.run(args=['mktemp'], stdout=StringIO()).\
            stdout.getvalue().strip()
        sudo_write_file(remote, keyring_path, keyring)

        # required when triggered using vstart_runner.py.
        remote.run(args=['chmod', '644', keyring_path])

        return keyring_path

And rather be fixed in it instead of trying to fix teuthology api.

@kshtsk
Copy link
Contributor

kshtsk commented Mar 30, 2021

Why just instead of:

        sudo_write_file(remote, keyring_path, keyring)

        # required when triggered using vstart_runner.py.
        remote.run(args=['chmod', '644', keyring_path])

write:

        remote.write_file(keyring_path, keyring, mode='0644')

(wondering if new kernel allows to use sudo for changing mode and ownership in tmp files?)

@rishabh-d-dave
Copy link
Contributor Author

The bug referred in the commit message is related to the code:

    def create_keyring_file(self, remote, keyring):
        keyring_path = remote.run(args=['mktemp'], stdout=StringIO()).\
            stdout.getvalue().strip()
        sudo_write_file(remote, keyring_path, keyring)

        # required when triggered using vstart_runner.py.
        remote.run(args=['chmod', '644', keyring_path])

        return keyring_path

Instead of teuthology api.

I never said the bug is in teuthology API. About the code referred to in the commit message , it's already being fixed. PTAL at ceph/ceph#40431.

@kshtsk
Copy link
Contributor

kshtsk commented Mar 30, 2021

So why this change is required? I don't think we need it.

@rishabh-d-dave
Copy link
Contributor Author

sudo_write_file(remote, keyring_path, keyring)

write:

remote.write_file(keyring_path, keyring)

No, that won't fix the issue. What is need is -

keyring_path = remote.mktemp()
remote.write_file(keyring_path, keyring, sudo=False)

But what is much much better than this is -

keyring_path = remote.mktemp(data=keyring)

This is simpler and more powerful because I get to create and write temporary file in a single call. But, much more importantly, it closes the possibility of having a test failure because someone forgot to set sudo to False in possibly one of many calls to write_file().

@kshtsk
Copy link
Contributor

kshtsk commented Mar 30, 2021

The bug referred in the commit message is related to the code:

    def create_keyring_file(self, remote, keyring):
        keyring_path = remote.run(args=['mktemp'], stdout=StringIO()).\
            stdout.getvalue().strip()
        sudo_write_file(remote, keyring_path, keyring)

        # required when triggered using vstart_runner.py.
        remote.run(args=['chmod', '644', keyring_path])

        return keyring_path

Instead of teuthology api.

I never said the bug is in teuthology API. About the code referred to in the commit message , it's already being fixed. PTAL at ceph/ceph#40431.

You said this "Helps fix https://tracker.ceph.com/issues/49466" which is not true.

@kshtsk
Copy link
Contributor

kshtsk commented Mar 30, 2021

sudo_write_file(remote, keyring_path, keyring)

write:

remote.write_file(keyring_path, keyring)

No, that won't fix the issue. What is need is -

keyring_path = remote.mktemp()

It is the same as: keyring_path = remote.run(args=['mktemp'], stdout=StringIO()).\ stdout.getvalue().strip()

remote.write_file(keyring_path, keyring, sudo=False)

As I said, teuthology api sudo=False is default, you should not point it exclusively, so there is no difference.
The remote.mktemp()

But what is much much better than this is -

keyring_path = remote.mktemp(data=keyring)

It depends on your needs, I agree it is more handy, as I mentioned earlier.

This is simpler and more powerful because I get to create and write temporary file in a single call. But, much more importantly, it closes the possibility of having a test failure because someone forgot to set sudo to False in possibly one of many calls to write_file().

Again, we have standard api write_file, and we change it to sudo=True unlikely, because it is odd.

@rishabh-d-dave
Copy link
Contributor Author

@kshtsk

You said this "Helps fix https://tracker.ceph.com/issues/49466" which is not true.

This code keyring_path = remote.mktemp(data=keyring) cannot work without this PR. So this PR is helping out the fix for the tracker issue.

It's best not to just fix the bug but to also fix the root cause of the bug, so that it can't occur again.

@kshtsk
Copy link
Contributor

kshtsk commented Mar 30, 2021

Summarising:

  1. This PR does not help or resolve the new feature of kernel to protect files in /tmp and it becomes more like extending of mktemp usability, so it is needed only to add data argument and use write_file not sudo_write_file. No need to use 'sudo=False', default operations should be sudo less as much as possible.
  2. The commit message does not correspond the idea of the PR, and have to be changed appropriately.

@kshtsk
Copy link
Contributor

kshtsk commented Mar 30, 2021

@kshtsk

You said this "Helps fix https://tracker.ceph.com/issues/49466" which is not true.

This code keyring_path = remote.mktemp(data=keyring) cannot work without this PR. So this PR is helping out the fix for the tracker issue.

But you still can use standard API to fix the issue, so no need to mention it here, so it is not necessary to have it.

It's best not to just fix the bug but to also fix the root cause of the bug, so that it can't occur again.

You are not fixing the root cause of the bug with this PR. The root cause was incorrect usage of sudo_write_file in test.

@rishabh-d-dave rishabh-d-dave force-pushed the no-sudo-for-tmp-files branch 2 times, most recently from b3b6ce1 to 79393ee Compare March 30, 2021 11:52
@rishabh-d-dave rishabh-d-dave changed the title orchestra/remote: add a method to write files in /tmp orchestra/remote: extend mktemp() to accept data Mar 30, 2021
@rishabh-d-dave
Copy link
Contributor Author

@batrick I've removed every mention of why sudo must not be used from this PR in last update

@rishabh-d-dave rishabh-d-dave force-pushed the no-sudo-for-tmp-files branch from 79393ee to ed41381 Compare March 30, 2021 12:02
@rishabh-d-dave rishabh-d-dave requested a review from kshtsk March 30, 2021 12:03
@rishabh-d-dave rishabh-d-dave force-pushed the no-sudo-for-tmp-files branch from ed41381 to 6e90e0b Compare March 30, 2021 15:57
@kshtsk
Copy link
Contributor

kshtsk commented Mar 30, 2021

@susebot run deploy

@susebot
Copy link

susebot commented Mar 30, 2021

Commit 6e90e0b is OK.
Check tests results in the Jenkins job: https://ceph-ci.suse.de/job/pr-teuthology-deploy/320/

Extend remote.Remote.mktemp() to accept data as a parameter and write
the data to the temporary file after it is created.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
@rishabh-d-dave rishabh-d-dave force-pushed the no-sudo-for-tmp-files branch from 6e90e0b to 1966a88 Compare March 31, 2021 03:14
@rishabh-d-dave rishabh-d-dave requested a review from kshtsk March 31, 2021 03:14
Copy link
Contributor

@kshtsk kshtsk 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 to go now, thanks for the patience, and sorry that it took that much time.

@kshtsk
Copy link
Contributor

kshtsk commented Mar 31, 2021

@batrick I think your change request is outdated.

@kshtsk kshtsk dismissed batrick’s stale review March 31, 2021 16:20

Dismissing change request because it was outdated with new commits and become irrelevant.

@batrick batrick merged commit 85d61ea into ceph:master Mar 31, 2021
@rishabh-d-dave
Copy link
Contributor Author

@kshtsk @batrick Thanks!

@rishabh-d-dave rishabh-d-dave deleted the no-sudo-for-tmp-files branch April 1, 2021 09:59
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.

4 participants