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

verdi profile delete: Make it storage plugin agnostic #6224

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Dec 13, 2023

Fixes #5515

The verdi profile delete implementation was hardcoded to work only for
the core.psql_dos storage plugin. However, it is possible for profiles
to use different storage plugins, causing the command to except.

The command now forwards to Config.delete_profile. This method gets
the storage plugin defined for the profile and constructs an instance of
it for the given profile. It then calls delete on the storage instance
if the delete_storage argument is set to True.

The new delete method is defined on the StorageBackend abstract base
class. It is intentionally not made abstract, but rather explicitly
raises NotImplementedError. Otherwise existing storage plugins outside
of aiida-core would no longer be instantiable before they implement
the method.

The various options of verdi profile delete to control what parts of
the storage are deleted, are simplified to just a single switch that
controls whether the storage is deleted or not.

The command now also properly detects if the delete profile was the
default, in which case another profile is marked as the new default if
any profiles remain at all.

@sphuber sphuber requested a review from mbercx December 13, 2023 10:01
@sphuber
Copy link
Contributor Author

sphuber commented Dec 13, 2023

This one is dedicated to Mr. ScopeCreep
Mr  ScopeCreep

@sphuber
Copy link
Contributor Author

sphuber commented Dec 13, 2023

@mbercx this is ready for review now

Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

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

Thanks @sphuber! I tried my best to break the command, but could only find a few nitpicks and comments.

aiida/cmdline/commands/cmd_profile.py Show resolved Hide resolved
aiida/cmdline/commands/cmd_profile.py Show resolved Hide resolved
aiida/cmdline/commands/cmd_profile.py Outdated Show resolved Hide resolved
aiida/cmdline/commands/cmd_profile.py Outdated Show resolved Hide resolved
@sphuber sphuber force-pushed the fix/verdi-profile-delete branch from ac90d8f to 891072f Compare December 13, 2023 20:58
@sphuber sphuber requested a review from mbercx December 13, 2023 20:59
@sphuber sphuber force-pushed the fix/verdi-profile-delete branch from 891072f to 6b408f7 Compare December 13, 2023 21:43
@sphuber
Copy link
Contributor Author

sphuber commented Dec 14, 2023

@mbercx I pushed a commit with some further improvements

  • The without or including storage deletion message is now in bold red.
  • Following my own adage of putting all functionality in the API and have verdi be a thin wrapper: I moved the logic for setting the new default inside Config.delete_profile. The only downside is that when the user deletes multiple profiles at once using verdi profile delete that the default may get reassigned multiple times. But I think that is acceptable.
  • The Config.delete_profile now prints the storage config, whether the storage is deleted or not. Ideally it was the storage plugin do it themselves, since they know which config attributes are most important and they can format the logger message in the optimal way, but their delete method won't be called if the storage is not deleted, and it is exactly in this case that we want the old configuration to be printed for the user. So I don't see a better solution for now. The upside is that this way, the config is always printed, whereas if we leave it up to the plugin, they could forget to implement this.

@mbercx
Copy link
Member

mbercx commented Dec 14, 2023

Thanks @sphuber, love the changes. After a discussion with @giovannipizzi, we're still not sure if it's a good idea to change the default behaviour, since:

  1. This will technically be a backwards-incompatible change.
  2. Even with all the reporting, it's still tedious to clean up a storage after a profile has been deleted in case the user doesn't know how, and could potentially collect a bunch of Postgres databases and then have no idea which one corresponds to which.

Some thoughts to still consider (maybe discuss at the AiiDA meeting today):

  1. Can we make the default storage-dependent? I.e. in case of psql_dos the default is true, for sqlite_zip the default is false, but if the user specifies '--delete-storage/--no-delete-storage' that overrides the default.
  2. Would it make sense to keep track of the storage configuration of all deleted profiles somewhere, e.g. in a YAML file called deleted_profiles.yaml in the $AIIDA_PATH/.aiida directory.
  3. Alternatively/Additionally, we make the default to delete the storage, but a sqlite_zip storage makes a copy of the archive and stores it in a similar location as the sqlite_dos.

@sphuber sphuber force-pushed the fix/verdi-profile-delete branch from 1b41d8d to 7a62650 Compare December 14, 2023 14:52
@sphuber sphuber requested a review from mbercx December 14, 2023 14:53

if not force and not click.confirm('are you sure you want to continue?'):
echo.echo_report(f'deleting of `{profile.name} cancelled.')
echo.echo_warning('This operation cannot be undone, are you sure you want to continue?', nl=False)
Copy link
Member

Choose a reason for hiding this comment

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

This prompt should only appear when the force flag is not used, right?

❯ verdi profile delete tmp -f --delete-data
Warning: Deleting profile `tmp`, including all data.
Warning: This operation cannot be undone, are you sure you want to continue?Report: Deleted storage directory at `/Users/mbercx/project/core/.aiida/repository/sqlite_dos_5b7189522ae34118b151f65f618d150c`.
Report: Data storage deleted, configuration was: {'filepath': '/Users/mbercx/project/core/.aiida/repository/sqlite_dos_5b7189522ae34118b151f65f618d150c'}
Warning: `tmp` was the default profile, no profiles remain to set as default.
Success: Profile `tmp` was deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Damn, my desire to have prompts prefixed with the nice Warning: strikes again...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. By the way, I changed the flags to --delete-data/--keep-data because I think that is going to be more clear for most users, rather than "storage" which is kind of vague. You agree?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I like it better! 👍

The `verdi profile delete` implementation was hardcoded to work only for
the `core.psql_dos` storage plugin. However, it is possible for profiles
to use different storage plugins, causing the command to except.

The command now forwards to `Config.delete_profile`. This method gets
the storage plugin defined for the profile and constructs an instance of
it for the given profile. It then calls `delete` on the storage instance
if the `delete_storage` argument is set to `True`.

The new `delete` method is defined on the `StorageBackend` abstract base
class. It is intentionally not made abstract, but rather explicitly
raises `NotImplementedError`. Otherwise existing storage plugins outside
of `aiida-core` would no longer be instantiable before they implement
the method.

The various options of `verdi profile delete` to control what parts of
the storage are deleted, are simplified to just a single switch that
controls whether the storage is deleted or not. The switch is not
defined at all by default. The user will have to explicitly select
either `--delete-data` or `--keep-data`, or they will be prompted what
value to choose. If the `--force` flag is specified and no explicit flag
to delete or keep the data, the command raises.

The command now also properly detects if the delete profile was the
default, in which case another profile is marked as the new default if
any profiles remain at all.
@sphuber sphuber force-pushed the fix/verdi-profile-delete branch from 7a62650 to eda96be Compare December 14, 2023 16:00
Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

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

Mr. Scope Creep is pleased. 😄

@sphuber sphuber merged commit 5015f5f into aiidateam:main Dec 14, 2023
19 checks passed
@sphuber sphuber deleted the fix/verdi-profile-delete branch December 14, 2023 16:29
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.

Config.delete_profile is leaking implementation details of PsqlDosBackend
2 participants