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

Fixed the yes/no prompt in verdi computer delete #6624

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

Conversation

Krishnabhujade
Copy link

This PR fixes the "yes/no" prompt in verdi computer delete

Fixes #6422

@agoscinski
Copy link
Contributor

I am sorry for the back and forth but reading now the conversation in issue #6422 more carefully and looking at the deletion in other parts of the code. We can change it to [y/N], this gives us consistency over the CLI which I think is nice. We use click.confirm in other parts of the code for this.

@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from ce1ff59 to ccc2832 Compare November 25, 2024 12:37
@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from 1225c23 to 1f5aea4 Compare November 25, 2024 15:42
@Krishnabhujade
Copy link
Author

I am sorry for the back and forth but reading now the conversation in issue #6422 more carefully and looking at the deletion in other parts of the code. We can change it to [y/N], this gives us consistency over the CLI which I think is nice. We use click.confirm in other parts of the code for this.

Ohk @agoscinski I will do '[y/N]'

@Krishnabhujade
Copy link
Author

@agoscinski
I am facing some problem in setting up the codebase locally

@agoscinski
Copy link
Contributor

No worries I take over. It should now work.

@Krishnabhujade
Copy link
Author

I want to contribute more to organisation so I want to install the codebase locally

@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from 7a9e03d to e3f8bef Compare November 26, 2024 09:15
@agoscinski agoscinski force-pushed the fix/yes/no-prompt-verdi-computer-delete branch from e3f8bef to a33cfb2 Compare November 26, 2024 09:33
@agoscinski
Copy link
Contributor

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.90%. Comparing base (ef60b66) to head (15b82d1).
Report is 146 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6624      +/-   ##
==========================================
+ Coverage   77.51%   77.90%   +0.40%     
==========================================
  Files         560      567       +7     
  Lines       41444    42178     +734     
==========================================
+ Hits        32120    32856     +736     
+ Misses       9324     9322       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

To simplify the testing of 'y' and 'yes' case without rerunning
unecessary database operations the tests for `verdi computer delete`
have been refactored.
@agoscinski agoscinski requested a review from khsrali November 26, 2024 14:40
@Krishnabhujade
Copy link
Author

Thank you sir

Copy link
Contributor

@khsrali khsrali left a comment

Choose a reason for hiding this comment

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

Thanks a lot @Krishnabhujade and @agoscinski ,
Some minor comments

def test_computer_delete_nonexisting_computer(self):
"""Test if `verdi computer delete` command works correctly for a nonexisting computer"""
# See if the command complains about not getting an nonexisting computer
self.cli_runner(computer_delete, ['computer_that_does_not_exist'], raises=True)
Copy link
Contributor

@khsrali khsrali Nov 28, 2024

Choose a reason for hiding this comment

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

Please check explicitly if the raise is due to NotExistent.
Also please pass user_input=y I know here it might not matter because the query comes before click.confirm,
however, later if someone changes the order of the logic in the code then test might silently pass..
Better to be precise.
Thanks

@@ -634,7 +634,7 @@ def _dry_run_callback(pks):
if pks:
echo.echo_report('The nodes with the following pks would be deleted: ' + ' '.join(map(str, pks)))
echo.echo_warning(f'YOU ARE ABOUT TO DELETE {len(pks)} NODES! THIS CANNOT BE UNDONE!')
confirm = click.prompt('Shall I continue? [yes/N]', type=str) == 'yes'
confirm = click.confirm('Shall I continue?', default=False)
if not confirm:
raise click.Abort
return not confirm
Copy link
Contributor

Choose a reason for hiding this comment

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

May I take the chance to improve the message at line 642:
(if there are no nodes, this is a bit annoying saying "0 nodes marked for deletion")

if node_pks: delete_nodes(node_pks, dry_run=dry_run or _dry_run_callback)

orm.Computer.collection.get(label=label)
# Safety check in case of --dry-run
options = [label, '--dry-run']
self.cli_runner(computer_delete, options)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.cli_runner(computer_delete, options)
self.cli_runner(computer_delete, options, user_input="y")

# Setup a computer to delete during the test
label = 'computer_for_test_label'
orm.Computer(
def test_computer_delete_existing_computer(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I found this test name kinda misleading for it's purpose

Suggested change
def test_computer_delete_existing_computer(self):
def test_computer_do_not_delete(self):

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.

More user friendly yes/no prompt in verdi computer delete
3 participants