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

exceptions: change error message for CommandFailedError #1652

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rishabh-d-dave
Copy link
Contributor

For the convenience of user, print the command that led to
CommandFailedError in error message as a str than as a list or a tuple.
This makes it more readable and enables the user to copy and use the
command without any hassles.

@@ -51,7 +51,12 @@ class CommandFailedError(Exception):
Exception thrown on command failure
"""
def __init__(self, command, exitstatus, node=None, label=None):
self.command = command
Copy link
Contributor

Choose a reason for hiding this comment

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

From one side this might seem useful for a user to copy and paste command,
but from another point of view, it is bad for debugging, it will be not possible to figure out what
exactly command was before it got to the Exception. Also, the next line joining command with spaces is absolutely not the same as it makes it quoted inside run methods, which makes it hard to reproduce issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From one side this might seem useful for a user to copy and paste command,

but from another point of view, it is bad for debugging, it will be not possible to figure out what
exactly command was before it got to the Exception.

I don't see how would figuring out become difficult since parameter would be printed as it is (at least individually). For example, ['ls', 'dir1'] would become ls dir1. I have grepped plenty times and either don't make much of a difference.

Also, the next line joining command with spaces is absolutely not the same as it makes it quoted inside run methods, which makes it hard to reproduce issue.

Same as what?

Umm... are you referring to this line when you say "quoted inside run methods"? I think there's no nice way around that but printing as string definitely takes away effort of deleting a dozen inverted commas every time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I mean the quotation thing.
Also, if you want to get the exact command, it is already printed in the logs, you just need to find the place where debug is printing the command out before the execution.

@@ -51,7 +51,12 @@ class CommandFailedError(Exception):
Exception thrown on command failure
"""
def __init__(self, command, exitstatus, node=None, label=None):
self.command = command
if isinstance(command, (list, tuple)):
self.command = ' '.join(command)
Copy link
Member

Choose a reason for hiding this comment

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

I think the right place for this transformation would be in the __str__ method. It would improve readability, yes.

Copy link
Contributor Author

@rishabh-d-dave rishabh-d-dave Jun 14, 2021

Choose a reason for hiding this comment

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

True, that'll be much better. Updated the patch now. Thanks!

Comment on lines +57 to +59
def __init__(self, cmd, exitstatus, node=None, label=None):
self.cmd = cmd
Copy link
Contributor

Choose a reason for hiding this comment

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

Why renaming command to cmd?

  • This change is not necessary.
  • Breaks the convention of naming arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why renaming command to cmd?

Lesser effort to type, and easier to keep statements under 79 characters which in turn saves us from hard to read split-over-several-line statements .

Comment on lines 64 to 73
if isinstance(self.cmd, (list, tuple)):
self.cmd = [str(Raw) if isinstance(x, Raw) else x \
for x in self.cmd]
self.cmd = ' '.join(self.cmd)
elif isinstance(self.cmd, str):
self.cmd = sub(r'Raw\([\'"](.*)[\'"]\)', r'\1', self.cmd)
else:
raise RuntimeError('variable "command" is not str, list or tuple')

Copy link
Contributor

Choose a reason for hiding this comment

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

Do not override the original command, just return the str representation computed in local variable.

Copy link
Contributor Author

@rishabh-d-dave rishabh-d-dave Jun 15, 2021

Choose a reason for hiding this comment

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

Okay. That would be better, I guess. Thanks!

import logging
import shutil

from teuthology.contextutil import safe_while
from teuthology.exceptions import (CommandCrashedError, CommandFailedError,
ConnectionLostError)
from teuthology.orchestra.run_helper import Raw, quote
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of run_helper I suggest more appropriate name for the module, util or tool or common or for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find run_helper appropriate since it contains classes that help run.py.

BTW I moving rest of misc. classes from run.py to run_helper.py too.

Copy link
Contributor

@kshtsk kshtsk Jun 15, 2021

Choose a reason for hiding this comment

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

that looks weird, if you really want to have run based classes it would have more appropriate to have this layout:

teuthology/orchestra/run/__init__.py
teuthology/orchestra/run/helper.py

instead of underscore separated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally feel this a bit of overkill but I don't really mind.

@batrick Any opinion?

for x in self.cmd]
self.cmd = ' '.join(self.cmd)
elif isinstance(self.cmd, str):
self.cmd = sub(r'Raw\([\'"](.*)[\'"]\)', r'\1', self.cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this branch is 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.

Transforms str 'param1 param2 Raw('&&") param3' to str 'param1 param2 && param3'.

Copy link
Contributor

Choose a reason for hiding this comment

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

why this is needed to transform I do not understand

Copy link
Contributor

Choose a reason for hiding this comment

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

or in which situation this is happening...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same reason for which i am converting list to str.

Copy link
Contributor

Choose a reason for hiding this comment

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

well... I don't understand why we do not use quote method here from the helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would that do the job?

$ python
Python 3.8.9 (default, Apr  6 2021, 00:00:00) 
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from teuthology.orchestra.run_helper import Raw, quote
>>> a = quote('a b Raw("&&") c')
>>> a
'a b Raw("&&") c'
>>> 

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, but how is it possible to have the Raw in the string? From my point of view if you have Raw in the str it means that you've made a typo and this command is not going to be run successfully.

@rishabh-d-dave
Copy link
Contributor Author

@kshtsk @batrick
teuthology.orchestra.run.spawn_asyncresult() is a dead function, there are no calls to it in teuthology codebase. Better to get rid of it?

@kshtsk
Copy link
Contributor

kshtsk commented Jun 15, 2021

@kshtsk @batrick
teuthology.orchestra.run.spawn_asyncresult() is a dead function, there are no calls to it in teuthology codebase. Better to get rid of it?

I don't know, Isn't it used in any named branch of ceph qa/tasks?

@rishabh-d-dave
Copy link
Contributor Author

rishabh-d-dave commented Jun 15, 2021

@kshtsk

@kshtsk @batrick
teuthology.orchestra.run.spawn_asyncresult() is a dead function, there are no calls to it in teuthology codebase. Better to get rid of it?

I don't know, Isn't it used in any named branch of ceph qa/tasks?

No call there too.

$ git pull --no-rebase && grep -rnI spawn_asyncresult qa/
Already up to date.

I will get rid of it.

rishabh-d-dave added a commit to rishabh-d-dave/ceph that referenced this pull request Jun 15, 2021
Class Raw has been moved from teuthology.orchestra.run to
teuthology.orchestra.run_helper. Update Ceph QA code accordingly.

Related PR: ceph/teuthology#1652.

Signed-off-by: Rishabh Dave <[email protected]>
Class Raw is needed in teuthology.exceptions and importing it from
teuthology.orchestra.run is not possible since it would lead to a
circular dependecy. Move these classes to a new module, run_helper.py,
to avoid this and import through run_helper.py instead.

Signed-off-by: Rishabh Dave <[email protected]>
For the convenience of user, print the command that led to
CommandFailedError in error message as a str than as a list or a tuple.
This makes it more readable and enables the user to copy and use the
command without any hassles.

This commit also uses the opportunity to rename the variable "command"
to "cmd" and "self.command" to "self.cmd" in CommandFailedError for
convenience and so that it's easy to keep statements under 80
characters.

Signed-off-by: Rishabh Dave <[email protected]>
Since the function is dead code, there are no calls to it in teuthology
or ceph repository, remove it.

Signed-off-by: Rishabh Dave <[email protected]>
rishabh-d-dave added a commit to rishabh-d-dave/ceph that referenced this pull request Jun 16, 2021
Class Raw has been moved from teuthology.orchestra.run to
teuthology.orchestra.run_helper. Update Ceph QA code accordingly.

Related PR: ceph/teuthology#1652.

Signed-off-by: Rishabh Dave <[email protected]>
rishabh-d-dave added a commit to rishabh-d-dave/ceph that referenced this pull request Sep 17, 2021
Class Raw has been moved from teuthology.orchestra.run to
teuthology.orchestra.run_helper. Update Ceph QA code accordingly.

Related PR: ceph/teuthology#1652.

Signed-off-by: Rishabh Dave <[email protected]>
rishabh-d-dave added a commit to rishabh-d-dave/ceph that referenced this pull request Nov 10, 2021
Class Raw has been moved from teuthology.orchestra.run to
teuthology.orchestra.run_helper. Update Ceph QA code accordingly.

Related PR: ceph/teuthology#1652.

Signed-off-by: Rishabh Dave <[email protected]>
rishabh-d-dave added a commit to rishabh-d-dave/ceph that referenced this pull request Jan 24, 2022
Class Raw has been moved from teuthology.orchestra.run to
teuthology.orchestra.run_helper. Update Ceph QA code accordingly.

Related PR: ceph/teuthology#1652.

Signed-off-by: Rishabh Dave <[email protected]>
@djgalloway djgalloway changed the base branch from master to main June 1, 2022 17:03
rishabh-d-dave added a commit to rishabh-d-dave/ceph that referenced this pull request Nov 29, 2022
Class Raw has been moved from teuthology.orchestra.run to
teuthology.orchestra.run_helper. Update Ceph QA code accordingly.

Related PR: ceph/teuthology#1652.

Signed-off-by: Rishabh Dave <[email protected]>
rishabh-d-dave added a commit to rishabh-d-dave/ceph that referenced this pull request Apr 27, 2023
Class Raw has been moved from teuthology.orchestra.run to
teuthology.orchestra.run_helper. Update Ceph QA code accordingly.

Related PR: ceph/teuthology#1652.

Signed-off-by: Rishabh Dave <[email protected]>
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.

3 participants